Blog Archive

Friday, December 6, 2013

Interview: Gamer Chelsea Levy on Compelling Stories and Villains in Games

In this post, I will be interviewing Chelsea Levy, who enjoys both digital and tabletop games in her free time. Chelsea and I will discuss story in  games. This post contains spoilers for Tales of Symphonia, Pokémon, and Final Fantasy Tactics Advanced.

Ada: Thank you for speaking with us today, Chelsea. My first question is about digital games. What's your favorite digital game? Tell us a little bit about why you especially enjoyed this game.

Chelsea: My favorite game was Tales of Symphonia. Not only was the game beautifully detailed and wonderfully designed graphic wise, it also had a captivating and beautiful story. You wanted to play the game multiple times to see all the multiple ways the story can go and what happens to the characters. They are developed characters that you seamlessly fall in love with and you are compelled to complete the story. It's an action RPG that broke away from the turn based style, and allowed a free roam battle field that was faster paced and easy to manipulate.

Ada: Are there any moments from Tales of Symphonia's story that you found especially memorable?

Chelsea: The game had a lot of plot twists. Characters that you thought were your allies ended up being some of your greatest enemies. After you are far into your journey to save your world, you find out that in order to save your world, you need to send another into despair.

Ada: Have you ever disliked a game's story? If so, what did you dislike about it?

Chelsea: Ever since the beginning of Pokémon there has always been the "bad team." Team Rocket was awesome. They made sense. In each game they need to up the danger and the bad guys become increasingly ridiculous. For example, Team Aqua and Team Magma have had some of the most poorly planned out motives. Aqua wants to make it rain forever making more area for water Pokémon to live. Which takes away from where humans, including them, can live. I guess they like submarines. Magma wants to erupt a volcano in order to expand the landmass for land Pokemon. Which would wipe out all human civilizations that were on the land. Not to mention the volcano was in the center of the main landmass so they would be covering land that already existed. The leader of Team Galactic wanted to eliminate human spirit. Plasma's leader wants to be the only person on the planet with Pokémon. Team Flare's leader wants to eliminate the human population because they were terrible. All Team Rocket wanted to do was be rich and steal stuff.

Ada: I agree. It seems like newer Pokémon games have a problem with forced villainy. Team Rocket's simplicity worked well for them.

Chelsea: They were criminals. It was simple. Everyone after is a maniac. There was a small jump from criminal activity to genocide.

Ada: It sounds like they need to take a more subtle approach when it comes to writing their villains. My next question relates to this concept. Have you ever played a game with an especially well-written villain?

Chelsea: Final Fantasy Tactics Advanced: the "villain" was a boy wanting to keep the town of Ivalice as a Final Fantasy-esque country to escape bullies, disappointment in his father, and be with an illusion of his dead mother. He was a villain with a lot of sympathy, and mostly a victim of his own naiveté. The only reason Mewt qualifies as a villain is because he finds out what is going on, and ignores it, willfully imposing his fantasy world on the town.

Ada: That's all the time we have for this interview, Chelsea. Thank you very much for your time! This was a great, informative interview.



Formatting Text in C++: Escape Sequences

We now have text games that provide our players with meaningful output, allow our players to make choices, and give our players more than one opportunity to input a correct response. Players might find the text in our text games too overwhelming as it is, because it is a large block of text. Our text game might benefit from a few well-placed blank lines, but we can format text in more sophisticated ways using escape sequences. Escape sequences change the way that output is formatted in cout statements.

Escape sequences begin with a backslash and are followed by another character. The backslash tells the compiler that an escape sequence is being used, and the character that follows the backslash tells the compiler which character to insert into the output. Escape sequences are placed inside of a string literal in a cout statement.

This chart shows several escape sequences that you may want to place in your text game, how they look in code, and how they look in output.

Escape Sequence Chart


Escape Sequence
Name
In Code
In Output
\n
Newline
cout << "1. Fight the evil worm.\n2. 
Teleport away.\n";
1. Fight the evil worm.
2. Teleport away.
\t
Horizontal tab
cout << "What will you do?" << endl;
cout << "1.\tFight the evil worm." 
     << endl;
cout << "2.\tTeleport away."
     << endl;
What will you do?
1.             Fight the evil worm.
2.             Teleport away.
\”
Double quote
cout << "Hello world!" << endl;
cout << "\"Hello,\" said the world." 
     << endl;
Hello world!
“Hello,” said the world.
\\
Backslash
cout << "The save file is in C:\\ 
My Documents." << endl;
 
The save file is in C:\ My Documents.
\a
Alert
cout << "The computer beeped. 
The AI knew about your betrayal.\a" 
     << endl;
 
The computer beeped. The AI knew about your betrayal.
The computer will beep as this text appears on the screen.

Experiment with escape sequences until you find a format that works for your text game.

Interview: Game Design Student Ryan Mendenhall on Story in Games

In this post, I interview game design student Ryan Mendenhall on story in games. Ryan has some advice on writing a memorable story in a game.


Validating Player Input: Loops

In this tutorial, we will learn how to give players more than one chance to input a response into our text games. When players enter a wrong number, our text games currently output an error message before quitting. Players may accidentally enter a wrong number while playing a text game. If we want players to be able to play through our text games even after they enter a wrong number, we should give them another opportunity to enter a correct response when they enter a wrong number. We can give players another opportunity to enter a correct response using a loop, which is a control structure that executes a series of statements until some condition is met. The loop we will use is called a while loop, and the condition will require that the player enters a correct response before the loop stops getting new responses from the player.

Part 1: Creating a While Loop That Gets Player Input


  1. Run Code::Blocks.
  2. Open the project file for your text game.
  3. Create an int variable called “validChoice”.
  4. int validChoice;
    
  5. Create a bool variable called “valid”.
  6. Set valid to false using an equals sign.
  7. bool valid = false;
    
  8. Add a line below the two variables and write
  9. while (valid == false)
    {
    
    }
    
  10. Use cout statements between the while loop's braces to give players a problem, two numbered choices, and a prompt for a response.
  11. {
        cout << "You encounter an unattended pot of gold." << endl
             << "1. Try to take the gold." << endl
             << "2. Leave the gold alone." << endl;
        cout << "Enter 1 or 2: ";
    }
    
  12. Use a cin statement between the while loop's braces to get the player’s response and read it into “validChoice”.
  13. cin >> validChoice;
    


We have a while loop now, but if we build and run our program we will encounter a problem called an infinite loop. An infinite loop happens when a loop’s condition is met and then never changes within the loop. Our while loop never changes “valid” to true, so our text game will never stop prompting the player for the a response, even if they input a correct response. The infinite loop in our text game can be fixed by creating a selection statement that changes “valid” to true if the player enters a correct response.

Part 2: Updating A While Loop’s Condition


  1. Create a selection statement with an if portion, and else if portion, and an else portion within the braces for the while loop. Make “validChoice” the condition for the selection statement.
  2. while (valid == false)
    {
        cout << "You encounter an unattended pot of gold." << endl
             << "1. Try to take the gold." << endl
             << "2. Leave the gold alone." << endl;
        cout << "Enter 1 or 2: ";
        cin >> validChoice;
        
        if (validChoice == 1)
        {
            
        }
        else if (validChoice == 2)
        {
            
        }
        else
        {
            
        }
    }
    
  3. Use a cout statement to output an outcome in the if portion of the selection statement.
  4. Set “valid” to true in the if portion of your selection statement.
  5. if (validChoice == 1)
    {
            cout << "A fairy appears!" << endl
                 << "She thanks you for guarding her treasure." << endl
                 << "You walk away feeling guilty." << endl;
            valid = true;
    }
    
  6. Use a cout statement to output an outcome in the else if portion of the selection statement.
  7. Set “valid” to true in the else if portion of your selection statement.
  8. else if (validChoice == 2)
    {
            cout << "You walk away, feeling righteous but " << endl
                 << "a bit foolish." << endl;
            valid = true;
    }
    
  9. Use a cout statement to output a message to the player in the else portion of the selection statement to let the player know that they entered a wrong response.
  10. else
    {
        cout << "You made a response in error. Try again." << endl;
    }
    
  11. Choose "Build" -> "Build."
  12. Choose "Build" -> "Run", if no errors were generated in Step 7.


Play your text game and try to input a few different numbers to see how the while loop works. The while loop should output an outcome for your choice if it’s correct, but it will repeat the prompt if you enter an incorrect response. You can place a while loop around any selection statement to give your players more than one chance to input a response.

I placed all of my text game’s selection statements inside of while loops that validate player input. My text game is in this Google Drive file, so you can check your code against mine if your text game generated any errors. In the next post, I will interview a student of game design who has advice about writing stories for games.

Thursday, December 5, 2013

Giving Players Choices: Nested If Statements

In this tutorial, we will learn how to create branching storylines that reflect your players' choices. We can create branching storylines by placing selection statements inside of other selection statements; this allows the story to change in ways that depend on the choices that players made earlier in the game. Selection statements placed within other selection statements are called nested if statements.

Let’s begin.

