Пример #1
0
        // NewGame
        public void StartGame()
        {
            // Suspend Graphic Update
            this.SuspendLayout();

            // Hide home page
            _home.Visible = false;
            _home.Hide();
            _loading.BringToFront();
            _loading.Visible = true;
            _loading.Show();
            _loading.Refresh();

            // Restart Graphics Updates
            this.ResumeLayout();

            // Suspend Graphic Update
            this.SuspendLayout();

            // Create the game & objects
            _game = new Game.Game();
            _gameMenu = new InGameMenu(this);
            _stats = new InformationsUC(this);
            _eventFlux = new EventFluxUC();
            _scenarioBox = new ScenarioBox(this);
            _actionMenu = new TabIndex(this);
            _infoBox = new InformationBox(this);
            _actionsPanel = new ActionsPanel(this);
            _grid = new SquareControl[Board.GridMaxRow, Board.GridMaxCol];
            _board = _game.Villages[0].VillageGrid;
            options = new Options();

            #region Grid Generation
            // Set double-buffering
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);

            for (int i = 0; i < Board.GridMaxRow; i++)
            {
                for (int j = 0; j < Board.GridMaxCol; j++)
                {
                    // Create
                    _grid[i, j] = new SquareControl(i, j);

                    // Hide & Configure
                    _grid[i, j].Visible = false;
                    _grid[i, j].SuspendLayout();
                    _grid[i, j].Left = 220 + (j * _grid[i, j].Width);
                    _grid[i, j].Top = 40 + (i * _grid[i, j].Height);
                    _grid[i, j].SendToBack();
                    this.Controls.Add(_grid[i, j]);
                    _grid[i, j].ResumeLayout();

                    // Add events
                    _grid[i, j].MouseMove += new MouseEventHandler(SquareControl_MouseMove);
                    _grid[i, j].MouseLeave += new EventHandler(SquareControl_MouseLeave);
                    _grid[i, j].Click += new EventHandler(SquareControl_Click);
                }
            }
            #endregion

            // Setting the grid
            _board.SetForNewGame(_game);
            _emptySquaresList = new List<SquareControl>();
            _emptySquaresList = SetEmptySquaresList(_emptySquaresList, _board, _grid);
            UpdateGrid(_board, _grid);

            #region Create, Hide and Configure objects
            // InGameMenu
            _gameMenu.SuspendLayout();
            _gameMenu.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
            _gameMenu.BringToFront();
            this.Controls.Add(_gameMenu);
            _gameMenu.ResumeLayout();
            _gameMenu.Visible = false;
            _gameMenu.Hide();

            // Stats
            _stats.SuspendLayout();
            _stats.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
            _stats.SendToBack();
            PushGeneralGold(_game.TotalGold); //PushGeneralGold(_game.Villages[0].Gold);
            PushPopulation(_game.TotalPop);
            PushGeneralFaith(_game.Villages[0].Faith);
            PushGeneralHappiness(_game.Villages[0].Happiness);
            PushGeneralCoins(_game.Offerings);
            PushOfferingsPointsPerTick(_game.Villages[0].OfferingsPointsPerTick);
            this.Controls.Add(_stats);
            _stats.ResumeLayout();
            _stats.Visible = false;
            _stats.Hide();

            // EventFlux
            _eventFlux.Visible = false;
            _eventFlux.Hide();
            _eventFlux.SuspendLayout();
            _eventFlux.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
            _eventFlux.SendToBack();
            this.Controls.Add(_eventFlux);
            _eventFlux.ResumeLayout();

            // ActionsPanel
            _actionsPanel.Visible = false;
            _actionsPanel.Hide();
            _actionsPanel.SuspendLayout();
            _actionsPanel.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
            _actionsPanel.SendToBack();
            this.Controls.Add(_actionsPanel);
            _actionsPanel.ResumeLayout();

            // ScenarioBox
            _scenarioBox.Visible = false;
            _scenarioBox.Hide();
            _scenarioBox.SuspendLayout();
            _scenarioBox.Anchor = AnchorStyles.Bottom;
            _scenarioBox.SendToBack();
            this.Controls.Add(_scenarioBox);
            _scenarioBox.ResumeLayout();

            // ActionMenu
            _actionMenu.Visible = false;
            _actionMenu.Hide();
            _actionMenu.SuspendLayout();
            _actionMenu.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top);
            _actionMenu.SendToBack();
            this.Controls.Add(_actionMenu);
            _actionMenu.ResumeLayout();
            _actionMenu.Refresh();

            // InfoBox
            _infoBox.Visible = false;
            _infoBox.Hide();
            _infoBox.SuspendLayout();
            _infoBox.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
            _infoBox.SetNothingSelected();
            this.Controls.Add(_infoBox);
            _infoBox.ResumeLayout();
            #endregion

            // Hide loading effects
            gleipnir_logo.Visible = false;
            gleipnir_logo.Hide();
            gleipnir_logo.Refresh();
            _loading.SendToBack();
            _loading.Visible = false;
            _loading.Hide();

            #region Show Elements
            _actionMenu.Visible = true;
            _actionMenu.Show();
            _stats.Visible = true;
            _stats.Show();
            _eventFlux.Visible = true;
            _eventFlux.Show();
            _scenarioBox.Visible = true;
            _scenarioBox.Show();
            _infoBox.Visible = true;
            _infoBox.Show();
            for (int i = 0; i < Board.GridMaxRow; i++)
            {
                for (int j = 0; j < Board.GridMaxCol; j++)
                {
                    _grid[i, j].Visible = true;
                    _grid[i, j].Show();
                }
            }
            #endregion

            #region Trace Window
            trace = new traceBox();
            //trace.Show();
            #endregion

            // Wait the scenario's end
            // LockEverything();
            PushText("","Bienvenue à Ragnar");
            // Timer
            if (_interval == 0)
                _timer = null;
            else
            {
                _timer = new System.Windows.Forms.Timer();
                _timer.Tick += (source, eventArgs) => { Step(); };
                _timer.Interval = _interval;
                _timer.Start();
            }
            GameStarted = true;

            // Restart Graphics Updates
            this.ResumeLayout();
        }
Пример #2
0
 private void UpdateGrid(Board board, SquareControl[,] grid)
 {
     // Map the current game board to the square controls.
     for (int i = 0; i < Board.GridMaxRow; i++)
     {
         for (int j = 0; j < Board.GridMaxCol; j++)
         {
             grid[i, j].Contents = board.GetSquareContents(i, j);
             grid[i, j].Refresh();
         }
     }
 }
Пример #3
0
 private void UpdateSquare(int row, int col, SquareControl[,] grid, Board board)
 {
     grid[row, col].Contents = board.GetSquareContents(row, col);
     grid[row, col].Refresh();
 }
Пример #4
0
 // Grid Methods
 private List<SquareControl> SetEmptySquaresList(List<SquareControl> list, Board b, SquareControl[,] g)
 {
     for (int i = 0; i < Board.GridMaxRow; i++)
         for (int j = 0; j < Board.GridMaxCol; j++)
             if(b.IsValidSquare(i, j))
                 list.Add(g[i, j]);
     return list;
 }