Build the gui layout of the gamecreate a class called

Assignment Help JAVA Programming
Reference no: EM13346889

Build the GUI layout of the game

Create a class called PipeGameApp.java which will be the main game user interface. The interface should have the title "The Frantic Pipe Layer" and contain an 11x11 grid of 40pixel x 40pixel buttons as shown below. The buttons should be arranged on a BoardPanel (which is a subclass of JPanel that you can download along with this assignment in the BoardPanel.java file). The BoardPanel ensures that the size of the buttons do not change. Make sure that your window opens with all buttons enabled and not selected.

2009_Build the GUI layout of the game.png

Working Buttons

The PipeGame class represents the actual game without the graphical user interface. The idea is that the game stores a grid of pipe shapes that are placed onto it. The user will be able to click on any unoccupied grid locations to place a pipe piece down. The very first pipe piece that must be placed is the valve pipe shown here to the right. All other pipe pieces must be non-valve pipes and may be one of the following:

627_Build the GUI layout of the game1.png

Also note that the valve pipe is a special one and is called pipesStart.GIF.

When the game is running, the cursor should always show the next (i.e., current) pipe piece that the user may place so that the user sees the pipe piece before placing it down. The getNextPipe() method in the PipeGame class returns the next pipe to be placed. You can then create an image icon for that pipe as follows:

ImageIcon i;
if (game.getNextPipe().isValve())

else
i = new ImageIcon("pipesStart.GIF");
i = new ImageIcon("pipes"+ game.getNextPipe().toString() +".GIF");

Then you can use the following code to change the cursor into any given pipe picture (assuming that tiles is the BoardPanel object that contains the buttons):

tiles.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(i.getImage(),
new Point(0,0), "pipe"));

Then to return the cursor to normal, you can just use:

tiles.setCursor(Cursor.getDefaultCursor());

Add appropriate event handlers to the buttons so that when the user clicks on a button, a pipe gets placed at that location. To do this, you simply need to store the image of that button. In JAVA, you can do this by setting the button's "selected icon" as follows:
String currentPipeCodes = game.getNextPipe().toString();
aButton.setSelectedIcon(new ImageIcon("pipes"+ currentPipeCodes +".GIF"));
aButton.setSelected(true);

Remember that the first pipe (i.e., the valve pipe) is a special case using the "pipesStart.GIF" file. Once any pipe is placed, a new randomly chosen pipe is used as the next pipe piece to be placed. Adjust the static Random() method in the Pipe class to return a random pipe piece (i.e., a new pipe that has random openings in the 4 directions) instead of the same piece each time. Make sure that your code works.

Look over the PipeGame class since it already maintains attributes for keeping track of a 2 dimensional grid of Pipe objects, the number of pipes that have been placed on the grid so far and the next pipe to be placed. An instance method called resetPipes() resets the grid so that all Pipes in the grid are null to begin and the next pipe to be placed is the valve pipe.

Make sure that you can place lotsa pipes all over the grid before continuing.

(3) Smart Pipe Placement

Now you will adjust your code so that pipes can only be placed on a grid location if the pipe actually fits with the (up to) 4 pipes around it. Also, once a pipe has been placed at a location, no other pipe can be placed there.

Each pipe piece is open in 1,2,3 or 4 directions. The end pieces are shown with red circles.

Pipes store 4 booleans, indicating whether or not the pipe is open at the top, right, bottom or left as well as a boolean indicating whether or not it is the valve piece (set to false for all 15 pieces shown above).

Instance methods fitsBelow(Pipe p), fitsAbove(Pipe p), fitsToLeftOf(Pipe p), and fitsToRightOf(Pipe p) return a boolean indicating whether or not the receiver pipe fits below, above, to the left of or to the right of the given pipe p, respectively. Note that two pipes "fit" together if they both have openings that meet when placed beside each other or both do NOT have openings.

Here are examples of pipes that "fit" beside one another:

1972_Build the GUI layout of the game2.png

Here are examples of Pipes that DO NOT "fit" beside one another:

1760_Build the GUI layout of the game3.png

Modify the instance method called placePipe(int row, int col) that tries to place the current pipe at the specified grid location. Currently the pipe is always placed whether or not it fits properly. Adjust the code so that if the pipe does not fit there, false is returned, otherwise true is returned. Also, if the pipe fits at this location, the number of placed pipes is incremented and a new randomly chosen pipe is chosen as the next pipe to be placed (not the valve, since there is only one valve allowed). The next page shows a valid board after a while of playing. Make sure to hand in all your pipe picture files as well, as they are needed to run your code.

2225_Build the GUI layout of the game4.png

Reference no: EM13346889

Questions Cloud

Scanning and parsingimplement the lexical and syntactic : scanning and parsingimplement the lexical and syntactic analysis of minifun programming language. the scanner splits up
Question 1which of the following statements is true for a : question 1which of the following statements is true for a trapdoor function f?answer a.the function f can be computed
1 object oriented programming class hierarchies : 1. object oriented programming class hierarchies inheritance and virtual functions in this part of the assignment you
Describe and evaluate this type of internal audit what : describe and evaluate this type of internal audit. what types of organisation would it be most useful for?required1
Build the gui layout of the gamecreate a class called : build the gui layout of the gamecreate a class called pipegameapp.java which will be the main game user interface. the
Offered a 20 million commercial loan priced using a 3month : offered a 20 million commercial loan priced using a 3month libor index100bp. after some preliminary research using a
Analyze the processed data in statistical survey below are : analyze the processed data in statistical survey. below are the results of the processed data.question 1 yes p 0.1986
Write a report on simple data analysis and : write a report on simple data analysis and comparison.explain briefly how simple data analysis methods you are to use
1 the economy cant be considered fully employed unless the : 1 the economy cant be considered fully employed unless the measured unemployment rate is below 1. agree or disagree and

Reviews

Write a Review

JAVA Programming Questions & Answers

  A method with the signature public static void

A method with the signature public static void printDetails(City[] cities) that will iterate through the cities and printthe details of the city using the displayDetails(...) method.

  Write a program that reads in a list of numbers from a file

write a program that reads in a list of numbers from a file and adds up all those numbers. You may hard code in the name of the file, allowing the user to input the filename is not required

  Give an example of an exception

A. Give an example of an exception that could be generated outside your code but caught within your code

  Elliptic curve encryption

write a program to implement Elliptic Curve encryption/decryption and program will read parameters, plaintext and ciphertextfrom a file named "input.txt" (under the same directory).

  A java program where the user designates

a java program where the user designates how many games they would like to play (for example user inputs 10 games) then they play the game, if lets say there is a tie after 10 games the game continues until either the user of the computer wins by 2

  Imagine that you have been assigned

Imagine that you have been assigned to implement a sorting program. The goal is to make this program general purpose, in that you don't want to define in advance what record or key types are used

  Design a program to help a videorental store

Design classes (class video, class customer, etc) based on your analysis above, using LINKED LISTS for the database elements read into the main memory.

  Write a program in java that reads contents of two vectors

Write a program in Java that reads contents of two vectors, and then displays the sum of these two vectors. The program should prompt the user to enter the size of the vectors first.

  Write a program to play a variation of the game

Roll two dice. Each die has six faces representing values 1, 1, ..., and 6. Check the sum of the two dice. If the sum is 2, 3, or 12 you lose; if the sum is 7 or 11, you win. If the sum is another value (4,5,6,8,9, or 10) a point is established.

  Write an interface for a bagadt that implements iterable

Write an interface for a BagADT that implements the Iterable interface. Include javadoc comments that will generate specifications for the BagADT so that someone who wants to implement this interface will know what each method does.

  Write the bubble sort

The village of Marengo conducted a census and collected records that have household data, including the number of occupants in each household.

  Define inventory program assignment from java class

This is part 6 of the inventory program assignment from Java class IT 215 from UOP and all the codes are written well and includes everything all the functionality from the previous parts and there's absolutely no errors.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd