Explore a dungeon filled with traps and treasure

Assignment Help Python Programming
Reference no: EM132403252

Assignment

In this question, we will write some classes with methods to allow the user to play a small game involving going through a dungeon looking for treasure. We will define two classes: a Player class and a Dungeon class. When writing your code for this question, please use the accompanying dungeon_template py file. It contains important helper code and has spaces for you to fill in, corresponding to each method below.

The Player class should contain the following methods:

1. A construct or that takes in one argument: a string with the name of the player. It should set the name attribute to be equal to the given argument, and also set a health attribute to the integer 10.

2. A get name method that returns the name of the player.

3. A get health method that returns the health of the player.

4. A set health method that sets the player's health to be equal to the given argument. If the given argument is not an integer, or it is an integer but not greater or equal to zero, then you must raise a ValueError.

The player will explore a dungeon filled with traps and treasure. The dungeon geography will be specified by a dungeon map file on disk, which you will load in and parse as a list of lists (see below for more details). A sample dungeon map file (dl. txt) is provided to you in the accompanying files. You can create other map files if you wish, but it is not a requirement for this assignment. As you will see when looking in the di.txt file, the dungeon map file contains a grid where the top-left character (first row, first column) represents the coordinate (0, 0) of the map. Here is the contents of the di.trt file, to better illustrate the representation:

The dungeon map conforms to the following format:

1. It must have the same number of rows as it has columns, and it must be of size at least 4x4.

2. There are three valid characters in the map: T for treasure, * for empty space, and x for an impassable wall. Any other characters are invalid.

3. There must be at least one T (one treasure) in the map.

When testing your code, make sure that the dl. txt file (or other map file, if you have created one) is in the same folder as your Python code file, so that you can load it properly.

The Dungeon class should contain the following methods:

1. A constructor that takes in two arguments: a string representing the filename of the dungeon map file, and an integer representing the number of traps to add to the map. It should call the read_map_file method (see below) to read in the map at the given filename, and store the returned list of lists into a class attribute called dungeon_map. Then, it should check if the above properties of the dungeon map are respected or not.

If there is any problem (non-square grid, grid smaller than 4x4, invalid character, no treasure), you must raise a ValueError and give an appropriate message for each case. You must also raise a ValueError if the number of empty spaces in the map is less than the specified num_traps argument, or if the num_traps argument is lower than zero. If there are no problems, then you should set an attribute num_traps equal to the argument of the same name, then call the add_traps method (the code for which is provided to you in the template file) in order to add traps to the map (which will be represented by the character).

2. The read_map_file method takes in one argument: a string containing the filename of the map file to load. It should read in the file from disk, and return a list of lists corresponding to the dungeon map contained in the file. Note that the returned list should not contain any strings; rather, it should contain n lists (where n is the number of rows in the file), and each of those lists will contain m single characters (where m is the number of columns in the file).

3. The get_coords_of_empty_spaces method takes in no arguments, and returns the x, y coordinates of empty spaces (' *' characters) in the dungeon map as a list of tuples. If there are no empty spaces, it should return an empty list.

4. The get_char_at method takes in one argument: a tuple containing two elements, corre-sponding to an (x, y) coordinate, and returns the character in the dungeon map at that (x, y) coordinate.

5. The visit square method takes in two arguments: a tuple containing two elements, corre-sponding to an (x, y) coordinate, and a player object. The method returns either True (if the game is over) or False (otherwise). It should call get_char_at to obtain the map character at that coordinate. The game is considered over if the current square contains treasure. If the square contains a trap (i.e., character), the player's health should be decremented by 1. If the player reaches 0 health in doing so, then the game is also considered over. If the game
is over, the function should (before returning True) also print a message to the screen telling the player why the game is over.

Filename

You must write this program in a file called dungeon.py.

Attachment:- Program File.rar

Reference no: EM132403252

Questions Cloud

What your channels of distribution will be : Explain who the target market for the product is, how you will set price, how you will promote your product and what your channels of distribution will be.
How much will be her recognized interest income this year : If she elects to amortize the bond premium, how much will be her recognized interest income this year?
How would you describe seahornet boards cash flows : How would you describe SeaHornet Boards' cash flows for 2011? Write a brief discussion
Calculating eac : You are evaluating two different silicon wafer milling machines. The Techron I costs $245,000, has a three-year life, and has pretax operating costs
Explore a dungeon filled with traps and treasure : Explore a dungeon filled with traps and treasure. The dungeon geography will be specified by a dungeon map file on disk, which you will load in and parse.
Calculating annuity values : Bilbo Baggins wants to save money to meet three objectives. First, he would like to be able to retire 30 years from now with a retirement income
Calculating total cash flows : Schwert Corp. shows the following information on its 2015 income statement: sales 5 $215,000; costs 5 $117,000; other expenses 5
What are the proceeds for the issuer : What are the proceeds for the issuer (in millions of dollars to the nearest three decimal places; don't show $ sign or commas eg 18.404)?
How many shares does the company need to issue : A new fleet of planes and needs to raise $28.3092 million (net of underwriting cost) to fund an expansion. If the offer price is $4 and the underwriters require

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd