-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLetsPlay.hs
30 lines (28 loc) · 1.13 KB
/
LetsPlay.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import Data.Strings (strEndsWith, strSplit)
import System.Process (callCommand)
import System.Environment (getArgs)
runmars :: String -> String -> String
runmars name marsDir = "java -jar " ++ marsDir ++ " output/" ++ name ++ ".asm"
main :: IO ()
main = do
args <- getArgs
let
(name, marsDir) =
case length args of
0 -> error "TOO BAD! No .game to play :("
1 -> error "TOO BAD! No path for Mars .jar file. T.T"
2 ->
let
mars = head args
file = args !! 1
in
if strEndsWith file ".game" then
(fst $ strSplit ".game" file, mars)
else
error "Wait a minute, are you sure this is a .game to play?"
_ ->
error "AMAZING, you can play more than just one .game at the same time, but I can not, try just one .game"
callCommand $ "stack run " ++ name ++ ".game"
-- callCommand $ "find Mars"
callCommand $ runmars (snd $ strSplit "/" name) marsDir
putStrLn $ "Thank you for playing '" ++ name ++ "' with us! Come back soon!"