예제 #1
0
        public FieldForm(string savegamePath, GameSettings standardSettings)
        {
            ReplayManager manager = new ReplayManager(savegamePath);
            manager.Load();

            if (manager.Image != null)
            {
                StartGuiInitialisation(manager.Image.Settings);
                StartGameWithReplayManager(savegamePath);
            }
            else
            {
                StartGuiInitialisation(standardSettings);
                StartGameInitialisation(standardSettings, false, null);
            }
        }
예제 #2
0
        /// <summary>
        /// Starts the initialization of all UI components as well as the initialization of the game.
        /// </summary>
        /// <param name="columns"></param>
        /// <param name="rows"></param>
        /// <param name="secondsPerStep"></param>
        /// <param name="isHost"></param>
        /// <param name="IsMultiplayer"></param>
        public void StartGameInitialisation(GameSettings settings, bool isMultiplayer, ReplayManager replay)
        {
            currentGame = new Game(fieldCell, settings, isMultiplayer, replay);
            currentGame.InitializeGame();
            InitializeGameEvents();
            currentGame.SetBallToMidpoint();

            //add the start round to the replay manager
            if (replay == null)
            {
                currentGame.CurrentReplayManager.Image.RoundImages.Add(currentGame.CreateRoundImage());
            }

            Show();
            Refresh();

            if (isMultiplayer)
            {
                AddOpenChatButton();
            }
            fieldGrid.Focus();
            currentGame.StartRoundTimer();
            currentGame.IsWaitingForHost += WaitingForHostChanged;
        }
예제 #3
0
 /// <summary>
 /// Raises the CreateNewGame()-method with the game image in a new replay manager.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void GameContinued(object sender, GameImageEventArgs e)
 {
     ReplayManager manager = new ReplayManager();
     manager.Image = e.Image;
     CreateNewGame(e.Image.Settings, true, manager);
     currentGame.SetRoundImage(manager.SearchImageAtRound(manager.SearchLastRoundNumber()), false);
     currentGame.SetCorrectGoals(currentGame.Round);
     currentGame.SetCorrectGoalsCount(currentGame.Round);
     CurrentMpHandler.MultiplayerGame = currentGame;
 }
예제 #4
0
        /// <summary>
        /// Starts a new game with the given GameSettings.
        /// 
        /// Opens a new ChatForm (hidden in the status strip) and a userlist to the form if it is a multiplayer game.
        /// </summary>
        /// <param name="Settings"></param>
        /// <param name="isMultiplayer"></param>
        private void CreateNewGame(GameSettings settings, bool isMultiplayer, ReplayManager replay)
        {
            this.Invoke((MethodInvoker)(() =>
            {
                Cursor = Cursors.Default;

                if (isMultiplayer)
                {
                    CurrentMpHandler.CurrentChatForm = new ChatForm(CurrentMpHandler.CurrentChats);
                    CurrentMpHandler.CurrentChatForm.ChatClosed += CurrentChatForm_ChatClosed;
                    CurrentMpHandler.CurrentLobby.ForceClose = true;
                    CurrentMpHandler.CurrentLobby.Close();
                }

                #region Settings
                int columns = settings.Columns;
                int rows = settings.Rows;
                int secondsPerRound = settings.SecondsPerRound;

                leftGoalHeight = settings.LeftGoalHeight;
                leftGoalYPosition = settings.LeftGoalYPosition;
                rightGoalHeight = settings.RightGoalHeight;
                rightGoalYPosition = settings.RightGoalYPosition;
                midfieldLineXPosition = settings.MidLineXPosition;
                midfieldPointYPosition = settings.MidPointYPosition;

                stadiumPanel.UpdateSettings(fieldCell, settings, directionLinesPanel.Location);
                #endregion

                if (currentGame != null)
                {
                    currentGame.IsStopped = true;
                    currentGame.RoundTimer.Stop();
                }

                StartGameInitialisation(settings, isMultiplayer, replay);
                if (isMultiplayer)
                {
                    informationPanel.AddUserList(CurrentMpHandler.Users, CurrentMpHandler.CurrentClient.ClientName);
                    CurrentMpHandler.RefreshUserList += CurrentMpHandler_RefreshUserList;
                    AddConnectionInformationLabel();
                }

                UpdateGoalsLabels();
                UpdateRoundLabel();
            }));
        }
예제 #5
0
        /// <summary>
        /// Loads the savegame at the path and opens the replay manager.
        /// </summary>
        /// <param name="path"></param>
        private void StartGameWithReplayManager(string path)
        {
            ReplayManager rm = new ReplayManager(path);
            rm.Load();

            //creates a new game if the game image has been loaded
            if (rm.Image != null)
            {
                CreateNewGame(rm.Image.Settings, false, rm);

                replayManager = new ReplayManagerForm(rm.SearchLastRoundNumber());
                replayManager.Round = currentGame.Round;
                currentGame.LeftSeconds = -2;
                InitializeManagerEvents();
            }
        }
예제 #6
0
        private bool ChooseSavefile()
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.Filter = "FSG-Files (*.fsg) | *.fsg";
            openDialog.CheckFileExists = true;
            DialogResult result = openDialog.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                string path = openDialog.InitialDirectory + openDialog.FileName;
                ReplayManager manager = new ReplayManager(path);
                manager.Load();
                if (manager.Image != null)
                {
                    manager.Image.RoundImages.RemoveRange(0, manager.Image.RoundImages.Count - 1);

                    CurrentClient.Send("game<>:" + serializer.Serialize(manager.Image));
                    CurrentClient.Send("settings<>:" + serializer.Serialize(manager.Image.Settings));
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }