Commits

rablador  committed 60d6ed5

Project startup. Some initial code based on an existing example.

  • Participants

Comments (0)

Files changed (5)

+__pycache__
+trash

File libs/__init__.py

Empty file added.

File libs/player.py

+# Player class
+class Player(object):
+  def __init__(self, name, gender, hair, age, location):
+    self.name = name
+    self.gender = gender
+    self.hair = hair
+    self.age = age
+    self.location = location
+    self.inv = []
+
+  def look(self):
+    place = self.location
+    print(place.description)

File libs/room.py

+# Room class
+class Room(object):
+  def __init__(self, name, description):
+    self.name = name
+    self.description = description
+from player import Player
+from room import Room
+
+# Rooms
+#
+# ===================
+# | |
+# | |
+# | 1 |
+# | |
+# | 3 2 |
+# | |
+# | |
+# | |
+# | |
+# ===================
+
+room1 = Room("Bedroom", "You are you in your own bedroom.\nTo the south, there is a garden past the back door.")
+room2 = Room("Garden", "You are in a garden with many flowers and a narrow stone path. \nTo the north, you see the backdoor of your house that enters your bedroom.\nA pathway leads west.")
+room3 = Room("Pathway", "You are in a narrow stone path with hedges on both sides of you.\nTo the east, there is a garden.")
+
+# Room coordinates (had to create all the rooms to assign them to coordinates)
+room1.coordinates = [0, 0, room2, 0]
+room2.coordinates = [room1, 0, 0, room3]
+room3.coordinates = [0, room2, 0, 0]
+
+player = Player("Mika", "m", "black", 20, room1)
+
+print(player.name, "Welcome to Text Adventure\n")
+print('Type "commands" to see the command list')
+
+# Menu
+# "commands" shows the commands available
+# "look" looks around in the current room
+#
+while True:
+  command = input('')
+  if command == "look":
+    player.look()