URI:
   DIR Return Create A Forum - Home
       ---------------------------------------------------------
       The New DS computer forum!!
  HTML https://dscomp.createaforum.com
       ---------------------------------------------------------
       *****************************************************
   DIR Return to: C++
       *****************************************************
       #Post#: 292--------------------------------------------------
       Tutorial #6 - Your first proper game. Lost Fortune. Part 1
       By: Hondaman Date: October 11, 2010, 1:46 pm
       ---------------------------------------------------------
       [center]Welcome to Tutorial No.6
       In this tutorial you will putting everything you have learned
       so-far into a game.[b][/center]
       [font=trebuchet ms][b]What you've learned so far -[/font]
       So far you have learned how to output text, how to make
       variables, and getting user-input.
       In this tutorial you will be putting everything you have learned
       so far into a simple game called
       [font=courier]Lost Fortune[/font]
       Lost fortune is a game you most likley havn't heard of before.
       So here is how it goes (Step by Step):
       1 - The user enters some basic information about a group they
       are in (not a real one)
       2 - The program uses that information and outputs a story
       including the information.
       3 - The custom story can be read and that is it.
       It is a really simple game, but the script will be quite long.
       All you need to know is, I recommend you copy me until you get
       the idea of what the program does and then edit it.
       So... Let's get started shall we...
       [font=trebuchet ms]Making the game -[/font]
       Part 1 - Preparing the variables.
       First off create a standard script thet would be used for text
       output but without the 'cout' line.
       So you should be left with
       [code]
       #include <iostream>
       using namespace std;
       
       int main()
       {
       
       system ("pause");
       return 0;
       }
       [/code]
       And now we need to make several variables.
       some will be 'char' and some will be 'int'
       but we will also be using 'string' which works with sequences of
       characters.
       to use 'string' we need to add another line of code under
       '#include <iostream>'
       We need to add '#include <string>'
       so now the header should be
       [code]
       #include <iostream>
       #include <string>
       [/code]
       And now we make the variables.
       Inside the 'main' function we need to add the following three
       lines.
       [code]
       const int GOLD_PIECES = 900;
       int adventurers, killed, survivors;
       string leader;
       [/code]
       in the first line you will see 'const int GOLD_PIECES = 900;'
       I guess you are wondering "W.T.H ??"...
       'const' is basicly the same as and can be used the same as any
       integer literal. Also notice how the 'GOLD_PIECES' is in
       capitals?
       This is a conventon, but a simple one...
       It simply tells any experianced programmer that the variable is
       a 'const' variable.
       And 'int adventurers, killed, survivors;' is simply three int
       variables.
       adventurers , killed and survivors.
       If you have several of the same type of variable you can simply
       list them on a line and seperate them by commas.
       Part 2 - Getting the users input for the game.
       Now that we have our variables setup,
       We need to get some information about the user and his group.
       This is used for telling the user what is going on and gives the
       user a sense of importance in the story.
       So firstly we want to welcome the user to the game and tell them
       what they will be doing.
       BUT!!! It is important that you know this first.
       And it's called, Tabulation.
       This may not be the correct word but what I'm talking about is
       tabs,
       Tabs are spaces much bigger than the normal space bar and are
       good for setting things out.
       Yout probebly thinking -
       "Oh god... How much coding will this take?"
       The answer is... 3 characters.
       yup thats it -
       [code]
       Vertical Tab - can be done by either      \v or \n\n
       Horizontal Tab - can be done by        \t
       [/code]
       \v is for vertical and the backslash simply tells the compiler
       to ignore the next character and run it as code.
       This is because you include it in the text line e.g.
       [code]
       #include <iostream>
       using namespace std;
       
       int main()
       {
       cout << "\vHello World!" << endl;
       system ("pause");
       return 0;
       }
       [/code]
       So this will output
       [code]
       
       
       Hello World!
       [/code]
       You can do the same with \t for a horizontal tab that will
       output
       [code]
       Hello World!
       [/code]
       Now that you have learned to use tabs.
       Lets add in two lines of code to our script that will make the
       program look alot more professional.
       [code]
       cout << "\tWelcome to Lost Fortune." << endl;
       cout << "\tPlease enter some of your information for the
       story.\v"
       [/code]
       so this with the script will look like -
       [code]
       #include <iostream>
       #include <string>
       using namespace std;
       
       int main()
       {
       const int GOLD_PIECES = 900;
       int adventurers, killed, survivors;
       string leader;
       
       cout << "\tWelcome to Lost Fortune." << endl;
       cout << "\tPlease enter some of your information for the
       story.\v"
       }
       [/code]
       Thanks for reading this tutorial. Please look at Part 2
       If you see any mistakes or problems with my tutorials please PM
       me.
       Hondaman.
       [center]<< Previous
  HTML http://www.dscompforums.tk/c/tutorial-5-getting-user-input/
       |
       Next >>[/center]
       #Post#: 297--------------------------------------------------
       Re: Tutorial #6 - Your first proper game. Lost Fortune. Part 1
       By: xboi209 Date: October 17, 2010, 4:55 pm
       ---------------------------------------------------------
       Can you make a tutorial about how to move/delete files and
       registry keys.(if possible)Also include how to run other files
       too
       *****************************************************