The Moosader Community

Visit the IRC at irc.freenode.net #Moosader! Community dedicated to programming and game development! Moosader.com
It is currently Wed Nov 13, 2019 7:51 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: Thu Apr 12, 2012 6:43 pm 
Offline
Site Admin
User avatar

Joined: Wed May 14, 2008 4:43 am
Posts: 2328
Location: Kansas City
Note: View this on Moosader.com (it is a lot cleaner...) here:
http://www.moosader.com/resources/tutorials/game-programming-prerequisite-test/


I'm putting this here, even though it has more to do with programming, purely because of the crowd it's aimed to.

I am wanting to make one or two videos on YouTube before working on my next tutorials that basically have a series of "Tests" so that you can understand whether or not you know enough C++ to begin doing game development.

The topics would be something like:
  • Output
  • Variables
  • Input
  • Conditional Statements
  • Arrays
  • Loops
  • Functions
  • Classes and Structs
  • Inheritance
  • Pointers and References
  • The concept of a struct, pointer, and linked list.
  • STL?
  • How .h and .cpp files work, #includes
  • Preprocessor commands, #pragma / #ifndefs, macro basics ?
  • Source Control?

That's probably the minimum I would say somebody needs to know in order to start with game programming with C++. I could put Polymorphism on there, but I probably wouldn't say that it's _required_ per se. Plus, if they understand that list, figuring out polymorphism won't take that much more work.

I also thought I'd present the test questions in game contexts, and possibly have about 3 questions per section, to get a more well-rounded coverage of those topics. What do you guys think?

_________________
Android apps by Moosader! - Open Source projects - Moosader.com


Top
 Profile  
 
PostPosted: Thu Apr 12, 2012 6:44 pm 
Offline
Site Admin
User avatar

Joined: Wed May 14, 2008 4:43 am
Posts: 2328
Location: Kansas City
Note: View this on Moosader.com (it is a lot cleaner...) here:
http://www.moosader.com/resources/tutorials/game-programming-prerequisite-test/


Game Programming Prerequisite Test
Post your answers to pastebin and link them here for review and critiquing.
Note to self: Put on Moosader.com w/ better formatting. Upload videos of how the gameplay should work, for clarification.

I'm trying to make a lot of these "Game"-like challenges (text RPG battles, etc.). They will hopefully also help you understand a little bit about how games work, from a really basic standpoint.


Part 1: Input, Output, and Variables.

Quote:
Test 1 - Short story
Write a C++ program that displays a short story, a couple paragraphs long. There should be new-lines in this program, but you can choose the best way to do this.

Image

Test 2 - How much you got?
Write a C++ program that asks the user for their name, age, and how much money they have. These should be string (or character array), int, and float. Output the data back to the user.

Image

Test 3 - Mad Lib
Write a mad lib in C++. Take your short story from Test 1 and remove some of the nouns, verbs, and adjectives. Ask the user to enter a series of corresponding nouns, verbs, and adjectives, and after they're done entering their answers, print out the story again, but insert the nouns, verbs, and adjectives back into the story to make something crazy.

Image


Summary
If you are having trouble implementing any of these, you need to spend more time studying C++.

Image
Image

Part 2: Conditional Statements

Quote:
Test 1 - How old are you?

Write a program that asks the user for their birth-year. From that, it approximates their age by comparing it to the current year.
  • If the user is older than 21, then print a statement that you give them a beer.
  • If they're younger than 21 but equal then or older than 18, then print a statement about how they can vote or enter the military.
  • If they're younger than 18 but equal to or older than 16, then print a statement about how they can drive now.
  • If they're under 16, then print that they don't get any perks... besides, y'know, being a kid.

Image

Test 2 - Fraction Math

Write a fraction math program. Have the user input:
  • Fraction 1's Numerator
  • Fraction 1's Denominator
  • Fraction 2's Numerator
  • Fraction 2's Denominator
Then, ask them what kind of operation to do: Add, subtract, multiply, or divide.
Use a conditional, and based on what operation they choose, do the appropriate math and print the answer.

If you don't remember fraction math, go review it. It's easy, don't forget your algebra.

Image

Test 3 - Choose your own Adventure

Create a short "Choose your own adventure" game.
Start at the beginning of the story, ask the user what they want to do, and then branch from there and print the next portion of the story. Have at least three "steps" (three times the user gets to choose what to do).

Image


Summary
If you are having trouble implementing any of these, you need to spend more time studying C++.

Image
Image

Part 3: Arrays

Quote:
Test 1 - Party Creation

