编程辅导 C C++ Java Python MIPS Processing 网络家教 在线辅导

编程家教 远程写代码 Debug 讲解答疑 课后答疑 不是中介,本人直接答疑

微信: ittutor QQ: 14061936 Email: ittutor@qq.com

导航

 WCOM115 Introduction to Computer Programming

Introduction

In this assignment we will try to make our fish game more appealing to gamers who want more challenge. The fish will now swim through a cloud of bubbles. Each bubble can be a poison or food. The fish could change its size based the bubble that it has encountered.

Similar to assignment 1, this assignment has been divided in the number of tasks in a logical order from easy to hard. You must do your task in the order that we have given. Marks will not be given if you do not follow this logical order. You must complete task1 before attempting task2 and completing task2 before attempting task3 and finish task3 before attempting task4.

A code template is given in this assignment which can be downloaded from the Assignment 2 section in iLearn. There are main program (events handler) and number of functions that you need to implement. You can think of each of these functions as jigsaw pieces which will be used to complete our fish game. In task 1 to 3, you do not need to modified any part of the main program. Each of the function that you have to implement will appear as a tab in processing IDE. You must implement each of the function in its own tab in the Processing IDE. Otherwise, you will NOT get full marks in that task. In each of the function, the function signature must not be changed and global variables must not be used/modified unless I have instructed for you to do so.

Functions setupFoodAndPoison, drawScore and the code in file main has been provided for you, please do not modified until you have accomplished task 1, 2 and 3.

The knowledge requires to do this assignment is in module 1 to 6.

Learning outcomes

1.    Apply problem solving skills to develop algorithms that solve small to medium-sized computational problems: Introductory experience in developing an algorithm to solve a problem from an informal specification of the problem.

2.    Design and code implementations of their algorithms in an imperative programming language: Practical experience in translating a simple algorithm into an equivalent Processing program that uses drawing, animation and variables.

3.    Use standard software engineering practices to document, debug and test their programs: Experience in developing a clear program from a specification, testing the conformance of the program to the specification, and debugging any problems that are detected.

 

Task 1

In this task, you are asked to implement the several functions described below. You can think of each of these functions as jigsaw pieces which will be used to complete our fish game.

1.    Implementing function drawFish with the following signature. The function should draw a fish of your imagination at the coordinate specified in parameters x and y. The size and the color of the fish is specified in parameter size and colorYour fish must not look like my fish and any of your class mates' fish and it must be drawn using Processing's drawing primitive. It also must look like a fish.

void drawFish(float x, float y, float size, color c)

2.    Implementing function fishHasLeftRightEdgeOfScreen with the following signature. The function should return true if the tail of the fish has left the screen and false otherwise. The logic of the function is the same as task 1.9 in assignment 1, however, you must use the parameters of the function in your logic instead of using global variable like in assignment 1. if you use global variable in this function, you will not be given mark in this task

3.  boolean fishHasLeftRightEdgeOfScreen(float fishPosX,

4.                                       float fishPosY,

                                     float fishCurrentSize)

5.    Implementing function drawBubbles with the following signature. The function should draw bubbles based on the parameters given which are described below. The look of the bubble is up to your imagination as long as they are drawn at the correct positions and size and they must not look like my bubbles and any of your class mates' bubble.

6.  void drawBubbles(float[] x, float[] y, float[] size,

                boolean[] food, boolean[] visible)

parameters

description

float[] x

array of horizontal (x) positions of each bubble

float[] y

array of vertical (y) positions of each bubble

float[] size

array of size (same width and height) of each bubble

boolean[] food

each element of this array is a boolean which indicates if the bubble is food or poison. If it is true, the bubble is food, otherwise it is poison bubble. Food and Poison bubble should be drawn differently

boolean[] visible

each element of this array is a boolean which indicates if the bubble should be visible (true for visible and falsefor invisible). An invisible bubble must not be drawn on screen.

You can think of the parameters as a table which tells you where and how to draw bubbles. For example (below), given that there are 5 entries in each parameters, however there should be only 3 bubbles drawn on screen because at index 1 and 3, the visible are false. At index 0, a poison bubble should be drawn at (100.0, 200.0) and the size should be 10.0.

index

float[] x

float[] y

float[] size

boolean[] food

boolean[] visible

0

100.0

200.0

10.0

false

true

1

100.0

200.0

30.0

false

false

2

10.0

400.0

60.0

true

true

3

89.0

70.0

30.0

false

false

4

59

20.0

50.0

true

true

 

bubble1

Sample video of the game after completing task1

Task 2

If you implement task 1 correctly, when you run the program you should see your fish swims to the right and reappear on the left. You should also see the bubbles drawn at a random locations on the screen.

In this task, you will implement 3 more functions that will check if your fish has collided with the bubbles. The size of fish should get bigger if the fish has eaten food bubble and decrease if the fish has eaten the poison bubble. This feature depends heavily on the correct implementation of all the functions in task1 and specially the function drawFish.

1.    Implementing function getNewFishSize which returns a new fish size based on what it has collided with. If it has collided with a food bubble, it should increase its size by 3 from its current size. If it has collided with a poison, it should decrease its size by 3 from its current size. Otherwise the size remains the same. However, the size of the fish should not be decrease until it disappears from the game screen or increase until it covers the whole game screen.

float getNewFishSize(float currentFishSize, int typeOfBubbleCollide)

parameters

description

currentFishSize

current size of the fish

typeOfBubbleCollide

the type of the bubble that the fish has collided with. The value of this parameter is 0 if the fish has not collided with anything, 1 if it has collided with food bubble and 2 if it has collided with poison bubble.

