聯系方式

您當前位置:首頁 >> Java編程Java編程

日期:2019-06-27 10:59

ASSIGNMENT 2: Game and Drawing Application

COURSE NUMBER: COMP 1010

COURSE TITLE: Introduction to Computer Science 1

TERM: Summer 2019

1

Assignment 2: Game and Drawing Application

DUE DATE: JUNE 23, 2019 AT 11:59PM

Preparation:

Review the following topics

Variables and final named constants

Trigonometry

Active Processing: setup() and draw()

State-driven programming

User-defined functions

Data types – int, float and boolean

Text

IF statement and relational boolean operators

Notes:

Name your sketches using your name, the assignment number, and the question number, exactly as in this

example: LastnameFirstnameA2Q1.

Your programs must run upon download to receive any marks.

Submit one pde file for each question.

Assignments must follow the programming standards document published on the course website on Moodle.

These assignments are your chance to learn the material for the exams. Code your assignments independently.

We use software to compare all submitted assignments to each other, and pursue academic dishonestly

vigorously.

Q1: A Simple Game Simulator - 10 marks

For this question, you will implement a simple

game simulator. A frame from the game is shown

on the right.

The game uses the character you created for

Assignment 1 and a food item. Your program

must create a food item (a simple red circle) at a

random location on the canvas. When the user

clicks on the food, the character must move

towards the food until it reaches the food, that is,

until the centre of the character reaches the

position of the mouse when the mouse was

clicked. When the character covers the food, the

food is considered eaten. The user receives a

score for every food item eaten. The score is

awarded based on the relative location of the food

and the character when the food item first appears

(see below).

When the food is eaten by the character, the

program must generate another food item in a random location for the character to eat. This

game play should continue until either the score reaches or exceeds a goal score or the score is

ASSIGNMENT 1: Game and Drawing Application

DEPARTMENT AND COURSE NUMBER: COMP 1010

2

less than a minimum required score to play. In either case, an appropriate message should be

printed on the canvas and the game stopped.

Your program must keep track of the score on the left in a score bar.

In each round of the game, draw a red circle to represent the food and draw your character.

Ensure that the whole food item is always drawn within the canvas (considering the score bar

and edges).

The game rules are as follows. Depending on where the new food item is located relative to the

character, the score gets a multiplier:

If the food is above and to the left of the character, multiply the score by 5

If the food is above and to the right of the character, multiply the score by 0.2

If the food is below and to the left of the character, multiply the score by 2

If the food is below and to the right of the character, multiply the score by 0.7

Use trigonometry to figure out the relative location of the food and the character. HINT:

calculate the angle between the food and the character and use it to identify the relative location.

For example, if the angle is between 0 and HALF_PI, the food is above and to the left of the

character.

The user should start the game with a certain initial score (e.g., 40) and a goal that s/he hopes to

reach (e.g., 400). The user must keep playing until either:

1) s/he reaches or exceeds the goal, or

2) s/he has a score of less than 1.

Show the score as a vertical bar against a white background on the left side of the screen. A

small bar near the bottom means the user has a low score. A bar that reaches the top of the

window means the user has reached or exceeded the goal. If the bar disappears, the user has lost.

You should also show the current score after each round as a text at the top part of the score bar.

As shown in the screenshot, the blue bar and the text indicate that the user has received a score of

200 so far in the game. You can refer to the demo video created for this question.

Notes:

You should use a canvas size of 500 by 500.

You should use 50 for the size of your character and 30 for the diameter of the food.

You should make global constants for the parameters of the game, such as the colors

used, sizes of the food and character, and so on. You should be able to quickly and easily

change the appearance of the food, the starting score, and so on.

You will also need global variables to keep track of the current score, the goal score, the

location of the character, food, and mouse when it was clicked, and so on.

Use a boolean variable to indicate whether or not the game is over. If the game is over,

the user shouldn’t be able to play and move the character.

Use float for the variables as you must use trigonometry.

You should use a constant to control the speed of the movement of the character. You

should divide the distance between the food and the character by this constant to create a

smooth movement effect.

You should erase the canvas for every round of the game and redraw the character, the

food, and the score bar.

ASSIGNMENT 1: Game and Drawing Application

DEPARTMENT AND COURSE NUMBER: COMP 1010

3

You can use the built-in function called mouseClicked() to capture the mouse

coordinates.

Q2: A Simple Paint Application - 10 marks

For this question, you will implement a simple drawing application that let users to draw and

choose some options for their drawings.

Here are the minimum requirements for the

application:

Use a canvas size of 800 by 600.

Pick at least three simple features

from a drawing application (e.g.,

color, background, shape, stroke

weight). Add the features' names in

the canvas with the text command.

Now pick at least four options for

each of these features (e.g., for color:

red, green, blue, yellow; for stroke

weight: 1, 2, 3, 4) and represent them

in the canvas (e.g., in the screenshot,

stroke colors are shown in rectangles,

thicknesses are shown with lines).

Add a large sub-canvas (i.e., rectangle) inside the main canvas. Restrict the drawing to

this subcanvas.

Add functionalities for the feature options in such a way that if the user clicks on an

option, s/he can draw lines or shapes in the sub-canvas with the selected options (e.g., if a

user clicks on a red stroke color, s/he will be able to draw with red ink).

This seems complex, but the amount of code should not be too large, and if you

implement it using many small functions, one at a time, it will be much easier. Here's a

suggested approach (you can do it differently if you prefer):

o Use a drawPalette() function to draw the palette of options. You may want to

further divide this into three smaller functions, one for each option.

o Use a checkPaletteClick() function to act appropriately if the user clicks in the

palette. Again, you might want to use three smaller functions, one for each of the

three options.

o Just as you would write the usual setup() and draw() functions, you can write a

mouseClicked() function, which contains code that you want to run when a mouse

click is detected.

o Use a drawInCanvas() function when the mouse is in the drawing area.

Assignment Notes:

Hand in two pde files, one each for Questions 1 and 2.

Make sure your files are named exactly as specified in the instructions at the beginning of

the assignment.

Follow all the programming standards.


相關文章

【上一篇】:到頭了
【下一篇】:沒有了

版權所有:編程輔導網 2018 All Rights Reserved 聯系方式:QQ:99515681 電子信箱:[email protected]
免責聲明:本站部分內容從網絡整理而來,只供參考!如有版權問題可聯系本站刪除。

25选5一等奖多少钱