Sie sind auf Seite 1von 3

Final Project: Write a simple dice program (Farkle Lite)

Simple Farkle Game


Understand the Problem

You will need to use a Java IDE of your choice, preferably IntelliJ IDEA.
Utilize the Model-View-Controller design pattern.
Implement a stopwatch, using multi-threading, into the same GUI as the game.
Create a button to roll the dice, and implement it using ActionListeners and ActionEvents
Practice implementing 2-D arrays with randomization to simulate a real dice roll

Download the dice images (.pngs)

Download the dice face images here: http://www.filedropper.com/dice-images

Select “Download This File”

Phase 1: Build the dice .png files and store them into an Icon array

Start by creating a static class in the Model. Declare a linear Icon array that holds 7 elements (Farkle uses 6 dice per
initial roll, but starting all indexes with 1, in this program, will make it much easier.

Phase 2: Create a method in the Model to get the score of each roll

In Farkle, 1s are 100 points and 5s are 50 points. Design a method that will take in an Icon argument and use logic to
return the correct point value. Use the values of the Icon array declared in the Model class to help with the logic.

Phase 3: Build the view

Create a DiceTable class within the View that will declare all panels to be used in the GUI:

pnlPlayArea, pnlTotalPoints, pnlHumanKeptDice, pnlRollButton

The constructor should instantiate JPanel objects for each panel and set the background colors of the GUI. It should also
add borders to easily distinguish which panel is which.

Stopwatch

Create a class for the stopwatch. To make this easier, keep in mind the number of milliseconds per second, hour, and
minute:
final static int MS_PER_SECOND = 1000;
final static int MS_PER_HOUR = 3_600_000;
final static int MS_PER_MINUTE = 60_000;

That said, design the stopwatch to display hours, minutes, and seconds. Include a Start and Reset button. The Start
button should turn into a Stop button, and back into a Start button when selected.

Design Packer and doNothing methods for multithreading.

Phase 4: Build the Controller

The controller should declare a 7x7 2-D array. Each row will store dice 1-6, and then dice from each row will be randomly
selected to be displayed on the GUI. Create a method to generate the JButton instances for each 2-D array element.
Create a method to fill each element with a dice icon. Create a method using Math.random() that returns a random
integer. The integer will be used to select random dice from each row. Create a method to roll each dice on the GUI.
Lastly, create a method that will allow the user to select the 1 and 5 dice and allocate them to the keptDice panel. To
begin the game, the GUI should start with 6 dice when the roll button is initially clicked. Add the rules of the game
somewhere on the GUI so the user understands the game.

Testing

Select Roll to begin the game. 6 dice should appear on the screen. Select every 1 and 5 that you see. They should
allocate to the left panel. Roll the dice again and repeat until you receive dice that don’t include a 1 or 5. From there,
you should select the dice anyway, and confirm that they don’t add anything to the total points. After getting the popup
that asks you to re-roll, do so and verify that 6 new dice appear on the table.

Das könnte Ihnen auch gefallen