Creating A Text-based Map For A Text Based RPG
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, to index 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.
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module