Currently, I am creating a text based RPG. I am wondering how I could go about creating a somewhat interactive map, defining specific tiles to hold certain world information like enemy AI and loot or places like towns and dungeons, how to create text based maps for those places, and how to track player movement throughout the world.
I want the world to be borderless, so that player's could hypothetically play the game forever. If I were to create a few classes defining a town, how could I pull a random town object to a certain tile in the world environment for the player to interact with?
How would I go about structuring my player classes, enemy and character AI classes, and room classes?
Lastly, how could I go about creating a text-based visual map for the player to use?
Thanks for any help
This questions was definitely too broad, so I narrowed it down a little bit. To focus on what I solved, I will first state the problem: 'How can I make a map -- primarily from a list -- that contains certain properties that can interact with players, i.e. enemy AI and loot tiles, and hold information about places like towns and dungeons, for the purpose of a text-based RPG?'
I solved this issue like this:
class Player(object):
def __init__(self, name):
self.name = name
def movement(self):
while True:
print room.userpos
move = raw_input("[W], [A], [S], or [D]: ").lower() #Movement WASD.
while True:
if move == 'w': #Have only coded the 'w' of the wasd for simplicity.
x, y = (1, 0) #x, y are column, row respectively. This is done
break ##to apply changes to the player's position on the map.
a = room.column + x #a and b represent the changes that take place to player's
b = room.row + y ##placement index in the map, or 'tilemap' list.
room.userpos = tilemap[a][b]
if room.userpos == 3:
print "LOOT!" #Representing what happens when a player comes across
return room.userpos ##a tile with the value 3 or 'loot'.
break
class Room(object):
def __init__(self, column, row):
self.userpos = tilemap[column][row]
self.column = column #Column/Row dictates player position in tilemap.
self.row = row
floor = 0
entry = 1
exit = 2
loot = 3 #Tile map w/ vairbale names.
tilemap = [[0, 1, 0], #[floor, entry, floor],
[3, 0, 0], #[loot, floor, floor],
[0, 2, 0]] #[floor, exit, floor]
room = Room(0, 0) #Player position for 'room' and 'Room' class -- too similar names
user = Player('Bryce') #for larger exercices, but I figure I could get away with it here.
def main(): #Loads the rest of the program -- returns user position results.
inp = raw_input("Press any button to continue.: ")
if inp != '':
user.movement()
print room.userpos
main()
If I were to load this program, and 'move' the character value forward with 'w', from index[0][0], to index[1][0] of the list -- up one row -- it returns the value 3. This is done by mapping the userpos variable of the Room class to specific indexes inside of a map list, and tracking any changes through Player function movement.