evac/Connect.hs

53 lines
2.3 KiB
Haskell
Raw Normal View History

2019-05-19 00:55:53 -04:00
module Connect where
import Types
2019-05-19 02:11:40 -04:00
import Groups
2019-05-19 00:55:53 -04:00
-- Passes state for X to hurt Y
conHurt :: MainCharacter -> MainCharacter -> BoardState -> BoardState
2019-05-19 02:11:40 -04:00
conHurt charX charY oldBoardState
| not $ isAdjacent charX charY oldGroups = oldBoardState
2019-05-19 00:55:53 -04:00
{ bsGameLog = (bsGameLog oldBoardState)
2019-05-19 02:11:40 -04:00
++ [ Right (show charX ++ " is not adjacent to " ++ show charY ++ ", could not hurt") ]
2019-05-19 00:55:53 -04:00
}
| isAlone charX oldGroups = oldBoardState
{ bsGameLog = (bsGameLog oldBoardState)
2019-05-19 02:11:40 -04:00
++ [ Left (show charX ++ " hurt " ++ show charY ++ ", " ++ show charY ++ " is downed") ]
2019-05-19 00:55:53 -04:00
, bsNeoTokyo = (bsNeoTokyo oldBoardState)
2019-05-19 02:11:40 -04:00
{ ntPutCards = filter (\x -> ((fst x) /= Left charX)) oldPut
, ntDowned = downChar charY oldDowned
2019-05-19 00:55:53 -04:00
}
2019-05-19 02:11:40 -04:00
}
| otherwise = oldBoardState
2019-05-19 00:55:53 -04:00
{ bsGameLog = (bsGameLog oldBoardState)
2019-05-19 02:11:40 -04:00
++ [ Left (show charX ++ " hurt " ++ show charY ++ ", " ++ show charY ++ " left their group") ]
2019-05-19 00:55:53 -04:00
, bsNeoTokyo = (bsNeoTokyo oldBoardState)
{ ntGroups = removeFromGroup charY oldGroups }
}
where
2019-05-19 02:11:40 -04:00
oldDowned = (ntDowned . bsNeoTokyo) oldBoardState
oldGroups = (ntGroups . bsNeoTokyo) oldBoardState
oldPut = (ntPutCards . bsNeoTokyo) oldBoardState
conAttract :: MainCharacter -> MainCharacter -> BoardState -> BoardState
conAttract charX charY oldBoardState
| not $ isAdjacent charX charY oldGroups = oldBoardState
{ bsGameLog = (bsGameLog oldBoardState)
++ [ Right (show charX ++ " is not adjacent to " ++ show charY ++ ", could not attract") ]
}
| isAlone charX oldGroups = oldBoardState
{ bsGameLog = (bsGameLog oldBoardState)
++ [ Left (show charX ++ " attracted " ++ show charY ++ ", " ++ show charY ++ " is ready") ]
, bsNeoTokyo = (bsNeoTokyo oldBoardState)
{ ntDowned = readyChar charY oldDowned }
}
| otherwise = oldBoardState
{ bsGameLog = (bsGameLog oldBoardState)
++ [ Left (show charX ++ " attracted " ++ show charY ++ ", " ++ show charY ++ "'s group joined " ++ show charX ++ "'s group") ]
, bsNeoTokyo = (bsNeoTokyo oldBoardState)
{ ntGroups = joinGroups charX charY oldGroups }
}
where
oldDowned = (ntDowned . bsNeoTokyo) oldBoardState
oldGroups = (ntGroups . bsNeoTokyo) oldBoardState