Exemple #1
0
        public void UpdatePlayerState(string playerId, IPlayerGameStateUpdate state)
        {
            TronPlayer player = (TronPlayer)this.players.FirstOrDefault(item => item.ID == playerId);

            if (player != null)
            {
                if (this.ValidateDirection(player.CurrentDirection, ((TronPlayerStateUpdate)state).Direction))
                {
                    player.CurrentDirection = ((TronPlayerStateUpdate)state).Direction;
                }
            }
        }
Exemple #2
0
 private bool HasPlayerHitAWall(TronPlayer player)
 {
     //out of boundary Y
     if (player.CurrentPositionY < 0 || player.CurrentPositionY >= this.settings.TronBoardSizeY)
     {
         return(true);
     }
     //out of boundary X
     if (player.CurrentPositionX < 0 || player.CurrentPositionX >= this.settings.TronBoardSizeX)
     {
         return(true);
     }
     //Hit player wall
     if (this.board[player.CurrentPositionY, player.CurrentPositionX] == 1)
     {
         return(true);
     }
     return(false);
 }
Exemple #3
0
        public IGameDataForPlayer AddPlayer(string player)
        {
            TronGameDataForPlayer data = new TronGameDataForPlayer();

            if (players.Count < this.options.NumberOfPlayers)
            {
                TronPlayer tronPlayer = new TronPlayer();
                tronPlayer.Name          = player;
                tronPlayer.ID            = Guid.NewGuid().ToString().Replace("-", "");
                tronPlayer.IsPlayerAlive = true;
                this.players.Add(tronPlayer);
                data.PlayerID        = tronPlayer.ID;
                data.BoardSizeX      = this.settings.TronBoardSizeX;
                data.BoardSizeY      = this.settings.TronBoardSizeY;
                data.NumberOfPlayers = this.options.NumberOfPlayers;
                data.PlayerState     = AddPlayerState.PlayerAdded;
                return(data);
            }
            data.PlayerState = AddPlayerState.GameIsFull;
            return(data);
        }