Last active
July 11, 2022 20:29
-
-
Save n1ckdm/72696bebca26642e8650e1959e135a40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Game Apply(Game game, IEvent evt) | |
{ | |
switch (evt) | |
{ | |
case GameCreatedEvent e: | |
return new Game | |
{ | |
State = EState.Created, | |
Player = e.PlayerEmail, | |
}; | |
case MoveDecidedEvent e: | |
if (game.State == EState.Created) | |
{ | |
return new Game | |
{ | |
State = EState.Waiting, | |
Player = e.PlayerEmail, | |
Move = e.Move, | |
}; | |
} else | |
{ | |
return game; | |
} | |
case GameWonEvent e: | |
return new Game | |
{ | |
State = EState.Won, | |
Player = game.Player, | |
Move = game.Move, | |
}; | |
case GameTiedEvent e: | |
return new Game | |
{ | |
State = EState.Tied, | |
Player = game.Player, | |
Move = game.Move, | |
}; | |
default: | |
throw new InvalidOperationException($"Unknown event: {evt}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment