Exemplo n.º 1
0
        public Game CreateGame(Player player1, Player player2)
        {
            Game game = new Game
            {
                Player1 = player1,
                Player2 = player2,
                Board = new GameBoard()
            };

            string group = Guid.NewGuid().ToString("d");
            _games[group] = game;

            player1.isPlaying = true;
            player2.isPlaying = true;
            player1.Symbol = "RedSymbol";
            player2.Symbol = "BlueSymbol";
            player1.Group = group;
            player2.Group = group;

            Groups.Add(player1.Id, group);
            Groups.Add(player2.Id, group);

            return game;
        }
Exemplo n.º 2
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.Id, groupName);
            Groups.Remove(game.Player2.Id, groupName);

            Player p1, p2;
            _players.TryRemove(player1Name, out p1);
            _players.TryRemove(player2Name, out p2);

            Game g;
            _games.TryRemove(groupName, out g);
        }
Exemplo n.º 3
0
 public Player GetOpponent(Game game, Player player)
 {
     return (game.Player1.Id == player.Id) ? game.Player2 : game.Player1;
 }