Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NEEDS TO BE DONE IN PYTHON 3 I'd like to introduce you to the next killer app, Balloons and Spikes!! . Although this is a

NEEDS TO BE DONE IN PYTHON 3

I'd like to introduce you to the next killer app, Balloons and Spikes!!. Although this is a simple text based game, don't be deceived; I'm sure this game will rival the likes of Candy Crush, Angry Birds, and Fruit Ninja. The goal of the game is pop as many balloons as you can. I'm sure you will agree it will provide hours of entertainment!

Balloons are represented by the "p" character and spikes are represented by the veritcal bar, or the pipe character, "|" (usually located above the enter key with the backslash). Each frame of the game, some random number of balloons are generated at the bottom of the screen, and some number of spikes are generated at the top of the screen. Balloons will rise one level and spikes will fall one level each frame. In the event that a spike encouters a balloon, the balloon pops and this is shown on the screen with the asterick character "*". Your score is increased for each balloon you pop! Two simple examples are below:

 image text in transcribed 

Many of you will want to write a game using the pygame module for your CY300 project. It is important to think through how you are going to represent the locations of the game objects in memory and keep track of objects as they move around the screen. The creator of Balloons and Spikes!! chose to represent the board as a list of lists of characters. Balloons, spikes, and pops are stored in three separate lists of tuples, where each tuple contains the (x,y) location of the object. For instance, if there are four active balloons during the frame, the balloon list will contain four (x,y) tuples. The tick function is called each frame in order to advance to the next frame. This tick function provides the logic to cause the balloons to rise one level, the spikes to fall one level, and detects any pops which occur when a spike finds a balloon. The tick function has two parameters: a list of tuples of balloon locations and a list of tuples of spike locations. This function returns a three-element tuple: a list of tuples for the next frame's balloons, spikes, and any pops which may occur.

For your homework, provide an implementation of the tick function. Although it is not strictly neccessary to use the code for the entire game, it may help you to review the code and understand how the game uses the tick function to advance from one frame to the next. The code for the game has been provided in balloons_and_spikes_starter_code.py. All you need to submit for this problem is your implementation of the tick function, not the code for the entire game!! The logic used for the tick function is as follows:

Cause each balloon to rise to the next higher row.

Check to see if any balloon have hit spikes. If so, put this (x,y) position in the list of "pop" locations, and remove the corresponding balloon and spike location from their lists.

Cause the spikes to fall to the next lower row.

Check again to see if any balloons have hit spikes. If so, put this (x,y) position in the list of "pop" locations, and remove the corresponding balloon and spike location from their lists.

Return a tuple containing three lists: the locations on the next frame of the balloons, spikes, and any pops which may have occurred. If no balloons were popped that frame, just return an empty list for the pop locations.

The first 50 frames of the the game are provided in balloons_and_spikes_output.txt. Below are some doctest strings which demonstrate the functionality of the tick function.

 >>> tick([(0, 5)], [(0, 0)]) ([(0, 4)], [(0, 1)], []) >>> tick([(3, 4), (0, 9)], [(0, 0), (5, 5)]) ([(3, 3), (0, 8)], [(0, 1), (5, 6)], []) Balloons rise first, so the "pop" occurs at the spike's location. >>> tick([(4, 6)], [(4, 5)]) ([], [], [(4, 5)]) If NUM_ROWS is 10, Balloons reaching row 0 and spikes reaching row 9 are removed, since we want to maintain our border of "#" characters. >>> tick([(1, 1), (2, 2)], [(4, 8), (3, 7)]) ([(2, 1)], [(3, 8)], []) A balloon and a spike two apart meet in the middle and that's the location of the pop. >>> tick([(3, 5)], [(3, 3)]) ([], [], [(3, 4)]) 
Frame 0 Frame 4 1# #p pip p# #p p p# Score Score Frame 1 Frame 5 #p pp l #pp p# p# Score Score lease take note of the decorative border of pound signs, "4", surrounding the screen. Balloons and spikes that make it all the way to edge of the creen fall or rise harmlessly away. Assume the board has 10 rows and 20 columns. Frame 8 #11p P p * #p lp pt Pp Score: 9 Frame 9 P p I #11p #p p lp pt Pp Score Frame 0 Frame 4 1# #p pip p# #p p p# Score Score Frame 1 Frame 5 #p pp l #pp p# p# Score Score lease take note of the decorative border of pound signs, "4", surrounding the screen. Balloons and spikes that make it all the way to edge of the creen fall or rise harmlessly away. Assume the board has 10 rows and 20 columns. Frame 8 #11p P p * #p lp pt Pp Score: 9 Frame 9 P p I #11p #p p lp pt Pp Score

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Explain the procedure for valuation of shares.

Answered: 1 week ago

Question

Which months of this year 5 Mondays ?

Answered: 1 week ago

Question

Define Leap year?

Answered: 1 week ago