コード例 #1
0
        public GameMultiplayerControl(Control Control, GameScreen GameScreen, int MapIndex, int SaveGameIndex, MultiplayerMatchStartInformation MP)
            : base(Control, GameScreen, MapIndex, SaveGameIndex, true)
        {
            this.UserName = MP.UserName;
            this.Password = MP.Password;
            this.MatchId = MP.MatchId;
            this.GameState = 0;
            this.MultiplayerMatch = true;
            this.MultiplayerFraction = MP.MultiplayerFraction;

            // timer checking if a newer game state is available
            NewGameStateAvailableTimer = new System.Windows.Forms.Timer();
            NewGameStateAvailableTimer.Interval = 1000;
            NewGameStateAvailableTimer.Tick += UpdateGameState;
            NewGameStateAvailableTimer.Start();

            // show multiplayer tab (gui) and update it's content
            GameScreen.TabItem_Multiplayer.Visibility = Visibility.Visible;
            GameScreen.Button_Restart.IsEnabled = false; // disable restart map button for multiplayer matches
            GameScreen.Label_Multiplayer_MatchID.Content = R.String("MatchID") + ": " + MatchId.ToString();
            GameScreen.Label_Multiplayer_MatchVersion.Content = R.String("MatchVersion") + ": " + GameState.ToString();

            // background worker
            BackgroundWorkerDownloadLatestGameState.DoWork += BackgroundWorkerDownloadLatestGameStateWork;
            BackgroundWorkerDownloadLatestGameState.RunWorkerCompleted += BackgroundWorkerDownloadLatestGameState_RunWorkerCompleted;
        }
コード例 #2
0
ファイル: Control.cs プロジェクト: Simsso/Crusades
 // shows the game screen
 public void ShowGameScreen(int MapIndex, int SavegameIndex, GameControl.MultiplayerMatchStartInformation MPInfo = null)
 {
     QuitCurrentScreen();
     GameScreen = new GameScreen(this, MapIndex, SavegameIndex, MPInfo);
     MainWindow.ContentControl_Main.Content = GameScreen;
 }
コード例 #3
0
ファイル: GameControl.cs プロジェクト: Simsso/Crusades
        public GameControl(Control Control, GameScreen GameScreen, int MapIndex, int SavegameIndex, MultiplayerMatchStartInformation MP)
        {
            this.GameScreen = GameScreen;
            this.Control = Control;

            // multiplayer
            if (MP != null)
            {
                this.UserName = MP.UserName;
                this.Password = MP.Password;
                this.MatchId = MP.MatchId;
                this.GameState = 0;
                this.MultiplayerMatch = true;
                this.MultiplayerFraction = MP.MultiplayerFraction;

                // timer checking if a newer game state is available
                NewGameStateAvailableTimer = new System.Windows.Forms.Timer();
                NewGameStateAvailableTimer.Interval = 1000;
                NewGameStateAvailableTimer.Tick += UpdateGameState;
                NewGameStateAvailableTimer.Start();

                // show multiplayer tab (gui) and update it's content
                GameScreen.TabItem_Multiplayer.Visibility = Visibility.Visible;
                GameScreen.Button_Restart.IsEnabled = false; // disable restart map button for multiplayer matches
                GameScreen.Label_Multiplayer_MatchID.Content = R.String("MatchID") + ": " + MatchId.ToString();
                GameScreen.Label_Multiplayer_MatchVersion.Content = R.String("MatchVersion") + ": " + GameState.ToString();

                // background worker
                BackgroundWorkerDownloadLatestGameState.DoWork += BackgroundWorkerDownloadLatestGameStateWork;
                BackgroundWorkerDownloadLatestGameState.RunWorkerCompleted += BackgroundWorkerDownloadLatestGameState_RunWorkerCompleted;
            }
            else
            {
                // hide multiplayer tab
                GameScreen.TabItem_Multiplayer.Visibility = Visibility.Hidden;
            }

            if (SavegameIndex != -1) // user wants to load a savegame
            {
                this.Game = Data.GetGame(SavegameIndex); // load savegame file

                if (Game == null)
                {
                    // error loading savegame
                    // Control.ShowMenuScreen();
                    Control.ShowToast(R.String("ErrorLoadingSavegame"));
                    return; // cancel game control initialization
                }
            }
            else // user wants to start a new game
            {
                this.Game = new Game(Map.GetMap(MapIndex));
            }

            if (Game.Map != null)
                GameScreen.InitializeBackground(Game.Map.Name, Game.Map.Buildings);

            // disable end turn button if the player is not allowed to move
            if (MP != null && MultiplayerFraction != Game.Turn)
                GameScreen.Button_EndTurn.IsEnabled = false;

            RefreshStatistic(true);
        }