Hi, this is my first attempt at actually making a game that is actually playable, instead of something boring that is just the same thing over and over.
The problem that I am having is that when the function startGame(); is called, the program closes. There are no errors, because I did have it recall the printPossibleChoices(); function and that worked. It's just the startGame(); doesn't appear to call the askForPlace(); function. Help?
Also something else that I dont understand is how to make the quitGame function erm... work. When the program runs, if I press 5 to close it straight away, then press 1 to say yes close it, it closes straight away. But if I do something else first like create new players then close it, it sometimes takes like 8 repetitions of pressing 5, 1, 5, 1.. to get the program to close.
#include <iostream>
#include <fstream>
using namespace std;
int playerCreateChoiceOrNot;
string playerName;
string newPlayerFileName;
int areYouSureYouWantToQuit;
string location;
int startGame();
int printPossibleChoices();
int askForPlace();
int inCasino();
int playRoulette();
int playSlots();
int quitGame(){
cout << "Are you sure you want to quit? 0 = no, 1 = yes: ";
cin >> areYouSureYouWantToQuit;
if(areYouSureYouWantToQuit == 0){
cout << "\n";
printPossibleChoices();
}
if (areYouSureYouWantToQuit != 1 && areYouSureYouWantToQuit != 0){
cout << "Please enter a valid choice.\n";
quitGame();
}
if(areYouSureYouWantToQuit == 1){
system("pause");
}
}
int startGame(){
int askForPlace();
}
int deletePlayer(){
cout << "Can not delete players.\n\n";
}
int getPlayerList(){
ifstream playerFile("C:\\Dev-Cpp\\programs\\game\\data\\players.txt");
cout << "Current players:\n\n";
while(playerFile >> playerName){
cout << playerName << "\n";
}
}
int printPossibleChoices(){
cout << "1. Choose a player.\n2. Create a new player.\n3. List current players.\n4. Delete a player.\n5. Quit.\n\n";
cin >> playerCreateChoiceOrNot;
if(playerCreateChoiceOrNot == 1){
cout << "Enter a player's name: ";
cin >> playerName;
cin.get();
startGame();
}
else if(playerCreateChoiceOrNot == 2){
cout << "Enter the name of the player: ";
cin >> playerName;
ofstream playerFile("C:\\Dev-Cpp\\programs\\game\\data\\players.txt", ios_base::app);
playerFile << playerName << "\n";
playerFile.close();
newPlayerFileName = playerName + ".txt";
ofstream newPlayerFile;
newPlayerFile.open(newPlayerFileName.c_str());
printPossibleChoices();
cout << "\n\n";
}
else if(playerCreateChoiceOrNot == 3){
getPlayerList();
printPossibleChoices();
cout << "\n\n";
}
else if(playerCreateChoiceOrNot == 4){
deletePlayer();
cout << "\n\n";
}
else if(playerCreateChoiceOrNot == 5){
quitGame();
}
else{
cout << "Please enter a valid choice.\n";
printPossibleChoices();
}
}
int main(){
printPossibleChoices();
}
int askForPlace(){
int destination;
cout << "Where would you like to go?\n\n1. Casino\n2. Bank\n3. Sports arena\n\n";
cin >> destination;
cout << "\n\n";
if(destination == 1){
location = "Casino";
inCasino();
}
if(destination == 2){
location = "Bank";
cout << "You are in the " << location;
}
if(destination == 3){
location == "Sports arena";
cout << "You are in the " << location;
}
}
int inCasino(){
int secondDestination;
cout << "You are in the " << location << "\n\nWhat would you like to play?\n\n1. Roulette\n2. Slot machines\n3. Go back";
cin >> secondDestination;
if(secondDestination == 1){
playRoulette();
}
if(secondDestination == 2){
playSlots();
}
if(secondDestination == 3){
askForPlace();
}
}
int playRoulette(){
}
int playSlots(){
}