#include <iostream>
#include <cstring>
#include <stdlib.h>
using namespace std;
void showintroduction ( void ){
cout << "Text Based Game Programming Second Try" << endl;
cout << "\nThis game is similar to Desolation. \n";}
void showsituation ( void ){
cout << "You can create you own character or use an already Premade character to try the game out first.\n";
}
void showchoice ( void ){
cout << "1. Make your own Character\n";
cout << "2. Use Premade Character\n";}
int getchoice (int min, int max){
int choice;
do
{
cout << "Please enter one of the above numbers.\n";
cin >> choice;
}
while( choice < min || choice > max);
return( choice );}
void showresults (int choice){
switch(choice){
case 1:
cout << "For now you can not go back, so all of your choices are final, for now anyway.\n";
cout << "You have choosen to create your own Character.\n";
cout << "You must first choose a class for your character befor you can continue.\n";
cout << "Here are your class choices.\n";
cout << "1: Rogue\n";
cout << "2: Fighter\n";
cout << "3: Cleric\n";
cout << "4: Wizard\n\n";
break;
case 2:
cout << "For now you can not go back, so all of your choices are final, for now anyway.\n";
cout << "You have choosen to use a Premade Character.\n";
cout << "Here are your character choices.\n";
cout << "1: Dante The Fighter\n";
cout << "2: Lok The Master Rogue\n";
cout << "3: Katherine The Cold Wizard\n";
cout << "4: Aeris The Healing Light\n\n";
break;
}
}
void showsituation1 (int choice){
switch (choice){
case 1:
cout << "You have choosen to make a Rogue.\n\n";
break;
case 2:
cout << "You have choosen to make a Fighter.\n\n";
break;
case 3:
cout << "You have choosen to make a Cleric.\n\n";
break;
case 4:
cout << "you have choosen to make a Wizard.\n\n";
break;}
}
void showsituation1A (int choice){
switch (choice){
case 1:
cout << "You have choosen to play as Dante The Fighter.\n";
break;
case 2:
cout << "You have choosen to play as Lok The Master Rogue.\n";
break;
case 3:
cout << "You have choosen to play as Katherine The Cold Wizard.\n";
break;
case 4:
cout << "You have choosen to play as Aeris The Healing Light.\n";
break;}
}
void showsituation2 (void){
cout << "Next you must choose a stat line up.\n";
cout << "Sorry you still can't go back so your choice is final.\n\n";
cout << " Strength Based Stats\n";
cout << "Strength +4\n";
cout << "Constitution +2\n";
cout << "Dexterity -1\n";
cout << "Intelligence 0\n";
cout << "Wisdom +1\n";
cout << "Charisma +1\n\n";
cout << " Dexterity Based Stats\n";
cout << "Strength +1\n";
cout << "Constitution +1\n";
cout << "Dexterity +4\n";
cout << "Intelligence 0\n";
cout << "Wisdom -1\n";
cout << "Charisma +2\n\n";
cout << " Intelligence Based Stats\n";
cout << "Strength -1\n";
cout << "Constitution +1\n";
cout << "Dexterity 0\n";
cout << "Intelligence +4\n";
cout << "Wisdom +2\n";
cout << "Charisma +1\n\n";
}
void showchoice1 (void){
cout << "Please choose one of the stat packs to continue.\n";
cout << "1: Strength Based\n";
cout << "2: Dexterity Based\n";
cout << "3: Intelligence Based\n";
}
void showresults1 (int choice){
switch (choice){
case 1:
cout << "\nYou have choosen the Strength Based Stat Package\n";
break;
case 2:
cout << "You have choosen the Dexterity Based Stat Package\n";
break;
case 3:
cout << "You have choosen the Intelligence Based Stat Package\n";
break;}
}
void showname (void){
cout << "\nNow for the final step: Entering your Character's name.\n\n";
}
int main (){
char str[11];
char name[11];
int choice;
showintroduction();
showsituation();
showchoice();
choice = getchoice(1, 2);
showresults( choice );
switch (choice){
case 1:
choice = getchoice(1, 4);
showsituation1(choice);
showsituation2();
showchoice1();
choice = getchoice(1, 3);
showresults1(choice);
showname();
cout << "Enter your character's name here:\n";
cin.getline(name, 11);
strcpy(str, "\nYour character's name is: ") << endl;
strcat(str, name);
cout << str << endl;
break;
case 2:
choice = getchoice(1, 4);
showsituation1A(choice);
break;}
}
Now my question, why is that in my game code the cin.getline code will not function properly yet in the following code it will (I followed a books code for this and it works wonderfully)
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char str[11];
char name[11];
cout << "Enter your character's name here:\n";
cin.getline(name, 10);
strcpy(str, "\nYour character's name is: ");
strcat(str, name);
cout << str << endl;
}
Please copy the codes to your compiler and run them then tell me what you think. Also to any new game programmers this code took me six months work to build and understand, but i think it is a good starting point for beginner game programmers. I don't care if anyone use this code for their own projects. So check out the codes and give your opinions please, I really want to know what you guys think.

New Topic/Question
Reply




MultiQuote




|