Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Write a class to hold player information, e.g. what room they are in
# currently.

102 changes: 66 additions & 36 deletions src/room.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# Implement a class to hold room information. This should have name and
# description attributes.

# working room repl
# v2 using room descriptions from class

# template for repl from RockPaperScissers
import random

# Create a RPS game where player can type r, p or s, the computer chooses
# a random move, and the game tells you who won.
# Specification
# The /src directory contains the files adv.py, which is where the main logic for the game should live, room.py, which will contain the definition of the Room class, and player.py, which will contain the definition of the Player class.

# Add a REPL parser to adv.py that accepts directional commands to move the player

# You should be able to play multiple games and the game will tell you
# Your score after each round.
# After each move, the REPL should print the name and description of the player's current room
# Valid commands are n, s, e and w which move the player North, South, East or West
# The parser should print an error if the player tries to move where there is no room.
# Put the Room class in room.py based on what you see in adv.py.

# Type quit to quit.
# The room should have name and description attributes.

# Create a REPL
# The room should also have n_to, s_to, e_to, and w_to attributes which point to the room in that respective direction.

# location and direction
# use a coordinate system for the room location and ID
Expand All @@ -30,15 +31,12 @@
# West
# if w = x -= 1



# Player Location
x = 0
y = 0

# north
movement_direction_choices = ['n', 's', 'e','w']

# the first 4 rooms are
# moving in the cardinal directions
movement_direction_choices = ['n', 's', 'e', 'w']


#stats1:
Expand All @@ -48,7 +46,6 @@
magica = 0
character_class_modifier = 0

stat_choices = ['r', 'p', 's']

#stats2:
earth = 0
Expand All @@ -59,14 +56,37 @@

elemnt_choices = ['e', 'a', 'f', 'm', 'w']

# room0_0 = (0, 0)
# room0_1 = (0, 1)
#room_choices = ['room0_0', 'room0_1']

# room names automatically adjuct to coordinates
room_choices = ['room0_0', 'room0_1']

# variable
new_room_description = ''
room0_0 = 'This is where your adventure starts. It looks like an apple.'
room0_1 = 'This room opens into a peanut shape, and smell like mint.'

# preliminary test (not yet all mapped)
# Room descriptions
room0_0 = "outside: Outside Cave Entrance, North of you, the cave mount beckons"
room0_1 = 'The narrow passage bends here from west to north. The smell of gold permeates the air.'


# room = {
# 'outside': Room("Outside Cave Entrance",
# "North of you, the cave mount beckons"),

# 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
# passages run north and east."""),

# 'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
# into the darkness. Ahead to the north, a light flickers in
# the distance, but there is no way across the chasm."""),

# 'narrow': Room("Narrow Passage", """The narrow passage bends here from west
# to north. The smell of gold permeates the air."""),

# 'treasure': Room("Treasure Chamber", """You've found the long-lost treasure
# chamber! Sadly, it has already been completely emptied by
# earlier adventurers. The only exit is to the south."""),
# }

#https://www.daniweb.com/programming/software-development/threads/111526/setting-a-string-as-a-variable-name
# food = 'bread'
Expand All @@ -84,24 +104,22 @@
# vars()[new_room]
# print(room0_0) # --> 123



# Define a function that compares player and cpu moves
# and returns 1 for a win, 0 for tie, -1 for loss



def player_move_and_outcome(player_move,x,y):

# X and Y vectors translate into
# X and Y vectors translate into:
# North
# if n = y += 1
# if n = y += 1
# South
# if s = y -= 1
# if s = y -= 1
# East
# if e = x += 1
# if e = x += 1
# West
# if w = x -= 1
# if w = x -= 1

# North
if player_move == "n":
Expand All @@ -116,10 +134,16 @@ def player_move_and_outcome(player_move,x,y):
elif player_move == "w":
x -= 1

# The updated vectors are turned into the coordinates of the room
# which is the same as the room-id
new_room_location = (x, y)

# this output the id of the new room, as coordinates in a tuple
return new_room_location


# this function updates the global (or desired)
# variable of the player location
def update_xy(player_move, x,y):
# North
if player_move == "n":
Expand All @@ -134,31 +158,39 @@ def update_xy(player_move, x,y):
elif player_move == "w":
x -= 1

# returns updated location values
return x,y


# LOOP
while True:
# PRINT
print(f"Stats: {health} / {strength} / {stamina} / {magica} / {character_class_modifier}")
# READ
# print("These are your current stats.")
# print(f"Stats: Health:{health} / Strength:{strength} / Stamina:{stamina} / Magica:{magica} / Character Class Modifier:{character_class_modifier}")
# print(f"Elemental Stats: {earth} / {air} / {fire} / {metal} / {wood}")

# print the current location of the player
print(f"You are now in room{x}_{y}. Where do you want to go next?")

# READ

# this is what the player will do
player_move = input("-> ")


# EVALUATE
# If player enter "quit", then quit the loop
if player_move == "quit":
print("Goodbye!")
break

elif player_move in movement_direction_choices:

# find out where the player moved:
starting_location = (x, y)



# updates room and player location to where the player
# chose to move, if a valid move.
new_room_location = player_move_and_outcome(player_move,x,y)
x, y = update_xy(player_move, x,y)

Expand Down Expand Up @@ -204,6 +236,4 @@ def update_xy(player_move, x,y):
#

else:
print("I did not understand that command")


print("I did not understand that command")