Part 1: Coding the Outer Selection Statement

  1. Run Code::Blocks
  2. Open the project file for your text game.
  3. Create two int variables named “firstChoice” and “secondChoice”.
  4. int firstChoice, secondChoice;
    
  5. Use a cout statement to present the player with a problem.
  6. cout << "After you deal with the wolf, you set off to your grandmother's house." << endl
         << "You travel the path until you come to a fork in the road." << endl;
    
  7. Use a cout statement to present the player with two numbered choices.
  8. cout << "1. Take the left fork." << endl
         << "2. Take the right fork." << endl;
    
  9. Use a cout statement to prompt the player for their choice.
  10. cout << "Enter 1 or 2: ";
    
  11. Use a cin statement to get the player’s choice and read it into “firstChoice”.
  12. cin >> firstChoice;
    
  13. Add an if portion to the selection statement that checks whether “firstChoice” is equal to 1.
  14. if (firstChoice == 1)
    {
        
    }
    
  15. Add an else if portion to the selection statement that checks whether “firstChoice” is equal to 2.
  16. else if (firstChoice == 2)
    {
        
    }
    
  17. Add an else portion to the selection statement.
  18. else
    {
        
    }
    
  19. Use a cout statement between the braces for the else portion of the selection statement to present a default outcome. This cout statement will only output this outcome if the player enters a choice other than 1 or 2.
  20. else
    {
       cout << "You're not sure what to do." << endl
            << "You turn around and head back home." << endl;
    }
    


Next, we will nest inner selection statements within our outer selection statement. The inner selection statements will give our players different choices to make, depending on which options they chose for the outer selection statement.

Part 2: Coding the Inner Selection Statements

  1. Use a cout statement inside of the braces for the if portion of your selection statement to present your player with a problem.
  2. cout << "You come upon a beautiful spring. You suddenly feel very thirsty." << endl
             << "Will you drink?" << endl;
    
  3. Use a cout statement to present your player with two numbered choices.
  4. 
    cout << "1. Drink." << endl
             << "2. Resist the urge to drink." << endl;
    
  5. Use a cout statement to prompt your player for their choice.
  6. cout << "Enter 1 or 2: ";
    
  7. Use a cin statement to get the player’s choice and read it into “secondChoice”.
  8. cin >> secondChoice;
    
  9. Add an if portion to the inner selection statement that checks whether “secondChoice” is equal to 1.
  10. 
    if (secondChoice == 1)
    {
            
    }
    
  11. Use a cout statement between the braces of the if portion to output the outcome for a choice of 1.
  12. {
           cout << "You drink and feel refreshed." << endl
                << "You continue on your way, picking up your pace." << endl;
    }
    
  13. Add an else portion to the inner selection statement.
  14. else
    {
    
    }
    
  15. Use a cout statement between the braces of the else portion to output the outcome of a choice of 2.
  16. {
       cout << "Reluctantly, you leave without drinking." << endl
            << "You continue on your way, thirsty and cranky." << endl;
    }
    
  17. Repeat steps 1 through 8 inside of the braces for the else if portion of the outer selection statement. Use a different problem, a different set of choices, and different outcomes.
  18. else if (firstChoice == 2) //player chose to take the right fork
    {
        cout << "There's a cute little bunny frolicking in a clearing." << endl
             << "Will you pet it?" << endl;
        cout << "1. Pet the bunny." << endl
             << "2. Leave the bunny alone." << endl;
        cout << "Enter 1 or 2: ";
        cin >> secondChoice;
    
        if (secondChoice == 1) //player chose to pet the rabbit
        {
            cout << "The bunny you're petting turns out to be a wizard, " << endl
                 << "who finds your petting offensive. He turns you into " << endl
                 << "a newt." << endl;
        }
        else //player did not choose to pet the rabbit
        {
            cout << "You go on your way without petting the rabbit, but " << endl
                 << "you know, somewhere in the back of your mind, that " << endl
                 << "you will always wonder about what could have been." << endl;
        }
    }
    
  19. Choose "Build" -> "Build."
  20. Choose "Build" -> "Run", if no errors were generated in Step 10.

Now, your text game’s story change as players make different choices. To make your text game’s story longer, you can place as many nested if statements inside of nested if statements as you need; experiment until you find something that works well for your text game.

If your code generated any errors, I've included my text game’s code in this Google Drive file, so you can check your text game’s code against mine. In our next tutorial, we will learn about how to give players more than one chance to input a valid choice with loops.

Tuesday, December 3, 2013

Giving Players Choices: Control Structures

In this post, we will learn how to use control structures to let our players choose what happens in our text game. Our text game will present players with two options to choose from, and will let them know the outcome of their choices.

Let’s begin.


