/// <summary> /// Only for tests /// </summary> public Player(int id, Guid guid, TeamColor team, PlayerType preferredRole, PlayerBoard board, Location location) { Id = id; Team = team; Role = preferredRole; PlayerGuid = guid; GameId = 0; PlayerBoard = board; PlayerBoard.Players[id] = new PlayerInfo(id, team, preferredRole, location); _stateCoordinator = new StateCoordinator("", team, preferredRole); }
public void InitializePlayer(int id, Guid guid, TeamColor team, PlayerType role, PlayerBoard board, Location location, LoggingMode loggingMode) { var factory = new LoggerFactory(); VerboseLogger = new VerboseLogger(factory.GetPlayerLogger(id), loggingMode); Id = id; Team = team; Role = role; PlayerGuid = guid; GameId = 0; PlayerBoard = board; PlayerBoard.Players[id] = new PlayerInfo(id, team, role, location); _stateCoordinator = new StateCoordinator("", team, role); }
public GameArea.GameObjects.Field GetFieldFromDirection(MoveType direction) { switch (direction) { case MoveType.left: return(PlayerBoard.GetField(Location.X - 1, Location.Y)); case MoveType.right: return(PlayerBoard.GetField(Location.X + 1, Location.Y)); case MoveType.up: return(PlayerBoard.GetField(Location.X, Location.Y + 1)); case MoveType.down: return(PlayerBoard.GetField(Location.X, Location.Y - 1)); } return(null); }
public void InitializeGameData(Location playerLocation, BoardInfo board, IEnumerable <PlayerBase> players) { PlayerBoard = new PlayerBoard(board.Width, board.TasksHeight, board.GoalsHeight); var playerBases = players.ToList(); foreach (var playerBase in playerBases) { PlayerBoard.Players.Add(playerBase.Id, new PlayerInfo(playerBase)); } PlayerBoard.Players[Id].Location = playerLocation; var playerStrategy = _strategyGroups[PlayerBoard.Players[Id].Team].GetStrategyFor(this, PlayerBoard, PlayerGuid, GameId, playerBases); Console.WriteLine($"Player has chosen {playerStrategy.GetType().Name} from {_strategyGroups[PlayerBoard.Players[Id].Team].GetType().Name}"); _stateCoordinator.UpdatePlayerStrategyBeginningState(playerStrategy.GetBeginningState()); _stateCoordinator.CurrentState = playerStrategy.GetBeginningState(); _gameStarted = true; }
public bool UpdateLocalBoard(DataMessage responseMessage) { bool updated = false; gameFinished = gameFinished || responseMessage.GameFinished; var playerId = responseMessage.PlayerId; if (playerId == this.ID && !gameFinished) { GetBoard.UpdateGoalFields(responseMessage.Goals); GetBoard.UpdateTaskFields(responseMessage.Tasks); GetBoard.UpdatePieces(responseMessage.Pieces); if (responseMessage.Pieces != null && responseMessage.Pieces.Length == 1) { var piece = responseMessage.Pieces[0]; if (piece != null) { if (GetPiece == null) // Player picks up piece { this.SetPiece(piece); GetBoard.GetTaskField(Location).Piece = null; } else if (GetPiece.ID == piece.ID && piece.Type != PieceType.destroyed) // Player tests piece { this.SetPiece(piece); } else if (GetPiece.ID == piece.ID && piece.Type == PieceType.destroyed) // Player tests piece { this.SetPiece(null); } } } if (responseMessage.Tasks != null && responseMessage.Tasks.Length == 1) { var field = responseMessage.Tasks[0]; if (field != null && GetPiece != null) { if (field.Piece != null && field.X == Location.X && field.Y == Location.Y && field.Piece.ID == GetPiece.ID) // player put down a piece { SetPiece(null); } } } if (responseMessage.Goals != null && responseMessage.Goals.Length == 1) { var field = responseMessage.Goals[0]; if (field.X == Location.X && field.Y == Location.Y) { if (field.Type == GoalFieldType.goal) //tylko wtedy ustawia się null { SetPiece(null); } //zawsze aktualizacja timestamp, bo jak już raz był na danym polu typu goal, to ma już do niego nie wracać var goalPlayer = PlayerBoard.GetGoalField(Location.X, Location.Y); goalPlayer.TimeStamp = DateTime.Now.AddYears(100); goalPlayer.Type = field.Type == GoalFieldType.goal ? GoalFieldType.goal : GoalFieldType.nongoal; } } if (responseMessage.PlayerLocation != null) { SetLocation(responseMessage.PlayerLocation.X, responseMessage.PlayerLocation.Y); } updated = true; } else if (gameFinished) { //wypisywnaie planszy po otryzmaniu Data, wymóg specyfikacji Console.WriteLine("!!!ACHTUNG!!!\nReceived DATA MESSAGE from GameMaster with GameFinished == true. PlayerId/ClientId:" + ID + "\nGUID: " + GUID); State = AgentState.SearchingForGame; PrintBoardState(); } ActionToComplete = ActionType.none; return(updated); }
public MoveType GetClosestUnknownGoalDirection() { return(new GoalDirectionInfo(PlayerBoard.GoalFields(Team), Team, Location).GetClosestDirection()); }