Add a Game type

The game engine can now be filled in.
arun
Abhinav Sarkar 2015-07-08 20:41:37 +05:30
parent 7b6377728d
commit e530f3aa68
3 changed files with 66 additions and 31 deletions

View File

@ -0,0 +1,8 @@
module Hastron.Game.Engine where
import Hastron.Game.Types
type GameStep = Game -> InEvent -> (Game, [OutEvent])
stepGame :: GameStep
stepGame game inEvent = undefined

57
src/Hastron/Game/Types.hs Normal file
View File

@ -0,0 +1,57 @@
module Hastron.Game.Types where
import Data.HashMap.Strict (HashMap)
type Point = (Int, Int)
data Direction = Left | Right | Up | Down deriving (Show, Eq, Ord, Enum)
data Velocity = Velocity Double Direction deriving (Show, Eq, Ord)
type PlayerId = Int
data PlayerState = PlayerAlive
| PlayerDead
| PlayerDisconnected
| PlayerLeft
deriving (Show, Eq, Ord, Enum)
type PlayerTrail = [Point]
data PlayerBoost = PlayerBoost { boostActive :: Bool
, boostFuel :: Double
} deriving (Show, Eq)
type PlayerScore = Int
data Player = Player { playerId :: PlayerId
, playerState :: PlayerState
, playerPosition :: Point
, playerVelocity :: Velocity
, playerTrail :: PlayerTrail
, playerBoost :: PlayerBoost
, playerScore :: PlayerScore
} deriving (Show, Eq)
data PlayerEndState = PlayerWinner | PlayerLoser | PlayerDropped
deriving (Show, Eq, Ord, Enum)
data GameState = GameStarted | GameInit | GameFinished
deriving (Show, Eq, Ord, Enum)
data Game = Game { gamePlayers :: [Player]
, gameState :: GameState
} deriving (Show, Eq)
data InEvent = InPlayerTurnLeft PlayerId
| InPlayerTurnRight PlayerId
| InPlayerBoostActivate PlayerId
| InPlayerBoostDeactivate PlayerId
| InPlayerStateChange PlayerId PlayerState
deriving (Show, Eq, Ord)
data OutEvent = OutPlayerPosition PlayerId Point Direction
| OutPlayerStateChange PlayerId PlayerState Point
| OutGameStateChange GameState
| OutGameOver (HashMap PlayerId (PlayerScore, PlayerEndState))
deriving (Show, Eq)

View File

@ -7,42 +7,12 @@ import Data.HashMap.Strict (HashMap)
import qualified Data.Text as T
import GHC.Generics
type Point = (Int, Int)
type Velocity = (Double, Double)
import Hastron.Game.Types
data User = User { userName :: T.Text
} deriving (Show, Eq, Ord, Generic)
instance Hashable User
data PlayerState = PlayerAlive | PlayerDead | PlayerDisconnected
deriving (Show, Eq, Ord, Enum)
type PlayerTrail = [Point]
data PlayerBoost = PlayerBoost { boostActive :: Bool
, boostFuel :: Double
} deriving (Show, Eq)
type PlayerScore = Int
data Player = Player { playerUser :: User
, playerState :: PlayerState
, playerPosition :: Point
, playerVelocity :: Velocity
, playerTrail :: PlayerTrail
, playerBoost :: PlayerBoost
, playerScore :: PlayerScore
} deriving (Show, Eq)
data GameState = GameStarted | GamePaused | GameStarting | GameFinished
deriving (Show, Eq, Ord, Enum)
data Game = Game { gamePlayers :: [Player]
, gameState :: GameState
} deriving (Show, Eq)
data RoomUserState = RoomUserJoined | RoomUserReady | RoomUserPlaying
deriving (Show, Eq)