Пример #1
0
        public void TesseraTest()
        {
            PenteController pc = new PenteController(9, 9, "Boris", "Kyle");

            pc.isTesting = true;

            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    PenteCellectaCanvas canvas = new PenteCellectaCanvas(row, col, pc, 10, 10);
                }
            }
            pc.PlaceFirstPiece();      //black
            pc.AttemptPlacement(0, 7); //white
            pc.AttemptPlacement(0, 1); //black
            pc.AttemptPlacement(1, 7); //white
            pc.AttemptPlacement(0, 2); //black
            pc.AttemptPlacement(2, 7); //white
            pc.AttemptPlacement(0, 3); //black
            pc.AttemptPlacement(3, 7); //white

            pc.CheckWin(0, 7, true);
            pc.Yell(true, 4);
            Assert.AreEqual(true, pc.isTessera, $"Tria Yell Does Not Work its {pc.isTessera} ");
        }
Пример #2
0
        public void checkHorizontalWinTest()
        {
            PenteController pc = new PenteController(9, 9, "TESTER1", "TESTER2");

            pc.isTesting = true;

            for (int row = 0; row < 9; row++)
            {     //start of first loo0p
                for (int col = 0; col < 9; col++)
                { //start of second loop
                    PenteCellectaCanvas canvas = new PenteCellectaCanvas(row, col, pc, 10, 10);
                }//end of second loop
            }//end of first loop

            //Place 5 Pieces in a Row to see if check win method equals 5
            //Horizontally
            pc.PlaceFirstPiece();      //black
            pc.AttemptPlacement(0, 7); //white
            pc.AttemptPlacement(0, 1); //black
            pc.AttemptPlacement(1, 7); //white
            pc.AttemptPlacement(0, 2); //black
            pc.AttemptPlacement(2, 7); //white
            pc.AttemptPlacement(0, 3); //black
            pc.AttemptPlacement(3, 7); //white
            pc.AttemptPlacement(8, 1); //black
            pc.AttemptPlacement(4, 7); //white
            Assert.AreEqual(5, pc.CheckWin(3, 7, true), "Vertical Win Does Not Work");
            Assert.AreEqual(5, pc.CheckWin(0, 7, true), "Vertical Win Does Not Work");
            Assert.AreEqual(5, pc.CheckWin(1, 7, true), "Vertical Win Does Not Work");
            Assert.AreEqual(5, pc.CheckWin(2, 7, true), "Vertical Win Does Not Work");
            Assert.AreEqual(5, pc.CheckWin(4, 7, true), "Vertical Win Does Not Work");
        }
Пример #3
0
        public void checkDiagonalWinTest()
        {
            PenteController pc = new PenteController(9, 9, "tester1", "tester2");

            pc.isTesting = true;

            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    PenteCellectaCanvas canvas = new PenteCellectaCanvas(row, col, pc, 10, 10);
                }
            }
            //Place 5 Pieces in a Row to see if check win method equals 5
            //Diagonal

            pc.PlaceFirstPiece();      //black
            pc.AttemptPlacement(7, 4); //white
            pc.AttemptPlacement(1, 1); //black
            pc.AttemptPlacement(6, 5); //white
            pc.AttemptPlacement(8, 0); //black
            pc.AttemptPlacement(5, 6); //white
            pc.AttemptPlacement(4, 0); //black
            pc.AttemptPlacement(4, 7); //white
            pc.AttemptPlacement(0, 4); //black
            pc.AttemptPlacement(3, 8); //white

            Assert.AreEqual(5, pc.CheckWin(7, 4, true), $"Diagonal Win Does Not Work, Highest Count Is: {pc.CheckWin(0, 1, true)}");
            Assert.AreEqual(5, pc.CheckWin(3, 8, true), $"Diagonal Win Does Not Work, Highest Count Is: {pc.CheckWin(3, 8, true)}");
        }
