public void parseRequest(Messages.GameMessages header, List <object> args, object sender)
        {
            if (!isConnected() && header != Messages.GameMessages.connect)
            {
                return;
            }
            List <NamedParameter> pars = null;

            switch (header)
            {
            case Messages.GameMessages.connect:
                pars = DataTypes.createList(args, DataType.name);
                this.connect((String)pars[0].data, (String)pars[1].data, (String)pars[2].data);
                break;

            case Messages.GameMessages.CreateMatch:
                sendFeedback("sendMessage", "Begin Create Game");
                this.sendData(header.ToString());
                break;

            case Messages.GameMessages.JoinMatch:
                sendFeedback("sendMessage", "Begin Join Game");
                pars = DataTypes.createList(args, DataType.name);
                String name = (String)pars[0].data;
                sendData(Messages.GameMessages.JoinMatch.ToString());
                sendData(name);
                break;

            case Messages.GameMessages.LeaveMatch:
                sendFeedback("sendMessage", "Begin Join Game");
                sendData(Messages.GameMessages.LeaveMatch.ToString());
                break;

            case Messages.GameMessages.UpdateMatches:
                sendData(Messages.GameMessages.SendActiveMatches);
                break;

            case Messages.GameMessages.playerQuit:
                this.isRunning = false;
                sendFeedback("sendMessage", "Player quit");
                this.sendData(header.ToString());
                break;

            case Messages.GameMessages.SendActiveMatches:
                this.sendData(header.ToString());
                break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        public void getMessageFromServerManager(Messages.GameMessages message, List <NamedParameter> data)
        {
            switch (message)
            {
            case Messages.GameMessages.gamesUpdated:
                //Tell client that game was created so they can react
                sendData(message.ToString());
                break;

            default:
                break;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method looks at the type of request the player sent,
        /// and puts the appropriate data and type in to msg.data before adding it to MyMessages
        /// </summary>
        /// <param name="player"></param>
        /// <param name="msg"></param>
        public void addNewMessage(DataPlayer player, Messages.GameMessages msg, String data = null)
        {
            player = players.Find(n => n.Equals(player));
            if (player == null)
            {
                sendFeedback("addNewMessage", "Player Not Found\n PlayerName:" + player.PlayerName + "\n" +
                             msg.ToString());
                return;
            }
            if (player.InGame)//Use in game handler
            {
                IPlayable  game    = games.Find(n => n.Player1.Equals(player) || n.Player2.Equals(player));
                DataPlayer player1 = players.Find(n => n.Equals(game.Player1)),
                           player2 = players.Find(n => n.Equals(game.Player2));
                switch (msg)
                {
                case Messages.GameMessages.UpdateMatch:
                    updatePlayerInMatch(player);
                    break;

                case Messages.GameMessages.somChosen:
                    SOM som = (SOM)Enum.Parse(typeof(SOM), data);
                    game.getMessageFromConnection(Messages.GameMessages.somChosen,
                                                  player,
                                                  new List <object> {
                        som
                    });
                    game.Match.Transcript += "SoM chosen:" + som.ToString() + "\n";
                    break;

                case Messages.GameMessages.GameOver:
                    //Reset players,remove finished match from list
                    player1.InGame = false;
                    player2.InGame = false;
                    Matches.Remove(player1.ActiveMatch);
                    player1.ActiveMatch = new Match();
                    player1.ActiveMatch = null;
                    player2.ActiveMatch = null;
                    game = null;
                    break;

                case Messages.GameMessages.SendActiveMatches:
                    updatePlayerInMatch(player);
                    break;

                default:    //Covers all argument requests
                    game.getMessageFromConnection(msg, player, null);
                    break;
                }
            }
            else //Use lobby handler
            {
                switch (msg)
                {
                case Messages.GameMessages.SendActiveMatches:
                    updatePlayer(player);
                    break;

                case Messages.GameMessages.CreateMatch:
                    createMatch(player);
                    break;

                case Messages.GameMessages.LeaveMatch:
                    leaveMatch(player);
                    break;

                case Messages.GameMessages.UpdateAll:
                    updatePlayer(player);
                    break;

                case Messages.GameMessages.JoinMatch:
                    if (data == null)
                    {
                        addSignalMessage(Messages.GameMessages.InvalidMatch, player);
                    }
                    else
                    {
                        joinMatch(data, player);
                    }
                    break;

                case Messages.GameMessages.PlayerReady:
                    lockInPlayer(player);
                    break;

                case Messages.GameMessages.PlayerNotReady:
                    lockOutPlayer(player);
                    break;

                case Messages.GameMessages.UpdateMatch:
                    updatePlayerInMatch(player);
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 4
0
 public void sendFeedback(string functionName, Messages.GameMessages feedback)
 {
     FeedbackWriter.WriteLine("Method:" + functionName + "   Feedback:" + feedback.ToString());
 }
Exemplo n.º 5
0
 public void sendData(Messages.GameMessages msg)
 {
     sendData(msg.ToString());
 }
Exemplo n.º 6
0
        /// <summary>
        /// This method looks at the type of request the player sent,
        /// and puts the appropriate data and type in to msg.data before adding it to MyMessages
        /// </summary>
        /// <param name="player"></param>
        /// <param name="msg"></param>
        public void addNewMessage(DataPlayer player, Messages.GameMessages msg, String data = null)
        {
            player = players.Find(n => n.Equals(player));
            if (player == null)
            {
                sendFeedback("addNewMessage", "Player Not Found\n PlayerName:" + player.PlayerName + "\n" +
                             msg.ToString());
                return;
            }
            if (player.InGame)//Use in game handler
            {
                DisputeGame game    = games.Find(n => n.Player1.Equals(player) || n.Player2.Equals(player));
                DataPlayer  player1 = players.Find(n => n.Equals(game.Player1)),
                            player2 = players.Find(n => n.Equals(game.Player2));
                switch (msg)
                {
                case Messages.GameMessages.UpdateMatch:
                    updatePlayerInMatch(player);
                    break;

                case Messages.GameMessages.somChosen:
                    int    i     = data.IndexOf("$");
                    String name  = data.Substring(0, i);
                    double value = Double.Parse(data.Substring(i + 1));
                    game.getMessageFromConnection(Messages.GameMessages.somChosen,
                                                  player,
                                                  new List <object> {
                        name, value
                    });
                    game.Match.Transcript += "SoM chosen:" + name + "\n";
                    break;

                case Messages.GameMessages.GameOver:
                    player1.InGame = false;
                    player2.InGame = false;
                    Matches.Remove(player1.ActiveMatch);
                    player1.ActiveMatch = new Match();
                    player1.ActiveMatch = null;
                    player2.ActiveMatch = null;
                    game = null;
                    break;

                default:    //Covers all argument requests
                    game.getMessageFromConnection(msg, player, null);
                    break;
                }
            }
            else //Use lobby handler
            {
                switch (msg)
                {
                case Messages.GameMessages.SendActiveMatches:
                    updatePlayer(player);
                    break;

                case Messages.GameMessages.CreateMatch:
                    createMatch(player);
                    break;

                case Messages.GameMessages.LeaveMatch:
                    leaveMatch(player);
                    break;

                case Messages.GameMessages.UpdateAll:
                    updatePlayer(player);
                    break;

                case Messages.GameMessages.JoinMatch:
                    if (data == null)
                    {
                        addSignalMessage(Messages.GameMessages.InvalidMatch, player);
                    }
                    else
                    {
                        joinMatch(data, player);
                    }
                    break;

                case Messages.GameMessages.PlayerReady:
                    lockInPlayer(player);
                    break;

                case Messages.GameMessages.PlayerNotReady:
                    lockOutPlayer(player);
                    break;

                default:
                    break;
                }
            }
        }
 void sendData(Messages.GameMessages data)
 {
     sendData(data.ToString());
 }