This video shows you everything you need to know to create a full text based adventure game in python of the 'choose your own adventure' style!!
We begin with how to print commands and prompts into the terminal window for a user, then show you how to get user inputs and how to decide what your code does next.
The only limits to what you can create with Python text games are whatever your mind can imagine! This is a great project for beginners and if you're ready for more in depth game tutorials be sure to check out the rest of the channel!!
Thanks for watching, don't forget to like and subscribe, and check out the channel! Good luck with your projects!
TIMESTAMPS: 00:00 Intro and Demo 2:29 Your First Inputs and Outputs 6:38 Making Decisions 9:40 Nesting For Loops 14:20 Take it to the next step!
what's going on you guys welcome back to
the channel and today's video is going
to be a great beginner project I'm going
to show you how to build a Choose Your
Own Adventure text Adventure game in
[Music]
Python okay so a Choose Your Own
Adventure game is basically a classic
style of video game as one as the very
early computer programmed games because
it was so simple to create and therefore
it's a really good beginner project but
there's still a lot of python and
object-oriented programming Concepts in
it that are going to be pretty useful
like understanding how to get inputs and
display outputs into the console window
as well as what to do with that data how
to compare different answers and choose
different paths and make decisions based
on input basically all advanced
programming is is taking different more
and more complex data and determining
what to do with that data so
understanding the fundamentals of how to
take in data and process it and make
decisions based off of that is actually
a really good fundamental lesson to
learn and then in a text Adventure it's
just fun because you get to be kind of
creative and you get to kind of do some
different things based on your own
creativity so let's uh let's just boot
this one up as a little example of what
we're going to play um and let's say we
want to play and let's say we want to go
to the
Jungle okay and we're in the rainforest
and they ask us if our tour guide has
been gone a while and if we want to
follow him or wait here let's say we
want to follow so we head off after the
guide and then we there's a river
there's a canoe nearby should we follow
by walking or canoe let's say we're
going to walk as soon as you walk into
the woods a huge snake crushes you to
death ending two out of six found so it
may seem like a just a simple stupid
little story obviously I kind of steered
us directly into a quick death just to
show you kind of the goal of this game
um and I want to say up front a lot of
what you're going to get out of this
project is going to actually be based on
your own creativity and where you take
it because ultimately if you're just
copying my adventure one for one um it's
set up to be a tutorial it's not
necessarily as in-depth as a full
program or full project would get you so
follow along let me know in the comments
if you have any questions uh at any
point and please be sure to leave a like
on the video if you found it useful
check out the channel for a ton of other
great content and subscribe if you're
enjoying what you're seeing all right so
let's get into the tutorial and uh let's
just start by asking the user for their
name so to do that we'll make a variable
called name and we'll just call this
input um and we'll say enter your name
and then we'll put it so something I
like to do whenever I do inputs I end it
with a space before closing out the
quotation marks and you'll see now if I
run this um it's going to say enter your
name and it gives us one space whereas
if I didn't have that space you can test
it in your program if you want the name
is going to be smooshed right up against
the exclamation mark it's not going to
look quite right so um that's why I do
that but then let's make the first line
after that just uh print and we'll I'm
actually going to do F so in F string if
you're not familiar with it if this is a
really beginner project for you it's one
of the um best tools to include
variables with strings so uh we have
that name variable and now we can just
put it in these curly brackets and say
Greetings name and if we want this to be
grammatically correct then we'll do it
this way and just so you can see why I
like the F string if we were going to do
it without that F before the string we'd
have to do greetings and then a space
and then outside of the quotation marks
we'd have to do plus and then name and
then if we were ever worried that this
variable could be something other than
um other than a string we'd also have to
include this St Str so say that was age
and not name and it was an
integer this formatted string those
curly brackets are going to turn into a
string anyways whereas you would need
this St Str so obviously especially by
the point you get to like numerous
variables in a statement um you're going
to really want the formatted string so
greetings
name welcome to your Advent Venture
there we go create a good little
atmosphere here and then let's go ahead
and get an input so this is going to be
just like name but we'll call this
variable
start and uh this is going to be just
the first one I use to give you an
example of like choosing um so we'll say
would you
rather rather play the game or die and
we'll use this one as it um we'll say or
Parish just because it's a little less
graphic maybe I don't know maybe it's
more graphic um but so we'll just say if
start equals
play then what we're going to do is
print
great let's play the game and if you
want to use uh quotations inside of your
inside of your um individual lines of
text and you use these single quotes you
have two options one you could either
swap these single quotes out for double
quotes um or if you're just way more
familiar with doing it this way and you
want your strings in single quotes you
can do a backs slash um single quotation
and then that'll Define it as a literal
um okay so we'll say let's play the game
but then let's do an else which is going
to be else and then we will just
print lame
okay you're and I'll show that now
you're dead now so uh this is just an
example this is the very first example
of how to make a decision so what I'll
show you here is we'll enter our name
we'll say Pete greetings Pete welcome to
your adventure would you rather play the
game or perish and actually you can see
I didn't put a space after uh the
question there so I'll say
perish lame okay now you're dead so I am
going to add a space there um but what's
cool is the way we wrote this is uh
anything other than play is just going
to kill the person right off the bat
because it's like they fundamentally
aren't understanding how the text game
is going to work so uh this is kind of a
good like vetting question to make sure
the person knows how to play wants to
play uh Etc so uh we'll just use that as
an example to get into the game and
these These are kind of the fundamentals
right here of how we're going to do this
so if you want to take a quick pause and
try to add some um more lines before
going on then this might be a good place
to break but if not let's just Soldier
on okay so then let's ask this second
question setting equals
input and we'll say
want to go
to the Jungle or the desert and this is
kind of a common theme in text games is
uh they kind of steer you in the
direction of the responses they're
expecting to get because they're limited
by how many responses the programmer
plans for so if this just said where do
you want to go and we had you know
Jungle Desert space uh middle of the
earth like if we had all these different
things programmed in it's still limited
by the programmer and how many options
they want to give the play player so
sometimes if you're trying to limit it
but you also want it to be fun to play
you kind of steer the player in what
their options
are so what we can do from there is
after our if else we can come down here
and now we've got the the only way we're
going to get to this rung of code um is
if we do setting because what you can do
anytime the code is like over so lame
okay you're dead now add this quit
statement and that'll finish your
program so it won't go on cuz if you
don't add the quit it's going to go and
look for setting even if they died um so
that little quit statement is useful
when you're completely done with your
program all right so we'll say if
setting equals and we'll do the jungle
first and we will say
print welcome to the
mighty
Amazon jungle no wait we'll say
rainforest but I guess it's It's a
Jungle still I
think your tour guide told you to
wait here dot dot dot all right we'll
create a little for booting and now on
this second line we're going to get a
response so we'll say response and it's
still going to be text it's going to
print out um just like that first line
that was just a print statement but now
we've created a second uh a second line
which is going to look better in the the
text game and we'll just say the
response is an input that we'll say but
he has been gone a long
time follow him or wait here okay and
now what we'll do is inside of this if
statement we'll create an additional
Branch so we'll say if response
equals follow
then we'll
print oh we'll
print you follow him into the trees and
we'll just do that for now we'll add
another layer of it later but then we'll
do L if response
equals
weight um and then we'll
print we'll
print you wait another time 10
minutes and he
still isn't
here uh and I need that I got take my
own advice and he still isn't here there
we go um okay so one more thing we want
to do is
else and we just want to print so this
means they didn't say wait or follow we
just want to print invalid
response you lose and then we'll um add
a quit here as well so that was kind of
a lot of typing because these text
Adventures are kind of monotonous in
terms of like putting the typing in um
but now I'm just going to run it and
show you what we did so we did I'm going
to make that a little bigger that's
better enter your name and let's say we
are Indiana Jones greetings Indiana
Jones welcome to your adventure would
you rather play the game or perish let's
play great let's play the game we're
going to go to the Jungle cuz we haven't
add anything for the desert yet so we go
to the Jungle all right we're in the
mighty Amazon rainforest your tour guide
told you to wait here but he's been gone
a long time follow him or wait here so
we will follow and we follow him into
the trees and that's all we get for now
but hopefully you're understanding the
methods with which we built this game um
so basically we could take this if
setting for the jungle and we could make
an take the entire thing make an L if
and now we'll do it for the desert and
instead of being in the mighty Amazon
rainforest we could be in the mighty
Sahara Desert we could put the exact
same sentence uh about waiting for the
tour guide and when we follow him
instead of falling him into the trees we
could follow them into the dunes and
when we wait we could still wait another
10 minutes and any invalid response is
still a loss so this is great and then
we can do another just else and then we
can steal this invalid Response Code cuz
this means when we asked if they would
rather go to the Jungle or the desert
they didn't put in Jungle or desert so
really that means invalid response you
lose so to look at that enter name we'll
say Han Solo and Welcome to our
adventure we want to play the game let's
go to the desert we're in the mighty
Sahara Desert now let's follow and we
follow him into the dunes but if we do
that again and this time went asks us
where to go um enter your name Alf
uh let's play the game do you want to go
to the Jungle or desert what if we want
to go to space invalid response you lose
so this is the core concept behind any
text Adventure game is just these
infinitely nestable if Loops so if
you're in the jungle if you choose to
follow him then you could do a um
another response like uh transport and
you could make that an input
saying you see a
canoe
nearby walk or take the canoe down the
river and then you can make based off of
that response you could say if transport
is equal to walk and then do whatever
here you want to um based on if they say
walk and then L if
transport is equal to canoe and then
whatever you want to do based on if they
select canoe in here and then you can
always put that else in saying invalid
response down here so I'm not going to
do too many more layers of that um I
will copy in what I had I had just a few
more options in this when I was kind of
demoing it in the beginning um where you
kind of the one thing I put in there was
the the different ways you could die in
this version um I would print out what
ending you had discovered so someone who
was enjoying the game and really want to
explore the whole thing could um could
technically play it out until they found
all six potential endings um so that's
kind of a fun way to do it but you can
see it's it really is just take a
question get an input from the player
back and then based on how they
responded to your question that's how
you want to proceed with the game so
it's totally the limits of this game and
how fun it is are just the limits of
your creativity the basics of the
programming it's an amazing way for you
to get familiar with python strings get
familiar with python in general how the
programming reads the indentation rules
as well as a lot of the if L if else
statements so I really like this as a
beginner uh project it's it's pretty fun
and it's pretty easy um if you have any
questions about how to do your own or
while you're programming it you have any
questions about what you saw in the
video just let me know in the comments
below and I'll get back to you as soon
as I can if you did enjoy this video
please consider leaving a like on the
channel subscribe to the channel it
helps me out a ton um and check out all
the other great content over there if
this was too easy for you then we do
have a lot of really in-depth Python and
Pi game game tutorials where we really
create full-fledged classic games like
pong space and
um things like that so be sure to check
the channel out for tons more like this
and as always thanks for watching and
good luck with your code thanks bye