subject

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);
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 08:00
Apex q: what does a low employment rate indicate? a. not many people are earning high salaries b. not many people are going to college c. not many people are renting their homes d. not many people have jobs
Answers: 2
question
Computers and Technology, 22.06.2019 21:50
Answer the following questions regarding your system by using the commands listed in this chapter. for each question, write the command you used to obtain the answer. a. what are the total number of inodes in the root filesystem? how many are currently utilized? how many are available for use? b. what filesystems are currently mounted on your system? c. what filesystems are available to be mounted on your system? d. what filesystems will be automatically mounted at boot time?
Answers: 1
question
Computers and Technology, 23.06.2019 06:30
When early motion pictures played in movie theaters, they were often accompanied by live organ or piano music. which of the following are the most likely reasons that this happened? (select all that apply). the music was provided to distract audience members from the loud sounds made when filmstrips were changed. the music accompanied the movies because the movies were silent and audiences were used to hearing music during plays in theaters. the music usually was played before, and sometimes after the movie, as an alternative form of entertainment. the music viewers to interpret the dramatic action in the films.
Answers: 2
question
Computers and Technology, 23.06.2019 15:20
An ou structure in your domain has one ou per department, and all the computer and user accounts are in their respective ous. you have configured several gpos defining computer and user policies and linked the gpos to the domain. a group of managers in the marketing department need different policies that differ from those of the rest of the marketing department users and computers, but you don't want to change the top-level ou structure. which of the following gpo processing features are you most likely to use? a, block inheritance b, gpo enforcement c, wmi filtering d, loopback processing
Answers: 3
You know the right answer?
Triangle peg solitaire is a game where you start with several pegs at fixed locations on a triangula...
Questions
question
English, 14.11.2021 22:20
question
History, 14.11.2021 22:20
question
Mathematics, 14.11.2021 22:20
question
Mathematics, 14.11.2021 22:20
Questions on the website: 13722367