Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this project you will implement the game ofGomoku(called Wuziqi in China). Rules of the game: The game is played on a grid of squares

For this project you will implement the game ofGomoku(called Wuziqi in China).

Rules of the game:

The game is played on a grid of squares for two players: Black and White. Black moves first. Each player alternates playing pieces on the board. Once played, a piece cannot be moved. A player wins if they get five of their pieces in a row, horizontally, vertically, or diagonally. In addition, we will add the following additional rules.

  • Overline:There must be exactly five in a row to win. Six or more in a row does not win, and the game continues.
  • Four-Four:A player may not make a move if that move simultaneously creates two or more groups of four in a row.
  • Three-ThreeA player may not make a move if that move simultaneously creates two or more groups of three in a row such that both ends of the three have empty squares.

Traditionally, the game is played on the intersections instead of the squares of the grid, but for simplicity, you can have the game played on the squares.

What you must do:

Important:Read the instructions for the testing part of this project. You need to design your code so that it is easy to test. If you put off writing the testing code to the end of the project, you may need to rewrite your code to get testing to work.

You are to create a class calledGomoku. TheGomokuclass extend the JavaFX Appliction class.

Designing your program

Below the instructions provide the basic steps you need to accomplish to get your game to work. However, it isstronglyrecommended that you spend some time designing what you will be coding before you code. It isvery stronglyrecommended that you employ helper methods and/or additional classes in the design of this game. Doing so will shorten the amount of work you need to do. As a hint, if you find yourself writing the same piece of code over and over, it might be easier to either write a helper method to do that operation or to write a class that extends the class you are working with so that the class a method that does what you need.

Create the board

You are to create a board by making a two-dimensional grid ofButtons. This simplest way to to that is to create aGridPaneinstance that will hold the buttons, and add theGridPaneto the JavaFXScene.

You can then create a 2-dimensional array ofButtons and add them to theGridPaneusing theaddmethod ofGridPanewith the appropriate values so that the location of a button in the array corresponds to its location in the display grid. (You are welcome to change this, but you should have a two-dimensional array in your program somewhere that stores the current board situation.)

For the basic display, you should give each button a color. There will be three basic visuals.

  • A "blank square" will be a button with a green background. You usesetBackgroundto set theBackgroundFills for the button, and doing that, you can set the color. Also set theInsetsfor theBackgroundFillso that the edges of the button are visible. (Be sure to look at the API so you understand what this refers to.)
  • A square with a player's piece on it will have a background that is a white or black piece on top of a green background. You again use thesetBackgroundmethod, but now the piece should be either white or black, and you should set both theInsetsand theCornerRadiiso that the piece looks like a round stone in the middle of the square.

You are welcome to change these visuals if you wish.Here is a picture of what your board should look like in the middle of a game:

image text in transcribed
\f

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

Students also viewed these Programming questions