Part 1: Using a Variable to Hold Players' Choices

  1. Run Code::Blocks.
  2. Choose “Open An Existing Project.”
  3. Find the project file for your text game (this file will have the name you chose for your project last time with a .cbp extension) and open it.
    This image shows the listing for a text game's project file. It is named "RedRidingHood.cbp"
    My text game's project file is named "RedRidingHood.cbp."
  4. Add a line after the end of the last cout statement in your text game.
  5. Create an int variable named "choice."
  6. int choice;
    
  7. Use a cout statement to present the player with a problem.
  8. cout << "A wild wolf appears! What will you do?" << endl;
    
  9. Use a cout statement to present the player with two numbered choices.
  10. cout << "1. Run from the wolf." << endl 
         << "2. Attempt to engage the wolf in meaningful dialogue." << endl;
    
  11. Use a cout statement to prompt the player for a choice.
  12. cout << "Enter 1 or 2: ";
    
  13. Use a cin statement to get the player's choice.
  14. cin >> choice;
    
  15. Choose "Build" -> "Build."
  16. Choose "Build" -> "Run", if no errors were generated in Step 10.

Part 2: Using a Selection Statement to Determine a Choice's Outcome


A control structure in C++ determines if a series of statements should be executed based on whether a condition is true or false. The control structure we will use is called a selection statement. If the condition is true, then the program executes the statements associated with the if portion of the selection statement (which means that the program will execute any statements between the brackets below the line with the condition). If the condition is false, then the program executes the statements below the else portion of the selection statement.The condition we will use for our control structure is the “choice” variable. If the “choice” variable holds 1, the program will execute statements that output the outcome of the first choice; if the “choice” variable holds 2, the program will execute statements that outputs the outcome of the second choice.


  1. Add a new line and write
  2. if (choice == 1)
    
  3. Add an opening brace on the next line. Code::Blocks will automatically add a closing brace for you two lines down.
  4. Use a cout statement to output the outcome of the first choice between the two braces.
  5. {
        cout << "You flee from the wolf." << endl
             << "The wolf wanders off dejectedly into the forest." << endl;
    }
    
  6. Add a new line below the closing brace and write
  7. else
    
  8. Add another opening brace and closing brace.
  9. Use a cout statement between the two braces to output the outcome of the second choice.
  10. {
        cout << "You speak with the wolf, who got lost in the forest looking for his friend, the huntsman." << endl
             << "You give the wolf directions and he thanks you profusely before continuing on his way." << endl;
    }
    
  11. Choose "Build" -> "Build."
  12. Choose "Build" -> "Run", if no errors were generated in Step 7.
We wrote an if portion of a selection statement in Step 1. The if portion of the selection statement contained the condition inside of a set of parentheses. The condition for our selection statement checked whether our “choice” variable held a value of 1 using a pair of equal signs. This pair of equal signs is called the equal to operator in C++. The equal to operator checks whether the value on the left is equal to the value on the right. If the value on the left is equal to the value on the right, then the program evaluates the condition as true. If the value on the left is not equal to the value on the right, then the program evaluates the condition to false. In the example from my Red Riding Hood game, if the player enters 1 then the condition will evaluate to true and the player will flee from the wolf. If the player enters 2 then the condition will evaluate to false and the player will speak with the wolf.


Part 3: Giving Players More Choices with Else If


Unfortunately, if players enter any number but 1 for their choice, then the condition will evaluate to false and the game will execute the statements associated with the else portion of the selection statement. If players choose another number, we want our game to output an outcome that makes sense. We can use an else if portion to the selection statement to provide players with more than two possible outcomes.
  1. Find your else statement and change it to
  2. else if (choice == 2)
    
  3. Add another line below the brackets for the else if statement, and write
  4. else
    
  5. Add another opening brace and closing brace.
  6. Use a cout statement between the two braces to output the outcome of an invalid choice.
  7. {
        cout << "You're not sure what to do, so you hide behind a tree until the wolf leaves." << endl;
    }
    
  8. Choose "Build" -> "Build."
  9. Choose "Build" -> "Run", if no errors were generated in Step 5.

In this control structure, the program checks the condition for the if portion of the selection statement first. If the condition for the if portion of the selection statement evaluates to false, then the program checks the condition for the else if statement. If the condition for the else if portion of the selection statement evaluates to false, then the program executes the statements associated with the else portion of the selection statement.


You now have an interactive text game that lets players make choices. If your text game generated any errors, I have the code from today’s text game in this Google Drive file so you can check your code against mine. In our next post, we will learn more about control structures, and how to use them to create branching storylines affected by players' choices.


Friday, November 22, 2013

C++ Variable Data Types [infographic]

This image is an infographic that explains the concept of variables and lists the sizes of different data types and what those data types hold.
C++ Variable Data Types Infographic



You can read more about variables in the "Variables. Data Types." tutorial on CPlusPlus.com. You will use different types of variables in the next post, when we learn about how we can use control structures to let our players choose what happens next in our text game.