Пример #4
0
        public void checkVerticalWinTest()
        {
            PenteController pc = new PenteController(9, 9, "TESTER1", "TESTER2");

            pc.isTesting = true;

            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    PenteCellectaCanvas canvas = new PenteCellectaCanvas(row, col, pc, 10, 10);
                }
            }
            //Place 5 Pieces in a Row to see if check win method equals 5
            //Vertically
            pc.PlaceFirstPiece();      //black
            pc.AttemptPlacement(7, 0); //white
            pc.AttemptPlacement(0, 1); //black
            pc.AttemptPlacement(7, 1); //white
            pc.AttemptPlacement(0, 2); //black
            pc.AttemptPlacement(7, 2); //white
            pc.AttemptPlacement(0, 3); //black
            pc.AttemptPlacement(7, 3); //white
            pc.AttemptPlacement(8, 1); //black
            pc.AttemptPlacement(7, 4); //white
            Assert.AreEqual(5, pc.CheckWin(7, 0, true), "Horizontal Win Does Not Work");
            Assert.AreEqual(5, pc.CheckWin(7, 1, true), "Horizontal Win Does Not Work");
            Assert.AreEqual(5, pc.CheckWin(7, 2, true), "Horizontal Win Does Not Work");
            Assert.AreEqual(5, pc.CheckWin(7, 3, true), "Horizontal Win Does Not Work");
            Assert.AreEqual(5, pc.CheckWin(7, 4, true), "Horizontal Win Does Not Work");
        }
Пример #5
0
        public void PlayerNameStoredTest()
        {
            PenteController pc = new PenteController(9, 9, "Boris", "Kyle");

            pc.isTesting = true;

            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    PenteCellectaCanvas canvas = new PenteCellectaCanvas(row, col, pc, 10, 10);
                }
            }
            Assert.AreEqual(true, pc.notWhitePlayer.Name == "Boris", "Player One Name Not Stored");
            Assert.AreEqual(true, pc.whitePlayer.Name == "Kyle", "Player Two Name Not Stored");
        }
Пример #6
0
        public void CaptureFiveWinsTest()
        {
            PenteController pc = new PenteController(9, 9, "TESTER1", "TESTER2");

            pc.isTesting = true;


            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    PenteCellectaCanvas canvas = new PenteCellectaCanvas(row, col, pc, 10, 10);
                }
            }
            pc.PlaceFirstPiece();      //black
            pc.AttemptPlacement(2, 1); //white
            pc.AttemptPlacement(1, 1); //black
            pc.AttemptPlacement(3, 1); //white
            pc.AttemptPlacement(4, 1); //black

            pc.AttemptPlacement(0, 5); //white
            pc.AttemptPlacement(0, 6); //black
            pc.AttemptPlacement(0, 4); //white
            pc.AttemptPlacement(0, 3); //black

            pc.AttemptPlacement(3, 7); //white
            pc.AttemptPlacement(2, 7); //black
            pc.AttemptPlacement(4, 7); //white
            pc.AttemptPlacement(5, 7); //black

            pc.AttemptPlacement(7, 3); //white
            pc.AttemptPlacement(7, 2); //black
            pc.AttemptPlacement(7, 4); //white
            pc.AttemptPlacement(7, 5); //black

            pc.AttemptPlacement(6, 0); //white
            pc.AttemptPlacement(5, 0); //black
            pc.AttemptPlacement(7, 0); //white
            pc.AttemptPlacement(8, 0); //black

            pc.checkCapture(4, 1, false);
            pc.checkCapture(0, 6, false);
            pc.checkCapture(6, 7, false);
            pc.checkCapture(7, 2, false);
            pc.checkCapture(8, 0, false);
            Assert.AreEqual(5, pc.NotWhiteCaptureCount, $"Capturing 5 Pairs Win Does Not Work Count Is: {pc.NotWhiteCaptureCount}");
        }
Пример #7
0
        public void SwitchBlackToWhiteTurnsTest()
        {
            PenteController pc = new PenteController(9, 9, "Boris", "Kyle");

            pc.isTesting = true;

            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    PenteCellectaCanvas canvas = new PenteCellectaCanvas(row, col, pc, 10, 10);
                }
            }
            pc.PlaceFirstPiece();      //black
            pc.AttemptPlacement(2, 3); //white
            Assert.AreEqual(false, pc.isWhitePlayersTurn, "Switching Turns DOes Not Work");
        }
Пример #8
0
        public void GridPiecePlacementTest()
        {
            PenteController pc = new PenteController(19, 19, "Tester1", "Tester2");

            pc.isTesting = true;
            for (int row = 0; row < 19; row++)
            {     //start of first loo0p
                for (int col = 0; col < 19; col++)
                { //start of second loop
                    PenteCellectaCanvas canvas = new PenteCellectaCanvas(row, col, pc, 20, 20);
                }//end of second loop
            }//end of first loop
            pc.PlaceFirstPiece();
            pc.AttemptPlacement(4, 7);
            pc.AttemptPlacement(0, 8);
            Assert.AreEqual(true, pc.board[4, 7].IsWhitePlayer, "The Piece Was not Places");
            Assert.AreEqual(true, !pc.board[0, 8].IsWhitePlayer, "Piece was not Placed");
        }
