Exemple #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
        }
Exemple #2
0
 static void Main(string[] args)
 {
     IUI ui = new ConsoleUI();
     GameLogic Game = new GameLogic(ui);
     Game.StartGame();
     Console.WriteLine("Thank you for playing hope to see again ");
     Console.ReadKey();
 }
Exemple #3
0
        public void TestingWinIn9Moves()
        {
            //Arange
            int[,] WinIn9 = new int[9, 2] { { 2, 2 }, { 2, 3 }, { 3, 2 }, { 1, 2 }, { 1, 3 }, { 3, 1 }, { 3, 3 }, { 2, 1 }, { 1, 1 } };
            MockUI ui = new MockUI(WinIn9, 9);
            bool expected = true;

            //Act
            GameLogic Game = new GameLogic(ui);
            Game.StartGame();
            bool actual = ui.GetAnnounceWinner();

            //Assert
            Assert.AreEqual(expected, actual);
        }
Exemple #4
0
        public void TestingAnotherGame()
        {
            //Arange
            int[,] anotherGame = new int[9, 2] { { 2, 2 }, { 2, 3 }, { 3, 2 }, { 1, 2 }, { 1, 3 }, { 3, 1 }, { 3, 3 }, { 1, 1 }, { 2, 1 } };
            MockUI ui = new MockUI(anotherGame, 9);
            bool expected = true;

            //Act
            GameLogic Game = new GameLogic(ui);
            Game.StartGame();
            bool actual = ui.GetAnnounceDraw();

            //Assert
            Assert.AreEqual(expected, actual);
        }