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; } } }
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); }
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); }