Exemplo n.º 1
0
        //Purpose: Displays the board in the console
        //Parameter: The board to display
        public void displayBoard(Board board)
        {
            char Rows = 'A';

            Console.Write("      0     1     2     3     4     5     6     7     8      \n");
            for (int i = 0; i < board.getSize(); i++)
            {

                if (i % 3 == 0)
                {
                    Console.Write("  ========================================================= \n");
                }
                else
                {
                    Console.Write("  --------------------------------------------------------- \n");
                }

                Console.Write(Rows);
                for (int j = 0; j < board.getSize(); j++)
                {
                    if (j % 3 == 0)
                    {
                        if (board.getValue(i, j) == 0)
                        {
                            Console.Write(" |||  ");
                        }
                        else if (board.getOriginalValue(i, j) == true)
                        {
                            Console.Write(" |||" + board.getValue(i, j) + "'");
                        }
                        else
                        {
                            Console.Write(" ||| " + board.getValue(i, j));
                        }
                    }
                    else
                    {
                        if (board.getValue(i, j) == 0)
                        {
                            Console.Write("  |   ");
                        }
                        else if (board.getOriginalValue(i, j) == true)
                        {
                            Console.Write("  | " + board.getValue(i, j) + "'");
                        }
                        else
                        {
                            Console.Write("  |  " + board.getValue(i, j));
                        }
                    }
                }

                Console.Write(" ||| \n");
                Rows++;
            }

            Console.Write("  ========================================================= \n");
        }
Exemplo n.º 2
0
        //Purpose: Displays the board in the console
        //Parameter: The board to display
        public void displayBoard(Board board)
        {
            char Rows = 'A';


            Console.Write("      0     1     2     3     4     5     6     7     8      \n");
            for (int i = 0; i < board.getSize(); i++)
            {
                if (i % 3 == 0)
                {
                    Console.Write("  ========================================================= \n");
                }
                else
                {
                    Console.Write("  --------------------------------------------------------- \n");
                }

                Console.Write(Rows);
                for (int j = 0; j < board.getSize(); j++)
                {
                    if (j % 3 == 0)
                    {
                        if (board.getValue(i, j) == 0)
                        {
                            Console.Write(" |||  ");
                        }
                        else if (board.getOriginalValue(i, j) == true)
                        {
                            Console.Write(" |||" + board.getValue(i, j) + "'");
                        }
                        else
                        {
                            Console.Write(" ||| " + board.getValue(i, j));
                        }
                    }
                    else
                    {
                        if (board.getValue(i, j) == 0)
                        {
                            Console.Write("  |   ");
                        }
                        else if (board.getOriginalValue(i, j) == true)
                        {
                            Console.Write("  | " + board.getValue(i, j) + "'");
                        }
                        else
                        {
                            Console.Write("  |  " + board.getValue(i, j));
                        }
                    }
                }

                Console.Write(" ||| \n");
                Rows++;
            }

            Console.Write("  ========================================================= \n");
        }
Exemplo n.º 3
0
 //Purpose: Checks the player's input to make sure it is valid
 //Parameters: the row, column, and the value
 //Returns: False if the input is invalid, else true
 public static Boolean checkInput(int userRow, int userColumn, int userValue, Board board)
 {
     if(userRow >= board.getSize() || userColumn >= board.getSize())
     {
         return false;
     }
     else if (userValue > 9 || userValue < 0)
     {
         return false;
     }
     else
     {
         return true;
     }
 }
Exemplo n.º 4
0
        }//end of play game

        //Purpose: Checks the player's input to make sure it is valid
        //Parameters: the row, column, and the value
        //Returns: False if the input is invalid, else true
        public static Boolean checkInput(int userRow, int userColumn, int userValue, Board board)
        {
            if (userRow >= board.getSize() || userColumn >= board.getSize())
            {
                return(false);
            }
            else if (userValue > 9 || userValue < 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 5
0
 //Purpose: Checks for a win
 //Parameters: the board
 //Returns: True if the player has won, else false
 public static Boolean checkForWin(Board board)
 {
     //check each space for a 0
     for (int i = 0; i < board.getSize(); i++)
     {
         for (int j = 0; j < board.getSize(); j++)
         {
             if (board.getValue(i, j) == 0)
             {
                 return(false);
             }
         }
     }
     //if all spaces have a value, then the player has won
     return(true);
 }
Exemplo n.º 6
0
        //Purpose: Checks for a win
        //Parameters: the board
        //Returns: True if the player has won, else false
        public static Boolean checkForWin(Board board)
        {
            //check each space for a 0
            for(int i = 0; i < board.getSize(); i++)
            {
                for (int j = 0; j < board.getSize(); j++)
                {
                    if (board.getValue(i,j) == 0)
                    {
                        return false;
                    }
                }

            }
            //if all spaces have a value, then the player has won
            return true;
        }