Computers and Technology

Triangle peg solitaire is a game where you start with several pegs at fixed locations on a triangular board. there is one location that does not have a peg in it. this location can be anywhere on the board, but it is usually the bottom-middle spot. you remove pegs one at a time by jumping over other pegs to empty slots, removing the jumped pegs from the board. you can only jump over the nearest neighbor pegs. the goal is to have only one peg remaining at the end.
• red pegs are pegs that currently cannot jump over any other pegs. • purple pegs are pegs that currently can jump over at least one other peg. • the green peg (after the first jump) is a peg that can be used to find the optimal solution (fewest pegs left at the end) from the current board configuration.
starting files:
• trianglepegsolitaire. zip • pegstate. java • pegs. java • pegfirstclickstate. java • pegsecondclickstate. java
lab:
• interfaces • dynamic changeability • two-way has-a • state design pattern
part i: peg state
triangle peg solitaire has three distinct states.
• first click: a clicked on peg has only one possible jump, so take that jump. • second click: a clicked on peg has two possible jumps, so two mouse clicks are required to execute the jump. • game over: there are no more legal jumps (the game is over). the next click will start a new game with the clicked-on location as the open spot.
what the states have in common is that they are all activated on a mouse click. take a look at pegstate. java. the only method in this interface is mouseclicked. the states that you will be writing will implement this interface.
part ii: pegs
use the state design pattern to complete pegs. java. remember that this design pattern requires a two-way has-a relationship. the states that you will need are pegfirstclickstate, pegsecondclickstate, and peggameoverstate. note that pegs has methods to determine if a peg has been clicked on or if an open slot has been clicked on. you will need both of these!
• public int findselectedpeg(int x, int y) o used to find out which peg was clicked on • public int findselectedslot(int x, int y) o used to find out which slot was clicked on • public arraylist getpossiblejumps(int select) o returns an arraylist of the possible jumps from pegs
part iii: the states
complete the three states. you will need to call methods on pegs. java. for peggameoverstate the mouseclicked method looks for the clicked-on slot. this slot becomes the open space for the new game. an invalid click stays in peggameoverstate.
the main method is in the trianglepegsolitaire class.
part 1:
pegstate. java
public interface pegstate
{
public void mouseclicked(int x, int y);
}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 15:00, MrTeriffic
1. what are the biggest risks when using the public internet as a wide area network (wan) or transport for remote access to your organization’s it infrastructure?
Answers: 2
image
Computers and Technology, 22.06.2019 06:30, westjayson69
Requirement types discussed during software development include functional and color scheme nonfunctional and code style constraint and nonfunctional fashionable and functional.
Answers: 2
image
Computers and Technology, 24.06.2019 18:00, bloop3r
Why is a multiview sketch drawinf different from other sketches like isometric, two point, and oblique
Answers: 1
image
Computers and Technology, 24.06.2019 22:10, gabriellabadon2
In command prompt, whats a command that will list only .ini files in c: \windows\system32 directory?
Answers: 1
Do you know the correct answer?
Triangle peg solitaire is a game where you start with several pegs at fixed locations on a triangula...

Questions in other subjects:

Konu
Geography, 21.09.2019 19:00
Konu
History, 21.09.2019 19:00