Adds basic server types

arun
Abhinav Sarkar 2015-07-08 19:37:55 +05:30
parent ce2413db34
commit 169c3b44dc
4 changed files with 73 additions and 8 deletions

View File

@ -1,15 +1,15 @@
-- Initial hastron.cabal generated by cabal init. For further
-- Initial hastron.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
name: hastron
version: 0.1.0.0
-- synopsis:
-- description:
-- synopsis:
-- description:
license: MIT
license-file: LICENSE
author: Abhinav Sarkar
maintainer: abhinav@abhinavsarkar.net
-- copyright:
-- copyright:
category: Game
build-type: Simple
extra-source-files: README.md
@ -17,8 +17,11 @@ cabal-version: >=1.10
executable hastron
main-is: Main.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.7 && <4.8
other-modules: Hastron.Server.Types
-- other-extensions:
build-depends: base >=4.7 && <4.9,
text >=1.2 && <1.3,
unordered-containers >=0.2.5 && <0.3,
hashable >=1.2 && <1.3
hs-source-dirs: src
default-language: Haskell2010
default-language: Haskell2010

View File

@ -0,0 +1,56 @@
{-# LANGUAGE DeriveGeneric #-}
module Hastron.Server.Types where
import Data.Hashable (Hashable)
import Data.HashMap.Strict (HashMap)
-- import qualified Data.HashMap.Strict as Map
import qualified Data.Text as T
import GHC.Generics
type Point = (Int, Int)
type Velocity = (Double, Double)
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)
data Room = Room { roomGames :: [Game]
, roomUsers :: HashMap User RoomUserState
} deriving (Show, Eq)
data ServerState = ServerState { serverName :: T.Text
, serverUsers :: [User]
, serverRooms :: [Room]
} deriving (Show, Eq)

0
src/Hastron/Types.hs Normal file
View File

6
src/Main.hs Normal file
View File

@ -0,0 +1,6 @@
module Main where
import Hastron.Server.Types
main :: IO()
main = putStrLn "Hello World"