project-description.pdf School of Computer Science COMPSCI 130: Software Fundamentals Project One: A simple arcade game Due: Wed 30th Jan 2019 at 23:59pm. Submit: A single text file containing your...

no reference needed


project-description.pdf School of Computer Science COMPSCI 130: Software Fundamentals Project One: A simple arcade game Due: Wed 30th Jan 2019 at 23:59pm. Submit: A single text file containing your Python code via Canvas. Worth: 10% of the final grade (10 marks) In this project, you will implement a simple arcade game, traditionally known as “Snake” The game consists of three classes. The first is a GameFramework class, which is designed to manage the creation of the window to display the game, the management of the events that are created when you press a key, and the animation loop that redraws the screen. You will not need to change the GameFramework class. The second class is a class called SnakeGame. This contains the logic for playing the game. You will be given this class and will need to read and understand the purpose of the code, as you will need to modify the game logic for parts 2 and 3 of the project. The third class is a class called Snake. You are expected to implement the Snake class for the first part of the project. Part A: Implement the Snake class This part is worth 5 marks. You will be provided with the skeleton code for the Snake class and must implement each of the following methods. class Snake: def __init__(self, home, size): def draw_segment(self, point): def draw(self): def move(self, direction): def hit_self(self): def hit_bounds(self, bounds): School of Computer Science COMPSCI 130: Software Fundamentals Part B: Implement a Target class This part is worth 3 marks In Part A, the snake automatically grows longer every 10 moves. In this part, you should prevent the snake from growing longer automatically. Instead, the snake will only grow when it hits a designated “target”. The target should be the same size as a snake segment, and should be located in a random position within the boundary of the game. If the snake collides with the target, then the snake will grow one segment longer (i.e the tail will not be removed on that turn). When the target is reached, the target will be repositioned at a new random location. At any time, there is only a single target. Create a new class called Target, which should have some similarities with the structure of the Snake class. You will have to alter the SnakeGame logic to introduce the Target class and make sure it has the correct behaviour. Part C: Implement an Enemy snake This part is worth 2 marks For this part, you will change the game logic to introduce an enemy snake that starts in a random location. The enemy snake will always head towards the target using the shortest path possible. If it reaches the target first, then the target will be repositioned and the enemy snake will grow longer. If the player snake collides with the enemy snake then the game is over. A Canvas discussion will be available for questions. An FAQ will be used to record the important points. Marking information The grading will be based the functional correctness (i.e., the code should perform the task as required), and also the style of the code (i.e., classes and methods should include well written docstrings, variable names are well chosen, the algorithms and code used to implement the functionality is easy to understand and well structured). Correctness Style Total Part A 3 2 5 Part B 2 1 3 Part C 1 1 2 Total 6 4 10 Note: This assignment is deliberately vague and unspecific so that you can make your own design decisions and decide how to implement the functionality required. Snake-project-A.pyimport turtle class Snake: #The snake moves by jumping one square at a time. def __init__(self, home, size): #home is the starting location (by default is 0, 0) #size is the size of the square in each cell of the snake #The snake location is stored as a list of tuples, where each tuple #is the position of a segment of the snake pass def draw_segment(self, point): #Draws a square equal to the size of the snake, where the location #given is the bottom left corner of the square pass def draw(self): #Draws each of the segments, and then draws the head with red colour pass def move(self, direction): #move the snake in the direction given by adding a new #head position to the list of locations, and removing #the end of the snake. The snake grows automatically every 10 #moves. That is, every 10 moves, the tail of the snake is not #removed. pass def hit_self(self): #check if the head of the snake has hit one of its own segments pass def hit_bounds(self, bounds): #left, top, right, bottom bounding box #check if the snake has hit the bounds given pass class SnakeGame: def __init__(self): #set up the window for the game, the methods that are called when keys are pressed, and #the method that is called each new game turn self.framework = GameFramework(800, 800, 'COMPSCI 130 Project') self.framework.add_key_action(self.move_right, 'Right') self.framework.add_key_action(self.move_up, 'Up') self.framework.add_key_action(self.move_down, 'Down') self.framework.add_key_action(self.move_left, 'Left') self.framework.add_key_action(self.setup_game, ' ') #Pressing space will restart the game self.framework.add_tick_action(self.next_turn, 100) #Delay (speed) is 100. Smaller is faster. #set of methods to keep track of which key was most recently pressed def move_right(self): self.last_key = 'Right' def move_left(self): self.last_key = 'Left' def move_down(self): self.last_key = 'Down' def move_up(self): self.last_key = 'Up' def setup_game(self): #initializes starting variables and begins the animation loop self.last_key = 'None' #No initial direction specified self.snake_size = 20 self.boundary_limit = {'left':-15, 'right':15, 'top':15, 'bottom':-15} snake_home = (0,0) self.snake = Snake(snake_home, self.snake_size) self.framework.start_game() def draw_bounds(self): #draws the box that defines the limit for the snake left = self.boundary_limit['left'] top = self.boundary_limit['top'] size = self.snake_size turtle.goto(left * size, top * size) turtle.pendown() for i in range(0, 4): #Draw a bounding square turtle.rt(90) turtle.forward(abs(left) * size * 2) turtle.penup() def next_turn(self): #called each time the game 'ticks' turtle.clear() snake = self.snake if self.last_key == 'Right': snake.move('right') if self.last_key == 'Up': snake.move('up') if self.last_key == 'Down': snake.move('down') if self.last_key == 'Left': snake.move('left') self.draw_bounds() snake.draw() if snake.hit_self() or snake.hit_bounds(self.boundary_limit): self.framework.stop_game() #game over
Jan 24, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here