






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A tutorial exercise and a homework assignment for the cpsc 231 course, which focuses on understanding the use of classes and objects, as well as file operations. The tutorial exercise involves creating a simple prison escape game, where the player character must navigate through a grid-based map while avoiding guards with varying attack ranges. The homework assignment builds upon the tutorial exercise, requiring students to implement additional features such as guard movement, player character updates, and win/loss conditions. Detailed instructions, grading criteria, and bonus opportunities for students to enhance their understanding of object-oriented programming and game development concepts.
Typology: Papers
1 / 12
This page cannot be seen from the preview
Don't miss anything!
(Learning Objective: understand the use of classes and objects, and file operations)
Weight: 1.25% of final grade Submission: Nothing Demonstrate your code to your tutorial TA. You may demonstrate as many times as you wish until you get it right. Your TA can provide feedback each time you demonstrate. To receive marks for the exercise, you must demonstrate to your TA before the end of your enrolled tutorial session on either Wednesday November 30th or Thursday December 1st. Detailed Descriptions The video game industry is a multi-billion dollar industry and it is growing so fast that it is making more money than movie, TV, and music industries combined. Source: 2022 Essential Facts About the Video Game Industry, Entertainment Software Association. In this exercise, you will start to create your own game called Prison Escape.
Step 1: Watch the video posted on D2L to see how the game is played when completed. This is a turn-based game. Every turn, the player character can move by one square, and each of the guards can move by one square. The player's goal is to escape through the door. If the player character moves within a guard's attack range, the guard immediately kills the player character. Step 2: Create a new py file to work on. Name your file classes.py. If it is not called this name, rename it. Step 3 : Download the new file, main.py, from D2L. main.py must be placed in the same directory as your own classes.py file. Download guards.txt and map.txt from D2L and place them in the same directory. The map.txt file contains the layout of the map for the game. The guards.txt file contains the locations and behaviour of the guards. Step 4 : Do not change anything in main.py. Start writing all your code in classes.py. You are allowed to import math, numpy. Nothing else should be imported. In your code, do not import main! It is the other way around: main.py imports classes. Except the import statements (if you choose to import math or numpy), you should not have any code that is outside a class. Import must happen at the top of the code. All your other code should be defined inside a class. Your classes and their methods are going to be used by main.py. You can use anything else that is not forbidden in this document, including creating additional methods in your classes. Step 5: Create a new class called game_map. game_map has the following methods you must create:
In the map file, # represents a wall. P represents the starting location of the player character. E represents the door to escape to. G (not shown in the image above) represents a guard. A space represents an empty space. You can assume this file always has 12 rows, and each row always has 16 columns. Other than that, your code has to read whatever is in the file. If it says that you don't have numpy or pygame , please install it first. The video on D2L shows you how to do it using PyCharm. Demonstrate to your TA that you have done this work.
Weight: 8 % of final grade Due date: Friday December 9th, at 11:59pm Estimated time needed to complete Assignment 4 : about the same as what you spent on Assignment 3. Submission : one classes.py file only, submit on the D2L Dropbox. You may submit as many times as you wish, and only the latest submission will be marked. Late Submissions: Submitting on December 10 th^ will use up one personal day. Submitting on December 11 th^ will use up two personal days, etc. You have a total of 5 personal days for the entire semester. No penalties for using personal days. An assignment will not be accepted if it is late and all personal days are already used.
Academic Integrity: This work must be completed individually. Please follow academic integrity rules as discussed during lecture. You may discuss your ideas in English (not in Python) with other students as much as you like, but make sure that when you write your code that it is your own. A good rule of thumb is to never let anyone else see your code, except your instructor and TAs. Detailed Descriptions Continue working from your tutorial exercise file. Step 6 : Create a new class called guard. guard has the following methods you must create: init(self, row, col, attack_range, movements) Parameters: row, an int representing the current row of this guard col, an int representing the current column of this guard attack_range, an int representing the attack range of this guard movements, a list representing the list of movements the guard will do. Returns: nothing. The init method should remember all the information given to it through the parameters. You can decide on the best ways to do that.
get_location(self) Parameters: Nothing Returns: a tuple of (int, int), representing the row and column of this guard's current location. move(self, current_grid) Parameter: current_grid, a 2D list of 12 rows by 16 columns representing the current grid of the map. Returns: a tuple of (int, int), representing the row and column of this guard's new location. This method moves the guard by one square according to the next command on the guard's movements list, and returns its new location. Guards cannot walk through walls or the player character or the exit, or walk off screen. For example, if it encounters a command "L" and its left square is not empty (or any other invalid The movements list always has the following format [<move 1 >, <move 2 >, …
moves), it remains where it is for this turn. Essentially it just wastes a turn doing nothing. Next turn it will go to the next command on its movements list. Complete this requirement last, after you've done the rest of the assignment. Use current_grid to determine where the walls are, etc. but current_grid will not be created until Step 7. enemy_in_range(self, enemy_row, enemy_col) Parameters: enemy_row and enemy_col, the row and column of the guard's enemy. Returns: a Boolean. True if the enemy at enemy_row and enemy_col is in attack range of this guard. False otherwise. Step 7 : We will go back to the game_map class and fill in the content of this class. init(self, map_file, guard_file) Parameters: map_file, a string representing the name of the map file guard_file, a string representing the name of the guard file Returns: nothing. The init method should read the content from map_file and remember it. You can decide on the best ways to do that. The init method should read the content from guard_file and remember it. For every guard, create a new object using the guard class you defined in Step 6. Keep all the objects in a list.
Returns: a list. The return value is a list of current guard objects. update_player(self, direction) Parameter: direction, a string whose value is one of the four: "U", "D", "L", "R" Returns: Nothing. This method updates the current location of the player character on the grid according to the given direction parameter – moving it one square up, down, left, or right. The player character cannot walk through walls or the guards, or walk off screen. For example, if it encounters the direction "L" and its left square is not empty (or any other invalid moves), it remains where it is for this turn. Essentially it just wastes a turn doing nothing while everyone else moves. Complete this requirement last, after you've done the rest of the assignment. update_guards(self) Parameters: Nothing Returns: Nothing. This method updates the current location of every guard for one turn. For each guard object, calling its move method will move it and have its new location returned. The move method was defined in step 6. Guards move in the order that they are defined in the guards file. player_wins(self) Parameters: Nothing Returns: a Boolean. Returns True if the player character is currently standing on the exit square. False otherwise. player_loses(self) Parameters: Nothing Returns: a Boolean. Returns True if the player character is within the attack range of any guard. False otherwise.
Grading For tutorial exercise: Grade Point Letter Grade Guidelines 4 A All correctly demonstrated to TA 3 B Mostly correct with minor errors 2 C Completed some work 1 D Barely started code 0 F Did not demonstrate to TA For homework assignment: Grade Point Letter Grade Guidelines 4 A+/A Fulfill^ all^ assignment specs, or only one mistake^ that is not an error 3.7 A- Two mistakes/one to two errors, or incomplete tasks 3.3 B+ Three^ to four^ mistakes/errors,^ or incomplete tasks,^ or code crashes on occasions 3 B Five to six^ mistakes/errors, or^ incomplete tasks, or^ code crashes on occasions 2.7 B- More than six^ mistakes/errors,^ or incomplete tasks,^ or code crashes on occasions 2.3 C+ Major^ mistakes/incomplete tasks, portion of code not written,^ and^ code^ crashes 2 C Missing^ code for^ one^ class,^ or^ crashes^ a lot, or use other^ disallowed^ imports^ or code 1.7 C- Missing more than one^ class, or large^ portion of code not written^ and code crashes^ a lot 1.3 D+ Code crashes every time and nothing else is^ returned 1 D Code does not run due to syntax errors 0 F Barely started code,^ or no submission, or late submission with no personal days left The assignment will be graded out of 4 , with the grade based on the program’s level of functionality and conformance to the specifications.