Microsoft Word - Assignment 4 - Zuma_fixed Assignment 4 – Zuma Due Date: Friday, December 6th 2019 at 23:55 Percentage overall grade: 5% Penalties: Late assignments allowed without penalty until...

1 answer below »
The assignment 4 file has the instructions to the python programming


Microsoft Word - Assignment 4 - Zuma_fixed Assignment 4 – Zuma Due Date: Friday, December 6th 2019 at 23:55 Percentage overall grade: 5% Penalties: Late assignments allowed without penalty until Monday, Dec 9th 2019 at 23:55 Maximum marks: 100 Zuma Description Zuma is a match-3 game where players shoot globes into an ever-growing line of visible globes. When three or more globes of the same colour appear next to each other, they are removed from the line and the player is awarded points. This removal may, in turn, trigger a chain reaction where another three or more globes of a matching colour become adjacent and must be removed; and so on. Bonus points are earned by creating chain reactions of match-3s. Partial example to illustrate match-3s and chain reactions (other aspects of game are ignored in this example): Action 1: a yellow globe is fired into the line at the location shown. +========================================+ | Y Y G G R R B B C C Y | | ↑ | | Y | +========================================+ Action 2: another yellow globe is fired into the line at the location shown. +========================================+ | Y Y G G R R Y B B C C Y | | ↑ | | Y | +========================================+ Action 3: a green globe is fired into the line at the location shown. +========================================+ | Y Y G G R R Y Y B B C C Y | | ↑ | | G | +========================================+ Action 4: another green globe is fired into the line at the location shown. +========================================+ | Y Y G G R R G Y Y B B C C Y | | ↑ | | G | +========================================+ Action 5: a red globe is fired into the line at the location shown. +========================================+ | Y Y G G R R G G Y Y B B C C Y | | ↑ | | R | +========================================+ A match-3 occurs between the red globes, and they are removed. +========================================+ | Y Y G G R R R G G Y Y B B C C Y | This triggers a chain reaction for the green globes, and they are removed. +========================================+ | Y Y G G G G Y Y B B C C Y | This triggers a chain reaction for the yellow globes, and they are removed. +========================================+ | Y Y Y Y B B C C Y | For an example of how a fully functional version of this game works in real-time, you can watch sample gameplay footage here: https://www.youtube.com/watch?v=Q-6qnTjf16o Assignment Specifications You are tasked with creating a lite version of the Zuma game, capable of firing player globes into the line at player-specified locations and handling the updates when match-3s occur. Task 1: Zuma class - public interface Download and save a copy of zuma.py skeleton code from eClass. This file contains a partially completed template for the Zuma class, as well as a fully implemented main() function that runs the Zuma game. DO NOT CHANGE ANY OF THE COMPLETED FUNCTIONS. Complete the public interface of the Zuma class according to the description below. Zuma(max_line_length, start_line_length, frames_per_globe, game_globes, player_globes) Initializes the game’s state to play a new level, using the input provided. (Refer to the docstring for this method for more information about each of the input parameters.) Specifically, it creates and fills three containers: one to store the line of visible globes on the game board; one to store globes that are pending (waiting to be added to the game board); and one to store shooting globes that the player can fire (one at a time) into the line of visible globes. You must choose appropriate data structures for these three containers. You may choose between a stack, a queue, and a doubly linked list for each. These data structures are provided for you – familiarize yourself with the implementations in the provided stack.py, queue.py, and dll.py, as these implementations may differ from the exact implementations covered in the lectures. You may use a different data structure for each of the three containers. Consider that you will need to insert fired globes into the visible line of globes, while the order of the pending and player globes does not change. getScore() – returns the player’s current score as an integer. Task 2: Zuma class – private methods Complete the following private methods of the Zuma class: __display_header() – displays the player’s score, the number of globes that are pending, the number of globes that the player has left to shoot (including the current shooter), and the number of actions remaining before a new globe is added to the line of visible globes. The header will be printed above the game board every time the player performs an action, and is called by the already completed __display_frame(). This method returns None. __display_game_board() – displays the game board’s current state, including the visible line of globes, and the player’s current shooting globe. Note that the width of the game board corresponds to the maximum number of globes that can be visible before triggering a game over. This game board is displayed (along with the header) every time the player makes an action, and is called by the already completed __display_frame. This method returns None. __move_left() – updates the player’s shooting position by one place (i.e. by one visible globe) to the left. Any attempt to move past the edge of the game board counts as an action, but does not update the actual shooting position. This method returns None. __move_right() – updates the player’s shooting position by one place (i.e. by one visible globe) to the right. Any attempt to move past the start of the visible globe line counts as an action, but does not update the actual shooting position. This method returns None. __fire() – removes the current shooting globe from the container of player’s globes, and inserts it into the line of visible globes at the player’s specified location. Any attempt to fire beyond the start of the line of visible globes counts as an action, but does not fire the globe. This method should NOT check for match-3s. This method returns None. __handle_match_three(chain_reaction_count) – recursive method to remove all sequences of match-3s from the line of visible globes. Note that you can assume that there will be no pre-existing match-3s in the line of pending globes. Because this method is recursive, it should also handle all chain reactions that may be triggered. This method returns the number of points earned from the matches, according to the following equation: points = removed_sequence_length2 * 10 * chain_reaction_count where chain_reaction_count is the current sequence that is being removed. When the first match-3 is removed, chain_reaction_count is 1; when this triggers a chain reaction, the chain_reaction_count is 2; when this triggers another chain reaction, the chain_reaction_count is 3, etc… For the example shown at the beginning of this assignment description, at action 5 the initial red globe match-3 earns 32*10*1 = 90 points. The green globe match-3 that is then triggered earns 42*10*2 = 320 points. The yellow globe match-2 that is then triggered earns 42*10*3 = 480 points. So the player earns a total of 890 points after action 5.
Answered Same DayDec 05, 2021

