コード例 #1
0
        /// <summary>
        /// The Reversi game model constructor. It dose not generate a game.
        /// </summary>
        /// <param name="dataAccess">The data access.</param>
        /// <param name="defaultGameTableSizes">The default game size.</param>
        public ReversiGameModel(IReversiDataAccess dataAccess = null, Int32 defaultGameTableSizes = 10)
        {
            _tableSizeSettingDefault = defaultGameTableSizes;

            if (dataAccess != null)
            {
                _dataAccess = dataAccess;
                _supportedGameTableSizesArray = _dataAccess.SupportedGameTableSizesArray;
                for (Int32 i = 0; i < _dataAccess.SupportedGameTableSizesArray.GetLength(0); ++i)
                {
                    if (_dataAccess.SupportedGameTableSizesArray[i] % 2 != 0 || _dataAccess.SupportedGameTableSizesArray[i] < 4)
                    {
                        throw new ReversiModelException();
                    }
                }
            }
            else
            {
                _supportedGameTableSizesArray = new Int32[] { 10 };
                defaultGameTableSizes         = 10;
            }

            _tableSizeSetting = _tableSizeSettingDefault;
            _activeTableSize  = 0;
            _isGameStarted    = false;

            _timer          = new Timer(1000, true);
            _timer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);

            _allDirections         = new Direction[] { ToUp, ToRightUp, ToRight, ToRightDown, ToDown, ToLeftDown, ToLeft, ToLeftUp };
            _allReversedDirections = new Direction[] { ToDown, ToLeftDown, ToLeft, ToLeftUp, ToUp, ToRightUp, ToRight, ToRightDown };
        }
コード例 #2
0
        /// <summary>
        /// The Reversi game model constructor. It dose not generate a game.
        /// </summary>
        /// <param name="dataAccess">The data access.</param>
        /// <param name="defaultGameTableSizes">The default game size.</param>
        public ReversiGameModel(IReversiDataAccess dataAccess = null, Int32 defaultGameTableSizes = 10)
        {
            _tableSizeSettingDefault = defaultGameTableSizes;

            if (dataAccess != null)
            {
                _dataAccess = dataAccess;
                _supportedGameTableSizesArray = _dataAccess.SupportedGameTableSizesArray;
                for (Int32 i = 0; i < _dataAccess.SupportedGameTableSizesArray.GetLength(0); ++i)
                {
                    if (_dataAccess.SupportedGameTableSizesArray[i] % 2 != 0 || _dataAccess.SupportedGameTableSizesArray[i] < 4)
                    {
                        throw new ReversiModelException();
                    }
                }
            }
            else
            {
                _supportedGameTableSizesArray = new Int32[] { 10 };
                defaultGameTableSizes = 10;
            }

            _tableSizeSetting = _tableSizeSettingDefault;
            _activeTableSize = 0;
            _isGameStarted = false;

            _timer = new System.Timers.Timer(1000.0); // It will invoke every 1 second.
            _timer.Elapsed += Timer_Elapsed; // It will invoke Timer_Elapsed private method

            _allDirections = new Direction[] { ToUp, ToRightUp, ToRight, ToRightDown, ToDown, ToLeftDown, ToLeft, ToLeftUp };
            _allReversedDirections = new Direction[] { ToDown, ToLeftDown, ToLeft, ToLeftUp, ToUp, ToRightUp, ToRight, ToRightDown };
        }
コード例 #3
0
        /// <summary>
        /// The Reversi game model constructor. It dose not generate a game.
        /// </summary>
        /// <param name="dataAccess">The data access.</param>
        /// <param name="defaultGameTableSizes">The default game size.</param>
        public ReversiGameModel(IReversiDataAccess dataAccess = null, Int32 defaultGameTableSizes = 10)
        {
            _tableSizeSettingDefault = defaultGameTableSizes;

            if (dataAccess != null)
            {
                _dataAccess = dataAccess;
                _supportedGameTableSizesArray = _dataAccess.SupportedGameTableSizesArray;
                for (Int32 i = 0; i < _dataAccess.SupportedGameTableSizesArray.GetLength(0); ++i)
                {
                    if (_dataAccess.SupportedGameTableSizesArray[i] % 2 != 0 || _dataAccess.SupportedGameTableSizesArray[i] < 4)
                    {
                        throw new ReversiModelException();
                    }
                }
            }
            else
            {
                _supportedGameTableSizesArray = new Int32[] { 10 };
                defaultGameTableSizes = 10;
            }

            _tableSizeSetting = _tableSizeSettingDefault;
            _activeTableSize = 0;
            _isGameStarted = false;

            _timer = new Timer(1000, true);
            _timer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);

            _allDirections = new Direction[] { ToUp, ToRightUp, ToRight, ToRightDown, ToDown, ToLeftDown, ToLeft, ToLeftUp };
            _allReversedDirections = new Direction[] { ToDown, ToLeftDown, ToLeft, ToLeftUp, ToUp, ToRightUp, ToRight, ToRightDown };
        }
コード例 #4
0
        /// <summary>
        /// It is invoked, when the system build up the components of the window and the window itself.
        /// </summary>
        /// <param name="sender">This object, we do not use it as a param.</param>
        /// <param name="e">Auto param, we do not use it.</param>
        private void GameForm_Load(object sender, EventArgs e)
        {
            // Resizing to be symetric.
            _topRowMinimumWidth = _topFlowLayoutPanelForAll.Width + _topFlowLayoutPanelForAll.Margin.Left + _topFlowLayoutPanelForAll.Margin.Right;
            _topRowMinimumHeight = _topFlowLayoutPanelForAll.Height + _topFlowLayoutPanelForAll.Margin.Top + _topFlowLayoutPanelForAll.Margin.Bottom;
            _player1GroupBoxMarginLeftDefault = _player1GroupBox.Margin.Left;
            _bottomButtonPanelMarginLeftDefault = _bottomButtonPanel.Margin.Left;

            Width = _topRowMinimumWidth + (2 * 8);
            Height = _topRowMinimumHeight + _menuStrip.Height + _statusStrip.Height + 37;

            // Init the data access type with the array, that contain the default table sizes.
            _dataAccess = new ReversiFileDataAccess(_supportedGameTableSizesArray);

            try
            {
                // Init model
                _model = new ReversiGameModel(_dataAccess, _tableSizeDefaultSetting);
            }
            catch (ReversiModelException)
            {
                MessageBox.Show("Model initialization problem." + System.Environment.NewLine + System.Environment.NewLine + "Unsupportable table size given to model. The program will close.", "Reversi");
                Close();
            }

            // Connect the events.
            _model.SetGameEnded += new EventHandler<ReversiSetGameEndedEventArgs>(model_SetGameEnded);
            _model.UpdatePlayerTime += new EventHandler<ReversiUpdatePlayerTimeEventArgs>(model_UpdatePlayerTime);
            _model.UpdateTable += new EventHandler<ReversiUpdateTableEventArgs>(model_UpdateTable);

            // We let the user exit, without asking anything at this point.
            _saved = true;
        }