Skip to content

Commit 9fecd21

Browse files
corrected player and room classes, added player object to adv.py, created function for grabbing directional input
1 parent 10705e4 commit 9fecd21

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎src/adv.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from room import Room
2+
from player import Player
23

34
# Declare all the rooms
45

@@ -37,7 +38,17 @@
3738
# Main
3839
#
3940

41+
def grab_direction():
42+
direction = input("\nPlease enter a direction of travel: ")
43+
return direction
44+
45+
print("Welcome to the game!\n")
46+
username = input("Please enter your players name: ")
47+
print(f"\nHello {username}, within this game you can navigate rooms using n, s, w, or e")
48+
4049
# Make a new player object that is currently in the 'outside' room.
50+
player = Player(username, room["outside"])
51+
print(player)
4152

4253
# Write a loop that:
4354
#

‎src/player.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
# currently.
33

44
class Player():
5-
name = ""
6-
current_room: "outside"
5+
def __init__(self, name, room):
6+
self.name = name
7+
self.current_room = room
78

89
def change_name(self, name):
910
self.name = name
1011
def move_room(self, new_room):
11-
self.current_room = new_room
12+
self.current_room = new_room
13+
14+
def __str__(self):
15+
return f"{self.name} is currently in the {self.current_room}"

‎src/room.py‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
# Implement a class to hold room information. This should have name and
2-
# description attributes.
2+
# description attributes.
3+
4+
class Room():
5+
def __init__(self, name, description):
6+
self.name = name
7+
self.description = description
8+
9+
def change_name(self, new_name):
10+
self.name = new_name
11+
12+
def change_description(self, new_description):
13+
self.description = new_description
14+
15+
def __str__(self):
16+
return f"{self.name}. {self.description}"

0 commit comments

Comments
 (0)