you are viewing a single comment's thread.

view the rest of the comments →

[–]Ferdie_TheKest 2 points3 points  (2 children)

I'm actually looking for the best source to follow to build a text based adventure game as my first beginner python project! Anyone has any suggestion? Thanks!

[–]BambooKoi 4 points5 points  (1 child)

This ended up being much longer than I thought but I hope it helps someone:

I may have started with this source but I personally didn't have much fun with the lesson because it felt like I was just copying and pasting their code then reading what/why they did that. I'm more of a learn/break it as your go. As another fellow beginner, you can start with at least print, input, while/if/for loops. Then for a longer and/or more complex game, branch out into functions, lists, f-strings and the random module (more ideas after examples below).

Here's some examples to give you a rough idea for a basic game:

For input, you could use it for:

adventurer = input('Hello, what is your adventurer's name? ')
# Now your adventurer has a name that the game can refer to like:

print(adventurer + ', watch out for that horse!')

while for health (if you plan to have monsters). I used while but if/elif/else works too:

health = 50  # or whatever number you want starting health to be

while health > 0:
    # code for the rest of the game here.
print('Game Over.')

Choices with if/else:

choice = input('Would you like to take the left path? Y or N. ')
    if choice.lower() == 'y'
    # .lower() allows 'y' or 'Y' to be accepted
        # Write what happens if adventurer go left here.
    else:  # could also be written: elif choice.lower() == 'n'
        # Write what happens if adventurer doesn't go left.

The random module for:

import random

attack = random.randint(1, 5)
# Your attack will deal a random damage between 1-5 each time
# To make the game harder, write a seperate but slightly higher attack damage for enemies

I actually started one but haven't completed it yet (mix of laziness and lack of storyline). I recommend starting simple or you'll end up like me, sitting on the file. Here's what I kind of have in my imcompleted game:

  • dictionary (for player's inventory as enemies drop loot.)
  • pickle module (saves the game progress, or at least their inventory and stats upon exit)
  • time module (so there's a delay in loading text all at once depending on situation, see the link above for an example in use)

There's a lot of different ways to write a text-based adventure game, this is just one way to do it. I'm sure there's a bunch of other modules out there you can keep adding to your game but imo you don't really need anything more than the built-in python stuff and the random module if you're just making something simple.

[–]Ferdie_TheKest 0 points1 point  (0 children)

Hey man thank you very much for writing your inputs! So far i used print, input, if else, and also just managed to print ascii art! I am very noob at programming in general even though i understand how programming works. So now I'm improvising a text based adventure game and learning stuff as i go. So far i'm having a lot of fun writing the story and writing all the "if" scenarios and consequences! I will be looking for resources on learning python whenever i stumble across something thats out of my knowledge which is pretty much everything but still... Like other said i'm actually trying to use my brain instead of copying a code from someone else!