Exemple #1
0
        public ReplayManager(GameSettings settings)
        {
            Image = new GameImage();
            Image.Settings = settings;

            FileName = "Football Savefile " + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".fsg";
            serializer = new XmlSerializer(typeof(GameImage));
        }
Exemple #2
0
        public void UpdateSettings(Rectangle[,] field, GameSettings settings, Point topLeftFieldCorner)
        {
            settingsAreSet = true;
            Field = field;
            Settings = settings;
            TopLeftFieldCorner = topLeftFieldCorner;

            SetSettings(settings);
        }
Exemple #3
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);
            }
        }
Exemple #4
0
        public static void Main(String[] args)
        {
            LogfilePath = "Logfile " + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".txt";

            int columns = 51; //standard 51
            int rows = 25; //standard 25
            int midfieldLineXPosition = 25; //standard 25
            int midfieldPointYPosition = 12; //standard 12
            int leftGoalHeight = 5; //standard 5
            int leftGoalYPosition = 10; //standard 10
            int rightGoalHeight = 5; //standard 5
            int rightGoalYPosition = 10; //standard 10
            int secondsPerStep = 1200;

            //standard settings
            GameSettings settings = new GameSettings(columns, rows, midfieldLineXPosition, midfieldPointYPosition, leftGoalHeight, leftGoalYPosition, rightGoalHeight, rightGoalYPosition, secondsPerStep, 100, true, true);
            try
            {
                //start the program with the safegame if the user dropped it to the executable
                if (args.Length > 0 && args[0].EndsWith(".fsg"))
                {
                    Application.Run(new FieldForm(args[0], settings));
                }
                else
                {
                    Application.Run(new FieldForm(settings));
                }
            }
            catch(Exception e)
            {
                MessageBoxButtons button = MessageBoxButtons.OK;
                MessageBoxIcon icon = MessageBoxIcon.Error;
                MessageBox.Show("Something went wrong.\nPlease have a look at the log file (" + Program.LogfilePath + ").", "Error", button, icon);

                File.AppendAllText(Program.LogfilePath, Program.TimeString + " [" + e.GetType() + "]: " + e.Message + " Source: " + e.Source + "\nInnerException: " + e.InnerException + "\nHelpLink: " + e.HelpLink + "\nStackTrace: " + e.StackTrace + "\n\n");
            }
        }
Exemple #5
0
        public void UpdateSettings(GameSettings settings)
        {
            ManualIndexChange = true;

            int secondsIndex = RoundSecondsBox.FindString(settings.SecondsPerRound + "");
            if (secondsIndex != -1)
            {
                RoundSecondsBox.SelectedIndex = secondsIndex;
            }
            else
            {
                RoundSecondsBox.Items.Add(settings.SecondsPerRound);
                RoundSecondsBox.Text = settings.SecondsPerRound + "";
            }

            int roundIndex = GameRoundsBox.FindString(settings.RoundsPerHalf + "");
            if (roundIndex != -1)
            {
                GameRoundsBox.SelectedIndex = roundIndex;
            }
            else
            {
                GameRoundsBox.Items.Add(settings.RoundsPerHalf);
                GameRoundsBox.Text = settings.RoundsPerHalf + "";
            }

            FirstKiBox.SelectedIndex = (settings.FirstTeamUsesKI) ? 1 : 0;
            SecondKiBox.SelectedIndex = (settings.SecondTeamUsesKI) ? 1 : 0;

            ManualIndexChange = false;
        }
        /// <summary>
        /// Updates the saved Settings with the new Settings and refreshed the stadium panel
        /// </summary>
        /// <param name="columns"></param>
        /// <param name="rows"></param>
        /// <param name="midfieldLineXPosition"></param>
        /// <param name="midfieldPointYPosition"></param>
        /// <param name="leftGoalHeight"></param>
        /// <param name="leftGoalYPosition"></param>
        /// <param name="rightGoalHeight"></param>
        /// <param name="rightGoalYPosition"></param>
        public void UpdateSettings(GameSettings settings)
        {
            Columns = settings.Columns;
            Rows = settings.Rows;
            MidfieldLineXPosition = settings.MidLineXPosition;
            MidfieldPointYPosition = settings.MidPointYPosition;
            LeftGoalHeight = settings.LeftGoalHeight;
            LeftGoalYPosition = settings.LeftGoalYPosition;
            RightGoalHeight = settings.RightGoalHeight;
            RightGoalYPosition = settings.RightGoalYPosition;

            StadiumPanel.Invoke((MethodInvoker)(() =>
            {
                StadiumPanel.UpdateSettings(fieldCell, settings, FieldGrid.Location);
                StadiumPanel.Refresh();
            }));
        }
        /// <summary>
        /// Updates the rounds per second and rounds per game Settings which are saved in the game Settings.
        /// </summary>
        /// <param name="Settings"></param>
        public void UpdateSettings(GameSettings settings)
        {
            this.Invoke((MethodInvoker)(() =>
            {
                manualIndexChange = true;

                gameSettingsPanel.UpdateSettings(settings);
                CurrentFieldSettingsPanel.UpdateSettings(settings);

                manualIndexChange = false;
            }));
        }
 /// <summary>
 /// Raises the GameSettingsChanged()-event with the Settings in the parameter as the argument.
 /// </summary>
 /// <param name="Settings"></param>
 private void RaiseSettingsEvent(GameSettings settings)
 {
     FieldSettingsEventArgs args = new FieldSettingsEventArgs(settings);
     GameSettingsChanged(this, args);
 }
