Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

how would I code a game of connect four using JAVA and the StdDraw class (it is very important that the code uses the StdDraw

how would I code a game of connect four using JAVA and the StdDraw class (it is very important that the code uses the StdDraw class) the requirements are below The game should follow all the rules of Connect 4. The rules include (but are not limited to) the following: The board should have 6 rows and 7 columns. Randomly choose which player goes first. Players alternate turns. Each time a player has a turn, they must drop one piece into a column of their choice. When a piece is dropped in a column, that piece should fall to the lowest possible spot in that column. Players cannot drop pieces into columns that are already filled up. The game is over whenever the first player connects four in a row either vertically, horizontally, or diagonally (note that there are two possible diagonal directions: [1] Lower-left to upper-right, and [2] Upper-left to lower-right). No additional pieces can be played once the game is over. Ties are possible. This happens when the board is completely filled up with pieces and neither player has four in a row. Specific Coding Requirements The board must be a 2D int array called board. The 2D array board should always have one of three possible values in each spot: 0- if there is no piece at that spot. 1- if player 1's piece is at the spot. 2- if player 2's piece is at the spot. You must have the following method declaration in your code. public static int checkForWinner (int[][] board) When you call this method, you must pass board as a parameter. The method should return the following int values once you have scanned through the board: 0- if there is no winner. 1- if player 1 is the winner. 2- if player 2 is the winner. 3- if there is a tie.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions