Esempio n. 1
0
        public static void Start()
        {
            Board board = new Board();

            board.GenerateCheckers();

            board.PlaceCheckers();
            board.DrawBoard();
            while (!board.CheckForWin())
            {
                Checker temp   = board.SelectChecker();
                int     oldRow = temp.Position[0];
                int     oldCol = temp.Position[1];
                board.MoveChecker2(temp);
                int newRow = temp.Position[0];
                int newCol = temp.Position[1];
                board.DeleteChecker(newRow, oldRow, newCol, oldCol);
                board.CreateBoard();
                board.PlaceCheckers();
                board.DrawBoard();
                if (board.CheckForWin())
                {
                    System.Console.WriteLine("Game Over!");
                    return;
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Board board = new Board();

            board.GenerateCheckers();
            board.DrawBoard();

            Console.WriteLine("Did you want to 'move' or 'remove' a piece?");
            string read = Console.ReadLine();

            do
            {
                switch (read)
                {
                case "move":
                    Console.WriteLine("Select checker row:");
                    int row = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Select checker column:");
                    int col = Convert.ToInt32(Console.ReadLine());

                    if (board.SelectChecker(row, col) != null)
                    {
                        Checker checker = board.SelectChecker(row, col);
                        Console.WriteLine("Move to new row:");
                        int newRow = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Move to new column:");
                        int newCol = Convert.ToInt32(Console.ReadLine());
                        checker.Position = new int[] { newRow, newCol };
                        board.DrawBoard();
                    }
                    else
                    {
                        Console.WriteLine("Invalid Move");
                        Console.WriteLine("Select checker row:");
                        row = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Select checker column:");
                        col = Convert.ToInt32(Console.ReadLine());
                    }

                    break;

                case "remove":
                    Console.WriteLine("Select the row of the checker to remove:");
                    int removeRow = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Select the column of the checker to remove:");
                    int     removeCol   = Convert.ToInt32(Console.ReadLine());
                    Checker doneChecker = board.SelectChecker(removeRow, removeCol);
                    board.RemoveChecker(doneChecker);
                    board.DrawBoard();
                    break;

                default:
                    Console.WriteLine("I didn't get that.. what was that again?");
                    break;
                }
            } while (board.CheckForWin() != true);

            // Below is for debugging
            // Console.WriteLine("hello, world");
        }
Esempio n. 3
0
        public Game()
        {
            Board board = new Board();

            board.GenerateCheckers();
            board.DrawBoard();
            while (!board.CheckForWin())
            {
                board.MoveChecker();
            }
        }
Esempio n. 4
0
        public Game()
        {
            // Your code here
            Board board = new Board();

            board.GenerateCheckers();
            board.DrawBoard();

            while (board.CheckForWin())
            {
                // Checker Movement
                board.MoveChecker();
                // Redraw Board
                board.DrawBoard();
            }
        }
Esempio n. 5
0
        public void startGame()
        {
            // instantiate a new instance of Board called boardgame
            Board boardgame = new Board();
            // initialize starting game color
            String color = "white";
            // create a boolean to see if checker placement was valid
            bool placedChecker;
            // create a boolean to see if checker was removed
            bool removedChecker;

            // call CreateBoard method on instance of board
            boardgame.CreateBoard();

            // loop that will run as long as there is no winner
            do
            {
                //Console.Clear();
                // call method that will output to the screen the board with its checkers in appropriate places
                Console.WriteLine(boardgame.DrawBoard());

                // user selects a checker to move
                Console.WriteLine($"{color}, please enter a row to move from:");
                int originRow = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine($"{color}, please enter a column to move from:");
                int     originColumn = Convert.ToInt32(Console.ReadLine());
                Checker checker      = boardgame.SelectChecker(originRow, originColumn, color);

                // Console.Clear();
                // Console.WriteLine(boardgame.DrawBoard());

                // place the checker in position on board based on user input
                Console.WriteLine("Please enter the row to move to: ");
                int destinationRow = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Please enter the column to move to: ");
                int destinationColumn = Convert.ToInt32(Console.ReadLine());
                placedChecker = boardgame.PlaceChecker(originRow, originColumn, destinationRow, destinationColumn, checker);
                if (placedChecker == false)
                {
                    do
                    {
                        Console.WriteLine(boardgame.DrawBoard());
                        // user selects a checker to move
                        Console.WriteLine($"{color}, please enter a row to move from:");
                        originRow = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine($"{color}, please enter a column to move from:");
                        originColumn = Convert.ToInt32(Console.ReadLine());
                        checker      = boardgame.SelectChecker(originRow, originColumn, color);

                        // Console.Clear();
                        // Console.WriteLine(boardgame.DrawBoard());

                        // place the checker in position on board based on user input
                        Console.WriteLine("Please enter the row to move to: ");
                        destinationRow = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Please enter the column to move to: ");
                        destinationColumn = Convert.ToInt32(Console.ReadLine());
                        placedChecker     = boardgame.PlaceChecker(originRow, originColumn, destinationRow, destinationColumn, checker);
                    }while(placedChecker == false);
                }

                // Console.Clear();
                //Console.WriteLine(boardgame.DrawBoard());

                // Removes jumped checker and the jumping checker from it's origin if checker was jumped
                // or just removes the checker from its origin if a checker is not jumped
                removedChecker = boardgame.RemoveChecker(originRow, originColumn, destinationRow, destinationColumn, checker);

                //Console.Clear();
                Console.WriteLine(boardgame.DrawBoard());

                // Checks if a Checker was removed in the turn. If there was and that player did not win,
                // program asks the player if they can make another move by jumping another opponent's Checker with
                // the same Checker they just played with. If player says no, it becomes the other players turn.
                // If no checker was removed, it becomes the other person's turn
                if (removedChecker && !boardgame.CheckForWin())
                {
                    String userInput = "";
                    do
                    {
                        Console.WriteLine("Do you have another move you can make with the same checker? [Y/N]");
                        userInput = Console.ReadLine().ToLower();
                    }while (userInput != "y" && userInput != "n");

                    if (userInput == "n")
                    {
                        if (color == "white")
                        {
                            color = "black";
                        }
                        else
                        {
                            color = "white";
                        }
                    }
                }  // Changes the player turn
                else if (!removedChecker)
                {
                    if (color == "white")
                    {
                        color = "black";
                    }
                    else
                    {
                        color = "white";
                    }
                }
            }while(!boardgame.CheckForWin());

            Console.WriteLine("{0} wins!!!", color);
        }
Esempio n. 6
0
        public Game()
        {
            Board board = new Board();

            board.GenerateCheckers();
            board.DrawBoard();

            Console.WriteLine("\nIf you want to move a checker one space diagonally forward, enter 'move'.");
            Console.WriteLine("\nIf a jump is available for one of your checker, you must enter 'jump'.");

            string choice = Console.ReadLine();

            do
            {
                switch (choice)
                {
                case "move":

                    Console.WriteLine("Enter checker Row to move:");
                    int row = int.Parse(Console.ReadLine());
                    Console.WriteLine("Enter checker Column:");
                    int column = int.Parse(Console.ReadLine());

                    if (board.SelectChecker(row, column) != null)
                    {
                        Checker checker = board.SelectChecker(row, column);
                        Console.WriteLine("Move to which Row: ");
                        int newRow = int.Parse(Console.ReadLine());
                        Console.WriteLine("Move to which Column: ");
                        int newColumn = int.Parse(Console.ReadLine());
                        checker.Position = new int[] { newRow, newColumn };
                        board.DrawBoard();
                    }
                    else
                    {
                        Console.WriteLine("Invalid input");
                        Console.WriteLine("Enter a valid checker Row:");
                        row = int.Parse(Console.ReadLine());
                        Console.WriteLine("Enter a valid checker Column:");
                        column = int.Parse(Console.ReadLine());
                    }
                    break;

                case "jump":

                    Console.WriteLine("Select checker Row to remove:");
                    int removeRow = int.Parse(Console.ReadLine());
                    Console.WriteLine("Select checker Column to remove:");
                    int     removeColumn  = int.Parse(Console.ReadLine());
                    Checker changeChecker = board.SelectChecker(removeRow, removeColumn);
                    board.RemoveChecker(changeChecker);
                    board.DrawBoard();
                    break;

                default:

                    Console.WriteLine("Invalid input.");
                    break;
                }
            } while (board.CheckForWin() != true);
        }
Esempio n. 7
0
        public Game()
        {
            Board board = new Board();

            board.GenerateCheckers();
            board.DrawBoard();

            // need to keep track of whose go it is, so it always goes b, w, b etc.
            string whoseTurn = "black";

            while (!board.CheckForWin())

            {
                bool validMove = false;
                Console.WriteLine("Select checker row:");
                int row = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Select checker column:");
                int col = Convert.ToInt32(Console.ReadLine());

                Checker checker = board.SelectChecker(row, col);

                // should now check if the checker exists and is the right color e.g.
                //if (!(checker == null) && (whoseTurn == checker.Color)
                //{}

                Console.WriteLine("Please move checker to an empty space.");
                Console.WriteLine("Move to which row:");
                int newRow = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Move to which Column:");
                int newCol = Convert.ToInt32(Console.ReadLine());

                // First we need to check if it's a valid move, i.e. it's either 1 diagonal away from the existing position, or it's 2 diagonals jumping over an opponent checker...

                Checker newPosChecker = board.SelectChecker(newRow, newCol);
                if (newPosChecker == null) // there's nothing there yet, so far so good
                {
                    // Is it one diagonal apart?
                    if (Math.Abs((row - newRow) * (col - newCol)) == 1) // it is exactly 1 row and 1 column apart?
                    {
                        validMove = true;
                        //checker.Position = new int[] { newRow, newCol }; // SEM - moved to below
                    }

                    // or is it exactly 2 row and 2 columns apart, with a checker in between?
                    else
                    {
                        if ((Math.Abs(row - newRow) == 2) && (Math.Abs(col - newCol) == 2)) // exactly 2 squares away, so far so good
                        {
                            // now to check whether something got jumped over ...?
                            int     deadCheckerRow = (row + newRow) / 2;
                            int     deadCheckerCol = (col + newCol) / 2;
                            Checker deadChecker    = board.SelectChecker(deadCheckerRow, deadCheckerCol);
                            if (!(deadChecker == null)) // and do we need to check the color of it? Can you jump over your own checkers?
                            {
                                validMove = true;
                                // remove the dead checker
                                board.RemoveChecker(deadChecker);
                                board.Grid[deadCheckerRow][deadCheckerCol] = " "; // the checker is removed, the grid position needs to be cleared
                            }
                        }
                    }
                }
                if (validMove == true)
                {
                    checker.Position     = new int[] { newRow, newCol };
                    board.Grid[row][col] = " "; // the checker is moved, the grid position needs to be cleared
                    whoseTurn            = SwitchTurns(whoseTurn);
                }
                else
                {
                    Console.WriteLine("Not a legal move");
                    Console.WriteLine("Enter any key");
                    Console.ReadLine();
                }
                board.DrawBoard();
            }
        }
Esempio n. 8
0
        public Game()
        {
            // initialize game
            Board board = new Board();

            board.CreateBoard();
            board.GenerateCheckers();
            board.PlaceCheckers();
            board.DrawBoard();
            turn = "black";

            while (!board.CheckForWin())
            {
                if (turn == "black")
                {
                    Console.WriteLine("Black's turn");
                }
                else
                {
                    Console.WriteLine("White's turn");
                }
                jump = board.jumpAvailable(this, this.turn);
                Console.Write("Enter starting row and column, " +
                              "separated by a comma: ");
                string rowAndColumn = Console.ReadLine();
                Regex  regex        = new Regex(@"\d, *\d");
                Match  match        = regex.Match(rowAndColumn);
                if (rowAndColumn != match.Value || rowAndColumn == "")
                {
                    Console.WriteLine("Invalid entry");
                    continue;
                }
                string[] coordinates    = rowAndColumn.Split(",");
                int      startingRow    = Convert.ToInt32(coordinates[0]) - 1;
                int      startingColumn = Convert.ToInt32(coordinates[1]) - 1;
                if (jump && !(jumpCheckers.Any(
                                  checker => startingRow == checker.Position[0] &&
                                  startingColumn == checker.Position[1])))
                {
                    Console.WriteLine("Invalid move");
                    jumpCheckers.Clear();
                    continue;
                }
                Checker movingChecker;
                if (board.Checkers.Find(checker => checker.Position.SequenceEqual(
                                            new int[] { startingRow, startingColumn })) != null)
                {
                    movingChecker =
                        board.Checkers.Find(checker => checker.Position.SequenceEqual(
                                                new int[] { startingRow, startingColumn }));
                }
                else
                {
                    Console.WriteLine("Invalid selection");
                    movingChecker = null;
                    continue;
                }

                board.SelectChecker(startingRow, startingColumn);
                Console.Write("Enter ending row and column, " +
                              "separated by a comma: ");
                rowAndColumn = Console.ReadLine();
                match        = regex.Match(rowAndColumn);
                if (rowAndColumn != match.Value || rowAndColumn == "")
                {
                    Console.WriteLine("Invalid entry");
                    continue;
                }
                coordinates = rowAndColumn.Split(",");
                int endingRow    = Convert.ToInt32(coordinates[0]) - 1;
                int endingColumn = Convert.ToInt32(coordinates[1]) - 1;
                if (jump && !(jumpCheckers.Any(
                                  checker => Math.Abs(endingRow - checker.Position[0]) == 2 ||
                                  Math.Abs(endingColumn - checker.Position[1]) == 2)))
                {
                    Console.WriteLine("Invalid move");
                    jumpCheckers.Clear();
                    continue;
                }
                board.MoveChecker(movingChecker, endingRow, endingColumn);
                jumpCheckers.Clear();

                if (turn == "black")
                {
                    turn = "white";
                }
                else
                {
                    turn = "black";
                }
            }
        }