Answer To: Microsoft Word - Assignment 4 - Zuma_fixed Assignment 4 – Zuma Due Date: Friday, December 6th 2019...

Ximi answered on Dec 08 2021
154 Votes
from stack import Stack
from queue import Queue
from dll import DoublyLinkedList
from scoreboard import Scoreboard

class Zuma:
"""
Defines the Zuma game and its text-based interface.
"""

# constants used to identify specific user actions based on keyboard input.
# Don't change these.
MOVE_LEFT = 'a'
MOVE_RIGHT = 'd'
FIRE = 'w'
QUIT = '/'
# constants for displaying the game's state on screen. Don't change these.
UP_ARROW = chr(8593)
BOMB_CHARACTER = '*'


def __init__(self, max_line_length, start_line_length, frames_per_globe,
game_globes, player_globes):
"""
Sets up the game's state to play a new game.
Parameters:
max_line_length (int): the maximum number of globes that can be visible
before the game over condition is triggered (game lost).
start_line_length (int): the number of globes that are visible at the
start of the level.
frames_per_globe (int): the number of frames that pass before a new
globe appears on screen.
game_globes (str): a sequence of values that will be used to initialize
the visible globes and pending globes.
player_globes (str): a sequence of values that will be used to initialize
the globes that players can shoot/fire.
"""
# globe containers
self.__visible_globes = DoublyLinkedList() #? select most appropriate data structure
self.__pending_globes = Stack() #? select most appropriate data structure
self.__player_globes = Stack() #? select most appropriate data structure

# additional private attributes
self.__score = 0
self.__quit = False
self.__player_position = 0 # index where player will insert a globe
self.__frame_count = 0 # num of frames since game started
self.__frames_per_globe = frames_per_globe
self.__max_line_length = max_line_length # max len of visible globes, else game over
########################################################################
########### COMPLETE THE INITIALIZATION OF THE ZUMA CLASS HERE #########
########################################################################
for globe in game_globes[:start_line_length]:
self.__visible_globes.add(globe)
for globe in game_globes[start_line_length:]:
self.__pending_globes.push(globe)
for globe in player_globes:
self.__player_globes.push(globe)

############################################################################
# public interface -- do not edit this method.
############################################################################
def play(self):
"""
Runs the game's gameplay loop.
"""
# display our frame zero before prompting for input the first time
self.__display_frame()

while not self.__check_game_over():
self.__frame_count += 1
self.__handle_input()
self.__update_state()
if not self.__quit:
self.__display_frame() # display updated header + board + instructions
# return to normal input handling after the game has finished
self.__display_game_over()


############################################################################
# public interface -- complete for the assignment.
############################################################################
def get_score(self):
"""
Returns the player's score in the game.
"""
return self.__score # delete pass and replace with your code

############################################################################
# private methods -- to be completed for assignment.
############################################################################
def __display_header(self):
"""
Displays the player's score, the number of globes pending to be added to
the globe row, the number of globes the shooter globes left, and the
number of turns remaining before a new globe automatically appears in
the visible globe line. The header will be printed before/above the game
board.
"""
print (self.get_score())
print (self.__pending_globes)
print (self.__player_globes) # delete pass and replace with your code

def __display_game_board(self):
"""
Displays the game board's current state
"""
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here