예제 #1
0
 public Player GetOpponent(Player player, Game game)
 {
     if (game.Player1.Id == player.Id)
     {
         return game.Player2;
     }
     return game.Player1;
 }
예제 #2
0
        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;
        }
예제 #3
0
 private Card FindCard(Game game, string cardName)
 {
     return game.Board.Pieces.FirstOrDefault(c => c.Name == cardName);
 }
예제 #4
0
        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;
        }
예제 #5
0
        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);
        }