Simple Python Project | Text-Based Adventure Game: Time Unraveled

Поделиться
HTML-код
  • Опубликовано: 14 окт 2024
  • In this python tutorial, we create a text-based adventure game called: Time Unraveled.
    This simple python project requires little to no previous python experience. The premise of the game is that you are trapped in a time loop and must escape by choosing the right series of paths. Clues are given when you take the wrong path.
    There are only a few aspects of this program: print statements (for the story), variables, functions (for each path), for loops, and [import time and import sys] to add a delay between lines so the screen doesn't flood with text. I walk through every step of the game and the source code is included below.
    This is the first program I've written in Python so far. I hope you enjoy the game!
    Download the full source file for this project here: github.com/tim...
    If you'd like more python tutorials, I put together a list of 10 easy to intermediate projects: compscicentral...
    Music used to make this video
    Adventures by A Himitsu / @ahimitsu Creative Commons - Attribution 3.0 Unported- CC BY 3.0 creativecommons... Music released by Argofox • A Himitsu - Adventures... Music provided by Audio Library • Adventures - A Himitsu...

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

  • @CompSciCentral
    @CompSciCentral  4 года назад +14

    I hope you enjoyed the game! Here are a few timestamps:
    0:00 Introduce myself
    0:06 Introduce the project
    0:25 5 Development steps
    3:09 LET THE CODING BEGIN
    3:14 ++Game Title
    3:59 ++Start Game?
    6:24 ++Intro Function
    10:05 ++Define remaining functions
    13:53 ++Path3
    20:52 ++Path3_1 and Path3_2
    29:09 ++Time delay (Game Title)
    31:40 ++Time delay (Intro Function)
    35:55 ++Time delay (Path3, Path3_1, and Path3_2) (And my cat meowing 😹)
    42:03 TESTING THE GAME

    • @greatfeeler4490
      @greatfeeler4490 3 года назад

      Can you please suggest a story or suggest from where can i get so that I can create programming on it I am unable to find one but inorder to create I need a story first so please🙁☹

    • @CompSciCentral
      @CompSciCentral  3 года назад

      @@greatfeeler4490 lol you don't know any stories? Why not recreate a text-based harry potter game, or a dungeon quest. Something along those lines

    • @greatfeeler4490
      @greatfeeler4490 3 года назад

      @@CompSciCentral I couldn't understand what you mean by recreate

    • @greatfeeler4490
      @greatfeeler4490 3 года назад

      @@CompSciCentral I am new to this I mean just few days before I heard I mean about game not python

    • @CompSciCentral
      @CompSciCentral  3 года назад +1

      @@greatfeeler4490 hey it's all good. By recreate I mean you can make your own story.

  • @benjenkins2415
    @benjenkins2415 4 года назад +25

    Exactly the type of project I was trying to find. Thanks for putting it out there.

  • @TheHeidishuler
    @TheHeidishuler 3 года назад +10

    Oh man am I happy to have found you!!I have worked on this assignment all week and struggled. Your tutorial was the most helpful.

    • @CompSciCentral
      @CompSciCentral  3 года назад +1

      Awesome! I'm happy that this helped with your assignment! I'll be posting more python tutorials like this in the future so feel free to subscribe if you'd like a heads up when they're released =D

  • @prettyzucchini2207
    @prettyzucchini2207 3 года назад +3

    Thankyou SO much for posting this.
    I am enrolled for my bachelors, and am starting my first CS course next month!
    I was so excited, I wanted to get a head start, because the projects are Text Based RPGs
    you have NO idea, or maybe you do. HOW MANY VIDEOS I HAD TO CLICK THROUGH to find something that explained it in such a straight forward, non complicated way.
    You have helped me so much!
    Thankyou!

    • @CompSciCentral
      @CompSciCentral  3 года назад

      It's my pleasure! You have no idea how happy reading comments like this makes me, lol. And I use YT for tuts and I know great it feels to FINALLY find the video you need. But congrats on starting CS! Good luck, I'm sure you'll do great!

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

    This was very helpful keep up the good work, I wanted to learn the aspects and the basic tree on the program and this was really good, You coulve cut up some parts, but overall the most helpful one byfar! Keep it up!

  • @akellner2
    @akellner2 3 года назад +1

    I start to learn to program in python and this helped me very much. It is a lot of fun to see, how you code the different paths and so I lerned a lot and could use it for my own text adventure. Since I played a little bit with your code, I really enjoy coding. With a textadventure it is a lot of fun and I can impliment a lot of new code I learn in several tutorials. Thank you very much.

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

    Thank you so much. I love the project, and the sound of the keyboard as well. Very ASMR,:)))

    • @CompSciCentral
      @CompSciCentral  4 года назад +1

      Thank you for watching and thanks for the compliment! I actually really enjoy the sound of the keyboard also!
      Take care,
      -Tim

  • @assassin1a88
    @assassin1a88 3 года назад +1

    This is Sick man! Thanks for taking the time to make this , it really helped me.

    • @CompSciCentral
      @CompSciCentral  3 года назад

      Hey no problem! I'm glad you enjoyed it!

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

    Just watching this to see your process of making everything is a ton of help! I still have a bit more basics to learn before making my own, but I'm definitely going to give it a shot, thank you!!

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

      That's awesome, I'm glad you found this helpful!

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

    This is awesome! Thanks for sharing!

  • @EyJoe
    @EyJoe 4 года назад +4

    Hi nice idea, i am a beginner in programming. I do this print("
    ") for newline or just after a text
    i think its better then always "print()". Your keyboard its a bit to loud (no hate)... keep going :D

    • @CompSciCentral
      @CompSciCentral  4 года назад +1

      Thanks for watching and for the feedback! I'll eventually get a new mic but the one I have currently ends up pretty close to the keyboard. But yea you're totally correct about the new line feature, that would probably be better and save us a few lines of code!
      -Tim @Comp Sci Central

    • @rhyle_7845
      @rhyle_7845 3 года назад +1

      Ey, you could also do something like
      print("This is the text I want to print", end="
      ")

  • @griswoldthegoblin9420
    @griswoldthegoblin9420 10 месяцев назад

    It helped me with my project, thanks.

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

    What a funny code style 😂, but i like this content

  • @cwaterbottles
    @cwaterbottles 3 года назад

    Thank you so much for this. This is exactly where I needed to be after diving into the CompSci rabbit hole. This is probably the type of project people should start out when trying to make games. This really helped me a lot to actually start and finish something. I think what I’m going to do now is take this concept and try to implement this idea with some classes, what do you think?

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

      Hey, I think that's a great idea! Did you ever end up adding to the project?

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

    Hello ! thank you so much for the tutorial but I have an error with the path :
    "path_2_1" is not definedPylancereportUndefinedVariable
    Do you have an idea of why I have this pb ? Thank you so much again for this amazing tutorial

  • @CloudU08
    @CloudU08 3 года назад

    This was extremely helpful. Thank you for showing me what I was doing wrong.

    • @CompSciCentral
      @CompSciCentral  3 года назад

      Thanks for the feedback! I’m happy to help

  • @Hana_Jenniee20
    @Hana_Jenniee20 4 года назад

    where did you write this program in? and thanks a lot this helped me a lot.and the keyboard sound is like ASMR i loved it

    • @CompSciCentral
      @CompSciCentral  4 года назад

      Thank you for watching, I'm so glad this helped! I used the free version of PyCharm IDE, I really like it :)

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

    This is great, minus the fact that I watched about 10 mins of someone writing a print statement.

    • @CompSciCentral
      @CompSciCentral  4 года назад

      yea lol there are so many print statements in this project. If I were to redo this tutorial, I would have copied and pasted those in to save everyone a little time in watching this. Anyway, thank you for watching. I hope you enjoyed it nonetheless!

  • @badger160
    @badger160 4 года назад +6

    putting empty prints in your code makes it ugly. Tip: use
    at the end of your print statement to skip a line

    • @CompSciCentral
      @CompSciCentral  4 года назад

      Thanks for the tip!

    • @stuartknox1621
      @stuartknox1621 3 года назад

      zXMurkyXz A bit of positivity to accompany your remark would be good. Someone takes the time to create and post this for others and all you do is criticise. Constructive criticism is helpful but why not praise the effort?

    • @badger160
      @badger160 3 года назад

      @@stuartknox1621 it was not ment like that, I was just giving him tips.

  • @oopsitsdeleted6996
    @oopsitsdeleted6996 4 года назад

    damn. so much dedication. great work man!

    • @CompSciCentral
      @CompSciCentral  4 года назад

      Thank you so much! I really appreciate it! :D

  • @basiladeeb
    @basiladeeb 3 года назад

    Why did you use the sys.stdout.write() and flush() methods in the for loop? The print() method you have been using throughout the program does the same job.

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

      Honestly, I watched another tutorial that used those methods for the text effect. I was just doing what they did lol

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

    when i hit run,my code prints downward instead of to the right.do you know why this may be happening?

    • @CompSciCentral
      @CompSciCentral  3 года назад

      It would help if I saw your code. Feel free to copy it to github and comment the link here and I’ll look at it. But the way you describe it sounds like it’s proceeding to the next line after it’s printing each character. The question is what part of the code is causing this.

  • @DimiG77
    @DimiG77 3 года назад

    Man this is awesome i really enjoy it! Thank you, so much!

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

    Hey, I was curious. My program isn't believing me when I define things, like no matter what it gives me "path3 isnt defined" even thoguh I clearly did. Is there a cause of this sort of thing?

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

    How do you run it in this black seperate window? I names it main.py but it just opens the pycharm editor.
    My deadline is tommorow!

  • @Sinister-zm1fb
    @Sinister-zm1fb 3 года назад +1

    Thanks a lot! I understood everything except the part when you opened your code in a different window. My file is already named main.py but when I open it it just shows a document with the code. Can I fix this?

    • @CompSciCentral
      @CompSciCentral  3 года назад

      Hey I'm sorry man it's tough for me to troubleshoot. Do you have Python installed on your computer?

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

    how do i get my python to look like yours? mine is just a core code block not a project file like yours.

  • @abeerarora1076
    @abeerarora1076 3 года назад

    superb project , loved it

  • @wilsonwoman3
    @wilsonwoman3 3 года назад

    I would love to know what program you are using to create this...what text editor are you using?

    • @CompSciCentral
      @CompSciCentral  3 года назад

      I used Pycharm for the IDE, I highly recommend it.

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

    How did you Made the Programm run on the Black background?

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

    if i use print delay fuctions instead does it still work?

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

    Thank yoy so much
    You helped me very much

  • @ferz1090
    @ferz1090 3 года назад

    If anyone wants to make these, I suggest using google forms to make one. There is a way you can make it so if you answer eg. B on one part, it takes you to section 17, but if you answer eg. A, it takes you to section 3 etc.

    • @CompSciCentral
      @CompSciCentral  3 года назад

      That’s a cool idea I never thought of that

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

    Did you forget the shortcut for copy paste whwv writing all those repetitive print statements

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

      No. I know it's repetitive and inefficient but sometimes when you're learning something new, the repetition can help.

  • @kdesano8
    @kdesano8 3 года назад

    Can we add a skip line button? Like when you press 'Spacebar' the text will skip to the whole dialogue. Just like in RPG when you are rushing through the speech by smashing a button.

    • @CompSciCentral
      @CompSciCentral  3 года назад +1

      Oh that's a great idea. I'm not sure how that would be implemented though.

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

      You can try to add settings for your game to disable animation.

  • @kattam312
    @kattam312 3 года назад

    if you don't mind me asking, how would you implement a feature where it saves the progress of the player so they can leave and return back ?

    • @CompSciCentral
      @CompSciCentral  3 года назад +3

      That's a great question. I don't think it's necessary for this game. Also, full disclosure, I've never attempted to do that so I'm not totally sure. However, my first guess on how to do that would be to import a .txt file and save all of the choices onto that as the player makes them. Then when the game reboots and imports the file again, it also loads all previous decisions.

    • @kattam312
      @kattam312 3 года назад

      @@CompSciCentral thanks, I will look into it !!

  • @lucarudloff687
    @lucarudloff687 3 года назад

    7:30 what does the I\ do in that line?😅 i'm totally new to programming...

    • @lucarudloff687
      @lucarudloff687 3 года назад

      Line 14

    • @CompSciCentral
      @CompSciCentral  3 года назад +1

      Hey Luca! I'm so happy to be one of your first stops on your journey to programming. The backslash ( \ ) is used to escape a special character. In this case, the special character is the single quote. I used single quotes to contain the string, so the program would see the single quote and think I was ending the string, unless I use a backslash just before it, then it treats it like a normal character. I hope that helps! If you'd like to learn more about this, here's a helpful article.
      www.w3schools.com/python/gloss_python_escape_characters.asp
      Good luck with your learning!

    • @lucarudloff687
      @lucarudloff687 3 года назад

      @@CompSciCentral thanks! I started actually programming now and ran into yet another problem: if i create a fike in pycharm and save it to my desktop, it:
      Splits my file into main.py and [wgat i named it].py
      2. Saces it as a .py, but if i click the file, doesn't open it in Pycharm. I have to manually srlect the programm again to get my code file up😅

    • @CompSciCentral
      @CompSciCentral  3 года назад

      @@lucarudloff687 That's interesting... I'm not sure what would cause that and to be honest, I'm not sure how to solve that. However, if you want to look into Pycharm's documentation, you might be able to find out why that's happening: www.jetbrains.com/pycharm/learn/

    • @lucarudloff687
      @lucarudloff687 3 года назад

      @@CompSciCentral thx, i will look into that😅

  • @johnstreety642
    @johnstreety642 3 года назад

    do you still have a link to the info graphic that you used to explain your code?

    • @CompSciCentral
      @CompSciCentral  3 года назад

      Here's a link to the document with everything including the graphic. I made it public :D docs.google.com/document/d/1VSsHlzn0hHnPtfY6jvJ3ZrnzYhLTmA3Km3VGtLCGODY/edit?usp=sharing

  • @sedenions
    @sedenions 3 года назад

    Within some of my functions, which I call chapters and sub-chapters, I have if statement after if statement. For some reason, my adventure program is selectively playing ALL of the options, choosing Yes when I typed in No, and ultimately giving me a hard time. Why is this? Should I make more functions and less if statements piled on top of each other?

    • @sedenions
      @sedenions 3 года назад

      Also, can each instance of my variable 'choice' be named the same, 'choice'? Or do I have to make 'choice1' and 'choice2' for each decision?

    • @CompSciCentral
      @CompSciCentral  3 года назад

      I would have to see your code to be sure so if want, put your code on github and drop the link here and I’ll take a look. But it sounds like possibly you should use elif or else instead of the following if statements. Also each variable needs a different name as long as it’s in the same function.

    • @lucarudloff687
      @lucarudloff687 3 года назад

      I have a similar problem... i hit "run" and it plays the game for me, choosing answers without any of my input... must've screwed up somewhere mid-code, bc it ran fine before

  • @lucarudloff687
    @lucarudloff687 3 года назад

    Ok, but: as soon as i tried running the game up to path1_2, it just began answering for me?! Like, picing Y and 1 all by itself?! Anyone else had that problem? Code was fine before

    • @CompSciCentral
      @CompSciCentral  3 года назад

      Hey Luca, I’m sorry you’re running into some issues, but keep working through the bugs in your code, I know you can do it! You can also start a github account and paste your code in there and share the link with me and I’ll be happy to look it over. Otherwise, you may want to use another resource to reference and this may be a good one. www.freecodecamp.org/learn/scientific-computing-with-python/ there’s some complex stuff in there, but the first part is beginner friendly and will teach you the basics. Other, just search for ‘python basics’ and you should find some good material.

  • @rhyle_7845
    @rhyle_7845 3 года назад

    I know this was 5 months ago but: I would recommend making a method to handle the slow printing so you don't have to copy and paste.

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

      Yea, looking back I definitely should have done something to eliminate some of the redundancies. Thanks for watching and for the tip, hope you're doing well :D

  • @wilsonwoman3
    @wilsonwoman3 3 года назад

    I myself have recently started learning Python. For anyone interested check our the courses on Python that are free at the EdX website. Also recommend downloading an app called "M1M0" that teaches you basic Python coding!

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

    Which version of Python is this? I have downloaded Pyton 3.10 and when I open Idle I got a white screen. Can someone help? XD

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

      Hey sorry I never got back to you! When you download python to your computer, you're just allowing your computer to understand python. You still need something like PyCharm, an IDE where you can write and run python programs. Let me know if that helps!

  • @tristancowen5636
    @tristancowen5636 3 года назад

    wouldn't a better of doing the print statements would be to just store all the dialogue in a text file (or even more sophisticated, a json file) and then print out all the indexes?
    seems quite lengthy and unsophisticated to write all that out!
    But anyhow, besides that, pretty cool tutorial.

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

      Yea I totally agree even as I was writing all of these print statements I was telling myself that there has to be a better way. Definitely unsophisticated but I was new to Python when I made this lol. But I appreciate your feedback, thanks for watching! And Happy new year!

  • @ronja2873
    @ronja2873 3 года назад

    Thank you so much!!

    • @CompSciCentral
      @CompSciCentral  3 года назад +1

      You're welcome! Have an awesome day :D

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

    Thanks so much for making this video! I've learnt a lot :-)

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

      You are very welcome! I'm glad you enjoyed it!

  • @rafinalam3015
    @rafinalam3015 3 года назад +1

    32:32 🤣🤣🤣👏

  • @questionmark_c
    @questionmark_c 3 года назад

    Maybe I'm just stupid. I did everything but I get a ERROR on my line 52 because I have Intro() but I don't know what I put in it. can someone explain what I put in it?

    • @CompSciCentral
      @CompSciCentral  3 года назад

      You're not dumb, errors happen all the time. If you have a github account, paste your code in a repository and put the link in a new comment and I'll take a look at it. You could also check the source code in the description and compare it to what you have.

    • @questionmark_c
      @questionmark_c 3 года назад

      @@CompSciCentral um I've never made a github account and I don't know how to post a project. Can you explain how I do that? If not it's ok.

    • @CompSciCentral
      @CompSciCentral  3 года назад

      Sorry man, I wouldn’t know how to explain in a comment but there are tutorials that have can help you make an account and upload the code quickly. If you do that I’ll happily troubleshoot it for you

    • @questionmark_c
      @questionmark_c 3 года назад

      @@CompSciCentral ok I'll do that

    • @questionmark_c
      @questionmark_c 3 года назад

      @@CompSciCentral I fixed the ERROR. Python must have thought I indented for a blank line.

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

    Great tutorial. Anyone told you that you sound just like Elon Musk 😅

  • @enosjonathanraharja5133
    @enosjonathanraharja5133 3 года назад

    i wish there's 2 players / multiplayer feature on this

    • @CompSciCentral
      @CompSciCentral  3 года назад +1

      That would be cool! I wonder how that would work...

  • @nickmorse7334
    @nickmorse7334 3 года назад

    Instead of print statements you can do def func(): pass

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

    I know I'm a couple years late on this one, but I managed to shorten the redundancies of the time delay a bit by adding all the print string lines into a list, then iterating through each list item, while also iterating through each character in those strings in the list.
    something like this:
    def path_1():
    path_1_list = ["
    This is the first line from this path.", "
    This is the second line from this path.", "
    This is the third.", "
    ETC..."
    for s in path_1_list:
    for char in s:
    sys.stdout.write(char)
    sys.stdout.flush()
    time.sleep(c)
    time.sleep(a)
    print()
    Then just do this for each path function rather than for each line in that path. And of course this adds the time delay to each of the lines, rather than just the spoken quotes as you had it, but still one way to cut out a lot of the redundancies in the code. Not the only way of course, but A way for sure.
    Thanks for the awesome tips on this code! Was a fun project to mess around with for sure.

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

      Very nice! I love this optimization! This can definitely be helpful for those that use this tutorial in the future.

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

    Doesn't look that efficient

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

      Oh, it's definitely not. Especially looking back on it. But it's a good place for beginners to start.