Python Text Based Adventure Game Tutorial!

Поделиться
HTML-код
  • Опубликовано: 14 окт 2024

Комментарии • 101

  • @brookestephen
    @brookestephen Год назад +16

    You could have used a directed graph to hold the story, and objects, with edges connecting the nodes and acting like doorways. You could use a Finite State Machine to keep track of the user's choices, and how they modify game state and achieve game goals. The text adventure you wrote couldn't save state or load state, because it doesn't use the Command Design Pattern. This is a nice beginner tutorial about conditionals and strings!

    • @lemastertech
      @lemastertech  Год назад +5

      Hi, thank you for all the suggestions on potential fixes or improvements! I did mean for this to be a very beginner friendly project to just get started with the basic concept of moving through a storyline. You would definitely not do a massive project in this style of course

    • @brookestephen
      @brookestephen Год назад +1

      @@lemastertech Yup! And it's good for that. I was really just thinking out loud, and I've been inspired to begin a project for a more complex game for more advanced coders.using data structures, graph theory, finite state machines and design patterns like Command

    • @anthonyowens9320
      @anthonyowens9320 6 месяцев назад +1

      do you know of any tutorials that explain what you are saying here in more depth? Im interested in learning more.

    • @twentyeight-p3h
      @twentyeight-p3h 6 месяцев назад

      we're cooked@@anthonyowens9320

  • @adventuresoftext
    @adventuresoftext 2 года назад +11

    I actually have a few little preview videos of my Open World Text Adventure on this channel. Been in development for 6 years. Haven't uploaded anything new yet but it's still being heavily worked on. It's set in Medieval Times with crafting, mining, fishing. Pretty much anything you can dream of doing in a Text Adventure. I also make my own Music in Famitracker. Python works great for this kind of development.

    • @lemastertech
      @lemastertech  2 года назад +2

      Oh dude that’s so cool man! What a fun and unique project, goodluck completing it!!

    • @adventuresoftext
      @adventuresoftext 2 года назад +3

      @@lemastertech it's been a tough road for sure, it's too ambitious for it's own good lol. Recently added multiprocessing so things like animals can make sounds, and having hotkeys so we can move around with the arrow keys.
      It's only downfall is still being in the CMD instead of a proper GUI. But I kinda like it being in a terminal setting, gives it that old school feel lol. But I'm still working very hard on it, have over 30 thousand lines of code split between 9 files. But my favorite thing is the forge, you mine ore like iron and light up the forge with some fuel type items like logs, spark it with your flint and steel, and smelt your iron to ingots. You can pump the bellow for heating up the forge faster, but the forge will heat up overtime while you do other things too. Also just added ovens and cooking.
      So much more to come but geez this is already huge as it is lol. Tile based map, with x and y coordinates, being 1000 x by 1000 y, so that's a million map tiles, so of course I created my own map tile generators and mapper functions to help me build. The game will first build the map of all grass, then I use my smaller mapper functions to build over top of the grass, but it's not destroying the grass, each tile has a previous tile list so if something gets destroyed it can revert back to the very original tile that was there. So that means grass contains a dirt tile, and dirt contrails a water tile.
      I just love what I've built and if it gains fans that's great, but either way I still want this game to be finished cause I want to play it myself lol. Almost everything is randomly generated, player actions have random outcomes (like crafting, you can fail, based on skill levels), I got a system like Mother Nature to handle replanting grass, flowers, bushes, animal spawners, enemy spawners, everything life basically. Everything at random based on time which is stimulated. There's quite a lot in this game already as you can tell, if I keep going I'll need to make like 5 more comments lol. But I'm glad you took the time to look at it at least. I've just recently started this channel in hopes of grabbing people and building a fan base. I'll be uploading more updates and features as they come.

    • @carlant_III
      @carlant_III Год назад +1

      @@adventuresoftextI've recently started a similar project of my own set in space and I've been thinking about doing some of the things you've done but had no idea how. I'm really interested in what you have. Good luck and I hope it's amazing. Can't wait to play hopefully

    • @adventuresoftext
      @adventuresoftext Год назад

      @@carlant_III You're more than welcome to ask questions on how things function. I'm not stingy lol.

    • @carlant_III
      @carlant_III Год назад

      @@adventuresoftext I'm just struggling starting. I've created a rooms system that allows you to travel to different rooms with different items that you can add to your inventory, as well as created the character instance to create characters, but now I'm in Limbo. I keep adding things that fundamentally change what was already written. Before all of this I had a whole separate code without a room system, but it felt too linear. The game has at least one main story but otherwise is pretty open. I saw your video of your demo, and how you have the weather and the map, and how all the new text shows up in the center, whereas mine scrolls.
      The question: where do I start? What do I make the base foundation of the code? For example do I start with the map, or a character, or an interface etc.
      What do I build everything off of

  • @dakotafrazier2985
    @dakotafrazier2985 Год назад +1

    See this video actually taught me something about how python works in general and how to program the if/elif lines. Good practice. Other videos just show you step by step tutorials instead of explaining what the actual code means and how it works like you've done here. With coding it's better to get the general idea of how it works if you're trying to learn it. Otherwise you're just copying someone else's code or game

    • @lemastertech
      @lemastertech  Год назад +1

      Thanks for the nice comment! I try to explain everything I’m doing in depth so you can get familiar with the concepts and not just follow my code exactly!

  • @hisuianarcanine9379
    @hisuianarcanine9379 Год назад +4

    Great tutorial! I was wondering, since nested if statements could get cumbersome after too many, what would be the best option to avoid nesting too deeply?
    I had a thought to make a list of the different areas/scenes and just go to that whenever the prompt allows. For example, in your example I would create area_list = [jungle, desert] and for example, if answer is in that, you go to a different part of your code that has that instead of a nested if statement.
    Does this work and would that be a good alternative to nested loops?

    • @lemastertech
      @lemastertech  Год назад +3

      Thanks for watching! I think your solution could definitely work! You could potentially make almost like a “storyboard” with different scenes and branches, and give every scene a unique index or id, then your code could always be the same regardless of the scene you’re in - you could start by printing “scene prompt” then potentially print valid responses on the next line, and then check what scene you enter based on that response but use the same code looping over and over to process it all!

  • @Steadyrock100
    @Steadyrock100 Год назад +2

    Thanks for posting this! Its going to be a great help for a project for what I have to do for class. I want to set up an inventory mode for items in the rooms that i go into. Whats the best way to do that?

    • @lemastertech
      @lemastertech  Год назад +2

      Hey that’s fun! I would suggest just start with an empty list called “inventory” and when someone gets an item add it to the inventory list, probably just as a string, and when you need a key or shovel or whatever else from the inventory you can just check using if “thing” in inventory! Goodluck!

  • @rosembermorales1995
    @rosembermorales1995 2 года назад +3

    This is a great video. I would love to turn this into a story version as I have some creative stories I ha e written

    • @lemastertech
      @lemastertech  2 года назад

      That would be really cool!! I think python is a very beginner friendly programming language and great for the creative folks!! There's tons of different options for the best ways to do that if you decided you wanted to have a bit more of a graphical user interface than the console window you might want to check out some of the pygame tutorials I've done too because that's a very user friendly GUI package as well.

    • @gurmeharsingh5228
      @gurmeharsingh5228 Год назад

      Im making a project like this could you help me with a story im really struggling

  • @Gramps36025
    @Gramps36025 Год назад +2

    Hey man thanks for uploading this, this is my first project and but it seems like this will be much more bigger then i had realized. So i need to implement a save and load mechanic and since this is my first project i don't really know how to. Can you help?

    • @lemastertech
      @lemastertech  Год назад +3

      Hi. Sounds fun- I would check out my tutorials on how to read and write from text files with python so you can store relevant player info and read it back in! Goodluck!

  • @ForTheSuperEarth
    @ForTheSuperEarth 4 месяца назад +1

    How to make something like, go back button, or go back to previous question or descision? Wich command should I use in Python?

    • @lemastertech
      @lemastertech  4 месяца назад

      Well you could pretty easily go back one question tier using the same nested if else’s but add an option for “return” as an answer! Or you could add a tracking variable that would increment as you progressed through the game and then at any time typing back could take you back to the previous question!

    • @ForTheSuperEarth
      @ForTheSuperEarth 4 месяца назад

      @@lemastertech thank you kind sir, you helped me a lot with my project. 🫡🤗

  • @mrunixman1579
    @mrunixman1579 2 года назад +3

    I am currently writing one due to my childhood dreams associating with this tower. It uses ASCII images too.
    I have tried one previously which was based on Granny's Garden also uses ASCII art.

    • @lemastertech
      @lemastertech  2 года назад

      That's awesome!! I'm always impressed by people who can pull off ASCII art! That takes a lot of patience!!!

    • @mrunixman1579
      @mrunixman1579 2 года назад +2

      @@lemastertech You can now draw the images in GIMP and convert them to ASCII images on the website.
      Granny's Garden one was done all by hand.
      One I am writing now is based on a childhood dream. Ascii art for this one shows the tower and the floor map. I am thinking of trying to draw this in CAD too.

  • @Flowermoond
    @Flowermoond 9 месяцев назад +1

    Is there a way to create empty lines between filled lines? I would like to avoid a text that is too narrow as it makes it harder to read.

    • @lemastertech
      @lemastertech  9 месяцев назад

      Hello! Easiest way would probably be to separate the second line you want into a second string variable so you can control the y height you blit it at!! Hope that helps! You could add a ton of spaces to one string and make it multi line too but that seems harder!

  • @tristenflores4097
    @tristenflores4097 Год назад +1

    In games, if the text message is very long, the developer breaks up the text by requiring the player to click "Continue" or press a button to proceed with the text. What code would be needed for this basic adventure game if I wanted to use a space character as an input?
    Example
    Text message: Is the text book wrong?
    *player presses spacebar and presses enter*
    Text message: It's wrong.

    • @tristenflores4097
      @tristenflores4097 Год назад +1

      if theres a different method you would use, please let me know. Thanks!

    • @lemastertech
      @lemastertech  Год назад

      Hi! Cool idea - I would suggest you have a max line length, and so if you type in a really long message, have a function break your long message into lines and then cycle through them using the space bar-
      To do this you would just need an event handling section under for event in PyGame.event.get()
      That would be if event.type == PyGame.KEYPRESSDOWN:
      If event.key == PyGame.K_SPACE:
      If active_line < current_message_lines:
      Active_line += 1
      Counter = 0
      Basically, if the message hasn’t finished yet, just increment the active line and reset your time counter! Hope this helps!

  • @umbrashadowgaming4974
    @umbrashadowgaming4974 8 месяцев назад +1

    What exactly does the \ do. If you would have printed the same line with out the \ wouldn't it have done the same thing?
    I recently started learning python and I'm kind of working on my first choose you own adventure game. My problem is I keep wanting to increase the complexity. Adding item and stats and all that. Very hard to keep it super simple lol.

    • @lemastertech
      @lemastertech  8 месяцев назад +1

      Haha hey nothing wrong with getting ambitious!! The \ character inside a string is special in python and is usually referred to as the literal I believe! Because a single quote ‘ or double quote “ could end the string, and the letter n is also used to indicate a new line you need the literal often to let the string know not to do or to do the special action associated with many of those characters! Hope this helps and good luck!!

    • @umbrashadowgaming4974
      @umbrashadowgaming4974 8 месяцев назад +1

      Thanks I'll have to experiment a little with \ symbols. I'm could confuse the program because it has a single quote. Good to know. I typically use " marks.

  • @onionbro9439
    @onionbro9439 Год назад +1

    Instead of quitting how would we program a retry option that would restart them at the first choice (after their name)?

    • @lemastertech
      @lemastertech  Год назад

      Hi! I would suggest you could make a while loop that is basically while response != “restart” then do your regular functionality but then put that all inside a function and call the function if the whole loop is exited! So basically your whole routine is inside a function and under a while loop, then if the while loop is exited call the function again!

  • @MystiCalifornia
    @MystiCalifornia 6 месяцев назад +2

    you just saved my gpa

  • @weemanling
    @weemanling 2 года назад +2

    So I don't like the way it quits on any input that doesn't match the string, would it not make sense to have the input decision running in a while loop so it doesn't just end the adventure if they accidentally mistype? If yes how would I do that.

    • @lemastertech
      @lemastertech  2 года назад +4

      Totally valid! You could just do it to where
      While response != “forest” and response != desert”
      response = input(“Forest or Desert? “)
      This would just keep prompting the user to enter forest or desert until they enter a valid request!

    • @weemanling
      @weemanling 2 года назад +2

      @@lemastertech thanks for such a quick response!

    • @miblert3717
      @miblert3717 Год назад +1

      yo dude we have the same profile pic and the same question wtf

  • @ManyDog
    @ManyDog Год назад +1

    So you only need if else and for loops to make an text based adventure game?

    • @lemastertech
      @lemastertech  Год назад

      Yes that is basically it. You could make the program a little smarter and put your message prompts and potential responses in a library and call them sequentially in a function, but that can get more complicated than it has to be!

  • @enfysgreen2758
    @enfysgreen2758 2 года назад +2

    can u do a more complex version where the player can recive damage from fight of by faling

    • @lemastertech
      @lemastertech  2 года назад +1

      I will do a more advanced text based game for sure in the future! I have my next couple games planned out but I’ll add it to my list! Thanks for the idea!

  • @NicholasBelov
    @NicholasBelov 6 месяцев назад +1

    so helpful

    • @lemastertech
      @lemastertech  6 месяцев назад

      Awesome, thank you for watching!!

  • @shotgun2010
    @shotgun2010 2 года назад +1

    What's the easiest way to set this up in a GUI so the text appears in actual text boxes and not a console

    • @lemastertech
      @lemastertech  2 года назад

      Hi, probably using PyGame. It’s a very beginner friendly GUI, Kivy and Tkinter could also each support it but I like Pygame! I have a lot of tutorials on that on my channel as well, goodluck!

  • @flipperflapper6682
    @flipperflapper6682 Год назад +1

    Why does when I open my Python, it looks more like Command Prompt? My Phyton looks different than yours. There is no File, Edit, View, etc

    • @lemastertech
      @lemastertech  Год назад

      Sounds like you installed python but not an IDE to develop in - try downloading an Integrated development environment and then it will work fine for you! I use pycharm, which is available free online from jetbrains.org

    • @flipperflapper6682
      @flipperflapper6682 Год назад

      ​@@lemastertech IDE? There is this thing called IDLE do you mean this? The one with IDLE Shell? oh maybe thats it.

    • @lemastertech
      @lemastertech  Год назад

      @@flipperflapper6682 No - not idle. IDE means integrated development environment. It is a software where you can edit and write python code wihtout needing to do it all in a console window. Google python IDE's and pycharm and visual studio will probably be some of the first ones suggested. Python is a programming language but you still want to write your code in an IDE

    • @flipperflapper6682
      @flipperflapper6682 Год назад

      @@lemastertech oh yeah I dont have it :( alright tnx.

    • @flipperflapper6682
      @flipperflapper6682 Год назад

      @@lemastertech Does it matter which 1 I download? can I just download pyCharm and follow your video?

  • @mushedsugarcane2022
    @mushedsugarcane2022 8 месяцев назад +1

    elif isn't working with mine...

    • @lemastertech
      @lemastertech  8 месяцев назад +1

      Elif is a very rudimentary python concept, if that’s not working it’s very likely your code has an error or something is mistyped!

    • @mushedsugarcane2022
      @mushedsugarcane2022 7 месяцев назад

      @@lemastertech thanks!

  • @KayLa-vv9kj
    @KayLa-vv9kj Год назад

    I'm currently working on an escape room game with 3 choices using lists. I keep coming up with an issue where two options give one way then the next right after for the else statement. I don't know how to fix it. I'm a beginner and it's just in one area. Could you perhaps look at my code and see what I could be doing wrong or any suggestions on how to fix it?

    • @lemastertech
      @lemastertech  Год назад

      Hi, I don’t have a good way of looking at your code but I can offer some advice! I don’t really understand your problem though - is it two different instructions happen one after the other without the user entering anything??

    • @KayLa-vv9kj
      @KayLa-vv9kj Год назад

      @@lemastertech Thank you for your response. I realize I did not explain it all that well. I did figure it out by messing around with it a bit. My issue was the pw was a certain number. so it was if it was correct, one thing happens, if it wasn't correct, something else would happen and then there was an option to go back. when I would choose to go back or put in the wrong code, it would run the if not equal prompt and the else option right after. for now, it seems to be working from all my testing.

    • @KayLa-vv9kj
      @KayLa-vv9kj Год назад

      Another question while you are here, how do I make text-style images like in your thumbnail. I've tried to find a tutorial on it but not quite sure what that style of art is called.

    • @lemastertech
      @lemastertech  Год назад

      @@KayLa-vv9kj Hi! That is called ASCII Art (ascii) because ascii is all the text symbols universally recognized so you can just search online for ascii art pieces and
      there's tons of examples online! goodluck!

    • @KayLa-vv9kj
      @KayLa-vv9kj Год назад +1

      @@lemastertech Awesome! Thank you so much!

  • @SirSkyro
    @SirSkyro Год назад +1

    What happens if they input something wrong i.e pick jungle or desert and they pick lake?

    • @lemastertech
      @lemastertech  Год назад

      Hi, the best way to handle these cases would be change your code to be while answer not in ['jungle', 'lake']: answer = input('pick next location')
      this would just repeat the question forever until they enter a valid response! I tried to show a short and simple way for this video but you can make it a lot more robust doing this!

    • @SirSkyro
      @SirSkyro Год назад +1

      @@lemastertech thank you!! Lifesaver

    • @lemastertech
      @lemastertech  Год назад

      @@SirSkyro you're welcome, thanks for watching and commenting!

  • @chxse4999
    @chxse4999 2 года назад +2

    best tutorial lol

    • @lemastertech
      @lemastertech  2 года назад

      Haha this was a simple one, I try to make some stuff for beginners and some more advanced ones!

    • @chxse4999
      @chxse4999 2 года назад

      @@lemastertech I some how managed to learn everything from this video and i can make a text based game on my own now lol this tutorial is really good!

  • @d_yosepholoan.s_1177
    @d_yosepholoan.s_1177 Год назад +1

    Thx sir

    • @lemastertech
      @lemastertech  Год назад

      You’re welcome thank you for watching!!

  • @basilalcantara1215
    @basilalcantara1215 2 года назад

    what app/website did you use?

    • @lemastertech
      @lemastertech  2 года назад +1

      I program using python in the pycharm IDE which is available free from jetbrains.org I believe!

    • @basilalcantara1215
      @basilalcantara1215 2 года назад

      @@lemastertech can I also do text based game programming in google colab??

    • @lemastertech
      @lemastertech  2 года назад +1

      @@basilalcantara1215 Hi! I think a text based adventure game should be possible in any programming language and on just about any IDE, I have not personally used Google collab for that purpose but I think you would be able to!

    • @basilalcantara1215
      @basilalcantara1215 2 года назад

      @@lemastertech thank you so much!

    • @jananip1201
      @jananip1201 3 месяца назад +2

      Can you tell me what version that you used

  • @itstart2106
    @itstart2106 2 года назад +2

    Cool. Please show pygame text based game

    • @codingcassowary6391
      @codingcassowary6391 2 года назад +1

      Pygame is the best!

    • @lemastertech
      @lemastertech  2 года назад +2

      Cool idea! I will work on something with a PyGame text adventure soon!! Thanks for the suggestion!

  • @lamasavage-ff2dg
    @lamasavage-ff2dg Год назад

    So what if I want to write male or female instead of the jungle and desert??

    • @lemastertech
      @lemastertech  Год назад

      Then… go ahead and write make or female instead of jungle and desert?

    • @lamasavage-ff2dg
      @lamasavage-ff2dg Год назад +1

      @@lemastertech would the follow-up be the same method as the code you wrote in the video? Sorry if I ask stupid questions, I am a self-taught and very new too

    • @lemastertech
      @lemastertech  Год назад

      @@lamasavage-ff2dg Hey no problem! Yes, your questions and follow ups would follow the exact same style just instead of jungle or desert you put if response == 'whatever you want', print('whatever prompt you want'), it does not have to be the same prompts I did here!! Good luck!

  • @lethaletori6146
    @lethaletori6146 Год назад

    Im learning to code to make a better version of s game i like

  • @lethaletori6146
    @lethaletori6146 Год назад

    Am i the only person that likes chocolate covered cherries

    • @lemastertech
      @lemastertech  Год назад +1

      I like chocolate covered cherries too!