-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
98 lines (78 loc) · 2.98 KB
/
game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from pymongo import MongoClient
from sys import path
path.append('.')
import os
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
from pyventureClasses import *
from pyventureClasses.commands import *
class Pyventure(object):
def __init__(self):
self.initializePlayer()
self.initializeCommands()
self.initializeRooms()
self.initializeMap()
self.currentRoom = 0
self.showIntroduction()
self.command = ""
if __name__ == "__main__":
self.main()
def main(self):
while(self.player.hp > 0 and self.numItems() > 0 and self.command != "quit"):
self.rooms[self.currentRoom].describe()
print self.map.showExits(self.currentRoom)
self.getCommand()
clear()
if self.command == "quit":
print "Though you are reknowned throughout the realms as a brave soul, you bravely run away."
elif self.player.hp <= 0:
print "You have tragically succombed to an inevitable violent end. Alas! Alack!"
elif self.numItems() == 0:
print "You have acquired every item in the game. Look at you, you little hoarder! You win!"
else:
print "For unknown reasons, the game has decided to end now. Maybe it was tired?"
print "The end."
def initializePlayer(self):
self.player = Player()
def initializeRooms(self):
self.rooms = [Foyer(self), LivingRoom(self), DiningRoom(self), Bedroom(self)]
def initializeMap(self):
if "TRAVIS" in os.environ:
neighbors = [
{"south": 1, "west": 2},
{"north": 0, "east": 3},
{"east": 0},
{"west": 1}
]
else:
neighbors = MongoClient(os.environ["MONGOLAB_URI"], int(os.environ["MONGOLAB_PORT"])).pyventure.maps.find_one({"name": "alpha"})["neighbors"]
self.map = Mapventure()
self.map.add(len(neighbors))
for i in range(len(neighbors)):
for direction in neighbors[i]:
self.map.connect(i, neighbors[i][direction], direction)
def initializeCommands(self):
self.commands = {
"move": Move(self),
"look": Look(self),
"get": Get(self),
"use": Use(self),
"drop": Drop(self),
"quit": Quit(self)
}
def numItems(self):
num = 0
for room in self.rooms:
num += len(room.items)
return num
def showIntroduction(self):
print "Pyventure = Win!"
print "There are a total of", self.numItems(), "items to collect in this house."
print "Gotta get 'em all!\n"
def changeRoom(self):
self.currentRoom = self.map.next(self.currentRoom, self.direction)
def getCommand(self):
self.command = details("\nWhat would you like to do?: ", self.commands)
self.commands[self.command].do()
if __name__ == "__main__":
p = Pyventure()