public Player GetOpponent(Player player, Game game) { if (game.Player1.Id == player.Id) { return game.Player2; } return game.Player1; }
public Game CreateGame(Player player1, Player player2) { var game = new Game() { Player1 = player1, Player2 = player2, Board = new Board() }; var group = Guid.NewGuid().ToString("d"); games[group] = game; player1.IsPlaying = true; player1.Group = group; player2.IsPlaying = true; player2.Group = group; Groups.Add(player1.ConnectionId, group); Groups.Add(player2.ConnectionId, group); return game; }
private Card FindCard(Game game, string cardName) { return game.Board.Pieces.FirstOrDefault(c => c.Name == cardName); }
private bool IsMatch(Game game, Card card) { if (card == null) return false; if (game.LastCard != null) { if (game.LastCard.Pair == card.Id) { return true; } return false; } return false; }
public void ResetGame(Game game) { var groupName = game.Player1.Group; var player1Name = game.Player1.Name; var player2Name = game.Player2.Name; Groups.Remove(game.Player1.ConnectionId, groupName); Groups.Remove(game.Player2.ConnectionId, groupName); Player p1; players.TryRemove(player1Name, out p1); Player p2; players.TryRemove(player2Name, out p2); Game g; games.TryRemove(groupName, out g); }