CMPS109 Programming Assignment 4

 

Objective

The objective of this assignment is to become familiar with building a Graphical User Interface (GUI) and event driven programming. You will do this in Java using Swing components.

Gomoku

 

For this assignment you will implement a two person game, Gomoku, to be played by two people sharing a single computer (taking turns with the mouse).

“Gomoku , also written Go-Moku is a Japanese board game traditionally played with Go pieces and board (black and white stones on a 19x19 line board). The stones are placed on the intersections of the board, with Black playing first. The winner is the first player to get an unbroken row of five stones, either orthogonally or diagonally.” (Taken directly from http://en.wikipedia.org/wiki/Gomoku which you can consult for more details.)

Your program should follow just the basic rules (called free-style in the referenced link above).

 

A Gomoku Playing Board

 

·         Your program should display the board as a rectangular grid of lines with black and white circles placed at the intersections to represent the pieces.

·         Black always moves first.

·         You should use some type of highlighting to distinguish the most recently played stone.

·         Your program should detect when the game has been won and highlight the winning row of stones.

·         Your program should allow for a sequence of games, displaying the number of wins by each player somewhere on the display.

·         Your program should have a File menu with Save, Load, and Exit. Save prints the current game to a user user selected file (use JFileChooser). Load sets the board using the contents of a file from a saved game. Exit ends the program after first confirming that the user really wanted to quit.

·         The file format for saved games should be a simple text file. The first line will contain a single integer, the size of the board. If the first line contains N then the following N lines must contain N characters plus a newline. The characters must be wither ‘.’, ‘B’, or ‘W’ with the obvious meanings of empty, Black, and White. If a load command encounters any problems with the input file it should display an alert indicating a problem with the file and then display the default empty 19x19 board.

·         Your program should include a menu item that allows the user to select a board size between 9x9 and 19x19. You can either allow for a specific set of choices (make sure there are at least three – 9x9, 15x15, and 19x19) or you can let them chose any board size in the range 9 to 19.

·         It is up to you if they are allowed to change the board size in the middle of a match. They should not be allowed to change the board size in the middle of a game.

·         If the board fills without a winner, declare it a draw ending the game with no score for either player.

·         Please put your main method in a class called Gomoku.

 

Extra Credit

 

A nice extra credit option would be to allow your program to be used either by two people, or by one person with the computer playing the other color.

Extra credit will also be given to a fully working program that creates a visually pleasing board (i.e. use images for the stones instead of simple black and white filled circles).