diff --git a/src/Hastron/Game/Engine.hs b/src/Hastron/Game/Engine.hs new file mode 100644 index 0000000..83942d0 --- /dev/null +++ b/src/Hastron/Game/Engine.hs @@ -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 diff --git a/src/Hastron/Game/Types.hs b/src/Hastron/Game/Types.hs new file mode 100644 index 0000000..2bbde81 --- /dev/null +++ b/src/Hastron/Game/Types.hs @@ -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) diff --git a/src/Hastron/Server/Types.hs b/src/Hastron/Server/Types.hs index caeca8f..7c60b7d 100644 --- a/src/Hastron/Server/Types.hs +++ b/src/Hastron/Server/Types.hs @@ -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)