That's pretty good for a first game. I did a similar game when I was learning Python.
Here are some notes about the game, and the source code:
The game crashes when you type a command that doesn't have spaces.
Traceback (most recent call last):
File "interpreter.py", line 15, in interpret
IndexError: list index out of range
The game crashed when I won a battle in the second room. The library.zip didn't contain fulltest.py, but I guess current_room somehow became None.
Traceback (most recent call last):
File "fulltest.py", line 61, in start
AttributeError: 'NoneType' object has no attribute 'describe'
Some kind of help command would be handy.
I recommend writing class names in CamelCase to distinguish them from variable and function names.
You can clear the screen with os.system("cls").
The interpreter isn't terribly good at handling incorrect input altogether, I've noticed. I noticed that if I put in random two-word phrases, it still behaves as if I attempted to move to another room. It started a battle when I typed in "blah blah". The interpreter automatically expects two-word commands and isn't prepared to deal with unexpected input.
Sorry fulltest.py wasn't in the library. I'm still getting the hang of cx_freeze, this is only the second or third time I've used it.
import roomhandler, enemy, combat, classes, random, sys
import interpreter as interpret
armor = classes.armor("Leather armor", 2)
sword = classes.weapon("Sword", 3, 4, 0)
player = classes.char(1, 15, 12, 13, sword, armor)
dlevel1 = [enemy.grue, enemy.grue2]
# The starting room, used to initialize the others
startroom = roomhandler.rooms("", "",
0, 0, 0, 0,
"", "", "", "")
# Rooms defined using the class found inside the
# roomhandler module. See that module for
# more information.
room2 = roomhandler.rooms("Second room", "This is the other room.",
0, 1, 0, 0,
"", startroom, "", "")
room3 = roomhandler.rooms("Third room", "This is another room.",
0, 0, 1, 0,
"", "", startroom, "")
spawnroom = roomhandler.rooms("Starting room", "This is the starting room.",
1, 0, 0, 1,
room2, "", "", room3)
# Updating attributes since all the rooms are defined now.
room2.connectedS = spawnroom
room3.connectedE = spawnroom
# Defines the global variable current_room.
current_room = spawnroom
# Describes the room for the first time. Outside the function so that
# it doesn't describe it twice.
current_room.describe()
def start():
global current_room
while True:
inp = interpret.interpret(input())
enemyroll = random.randint(1, 20)
if enemyroll >= 10:
current_room = roomhandler.move(current_room,inp)
enemy = dlevel1[random.randint(0, len(dlevel1)-1)]
print("\nThere is a " + enemy.name + " in this room!\n")
combat.combatmenu(player, enemy)
if player.hp <= 0:
sys.exit()
else:
current_room.describe()
enemyroll = random.randint(1, 20)
elif enemyroll <= 10:
current_room = roomhandler.move(current_room,inp)
current_room.describe()
enemyroll = random.randint(1, 20)
I imagine the crash after the battle had something to do with unexpected input, as it works fine for me until I intentionally enter something wrong. It attempted to change current_room to the connected room, but interpret.interpret(input()) never returned a valid direction, thus the crash immediately after the battle.
Starting room
This is the starting room.
There is an exit to the north. There is no exit to the south.
There is no exit to the east. There is an exit to the west.
la lah
You cannot do that!
There is a Spawn in this room!
...
The magical force hits the Spawn, doing 11 damage!
You won!
Press return to exit.
Traceback (most recent call last):
File "C:\Python32\Projects\ML20 Engine\fulltest.py", line 68, in <module>
start()
File "C:\Python32\Projects\ML20 Engine\fulltest.py", line 61, in start
current_room.describe()
AttributeError: 'NoneType' object has no attribute 'describe'