2.    Implementing function fishCollideWithABubble which returns true if the fish has collided with a bubble specified in the parameters and false otherwise. Your lecturer will show how collision detection can be done.

3.  boolean fishCollideWithABubble(float fishPosX, float fishPosY,

4.                             float fishCurrentSize,

5.                             float aBubblePosX, float aBubblePosY,

                           float aBubbleCurrentSize)

parameters

description

float fishPosX

current horizontal (x) positions of the fish

float fishPosY

current vertical (y) positions of the fish

float fishCurrentSize

current size of the fish

float aBubblePosX

horizontal (x) positions of the bubble to be checked if it has collided with the fish

float aBubblePosY

vertical (y) positions of the bubble to be checked if it has collided with the fish

float aBubbleCurrentSize

current size of the bubble to be checked if it has collided with the fish

6.    Implementing function checkFishCollision which checks collision with all the visible bubbles currently on the game screen. The function returns 1 if the fish has collided with a visible food bubble, returns 2 if the fish has collided with a visible poison bubble and return 0 if the fish has not collided with any bubble. The visibility of the collided bubble should be turn off (false). To gain full mark for this one, this function should call function fishCollideWithABubble with in a loop to check if your fish has collided with a bubble.

7.  int checkFishCollision(float fishPosX, float fishPosY, float fishCurrentSize,

8.                        float[] bubblesPosX,

9.                        float[] bubblesPosY,

10.                                  float[] bubblesSize,

11.                                  boolean[] bubblesIsFood,

                      boolean[] bubblesIsVisible)

parameters

description

float fishPosX

current horizontal (x) positions of the fish

float fishPosY

current vertical (y) positions of the fish

float fishCurrentSize

current size of the fish

float[] bubblesPosX

array of horizontal (x) positions of each bubble

float[] bubblesPosY

array of vertical (y) positions of each bubble

float[] bubblesSize

array of size (same width and height) of each bubble

boolean[] bubblesIsFood

each element of this array is a boolean which indicates if the bubble is food or poison. If it is true, the bubble is food, otherwise it is poison bubble. Food and Poison bubble should be draw differently

boolean[] bubblesIsVisible

each element of this array is a boolean which indicates if the bubble should be visible (true for visible and false for invisible). An invisible bubble should not be checked for collision.

 

bubble1

Sample video of the game after completing task2

Task 3

With the completion of task 2, when our fish swims into a bubble, the bubble will disappear from the game screen. However our game can be a bit boring, because the bubbles are static.

In this tasks, you will implement 2 functions that will move the bubbles and add the scoring to the game.

1.    Implementing function moveBubbles. which moves every visible bubbles on the screen upward at a random speed between -1 and 3 pixels per frame. When a bubble left the top edge of the screen, it should restart again at the bottom of the screen and continue moving upward. An invisible bubble must not be moved.

void moveBubbles(float[] x, float[] y, boolean[] visible)

parameters

description

float[] x

array of horizontal (x) positions of each bubble

float[] y

array of vertical (y) positions of each bubble

boolean[] visible

each element of this array is a boolean which indicates if the bubble should be visible (true for visible and false for invisible). An invisible bubble should not be moved.

2.    Implementing function calculateScore which calculates score of the game base on the rate of food and poison bubble that the fish has eaten so far. The function must returns an array of type float which has exactly 2 elements. The first element (index 0) contains the rate of food eaten and the second element (index 1) contains the rate of poison eaten by the fish.

The rate of food and poison eaten can be calculated using the formula below.

o    foodEatenRate = nFoodEaten / gameTime

o    poisonEatenRate = nPoisonEaten / gameTime

float[] calculateScore(float gameTime, int nFoodEaten, int nPoisonEaten)

parameters

description

float gameTime

current time spend playing this game

int nFoodEaten

current number of food bubbles that has been eaten so far

int nPoisonEaten

current number of food bubbles that has been eaten so far

 

bubble2

Sample video of the game after completing task3

Task 4

In task 3, you have made the game more challenging to the game player by making the bubbles move and adding the new scoring system based on the rate of food and poison eaten. Somehow, the player has complained about the problems which are listed below:

·         The text displaying of the scores is really hard to understand.

·         The control options of the fish are very limited, only in up and down direction.

·         The game keeps going and never end, even the bubbles has all been eaten.

In this task you will try to fix the problems above by using the open-ended method. With the open-ended method, we do not tell you what the result must look like or how to solve the problem, but you must use your creativity and come up with idea to solve the problems. In subtask 2 and subtask 3 below, you may modify the main program. However the modification must not change the output of the 3 previous tasks that you have accomplished

1.    Modifying the function drawScore, so that it displays the score in graphical form instead of text display which the function currently uses. The new graphical score must not take too much area of the game screen and must be different from the default one that is given to you and your class mate.

2.    Game ending rules: This task is an open-ended type of task. To do this task you must first think about what you want to game ending rules to be like. Then write a paragraph in English describing your idea and consult with your lecturer if it is ok to implement your idea. Your lecturer will keep that paragraph of text of the description you have provided for marking your code.

3.    Modifying fish controlling method: This task is an open-ended type of task. To do this task you must first think about what you want the control of the game to be like. Then write a paragraph in English describing your idea and consult with your lecturer if it is ok to implement your idea. Your lecturer will keep that paragraph of text of the description you have provided for marking your code. A default behavior of the control has been provided, the one that you are going to purpose must be significantly different from the default one.

 

相关推荐