1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
k0ka [10]
3 years ago
12

I'm having trouble with an assignment of mine. I'm making a text based adventure game for extra credit in my class and I'm stuck

on where to continue the code. Basically it's a text based adventure game written in PYTHON. Effectively most rooms have an item and the player MUST obtain two of these items (The Magic Sword and Magic Shield) to defeat the lich, if the player does not have these items, then the game gives an instant game over. This is the code I have done so far, it's the going from room to room portion.
#First, all the rooms are set up.
rooms = {
'Entrance': {'East': 'Private Study'},
'Dining Hall': {'South': 'Kitchen', 'North': 'Entrance', 'East': 'Armory', 'West': 'Hidden Room', 'Item': 'Map'},
'Kitchen': {'North': 'Dining Hall', 'East': 'Dungeon', 'Item': 'Food'},
'Dungeon': {'West': 'Kitchen', 'Item' : 'Lich'},
'Old Bedroom': {'South': 'Armory', 'Item': 'Potion'},
'Armory': {'West': 'Dining Hall', 'North': 'Old Bedroom', 'Item': 'Magic Shield'},
'Private Study' : {'West' : 'Entrance', 'Item' : 'Hidden Room Key'},
'Hidden Room' : {'East' : 'Dining Hall', 'Item' : 'Magic Sword'}
}
#Then the starting room is set
room = 'Entrance'
#This definition will set up the function to move betweem rooms.
def move_to_room(room, direct):
new_room = room
for a in rooms:
if a == room:
if direct in rooms[a]:
if isinstance(rooms[a][direct], list): #This if function is set up incase there are ever two paths in a room
b = input()
if b == '1':
new_room = rooms[a][direct][0]
else:
new_room = rooms[a][direct][1]
else:
new_room = rooms[a][direct]
return new_room
#The while loop is the full gameplay loop, the majority in which the player will see.
#First it will display what room the player is currently in, then asks them what they wish to do.
while 1:
print('\nYou have entered', room)
print('If you wish to stop playing, please enter "Stop" or "stop"')
print("Please enter north, south, east, or west please.")
direct = input('\nWhich direction do you want to enter?: ')
#If the player enters stop, then the game stops
if direct == 'Stop' or direct == 'stop':
exit(0)
#The main if for moving between rooms, there is a a there are no paths, then they player cannot move that way
if direct == 'east' or direct == 'west' or direct == 'north' or direct == 'south':
new_room = move_to_room(room, direct)
if new_room == room:
print('There is a wall in your path! Please enter another direction: ')
else:
room = new_room
#Another if incase the player enters with capital letters in their directions
if direct == 'East' or direct == 'West' or direct == 'North' or direct == 'South':
new_room = move_to_room(room, direct)
if new_room == room:
print('There is a wall in your path! Please enter another direction: ')
else:
room = new_room
#If there is an invalid entry that doesn't fit in the rooms, then the player will be told to enter it again.
else:
print('\nINVALID DIRECTION, PLEASE ENTER A VALID OPTION')
Computers and Technology
1 answer:
mihalych1998 [28]3 years ago
7 0
Invalid format in my brain
You might be interested in
Help me out here pleaseeeee
mel-nik [20]

Answer:

Payment

Explanation:

3 0
3 years ago
Read 2 more answers
Sending a busy manager a long email represents a problem in which area of the communication process
FromTheMoon [43]
Time management,they wouldn’t have enough time to read it and they would become more stressed out
3 0
4 years ago
Write a program to find and print the sum of the first n cubes in the following four ways.
klio [65]

Answer:

The solution code is written in Java.

  1. public class Main {
  2.    public static void main(String[] args) {
  3.           System.out.print("Please enter a number: ");
  4.           Scanner console = new Scanner(System.in);
  5.           int n = console.nextInt();
  6.           calculateSum1(n);
  7.           calculateSum2(n);
  8.           calculateSum3(n);
  9.           calculateSum4(n);
  10.    }
  11.    public static void calculateSum1 (int num){
  12.        int sum1 = 0;
  13.        for(int i=1; i <= num; i++){
  14.            sum1 += i*i*i;
  15.        }
  16.        System.out.println("Sum 1 : " + sum1);
  17.    }
  18.    public static void calculateSum2 (int num){
  19.        int sum2 = num * num * (num + 1) * (num + 1) / 4;
  20.        System.out.println("Sum 2 : " + sum2);
  21.    }
  22.    public static void calculateSum3 (int num){
  23.        int sum3 = 0;
  24.        for(int i=1; i <=num; i++){
  25.            sum3 += i;
  26.        }
  27.        sum3 = sum3 * sum3;
  28.        System.out.println("Sum 3 : " + sum3);
  29.    }
  30.    public static void calculateSum4 (int num){
  31.        int sum4 = (num * (num + 1) * (2*num + 1)) / (4+2);
  32.        System.out.println("Sum 4 : " + sum4);
  33.    }
  34. }

Explanation:

Firstly we create four different methods that calculate the sum of the first n cubes in different ways (Line 13 - 43).

This is important to understand the concept of  operator precedence to work out the different ways of summation.

For example, The operator * and / will always have higher precedence than +.

On another hand, any expression enclosed within the parenthesis will have highest precedence and therefore the value will be evaluated prior to others.  

This is also important to understand the expression evaluation will always start from left to right.

3 0
4 years ago
How do you turn on the Track Changes feature in a spreadsheet?
myrzilka [38]
I would "turn on" this track changer as I would usually go to the top left corner, where it would say edit, and then, usually, as you look down at the bottom, you would then see where it would then be a switch that would say "turn on" or "turn off" track changer.
4 0
4 years ago
Which of the following statements is false? A constructor is similar to a method but is called implicitly by the new operator to
Volgvan

COMPLETE QUESTION:

Which of the following statements is false?

A) A constructor is similar to a method but is called implicitly by the new operator to initialize an object's instance variables at the time the object is created.

B0 Scanner method next reads characters until any white-space character is encountered, then returns the characters as a String.

C)A class instance creation expression begins with keyword new and creates a new object.

D) To call a method of an object, follow the object name with a comma, the method name and a set of parentheses containing the method's arguments.

Answer:

D) To call a method of an object, follow the object name with a comma, the method name and a set of parentheses containing the method's arguments.

Explanation:

To call a method, the name of the object is not followed by a comma (,) but with a dot (.) operator, the method's name and a set of parentheses containing the method's arguments, then follows.

4 0
3 years ago
Other questions:
  • Select the correct answer.
    8·1 answer
  • Basic engine operation can be divided into four stages. These stages are
    13·1 answer
  • Assume that the myname.txt file is currently closed. write the code segment that opens the file without erasing it, write anothe
    13·1 answer
  • A(n ________ is information that is passed to a function, and a(n ________ is information that is received by a function.
    15·1 answer
  • 14. You can store data copied from any Office application file with the
    14·1 answer
  • Which of the following views hides the ribbon and shows text on the screen in an easy-to-read format?: *
    11·1 answer
  • What wireless networking standard provides the best performance at the farthest edge of its reach
    8·1 answer
  • Review the HTML tags that we have gone over in this lesson. Research HTML tags on the web and identify two new tags. Use these t
    9·1 answer
  • Pick a web browser (a leading one or perhaps a lesser-known one that you use) and examine the Privacy and Security features and
    10·1 answer
  • Video games, regardless of their level of realish, had added a new dynamic to the world games and Entertainment the ability to s
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!