Handling mouse input, Computer Graphics

When you set up your project, create the class as an "ACM Graphics Program", rather than a plain class. This will perform the necessary preparations for you to use mouse input in your program.

There are three main tasks that you need to consider when implementing this program:

1. Identifying the numerical values, boolean values, and graphical objects that you will need to use in your program and declaring the fields for them.

2. Initializing the fields above to reflect the initial game state and add the graphical objects to the canvas.

3. Responding to a mouse click from the player and performing the appropriate logic to execute their turn. any method in the class.

What fields do you need? First, think about what you need to store the state of the game.  We can identify three numerical values: the trough score, player 1's score, and player 2's score. Think about which primitive type would be best here. Are the scores fractional or
are they whole numbers?

Next, you need a way to keep track of which player's turn it is. Here are a couple strategies that you can think about: you could use an integer variable that keeps track of which player's turn it is. Or, since you only have two players, you could use a boolean value that indicates "whether or not it's player 1's turn" (or alternatively, player 2's turn).

Identifying the graphic objects should be fairly self-explanatory, based on the description above. Remember to make sure that the graphics at startup reflect the initial state of the game (the correct player should be displayed bold, for example, and the score labels should all be set to 0).

Task: Initializing the Fields

As in the other graphics programs you've seen, this initialization code can go in the run () method. Don't forget to initialize the variables that represent the game state as well as the graphical objects.

Task: Handling Mouse Input

The mouseClicked() method is where you will respond to the user clicking on one of the objects on your canvas. You need to determine which object was clicked (refer to the GUI examples shown in class) and execute the appropriate action by implementing the game rules described at the top of the assignment. Remember that you need to update both the numeric values that represent the game state as well as the labels on the screen.

Posted Date: 2/28/2013 6:35:02 AM | Location : United States







Related Discussions:- Handling mouse input, Assignment Help, Ask Question on Handling mouse input, Get Answer, Expert's Help, Handling mouse input Discussions

Write discussion on Handling mouse input
Your posts are moderated
Related Questions
Combination of Positive and Negative Accelerations Actually, it is not that a body once decelerated or accelerated will remain so, although the motion may include both speed-up

Main Objectives of this connector is to allow full duplex communication between peripherals that uses such connector such PIC Demo board, ICD2 Debugger etc. The RS32 connector pin

Question 1: Name at least four file formats and explain in detail what they mean and how they are use? Question 2: What are "Process Colours"? Answer in a single para

Distinguish between window port & view port?  A portion of a picture that is to be displayed by a window is called as window port. The display area of the part selected or the f

In computers, colours are created by blending different combinations of red, green and blue. These colours are normally specified as three two-digit hexadecimal numbers in html, ph

1. For the polygon shown in Figure on the next page, how many times will the vertex V 1 appear in the set of intersection points for the scan line passing through that point?  How

Ask question #Minimum how can we use stroke method method for character generation? 100 words accepted#

What is persistence and resolution?  The time it takes the emitted light from the screen to decay one tenth of its original intensity is known as a persistence.  The maximum

Consider the line segment AB in 3-Dimentional parallel to the z-axis along with end points A (- 5,4,2) and also B (5,-6,18). Carry out a perspective projection upon the X=0 plane;

Illumination Model - Polygon rendering and ray tracing methods Theoretically illumination is exposure of a thing to the light that contributes to light reflected by an object