Created
April 14, 2020 18:50
-
-
Save Raagh/41433431aaac709de1aff0d462dbe51c to your computer and use it in GitHub Desktop.
Functional snake game - Part 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Core where | |
type Columns = Int | |
type Rows = Int | |
type Point = (Rows, Columns) | |
type Apple = Point | |
type Snake = [Point] | |
type Moves = [Move] | |
data Move = North | South | West | East deriving (Show) | |
data State = State { | |
apple :: Apple, | |
snake :: Snake, | |
moves :: Moves | |
} deriving (Show) | |
initialSnake :: Snake | |
initialSnake = [(1,1)] | |
initialApple :: Apple | |
initialApple = (5,5) | |
initialState :: State | |
initialState = State initialApple initialSnake [North] | |
move :: State -> Move -> State | |
move s m = State (apple s) (snake s) [North] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment