Making a text-based adventure game
2020-03-10In this post I will show you how to make a ruby project. Go to a coding platform. Make a new folder and call it . Let’s start off with a variable. Enter this into the code So this is cool but we never use it anywhere. Add this to the code Here we are a sample/random item from the array we made, but what if we wanted to use the place we are at in the story line? Add this before the : Then replace: With: And now we can know which we go to. Now we can do this: With this these will at around the same time. To fix this, between: And: Add: Let’s test these out. Go to terminal Then to run it You should see: Obviously the would be: hedge maze, airport, train station or road. One thing though… on the way to an airport you would probably not see a chicken. So lets make some variables up at the top: Add some content: Now how would we find the animal based on the place… Functions! Let’s make a findAnimal function: So this checks what is and returns the correct animal. Now let’s replace With: Checking your code. We have gotten the start of the adventure made. Let’s make sure we did it right. Is this your code: If not then you can just copy and paste by highlighting the text and pressing (command) and then going to your code and pressing .