Write a program where it tells you that you get a party of 4 RPG characters (not letters :P). Characters will have:
  • A name
  • A class
  • Strength rating
For now, you can store all of these in separate arrays, just make sure the indices match for the same character. Also remember that this is not the best way to implement something like this, and you'd generally want a class. If i see you storing your character's X and Y coordinates in separate variables floating in the global ether of your program, I will not help you debug.
Anyway, have the user input a name.
Display a numbered list of classes the user can choose, and get their choice. Based on the number they choose, assign the character's class name, and give them a specific strength rating.

After the user is done inputting, output all of the characters' attributes (name, class, strength) in a nice list.

Image

Test 2 - Map Selector

Create an array of strings. Store a bunch of map names in that array, like a text adventure.
Have the user input the index of what map they want to go to.
Based on the index inputted, display the corresponding description.

Image

Test 3 - Map Navigation

Repeat Test 2, but instead of having the user input the index, let them enter "North", "South", "East" or "West" and have them move to a corresponding map.
The best way to do this would be to figure out the full width/height of the map (ie 3 rooms wide x 2 rooms high) and use the index to figure out where it is in relation to other maps.

There will be math involved to figure out how to get from map "4" to map "1", and if you're having trouble we can help you, but it's not that hard. Sketch out a few cases on paper to help you solve.

0 1 2
3 4 5

Room 3 north = 0
Room 4 north = 1
Room 5 north = 2
What is the pattern? :|

Image


Summary
If you are having trouble implementing any of these, you need to spend more time studying C++.

Image
Image

Part 4: Loops

rough notes: something about looping the program until the user chooses to quit. looping while they're entering invalid data.

Quote:
Test 1 - RPG Battle

Tell the user that they've encountered a monster. The monster has 100 health.

Create an array of strings that stores character class names.
Use a for loop to iterate through the class array and output all of the options.

Let the user choose a class name.
Each class should have a different strength. With an if statement, set the user's strength rating- some strengths are above 100 and some are below.

With a while loop, continue doing the following while the monster's health is greater than 0:
  • Output the monster's health
  • Display "You hit the monster for [user's strength rating] damage!"
  • Subtract the strength rating amount from the monster's health

When the monster's health is equal to or less than 0, display a victory message.

Image

Test 2 - Weapon Shop

