Пример #1
0
        /// <summary>
        /// Create a new game, using the given map.
        /// </summary>
        /// <param name="map"></param>
        public ClientGame(string gameName, string server, int port)
        {
            dispatcher       = System.Windows.Threading.Dispatcher.CurrentDispatcher;
            this.gameName    = gameName;
            world            = new Game(map);
            map.OnMapChange += (_, __) => { if (OnMapChange != null)
                                            {
                                                OnMapChange(this, EventArgs.Empty);
                                            }
            };
            world.OnGameEnded += (_, args) => {
                switch (args.Result)
                {
                case GameResult.HumansWin:
                    if (HumansWin != null)
                    {
                        HumansWin(this, EventArgs.Empty);
                    }
                    break;

                case GameResult.ZombiesWin:
                    if (ZombiesWin != null)
                    {
                        ZombiesWin(this, EventArgs.Empty);
                    }
                    break;

                case GameResult.Draw:
                    if (Draw != null)
                    {
                        Draw(this, EventArgs.Empty);
                    }
                    break;

                default:
                    break;
                }
            };
            world.OnPlayerRemoved += (_, __) => { if (OnMapChange != null)
                                                  {
                                                      OnMapChange(this, EventArgs.Empty);
                                                  }
            };
            connection.ConnectToServer(server, port);
            // Setup complete.  Now receive the rest of the commands for the game.
            connection.OnCommandReceived += connection_OnGameCommand;
        }