コード例 #1
0
        public void HandleOnGameMaster(Messages.GameMaster.IConnection connection)
        {
            var sender = connection.GameState.GetPlayerByGuid(this.playerGuid);

            if (connection.GameState.GetPlayerById(this.withPlayerId) == null)
            {
                RejectKnowledgeExchange msg = new RejectKnowledgeExchange(this.withPlayerId, sender.Id, true);
                var serializer = new Messages.XmlHandling.Serializer(msg);
                connection.SendMessage(serializer.Serialize());
            }
            else
            {
                Tuple <ulong, ulong> pair = new Tuple <ulong, ulong>(sender.Id, this.withPlayerIdField);

                if (connection.GameState.PlayerPairs.FirstOrDefault(x => x.Item1 == sender.Id && x.Item2 == this.withPlayerId) == null)
                {
                    //no pair yet
                    KnowledgeExchangeRequest msg = new KnowledgeExchangeRequest(this.withPlayerId, sender.Id);
                    var serializer = new Messages.XmlHandling.Serializer(msg);
                    connection.GameState.PlayerPairs.Add(pair);
                    connection.DelayMessage(serializer, connection.GameState.ActionCosts.KnowledgeExchangeDelay);
                }
                else
                {
                    // pair exists
                    connection.GameState.PlayerPairs.RemoveAll(x => x.Item1 == sender.Id && x.Item2 == this.withPlayerId);
                    AcceptExchangeRequest msg = new AcceptExchangeRequest(this.withPlayerId, sender.Id);
                    var serializer            = new Messages.XmlHandling.Serializer(msg);
                    connection.SendMessage(serializer.Serialize());
                }
            }
        }
コード例 #2
0
        public void HandleOnGameMaster(Messages.GameMaster.IConnection connection)
        {
            var guid      = Guid.NewGuid();
            var gameState = connection.GameState;
            var msg       = new ConfirmJoiningGame(gameState.GameId, guid, this.playerId, new Player(this.playerId, this.preferredTeam, this.preferredRole));

            connection.AddPlayer(guid, msg.playerId, this.preferredTeam, this.preferredRole);

            var serializer = new Messages.XmlHandling.Serializer(msg);

            connection.SendMessage(serializer.Serialize());
            if (((ulong)gameState.RedPlayers.Count == gameState.RedTeamMax)
                &&
                ((ulong)gameState.BluePlayers.Count == gameState.BlueTeamMax))
            {
                gameState.GameStarted = true;
                var gameMsg = new Game();
                gameMsg.Players = new Player[gameState.RedTeamMax + gameState.BlueTeamMax];
                int index = 0;
                for (int i = 0; i < (int)gameState.RedTeamMax; i++, index++)
                {
                    var p = gameState.RedPlayers[i];
                    gameMsg.Players[index] = new Player(p.Id, p.TeamColour, p.PlayerType);
                }
                for (int i = 0; i < (int)gameState.BlueTeamMax; i++, index++)
                {
                    var p = gameState.BluePlayers[i];
                    gameMsg.Players[index] = new Player(p.Id, p.TeamColour, p.PlayerType);
                }
                connection.GameState.SetPlayerLocations();
                Console.WriteLine("Sending game msg");
                gameMsg.Board             = new GameBoard();
                gameMsg.Board.goalsHeight = (uint)connection.GameState.GoalAreaLength;
                gameMsg.Board.tasksHeight = (uint)connection.GameState.TaskAreaLength;
                gameMsg.Board.width       = (uint)connection.GameState.BoardWidth;

                foreach (var player in connection.GameState.RedPlayers)
                {
                    gameMsg.playerId       = player.Id;
                    gameMsg.PlayerLocation = player.Location;
                    serializer             = new Serializer(gameMsg);
                    connection.SendMessage(serializer.Serialize());
                }
                foreach (var player in connection.GameState.BluePlayers)
                {
                    gameMsg.playerId       = player.Id;
                    gameMsg.PlayerLocation = player.Location;
                    serializer             = new Serializer(gameMsg);
                    connection.SendMessage(serializer.Serialize());
                }
                var gameStartedMsg = new GameStarted(connection.GameState.GameId);
                serializer = new Serializer(gameStartedMsg);
                connection.SendMessage(serializer.Serialize());

                connection.GameState.StartSpawningPieces();
            }
        }
コード例 #3
0
ファイル: Move.cs プロジェクト: m-s-z/SE2
        public void HandleOnGameMaster(Messages.GameMaster.IConnection connection)
        {
            IPlayer player = connection.GameState.BluePlayers.FirstOrDefault(p => p.Guid.ToString() == this.playerGuid);

            if (player == null)
            {
                player = connection.GameState.RedPlayers.FirstOrDefault(p => p.Guid.ToString() == this.playerGuid);
            }
            //TO DO:location of piece carried by player should also change
            var location = Validate(connection, player);
            var piece    = connection.GameState.Pieces.FirstOrDefault(p => p.Piece.playerId == player.Id && p.Piece.playerIdSpecified == true);

            if (piece != null)
            {
                piece.Location = location;
            }
            var msg = new Data();

            msg.PlayerLocation = player.Location = location;
            msg.playerId       = player.Id;
            msg.gameFinished   = connection.GameState.GameFinished;
            var  serializer = new Messages.XmlHandling.Serializer(msg);
            Task delay      = new Task(() => {
                System.Threading.Thread.Sleep((int)connection.GameState.ActionCosts.MoveDelay);
                connection.SendMessage(serializer.Serialize());
                Console.WriteLine("I have waited for: " + (int)connection.GameState.ActionCosts.MoveDelay);
            });

            delay.Start();
        }