Make Hannah pay attention who it plays against and watch when they log out
This commit is contained in:
parent
70584add93
commit
0c7e4c8b50
1 changed files with 8 additions and 2 deletions
|
@ -33,6 +33,7 @@ data State =
|
||||||
| Playing {
|
| Playing {
|
||||||
key :: PlayerKey
|
key :: PlayerKey
|
||||||
, name :: Text
|
, name :: Text
|
||||||
|
, against :: PlayerKey
|
||||||
}
|
}
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
|
@ -68,9 +69,9 @@ answer welcome@(Message.Welcome {}) Initial = do
|
||||||
answer (Message.Relay {Message.from, Message.message = Message.LogIn {Message.name}}) (Connected {key})
|
answer (Message.Relay {Message.from, Message.message = Message.LogIn {Message.name}}) (Connected {key})
|
||||||
| from == key = return $ LoggedIn {key, name}
|
| from == key = return $ LoggedIn {key, name}
|
||||||
|
|
||||||
answer (Message.Relay {Message.message = Message.Invitation {}}) (LoggedIn {key, name}) = do
|
answer (Message.Relay {Message.from, Message.message = Message.Invitation {}}) (LoggedIn {key, name}) = do
|
||||||
send $ Message.Answer {Message.accept = True}
|
send $ Message.Answer {Message.accept = True}
|
||||||
return $ Playing {key, name}
|
return $ Playing {key, name, against = from}
|
||||||
|
|
||||||
answer (Message.Relay {Message.message = Message.Invitation {}}) state = do
|
answer (Message.Relay {Message.message = Message.Invitation {}}) state = do
|
||||||
send $ Message.Answer {Message.accept = False}
|
send $ Message.Answer {Message.accept = False}
|
||||||
|
@ -84,6 +85,11 @@ answer (Message.Game {Message.game, Message.logs}) state@(Playing {key, name}) =
|
||||||
_ -> send (Message.Play {Message.move = AI.move key game}) >> return state
|
_ -> send (Message.Play {Message.move = AI.move key game}) >> return state
|
||||||
else return state
|
else return state
|
||||||
|
|
||||||
|
answer (Message.Relay {Message.from, Message.message = Message.LogOut}) (Playing {key, name, against})
|
||||||
|
| from == against = send Message.Quit >> return (LoggedIn {key, name})
|
||||||
|
|
||||||
|
answer (Message.Relay {}) state = return state
|
||||||
|
|
||||||
answer Message.Pong state = ping >> return state
|
answer Message.Pong state = ping >> return state
|
||||||
|
|
||||||
answer (Message.Error {Message.error}) state = do
|
answer (Message.Error {Message.error}) state = do
|
||||||
|
|
Loading…
Reference in a new issue