Beispiel #1
0
        public void InitGame()
        {
            Width  = WindowSize;                                           // Set width of form
            Height = WindowSize;                                           // Set height of form

            MainPanel.Paint     += OnDraw;                                 // Add a Paint Event Handler
            MainPanel.MouseDown += OnMousePress;                           // Add a Mouse Event Handler

            FieldWidth  = (MainPanel.Width - BordMargin * 2) / BoardSize;  // Set width of the grid fields
            FieldHeight = (MainPanel.Height - BordMargin * 2) / BoardSize; // Set height of the grid fields

            XOSize = FieldWidth / 2;                                       // Set size of Xs and Os to half the width of a field

            BoardState = new FieldState[BoardSize, BoardSize];             // Initialize two dimensional grid array
            for (int c = 0; c < BoardSize; c++)
            {
                for (int r = 0; r < BoardSize; r++)
                {
                    BoardState[c, r] = FieldState.EMPTY; // Set default value to empty state
                }
            }

            Logic = new GameLogic(this);             // Initialize game logic
            Logic.CreateNewPlayer(PlayerType.HUMAN); // Assign player 1 to X
            Logic.CreateNewPlayer(PlayerType.ROBOT); // Assign bot to O

            Logic.StartGame();                       // Starts the game
        }