Dec-02-2019, 10:25 AM
I'm struggling to know an exercise from my python book on game architecture. This is for roguelike game structure.
It is an follows:
define a class of type Room, with an __init__ function which takes two values, a width and a height, and uses those to define the object's room size. You should also define class variables x,y which give the initial location of the user in the room (best to make this location (0,0) to start with).
write a helper function/method for your class which allows the room to draw itself
write class functions/methods named left, right, up, down which change the location of the user in the room - taking proper account of the room walls!
Your main program should then be the following to allow keyboard control of the user in the room:
myRoom = Room(4,4)
myRoom.draw()
while True:
s = input()
if s=='a': myRoom.left()
if s=='s': myRoom.right()
if s=='q': myRoom.up()
if s=='z': myRoom.down()
if s=='x':
print("all done")
break
myRoom.draw()
It is an follows:
define a class of type Room, with an __init__ function which takes two values, a width and a height, and uses those to define the object's room size. You should also define class variables x,y which give the initial location of the user in the room (best to make this location (0,0) to start with).
write a helper function/method for your class which allows the room to draw itself
write class functions/methods named left, right, up, down which change the location of the user in the room - taking proper account of the room walls!
Your main program should then be the following to allow keyboard control of the user in the room:
myRoom = Room(4,4)
myRoom.draw()
while True:
s = input()
if s=='a': myRoom.left()
if s=='s': myRoom.right()
if s=='q': myRoom.up()
if s=='z': myRoom.down()
if s=='x':
print("all done")
break
myRoom.draw()