Exemple #9
0
 /// <summary>
 /// Sets all settings.
 /// </summary>
 /// <param name="settings"></param>
 private void SetSettings(GameSettings settings)
 {
     this.midfieldLineXPosition = settings.MidLineXPosition;
     this.midfieldPointYPosition = settings.MidPointYPosition;
     this.leftGoalHeight = settings.LeftGoalHeight;
     this.leftGoalYPosition = settings.LeftGoalYPosition;
     this.rightGoalHeight = settings.RightGoalHeight;
     this.rightGoalYPosition = settings.RightGoalYPosition;
 }
Exemple #10
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;
        }
Exemple #11
0
        /// <summary>
        ///  Initializes the components.
        /// </summary>
        /// <param name="columns"></param>
        /// <param name="rows"></param>
        private void InitializeComponents(GameSettings settings)
        {
            int columns = settings.Columns;
            int rows = settings.Rows;

            #region Statusstrip
            informationStatusStrip = new StatusStrip();
            informationStatusStrip.Renderer = new CustomRenderer(new CustomColorTable());

            Controls.Add(informationStatusStrip);
            #endregion

            #region Game Panels
            Panel rootPanel = new Panel();
            rootPanel.Size = ClientSize;
            rootPanel.BackgroundImage = Properties.Resources.Stadium;
            rootPanel.Location = new Point(0, 20);
            rootPanel.BorderStyle = BorderStyle.FixedSingle;

            informationPanel = new InformationPanel();
            informationPanel.Size = new Size(ClientSize.Width, 130);
            informationPanel.Location = new Point(10, 0);
            informationPanel.BackColor = Color.Transparent;

            //Initialize stadium panel
            stadiumPanel = new FieldPanel(true);
            stadiumPanel.Size = new Size(ClientSize.Width, ClientSize.Height);
            stadiumPanel.Location = new Point(0, 60);
            stadiumPanel.BackColor = Color.Transparent;

            int edgeLength = 20;

            columns += 2;
            rows += 2;

            directionLinesPanel = new Panel();
            directionLinesPanel.Size = new Size((columns) * edgeLength, (rows) * edgeLength);
            directionLinesPanel.BackColor = Color.Transparent;
            directionLinesPanel.Paint += directionLinesPanel_Paint;
            directionLinesPanel.Location = new Point(70, 85);

            fieldGrid = new BufferedPanel();
            fieldGrid.Size = directionLinesPanel.Size;
            fieldGrid.BackColor = Color.Transparent;
            fieldGrid.Location = new Point(0, 0);
            fieldGrid.Paint += fieldGrid_Paint;
            fieldGrid.MouseMove += fieldGrid_MouseMove;
            fieldGrid.MouseDown += fieldGrid_MouseDown;
            fieldGrid.MouseUp += fieldGrid_MouseUp;

            fieldCell = new Rectangle[columns, rows];
            for (int r = 0; r < rows; r++)
            {
                for (int c = 0; c < columns; c++)
                {
                    Rectangle cell = new Rectangle();
                    cell.Size = new Size(edgeLength, edgeLength);
                    cell.Location = new Point(c * edgeLength, r * edgeLength);
                    fieldCell[c, r] = cell;
                }
            }

            directionLinesPanel.Controls.Add(fieldGrid);

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

            rootPanel.Controls.Add(informationPanel);
            rootPanel.Controls.Add(stadiumPanel);

            Controls.Add(rootPanel);
        }
Exemple #12
0
 public FieldForm(GameSettings settings)
 {
     StartGuiInitialisation(settings);
     StartGameInitialisation(settings, false, null);
 }
Exemple #13
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();
            }));
        }
Exemple #14
0
        /// <summary>
        /// Saves the game settings, sets the settings for the form and initializes all gui components.
        /// </summary>
        /// <param name="settings"></param>
        private void StartGuiInitialisation(GameSettings settings)
        {
            this.midfieldLineXPosition = settings.MidLineXPosition;
            this.midfieldPointYPosition = settings.MidPointYPosition;
            this.leftGoalHeight = settings.LeftGoalHeight;
            this.leftGoalYPosition = settings.LeftGoalYPosition;
            this.rightGoalHeight = settings.RightGoalHeight;
            this.rightGoalYPosition = settings.RightGoalYPosition;

            Icon = Properties.Resources.Icon;
            Text = "Football";
            ClientSize = new Size(1200, 760);
            MaximumSize = new Size(1216, 798);
            StartPosition = FormStartPosition.CenterScreen;
            FormBorderStyle = FormBorderStyle.FixedSingle;

            InitializeMenuStrip();
            InitializeComponents(settings);
            InitializeEvents();

            Show();
        }