Esempio n. 1
0
        /// <summary>
        /// Handles <see cref="GameState.CurrentChanged"/> event.
        /// </summary>
        /// <param name="sender">Event source.</param>
        /// <param name="e">An <see cref="EventArgs"/> containing event data.</param>
        private void State_CurrentChanged(object sender, EventArgs e)
        {
            MarkDisplay markDisplay = (MarkDisplay)upperPanel.Controls[CurrentDisplay];

            markDisplay.Current = controller.State.Current;

            if (controller.Timing != null)
            {
                CountingDownLabel counter = (CountingDownLabel)upperPanel.Controls[TimeLeft];
                counter.Time = TimeSpan.FromSeconds(controller.Timing.MoveTime);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes main window.
        /// </summary>
        public override void InitializeWindow()
        {
            Label lblCurrentInfo = new Label
            {
                Text      = "Aktualny gracz: ",
                Name      = CurrentInfo,
                AutoSize  = true,
                Font      = SystemFonts.CaptionFont,
                ForeColor = Color.Blue
            };
            MarkDisplay markDisplay = new MarkDisplay
            {
                Current = Mark.Cross,
                Size    = new Size(40, 40),
                Name    = CurrentDisplay
            };
            Label             lblTimeLeftInfo = null;
            CountingDownLabel lblTimeLeft     = null;

            if (controller.Timing != null)
            {
                lblTimeLeftInfo = new Label
                {
                    AutoSize  = true,
                    Font      = SystemFonts.CaptionFont,
                    ForeColor = Color.Blue,
                    Name      = TimeLeftInfo,
                    Text      = "Czas do wykonania ruchu:"
                };
                lblTimeLeft = new CountingDownLabel
                {
                    AutoSize  = true,
                    Font      = SystemFonts.CaptionFont,
                    ForeColor = Color.Blue,
                    Name      = TimeLeft,
                    Time      = TimeSpan.FromSeconds(controller.Timing.MoveTime)
                };
            }

            mapView.Location      = new Point(0, 50);
            mapView.Size          = new Size(MainWindow.ClientSize.Width, MainWindow.ClientSize.Height - 50);
            mapView.MapViewClick += MapView_MapViewClick;

            upperPanel = new CenteringPanel
            {
                Size     = new Size(MainWindow.ClientSize.Width - 120, 50),
                Location = new Point(0, 0),
                DefaultControlsDistance = 10
            };

            upperPanel.SuspendLayout();
            upperPanel.AddToPanel(lblCurrentInfo);
            upperPanel.AddToPanel(markDisplay);
            if (lblTimeLeft != null)
            {
                upperPanel.AddToPanel(lblTimeLeftInfo, 20);
                upperPanel.AddToPanel(lblTimeLeft, 0);
            }
            upperPanel.ResumeLayout();

            optionsBtn = new Button
            {
                Text      = "Opcje",
                Size      = new Size(100, 35),
                BackColor = Color.Green,
                ForeColor = Color.White,
                Location  = new Point(MainWindow.ClientSize.Width - 110, 7),
                FlatStyle = FlatStyle.Flat
            };
            optionsBtn.Click += OptionsButton_Click;

            MainWindow.Controls.Add(mapView);
            MainWindow.Controls.Add(upperPanel);
            MainWindow.Controls.Add(optionsBtn);

            controller.State.TicTacToeMap.MarksChanged += (sender, e) =>
            {
                MainWindow.BeginInvoke(new MarksChangedEventHandler(Map_MarksChanged), sender, e);
            };
            controller.WinConditionMet += (sender, e) =>
            {
                MainWindow.BeginInvoke(new WinConditionMetEventHandler(Controller_WinConditionMet), sender, e);
            };
            controller.State.CurrentChanged += (sender, e) =>
            {
                MainWindow.BeginInvoke(new EventHandler(State_CurrentChanged), sender, e);
            };

            if (controller.Timing != null)
            {
                controller.Timing.Tick += (sender, e) =>
                {
                    MainWindow.BeginInvoke(new EventHandler(Timing_Tick), sender, e);
                };
                controller.Timing.Start();
            }
        }