Пример #9
0
        /// <summary>
        /// Create canvas object with the "cell" argument as its datacontext
        /// </summary>
        /// <param name="cell">The PenteCellecaCanvas data to be bound to the canvas</param>
        /// <returns>A Canvas object to be used elsewhere</returns>
        private Canvas CreateCanvas(PenteCellectaCanvas cell)
        {
            // set a binding converter to get opacity based on an empty or filled cell
            Binding opacityBinding = new Binding("IsWhitePlayer")
            {
                Source    = cell,
                Converter = new BoolToOpacityConverter()
            };

            // set a binding converter to get piece color based on an empty or filled cell
            Binding colorBinding = new Binding("IsWhitePlayer")
            {
                Source    = cell,
                Converter = new BoolToBrushConverter()
            };

            // create the canvas for the grid
            Canvas canvas = new Canvas()
            {
                DataContext = cell,
                Background  = Brushes.Transparent
            };

            // create the shape to be a child of the canvas, representing a game board piece
            Ellipse s = CreatePiece();

            colorBinding.ConverterParameter = s;
            // set shape color based on current status of the piece (open, player1, or player2)
            s.SetBinding(ForegroundProperty, colorBinding);

            // set opacity binding for the canvas and piece based on who controls it
            canvas.SetBinding(OpacityProperty, opacityBinding);
            s.SetBinding(OpacityProperty, opacityBinding);

            // add shape
            canvas.Children.Add(s);

            // subscribe to action handlers
            canvas.PreviewMouseDown += cell.ProcessCanvas_Click;
            canvas.MouseEnter       += cell.ProcessCanvas_Hover;
            canvas.MouseLeave       += cell.ProcessCanvas_Hover;

            return(canvas);
        }
Пример #10
0
        public void BlackSecondMoveOutOfBoundaryTest()
        {
            PenteController pc = new PenteController(9, 9, "Boris", "Kyle");

            pc.isTesting = true;

            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    PenteCellectaCanvas canvas = new PenteCellectaCanvas(row, col, pc, 10, 10);
                }
            }
            pc.PlaceFirstPiece();      //black
            pc.AttemptPlacement(1, 4); //white
            pc.AttemptPlacement(4, 3); //black
            pc.AttemptPlacement(3, 4); //white

            Assert.AreEqual(null, !(pc.board[4, 3].IsWhitePlayer), "Black Cannot Place Piece In Boundary");
        }
Пример #11
0
        public void CaptureDiagonalStoneTest()
        {
            PenteController pc = new PenteController(9, 9, "TESTER1", "TESTER2");

            pc.isTesting = true;

            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    PenteCellectaCanvas canvas = new PenteCellectaCanvas(row, col, pc, 10, 10);
                }
            }
            pc.PlaceFirstPiece();      //black
            pc.AttemptPlacement(3, 3); //white
            pc.AttemptPlacement(0, 0); //black
            pc.AttemptPlacement(2, 2); //white
            pc.AttemptPlacement(1, 1); //black
            pc.checkCapture(3, 3, false);

            Assert.AreEqual(null, pc.board[2, 2].IsWhitePlayer, "Diagonal Capture Stones Does Not Work");
            Assert.AreEqual(null, pc.board[3, 3].IsWhitePlayer, "Diagonal Capture Stones Does Not Work");
        }
Пример #12
0
        /// <summary>
        /// Creates the base grid for the gameboard, which will be interacted with during gameplay.
        /// Holds pieces and data relevent to game decisions.
        /// </summary>
        public void CreateGrid()
        {
            // for each row in the grid
            for (int row = 0; row < GameBoardRowCount; row++)
            {
                // for each column in this row
                for (int col = 0; col < GameBoardColumnCount; col++)
                {
                    // create the base label object that will interact with the players
                    PenteCellectaCanvas cell = new PenteCellectaCanvas(col, row, penteController, CELL_HEIGHT, CELL_WIDTH);
                    cell.timer = countdownTimer;
                    Canvas canvas = CreateCanvas(cell);

                    // add the label to the grid
                    mainGrid.Children.Add(canvas);
                }         // end inner for loop
            }             // end outer for loop
            Binding binding1 = new Binding("CurrentPlayerName")
            {
                Source = penteController
            };

            lblCurrentPlayer.SetBinding(ContentProperty, binding1);
        }
Пример #13
0
 public void PutCanvas(int x, int y, PenteCellectaCanvas canvas)
 {
     //Console.WriteLine(x + " " + y);
     board[x, y] = canvas;
 }