Beispiel #1
0
 public Game(int id, PlayerContract player1, bool isPrivate)
 {
     GameId     = id;
     Player1    = player1;
     IsPrivate  = isPrivate;
     player1Box = new BlockState[10, 10];
     player2Box = new BlockState[10, 10];
     Start      = DateTime.Now;
     Moves      = new List <Move>();
 }
Beispiel #2
0
 public Game JoinGame(PlayerContract player, int gameId)
 {
     if (!games.ContainsKey(gameId))
     {
         return(null);
     }
     else
     {
         games[gameId].Player2 = player;
         return(games[gameId]);
     }
 }
Beispiel #3
0
        public Game StartGame(PlayerContract player1, bool isPrivate = false)
        {
            int gameId = gameIdGenerator.Next();

            while (games.ContainsKey(gameId) || gameId == 0)
            {
                gameId = gameIdGenerator.Next();
            }
            Game g = new Game(gameId, player1, isPrivate);

            games.Add(gameId, g);
            return(g);
        }
Beispiel #4
0
        public Game FindGame(PlayerContract player)
        {
            //try find free game
            int found = games.Where(kp =>
                                    kp.Value.Player2 == null &&
                                    kp.Value.Player1.PlayerId != player.PlayerId &&
                                    !kp.Value.IsPrivate).Select(kp => kp.Key).FirstOrDefault();

            if (found != 0)
            {
                games[found].Player2 = player;
                return(games[found]);
            }
            else
            {
                return(StartGame(player));
            }
        }