Create a weapon shop.
Give the player 500 money.
Create two arrays that correspond with each other (again this should be a class, but this isn't testing for classes right now, but if you're really serious about this DON'T USE SEPARATE ARRAYS like this!)
The arrays are: Item Name and Item Price.
The array is a fixed size: 10. This is the most the user can carry. At the beginning, it's empty, the player has nothing.

First, create a loop that keeps running until the player chooses "quit" from the menu.
Display a menu:
  • 1. Buy
  • 2. Sell
  • 3. Quit
Get the user's input. If the user's input is not 1, 2, or 3, then loop through the list infinitely until they finally enter something valid.

If they choose buy, display a list of items for sale.
When they choose an item, check to make sure they have enough money.
If they have enough money, subtract it from their purse and add the item name and item price to their inventory arrays.
If they don't have enough money, tell them they don't and go back to the main menu.

If they choose sell, then display the list of their items and item prices.
If they select an item, add the amount of money to their purse. Remove the item from the Name and Price arrays. This might require re-ordering your array.

Image

Test 3 - ASCII Pickin' Sticks

Each cycle, draw out a simple ASCII map. (Cycle meaning the game plays in a loop until the user wants to exit. Each Cycle consists of: Draw, Get Input, Update).
As the user to input what direction they want to go, "North", "South", "East", "West". They can also type "Exit" to close the game.
Adjust the player's X,Y coordinates and begin next cycle to redraw the map.

Keep track of the Player coordinates, and a Stick coordinates.
Once the player touches the stick, add 1 to their score and generate random coordinates for the stick.

##########
#.....-..........#
#................#
#....@........#
##########

Image


Summary
If you are having trouble implementing any of these, you need to spend more time studying C++.

Image
Image

Part 5: Functions

Test 1 - RPG Battle 2

You're going to rewrite the RPG Battle from Part 4 (Loops) Test 1.

Keep looping until the monster dies or the player dies.
Have stats for HP, ATK, and DEF for both the Player and Monster.

Each cycle, display the Player and Enemy's HP stats, then ask the user what they will do.

Get the user to input whether to "attack" or "heal".
Based on what they enter, call an "Attack" or "Heal" function.

Both Player and Monster can use the Attack function.
It will take "Attacker ATK", "Victim HP", and "Victim DEF" as arguments,
and return "New Victim HP". You will set the Player or Enemy's HP to the value returned.

The Heal function will take the "Healer HP" and return the new HP.

Image

Quote:
Test 2 - Where Am I?

The user is going to be on one map. They will be able to do various commands, such as:
  • Examine
  • Examine [itemname]
  • Smell
  • Smell [itemname]
  • Poke [itemname]

In main, get the user input. Check to see if the user input contains "Examine", "Smell", or "Poke" and then pass the data to the appropriate
Examine(), Smell(), or Poke() functions. Pass the item they're manipulating as an argument, or "" for none so they can examine/smell the entire map.

Quote:
Utility Functions -
C++ can be a bit of a pain with string manipulation.
Here's how you can check to see if a String contains a word:
Code:
bool StringContains( const std::string& haystack, const std::string& needle )
{
    size_t notFoundLen = std::string::npos;
    return ( haystack.find( needle ) != notFoundLen );
}


Here's my "Split String" function, to separate words by a delimiter (use ' ' for a space character):
Code:
std::vector<std::string> SplitString( const std::string& text, char delim )
{
    std::vector<std::string> lstStrings;

    unsigned int begin = 0;
    for ( unsigned int i = 0; i < text.size(); i++ )
    {
        if ( text[i] == delim && i == begin )
        {
            begin++;
        }
        else if ( text[i] == delim )
        {
            lstStrings.push_back( text.substr( begin, i - begin ) );

            begin = i+1; // Start after this delimiter
        }

        if ( i == text.size() - 1 && text[i] != delim )
        {
            lstStrings.push_back( text.substr( begin, text.size() - begin ) );
        }
    }

    return lstStrings;
}

It returns a vector of strings (vector<string>). If you don't know what index to pass to the function, try
Code:
vector<string> lstWords = SplitString( "examine potato", ' ' );
for ( int i = 0; i < lstWords.size(); i++ )
{
   cout << i << ": " << lstWords[i] << endl;
}

and run the program to verify. You need to pass the item in to the function.

You can copy-paste this code into your program (or anywhere else, I don't care how you use it).


So you will have:
main() - Gets user input, splits the input into ACTION and ITEM. ITEM might not exist, since they can type only "examine".
ACTIONS: Examine, Smell, Poke
ITEMS: You can make up whatever you want.

Code:
Examine( string item = "" )
Smell( string item = "" )
Poke( string item = "" )


These three functions have default parameters. If nothing is passed in as "item", it defaults to empty string.

Inside each function, have if statements to figure out what the item is, and output the appropriate response.

EX:
Smell Potato
>> "The Potato smells like dirt"

Image

Test 3

derp derp.

Image


Summary
If you are having trouble implementing any of these, you need to spend more time studying C++.

Image
Image

Part 6: Classes and Structs

Quote:
Test 1 - Map Navigation 2

You're going to rewrite the Map Navigation from Part 3 (Arrays) Test 3, but you're going to use Classes this time.

First, you will have a Map class. The Map class will contain the map's Name, Description, and "ToWest", "ToEast", "ToNorth", and "ToSouth". These will identify its neighbor maps. If you know how to use pointers, that would be the cleanest way, but since this isn't a pointer test, you can make it store a string Name or int Id, whatever you feel like would work best.
The Map class will also have functions for:
  • DisplayDescription
  • GetNeighbor( direction )

Then you will have a vector or array of Maps. Set up all your maps.

You will keep track of the Current Map, also. You can do this by keeping track of the index of the vector/array.

Each cycle, display the description of the current map.
Get the user's input ("North", "South", "East", "West") and then pass that value to the map's GetNeighbor function. Use the return value to change the value of Current Map, or, if there is no neighbor in that direction, display a message saying so and get the user's input again. (Hint: Use a While statement to keep getting input until its valid).
When the cycle restarts, it will then display the new description.

Image

Test 2 - RPG Battle 3

You will rewrite an RPG Battle, similar to Part 5 (Functions) Test 1 and Part 4 (Loops) Test 1.

Your game runs the same-
Every cycle, display the Enemy and Player's HP.
Get the user's input ("Attack", "Heal").
Update game (attack or heal, etc.)

You will have classes:
  • Enemy
  • Player

And this can be a class OR struct, depending on your preference:
  • Stats

Stats will have:
  • HP - Goes into Healing and Attack calculation
  • ATK - Goes into Attack calculation
  • DEF - Goes into Attack calculation
  • SKIL - Goes into Healing calculation
(You can name them whatever)

Enemy and Player will both have:
  • A Stats object
  • DisplayHP function
  • GetHit function
  • HealSelf function
And any members you want to add, and necessary accessors (Name, Class, AttackStat...)

Set up the Enemy and Player objects, give them whatever stats you want.
Create an equation for Heal and Attack for both. The Attack function will need parameters like "Attacker ATK" value so you can calculate the damage.
Attack and Heal should both affect the class' HP.

Keep getting input from the user until either the Enemy or Player dies.

Image



Summary
If you are having trouble implementing any of these, you need to spend more time studying C++.

Image
Image

Part 7: Inheritance

Quote:
Test 1 - RPG Battle 4

Related tests:
  • Part 4 Test 1 (Loops)
  • Part 5 Test 1 (Functions)
  • Part 6 Test 2 (Classes)

This is pretty much exactly the same to Part 6 Test 2, except you will use inheritance, as follows:

Create a class "Character". Enemy and Player will inherit from it.
GetHit function will be virtual, so you can override them in the children.
Put all redundant code into the parent class (ie, they both have Stats and the same functions).
Don't put "HealSelf" in the Character class. Only Player will have this.

Now, to specialize those classes.
Under Player, add:
  • HealSelf spell
  • Fireball spell

HealSelf will affect the player's HP based on a calculation of HP and Skil.
Fireball will return a damage amount based on the player's Skil. It will then be passed to the Enemy's "GetHit", to be adjusted for their HP/DEF stats.

Under Enemy, add:
  • Defend
  • ChooseWhatToDo
  • Attack
  • Rage
  • default defense variable (const)
  • default attack variable (const)
The enemy class needs "AI" stuff, whereas the player is controlled by the user.

In ChooseWhatToDo, the enemy should randomly choose whether to Defend, Rage, or Attack.
At the beginning, reset the defense variable back to the default.

If the enemy decides to Defend, the defend variable increases for the next round.

If the enemy decides to Rage, the attack stat is temporarily increased but he does not attack.

If the enemy decides to Attack, get the enemy's attack value and pass it to the Player's GetHit function.
After the attack, the value should be reset back to the default attack value.

Keep looping the program until either the Player or Enemy dies.


Image

Test 2 - ASCII Pickin' Sticks 2

This is a rewrite of Part 4 Test 3 (Loops).

Your ASCII Pickin' Sticks game will be rewritten to use classes and inheritance.

Classes you will have:
  • Entity
  • Character : inherits from Entity
  • Player : inherits from Character
  • Npc : inherits from Character
  • Item : inherits from Entity
  • Stick : inherits from Item
  • Rock : inherits from Item

The Player and NPC will both go after the stick, but the NPC is controlled by the computer.

The stick gives either the Player or NPC points.

Neither the Player or the NPC can pass a Rock.

The Entity class will have what is in common between Characters and Items (coordinates, ASCII symbol variable...)
The Character class will have what is in common between Player and NPC (score...)
The Player class will take the user-inputted Direction and move accordingly.
The NPC will call something like DecideWhatToDo and move in a way it thinks is good.

If either the Character or NPC hit the stick, their score will increase and the stick's coordinates will regenerate.

If either tries to walk into a Rock, it will not let them move that direction.

Each cycle, draw the ASCII map and each user's score.
Then, get the user's input.
Then, run the update routines (NPC DecideWhatToDo, check for collisions between Player/Enemy and Stick)

First Character to a score of 10 wins.

Image



Summary
If you are having trouble implementing any of these, you need to spend more time studying C++.

Image
Image

Part 8: Pointers and References

Quote:
Test 1 - Map Navigation 3

Related tests:
  • Part 3 Test 3 (Arrays)
  • Part 6 Test 1 (Classes)

This will be very similar to the Map Navigation 2 test, except we'll use pointers and references!

The things you will change here, will be:
Map Neighbors - These will instead be POINTERS to the actual Map object.
Current Map - This will also be a POINTER to the current Map.

(Write more later...)

Image

Test 2 - Quiz Game

This game will ask you a series of questions that have multiple-choice answers.

Create a Question class and Answer class.

The Answer class will have:
  • AnswerText
  • bool isCorrectAnswer
And any necessary functions.

The Question class will have:
  • QuestionText
  • vector<Answer> lstAnswers
  • bool IsRightAnswer( int answeredNumber )
  • DisplayAnswerOptions
  • DisplayQuestion
And any necessary functions to set up the questions, etc.

DisplayAnswerOptions will display the index of the answer and the text for that answer.
IsRightAnswer will return whether or not the passed in index belongs to the correct answer.

Before the game loop, create a bunch of questions and their answers, and add it to a vector<Question> lstQuestions vector.

In the game loop, generate a random number to get which question to ask.
Set a "CurrentQuestion" pointer equal to this question.

Display the Question and the Answer options.
Get the input from the user (1 through 4, or something)
Pass it to the IsRightAnswer function. If it's right, increment the player's score. Also increment the amount of questions answered, whether they were right or not.

Image

(I need a question for using references, which I actually use more than pointers it seems like, but I can't think of anything right now.)


Summary
If you are having trouble implementing any of these, you need to spend more time studying C++.


Image
Image

Part 9: Design and Structure

Basically test that the budding programmer understands the concept of modularity; do they put Entities in an Entity Manager or pile everything in main?

Image
Image


"Game Programming Prerequisite Test" by Rachel J. Morris
(c) 2012 Rachel J. Morris

_________________
Android apps by Moosader! - Open Source projects - Moosader.com


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 6:47 am 
Offline
Black Mage
Black Mage
User avatar

Joined: Thu May 20, 2010 1:05 am
Posts: 173
I am having a lot of trouble implementing derp derp. Could you write a tutorial for me?


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 6:54 am 
Offline
Goblin
Goblin
User avatar

Joined: Sun Jun 12, 2011 11:48 am
Posts: 102
Location: .de
Des Tomate wrote:
I am having a lot of trouble implementing derp derp. Could you write a tutorial for me?


Try this:
http://esolangs.org/wiki/Ook!


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 3:56 pm 
Offline
Undine
Undine
User avatar

Joined: Wed Mar 31, 2010 5:44 am
Posts: 83
i think this is a good idea, it might actually be interesting to implement this with an automated scoring system - ie. web based submissions/tracking; a bit like spoj.pl. i know this might be a bit difficult/costly to implement, but maybe something like the ideone.com API would make it possible without those costs/complexities of code execution/evaluation? just a thought =]


Top
 Profile  
 
PostPosted: Wed Apr 18, 2012 8:47 am 
Offline
Eater of Comics
Eater of Comics
User avatar

Joined: Wed Mar 31, 2010 10:06 pm
Posts: 1015
I agree this is a pretty good idea. Of course there's no way of knowing whether a user has fully taken and passed the test so there will still be people who are asking questions above their level.

_________________
mv2112 wrote:
O.o

BlackPhantom wrote:
"And the lord said let there be videos! And he saw it was awesome." -Awsome 1:12


Top
 Profile  
 
PostPosted: Wed Apr 25, 2012 8:45 pm 
Offline
Larc
Larc
User avatar

Joined: Fri Nov 19, 2010 6:11 pm
Posts: 314
Location: South Lanarkshire, UK
Hm, I like this self assessment idea. I was going to recommend making it language agnostic. Might have a fiddle with it myself - might be a good jumping off point in to pickin' up, eugh... C++.

_________________
For sale: Baby shoes, never worn.
Arse That


Top
 Profile  
 
PostPosted: Wed Apr 25, 2012 9:17 pm 
Offline
Psychonaut
User avatar

Joined: Sat May 14, 2011 8:57 pm
Posts: 621
Location: Azle, Texas
I like the idea as well.

When this is finished, I can try out the assessment myself and post my code. I hope others will do the same, as that would be cool to see how each person creates it.

_________________
Take ctrl of your life, alt your future as you see fit, and delete all that stands in your way.
- Ctrl+Alt+Delete


Top
 Profile  
 
PostPosted: Thu Apr 26, 2012 8:48 pm 
Offline
Koopa
Koopa

Joined: Tue Apr 10, 2012 6:07 am
Posts: 41
I am going to use this to learn C++ thanks for posting it! :D


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 12:05 pm 
Offline
Site Admin
User avatar

Joined: Wed May 14, 2008 4:43 am
Posts: 2328
Location: Kansas City
I've added a lot of questions to this. It's still not done, I need to think of some more, but let me know what you think.

Sections with new questions:
  • Loops (last test)
  • Functions
  • Classes and Structs
  • Inheritance
  • Pointers and References

I think later, I'll add this to the "Resources" page of my website, so it'll be easier to read!
I will also write these programs myself and record video to show what exactly I have in mind.

I can also post my code, because really, even if you cheat we can totally tell whether you "get it" by the questions you ask.

_________________
Android apps by Moosader! - Open Source projects - Moosader.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron