Example #1
0
        /// <summary>
        /// Creates a game for Match m, and adds it to the list of games. Tells players of the match that they are in game,
        /// and send signal to clients
        /// </summary>
        /// <param name="m"></param>
        private void startMatch(Match m)
        {
            DisputeGame game = new DisputeGame()
            {
                Match = m
            };

            game.FeedbackWritter = this.FeedbackWriter;
            //Register as observer so game can send messages back
            (game as IGameObservable).registerObserver(this);

            games.Add(game);
            players.Find(n => n.Equals(m.Player1)).InGame = true;
            players.Find(n => n.Equals(m.Player2)).InGame = true;

            MyMessages[m.Player1.PlayerName].Add(new WCFMessage()
            {
                Type = Messages.DTOType.match,
                Data = new DisputeDTO()
                {
                    Message = Messages.GameMessages.StartingMatch, Match = m
                }
            });
            MyMessages[m.Player2.PlayerName].Add(new WCFMessage()
            {
                Type = Messages.DTOType.match,
                Data = new DisputeDTO()
                {
                    Message = Messages.GameMessages.StartingMatch, Match = m
                }
            });
            m.Transcript = "Starting Match\n";
            updateMatchData(m);

            //Now update players in match, we may not need this because the starting match messages above
            //updatePlayerInMatch(m.Player1);
            //updatePlayerInMatch(m.Player2);
        }
Example #2
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;
                }
            }
        }