public void HandleMessage(Common.Schema.Game message) { Player.game.Players = message.Players; Player.game.Board = message.Board; Player.game.Location = message.PlayerLocation; Player.game.Fields = new Common.SchemaWrapper.Field[message.Board.width, 2 * message.Board.goalsHeight + message.Board.tasksHeight]; ConsoleDebug.Good("Game started"); Player.ReadyForAction?.Invoke(); }
public void HandleMessage_Game() { PlayerClient player = new PlayerClient(new ConnectionMock(), new Common.Config.PlayerSettings(), new AgentCommandLineOptions(), new Player.Net.Game()); Common.Schema.Game game = new Common.Schema.Game() { Board = new GameBoard() { goalsHeight = 4, tasksHeight = 4, width = 3 } }; player.Handler.HandleMessage(game); Assert.AreEqual((uint)3, player.Game.Board.width); Assert.AreEqual((uint)4, player.Game.Board.tasksHeight); Assert.AreEqual((uint)4, player.Game.Board.goalsHeight); Assert.AreEqual(3, player.Game.Fields.GetLength(0)); Assert.AreEqual(12, player.Game.Fields.GetLength(1)); }
public void HandleMessage(JoinGame message, Socket handler) { lock (BoardLock) { var selectedTeam = SelectTeamForPlayer(message.preferredTeam); //both teams are full if (selectedTeam == null) { gameMaster.Connection.SendFromClient(handler, XmlMessageConverter.ToXml(new RejectJoiningGame() { gameName = message.gameName, playerId = message.playerId })); gameMaster.Connection.SendFromClient(handler, XmlMessageConverter.ToXml(new GameStarted() { gameId = this.gameId })); return; } var role = message.preferredRole; if (role == PlayerType.leader) { if (selectedTeam.HasLeader) { role = PlayerType.member; } } var guid = Utils.GenerateGuid(); var fieldForPlayer = Board.GetEmptyPositionForPlayer(selectedTeam.Color); fieldForPlayer.PlayerId = message.playerId; if (role == PlayerType.leader) { selectedTeam.AddLeader(new Wrapper.Leader(message.playerId, guid, selectedTeam, fieldForPlayer.X, fieldForPlayer.Y)); } else { selectedTeam.Players.Add(new Wrapper.Player(message.playerId, guid, selectedTeam, fieldForPlayer.X, fieldForPlayer.Y)); } var answer = new ConfirmJoiningGame(); answer.playerId = message.playerId; answer.privateGuid = guid; answer.gameId = this.gameId; answer.PlayerDefinition = new Player() { id = message.playerId, team = selectedTeam.Color, type = role }; var answerString = XmlMessageConverter.ToXml(answer); gameMaster.Connection.SendFromClient(handler, answerString); } if (IsReady) { var board = Board; var players = Players.Select(p => p.SchemaPlayer).ToArray(); foreach (var player in Players) { var startGame = new Common.Schema.Game() { Board = board.SchemaBoard, playerId = player.Id, PlayerLocation = new Location() { x = player.X, y = player.Y }, Players = players }; var gameString = XmlMessageConverter.ToXml(startGame); //ConsoleDebug.Message(gameString); gameMaster.Connection.SendFromClient(handler, gameString); //send GameStarted message to server so it won't show it as an open game var gameStarted = new GameStarted() { gameId = gameId }; var startedString = XmlMessageConverter.ToXml(gameStarted); gameMaster.Connection.SendFromClient(handler, startedString); } //place first pieces for (int i = 0; i < gameMaster.Settings.GameDefinition.InitialNumberOfPieces; i++) { PlaceNewPiece(Board.GetRandomEmptyFieldInTaskArea()); } //start infinite Piece place loop GameInProgress = true; GeneratePieces(); } }