diff --git a/computerchoice.bmp b/computerchoice.bmp new file mode 100644 index 0000000..dac36b2 Binary files /dev/null and b/computerchoice.bmp differ diff --git a/iconPaper.bmp b/iconPaper.bmp new file mode 100644 index 0000000..3290123 Binary files /dev/null and b/iconPaper.bmp differ diff --git a/iconRock.bmp b/iconRock.bmp new file mode 100644 index 0000000..ba9de38 Binary files /dev/null and b/iconRock.bmp differ diff --git a/iconScissors.bmp b/iconScissors.bmp new file mode 100644 index 0000000..20bf991 Binary files /dev/null and b/iconScissors.bmp differ diff --git a/logic.exe b/logic.exe new file mode 100644 index 0000000..eb1db24 Binary files /dev/null and b/logic.exe differ diff --git a/logic.hs b/logic.hs new file mode 100644 index 0000000..e0d929f --- /dev/null +++ b/logic.hs @@ -0,0 +1,84 @@ +import qualified Graphics.Gloss.Interface.Pure.Game as Gloss +import qualified Graphics.Gloss.Data.Bitmap as Bitmap +import qualified Data.Map as Map +import Data.List +import Data.Maybe +import System.Random (randomRIO) + +data Move = Paper | Rock | Scissors | Tie deriving (Eq, Ord, Show) +--data Result = Computer | Human | Tie deriving (Eq, Ord, Show) + +data Game = Game { + human :: Maybe Move, + computer :: Move, + humanScore :: Int, + computerScore :: Int +} + +beats :: Move -> Move +beats move = case move of + Paper -> Scissors + Rock -> Paper + Scissors -> Rock + + +score :: Move -> Move -> Move +score this_move other_move + | this_move == beats other_move = this_move + | this_move == other_move = Tie + | otherwise = other_move + +score' (Game h@(Just this_move) other_move hs cs) + | this_move == beats other_move = this_move + | this_move == other_move = Tie + | otherwise = other_move + +updateScore (Game h@(Just this_move) other_move hs cs) + | this_move == beats other_move = Game h other_move (hs+1) cs + | this_move == other_move = Game h other_move hs cs + | otherwise = Game h other_move hs (cs+1) + +--Define a random choice +pick :: [a] -> IO a +pick xs = randomRIO (0, length xs -1 ) >>= return . (xs !!) + +whatdoescomputersay = pick [Rock, Paper, Scissors] + +handleEvent (Gloss.EventKey (Gloss.Char keypress) Gloss.Down _ (_, _)) game@(Game h c hs cs) + | keypress == 'p' = updateScore (Game (Just Paper) c hs cs) + | keypress == 'r' = updateScore (Game (Just Rock) c hs cs) + | keypress == 's' = updateScore (Game (Just Scissors) c hs cs) + | otherwise = Game (Nothing) c hs cs + +handleEvent _ game = game + +main = do + let possibleMoves = [Paper, Rock, Scissors] + computer <- pick possibleMoves + + rockwin <- Bitmap.loadBMP "rockwins.bmp" + paperwin <- Bitmap.loadBMP "paperwins.bmp" + scissorswin <- Bitmap.loadBMP "scissorswin.bmp" + tie <- Bitmap.loadBMP "tie.bmp" + rockPicture <- Bitmap.loadBMP "iconRock.bmp" + scissorsPicture <- Bitmap.loadBMP "iconScissors.bmp" + paperPicture <- Bitmap.loadBMP "iconPaper.bmp" + yourchoice <- Bitmap.loadBMP "yourchoice.bmp" + computerchoice <- Bitmap.loadBMP "computerchoice.bmp" + + let userUI = Map.fromList [(Paper, paperPicture), (Scissors, scissorsPicture), (Rock, rockPicture)] + let results = Map.fromList [(Rock, rockwin), (Paper, paperwin), (Scissors, scissorswin), (Tie, tie)] + let all_pictures = [(Gloss.translate (-275) 0 rockPicture), (Gloss.translate 0 0 paperPicture), (Gloss.Translate 275 0 scissorsPicture)] + + let display game@(Game human computer humanScore computerScore) = if human == Nothing then Gloss.Pictures ([Gloss.Translate (-550) (300) (Gloss.Color Gloss.white (Gloss.Text "Press p, r, or s!"))]++all_pictures) else Gloss.Pictures [results Map.! (score' game), Gloss.Translate (-500) 0 (userUI Map.! fromJust (human)), Gloss.Translate 500 0 (userUI Map.! computer), Gloss.Translate (-500) 250 yourchoice, Gloss.Translate 500 250 computerchoice] + + let initialGame = Game (Nothing) computer 0 0 + + Gloss.play + (Gloss.InWindow "Rock Paper Scissors" (1920,1080) (0,0)) + Gloss.black --background color + 10 + initialGame + display + handleEvent + (\f g -> g) diff --git a/paperwins.bmp b/paperwins.bmp new file mode 100644 index 0000000..79a4eba Binary files /dev/null and b/paperwins.bmp differ diff --git a/rockwins.bmp b/rockwins.bmp new file mode 100644 index 0000000..5bb4c89 Binary files /dev/null and b/rockwins.bmp differ diff --git a/scissorswin.bmp b/scissorswin.bmp new file mode 100644 index 0000000..6f0e44a Binary files /dev/null and b/scissorswin.bmp differ diff --git a/tie.bmp b/tie.bmp index 54ae2fe..44c56fb 100644 Binary files a/tie.bmp and b/tie.bmp differ diff --git a/yourchoice.bmp b/yourchoice.bmp new file mode 100644 index 0000000..0344c3c Binary files /dev/null and b/yourchoice.bmp differ