Handling mouse input, Computer Graphics

Assignment Help:

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.


Related Discussions:- Handling mouse input

Achieve a perspective projection on the plane of unit cube, Achieve a persp...

Achieve a perspective projection on the z = 0 plane of the unit cube, demonstrated in Figure (l) from the cop at E (0, 0, 10) upon the z-axis. Figure: I 01:  currently c

How does the z-buffer algorithm find out which surfaces, Illustration 1: H...

Illustration 1: How does the z-buffer algorithm find out which surfaces are hidden? Solution : Depth or Z-buffer algorithm employs a two buffer area each of two-dimensional ar

Avi codec format, AVI CODEC Formats: Various AVI file formats other than t...

AVI CODEC Formats: Various AVI file formats other than the DV Types 1 and 2 formats are there discussed earlier. All such the other formats involve the utilization of Compressor o

Sutherland hodgeman polygon clipping algorithm, What is clipping? Explain S...

What is clipping? Explain Sutherland Hodgeman polygon clipping algorithm with example.  OR Write the algorithm for Sutherland Hodgeman Polygon. Beginning with the initial set of p

Objectives-introduction to computer graphics, Objectives After complet...

Objectives After completing this section, you must be familiar with: explain computer graphics, its characteristics and features; Conversations about applicat

Linearly interpolate - modeling and rendering, Linearly interpolate - Model...

Linearly interpolate - Modeling and Rendering I 4 = I 1 + t (I 2 - I 1 ); here t = (|y 1 - y 2 |)/(|y 1 - y 2 |) I D = I A + t (I B - I A ); here t = (|AD|)/(|AB|)

Briefly describe what you understand by smoothing, Question: (a) List a...

Question: (a) List and explain different types of lights that can be used in After Effects. (b) How is the density of dots between the boxes in a motion path related to th

Parameterized systems - computer animation, Parameterized Systems - Compute...

Parameterized Systems - Computer Animation Parameterized Systems is the systems which permit objects motion features to be given as part of the object descriptions. The adjus

What do you mean by parabolic splines, What do you mean by parabolic spline...

What do you mean by parabolic splines?  For parabolic splines a parabola is fitted by the first three points p1, p2,p3 of the data array of kot points. Then a second parabolic

Write Your Message!

Captcha
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