Sign in to follow this  

Pointer Help

This topic is 3594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm attempting to write a text based game and make a save function however I am having trouble sending the player to the saveGame function. The line causing the error is near the bottom, I've put an comment saying ERROR HERE at the line. And did my best to make it noticable in the gameLoop
#include "DungeonDunston.h"

void gameLoop(bool newgame)
{
	srand(time(NULL));
	bool gameOver=false;
	PLAYER* human=new PLAYER;
	int decision, charChoice, remainingIntel, remainingMoney, remainingTime;
	int tempIntel=0, tempMoney=0, Event=0, number=0, totalscore=0;
	char saveGame, noSave, again;
	string name;
	

	while(gameOver!=true) //If game is not over continue playing.
	{

		if(newgame==true) //If it's a new game then have player select a character. 
		{
		cout<<"You have several options as to what type of character you want. You can choose"<<endl; 
		cout<<"between:"<<endl;
		cout<<"1) The Nerd- has more intellegence but does not have much money."<<endl;
		cout<<"2) The Frat Boy- has more money but has less intellegence."<<endl;
		cout<<"3) The Average Joe-has a good mixture of both."<<endl;
		cout<<endl;
		cout<<"What type of character would you like to be? ";
		cin>>charChoice;
		cout<<endl;
		cout<<endl;

		switch(charChoice)
		{
			case 1: //Set's up the Nerd choice with more intellegence
				human->setMoney(10);
				human->setIntel(20);
				human->setTime(200);
				human->setSteps(15);
				break;
			case 2: //Set's up the Frat boys choice with more money
				human->setMoney(20);
				human->setIntel(10);
				human->setTime(200);
				human->setSteps(15);
				break;
			case 3: //Set's up the regular guy
				human->setMoney(15);
				human->setIntel(15);
				human->setTime(200);
				human->setSteps(15);
				break;
			default:
				cout<<"You inputted a wrong number."<<endl;
				break;
		}
	
		newgame=false;
		
		// Story of what you are trying to do.
		cout<<"Today you have a test in your Comp 6320 class. Unfortunatley for you missed the"<<endl;
		cout<<"early bus and are running late to class. Luckily you made it to Dunstan Hall"<<endl;
		cout<<"but you had to come in the door that's the farthest from your room because of"<<endl;
		cout<<"the construction going on around the building. You have "<<human->getTime()<<" seconds before"<<endl;
		cout<<"class starts and you know that there are proffessors and other people who need"<<endl;
		cout<<"to see you along the hall but you don't have time for them. So do your"<<endl;
		cout<<"best to avoid them or at least get rid of them as soon as possible."<<endl;
		cout<<endl;
		cout<<endl;
	
		cout<<"If you run out of time to get to class or if your mentally exhausted or run out"<<endl;
		cout<<"of money for the blue book that you need to buy from the teacher since you"<<endl;
		cout<<"didn't have time to stop at the book store you'll fail the test. If you get low"<<endl;
		cout<<"on money or intellgence you can study or search for some loose change. You"<<endl;
		cout<<"better get going otherwise you\'re going to be late."<<endl;
		cout<<endl;
		cout<<endl;

	}
	else //If not a game set the old loaded game up.
	{
	//loadGame();
	}


	// Actual game loop
		cout<<"What would you like to do?"<<endl;
		cout<<"1) Continue walking to class"<<endl;
		cout<<"2) Study (Takes time)"<<endl;
		cout<<"3) Search for change (Takes time)"<<endl;
		cout<<"4) Veiw your mental stamina and money"<<endl;
		cout<<"5) Quit the game"<<endl;
		cout<<endl;
		cout<<"Please choose an action: ";
		cin>>decision;
		cout<<endl;

		switch(decision) // Main portion of the game.
		{
			case 1: // Continue walking to class
				human->loseSteps(1);
				human->loseTime(10);
	
				Event=rand()%15;
				number=1+rand()%8;


				switch(Event)
				{
				case 1:
					human->loseIntel(number);
					cout<<"One of your professors pops out of their office and asks you if you have the "<<endl;
					cout<<"homework that you owe them. You give him the homework you owe him. "<<endl;
					cout<<"(Lose "<<number<<" intellegence)"<<endl;
					cout<<endl;
					cout<<endl;
					break;
				case 3:
					human->loseIntel(number);
					cout<<"One of your friends pop out of the study room and asks you if you have the stuff"<<endl;
					cout<<"for the project you are working on together. You give him your part of the"<<endl;
					cout<<"project. (Lose "<<number<<" intellegence)"<<endl;
					cout<<endl;
					break;
				case 4:
					human->loseMoney(number);
					cout<<"One of your friends pops out and asks if you have that money you owe him."<<endl;
					cout<<"You pay him the $"<<number<<" you owe him."<<endl;
					cout<<endl;
					cout<<endl;
					break;
				case 7:
					human->loseMoney(number);
					cout<<"The president of the ACM sees you coming down the hall and asks for the money for dues."<<endl;
					cout<<"You tell him you don't have much with you and give him $"<<number<<"."<<endl;
					cout<<endl;
					cout<<endl;
					break;
				case 8:
					cout<<"There is this girl who stops and ask you if you know where the room for her"<<endl;
					cout<<"class is. Being polite you tell her where the room is but it costs you another"<<endl;
					cout<<"10 seconds."<<endl;
					human->loseTime(10);
					cout<<endl;
					cout<<endl;
					break;
				case 9:
					cout<<"A grad student stops you in the hall and asks you to do a quick little problem"<<endl;
					cout<<"solving for his research project. (Lose 10 more seconds and "<<number<<" intellegence)"<<endl;
					human->loseTime(10);
					human->loseIntel(number);
					cout<<endl;
					cout<<endl;
					break;
				case 12:
					cout<<"A classmate comes out in the hallway and gives you some project work he owes you.(Gain "<<number<<" intellegence)"<<endl;
					human->addIntel(number);
					cout<<endl;
					cout<<endl;
					break;
				case 13:
					cout<<"A friend comes out in the hallway and gives you some money he owes you.(Gain $"<<number<<")"<<endl;
					human->addMoney(number);
					cout<<endl;
					cout<<endl;
					break;
				case 14:
					human->addTime(30);
					cout<<"You run into a friend and he wants to talk to you but you tell him you have a "<<endl;
					cout<<"test in a few seconds. He say hey your watch is running a little fast. "<<endl;
					cout<<"You still have "<<human->getTime()<<" before your test."<<endl;
					cout<<endl;
					cout<<endl;
					break;
				default:
					cout<<"You continue walking forward and no one bothers you."<<endl;
					cout<<endl;
					cout<<endl;
					break;
				}

			cout<<endl;
				break;
			case 2: // Study (increase intellegence)
				tempIntel=1+rand()%5;
				cout<<"You studying some and feel smarter. (Intellegence increases by "<<tempIntel<<")"<<endl;;
				human->addIntel(tempIntel);
				human->loseTime(10);
				cout<<endl;
				break;
			case 3: // Search for money (increase money)
				tempMoney=1+rand()%5;
				cout<<"Searching for change in your backpack and find $"<<tempMoney<<" you didn't know you had."<<endl;
				human->addMoney(tempMoney);
				human->loseTime(10);
				cout<<endl;
				break;
			case 4:  // Prints out stats and positions
				cout<<"===================="<<endl;
				cout<<"|  Veiwing stats.  |"<<endl;
				cout<<"===================="<<endl;
				cout<<"You have: $"<<human->getMoney()<<endl;// Expected should be 10.
				cout<<"Your intellegence is: "<<human->getIntel()<<endl;// Expected should be 10.
				cout<<"You have "<<human->getTime()<<" minutes until your test."<<endl;// Expected should be 10.
				cout<<"The steps left you need to take to reach the class is: "<<human->getSteps()<<endl;//Expected should be 30.
				cout<<endl;
				cout<<endl;
				break;
			case 5: // Ends the game if you don't feel like playing anymore.
				gameOver=true;
				break;
			default: 
				cout<<"Try again you inputed something wrong."<<endl;
				break;
		}



		// If quit has been choosen ask if they would like to save.
		if(gameOver==true)
		{
			cout<<"Would you like to save your game? (Y/N) ";
			cin>>saveGame;
			cout<<endl;
			cout<<endl;
						
			if(saveGame!='y'&& saveGame!='Y') //If they don't want to save make sure they don't want to save.
			{
				cout<<"Are you sure you don't want to save? (Y/N)";
				cin>>noSave;
				cout<<endl;
				cout<<endl;
				if(noSave=='y' && noSave=='Y')//If they decided they wanted to save then save
				{
/*----------------------------------------------------------------------------*/
					saveGame( &human );//<--ERROR HERE
/*----------------------------------------------------------------------------*/
				}

			}
			else // It they choose to save then save.
			{
				//saveGame();
			}
		}
		else //If they didn't quit check for other game ending reasons.
		{
			if(human->getTime() <=0)
			{
				cout<<"You are late to the test and failed."<<endl;
				gameOver=true;
			}
			else
				if(human->getMoney() <=0)
				{
					cout<<"You ran out of money and can't pay for the bluebook. So you don't go to"<<endl;
					cout<<"the test."<<endl;
					gameOver=true;
				}
				else
					if(human->getIntel() <=0)
					{
						cout<<"You are too mentally exhausted to take the test and fail to remember where you" <<endl;
						cout<<"were going."<<endl;
						gameOver=true;
					}
		}

		if(human->getSteps()==0)
		{
			gameOver=true;
			remainingIntel=human->getIntel();
			remainingMoney=human->getMoney();
			remainingTime=human->getTime();

			totalscore=remainingIntel*remainingMoney*remainingTime;

			cout<<"Congratulations you have won the game!!!"<<endl;
			cout<<"You final score is: "<<totalscore<<endl;
			cout<<endl;
			cout<<"Enter your name for the high score list: ";
			getline(cin, name);
			getline(cin, name);
			cout<<endl;
			cout<<"Again, congratulations "<<name<<" again for winning."<<endl;
			cout<<endl;
			cout<<"Would you like to play again? (Y/N) ";
			cin>>again;
			cout<<endl;
			cout<<endl;

			if(again!='n'&& again!='N')
			{
				gameOver=false;
				newgame=true;					
			}
		}
	}

	cout<<"Thank you for playing the Dunston Dungeon. We hope you play again."<<endl;
	cout<<endl;
	cout<<endl;
	cout<<endl;

}


#include "DungeonDunston.h"

void saveGame(PLAYER *human)
{
	char FileName[20];

	cout<<"Enter the name of which you want to create the save? "<<endl;
	cin >> FileName;
    ofstream Save(FileName, ios::out);
	Save<<human->getMoney()<<" "<<human->getIntel()<<" "<<human->getTime()<<" "<<human->getSteps()<<endl;
	Save.close();
}



I get error C2064: term does not evaluate to a function taking 1 arguments I'm having trouble figure it out any help would be greately appreciated.

Share this post


Link to post
Share on other sites
saveGame is a char variable and not a function. If there is a function with that name the local variable hides it to that part of the code.

Change the name of the local variable or change the name of the function.

Share this post


Link to post
Share on other sites
The way to avoid this kind of thing is to write simpler code and organize things more neatly, by extracting code into functions and by scoping variables as tightly as possible. You can, and should, declare variables near first use, and initialize them with their initial value, whenever possible.

Also, there is no reason for dynamically instantiating the Player instance here.

Share this post


Link to post
Share on other sites
Also, when you're using bool values in conditional statements, you do not need to make a comparison because a comparison is only used to determine true or false, but if you're dealing with boolean values - which are only true or false - there's no need to make a comparison, you already have the information you need (is it true or false?). So, instead of doing this:

while(gameOver!=true) //If game is not over continue playing.

You can just do this:

while(!gameOver) // While game is not over

Share this post


Link to post
Share on other sites
Quote:
Original post by Shakedown
Also, when you're using bool values in conditional statements, you do not need to make a comparison because a comparison is only used to determine true or false, but if you're dealing with boolean values - which are only true or false - there's no need to make a comparison, you already have the information you need (is it true or false?). So, instead of doing this:

while(gameOver!=true) //If game is not over continue playing.

You can just do this:

while(!gameOver) // While game is not over


+1 on that, it makes it nice and easy to look at.

Share this post


Link to post
Share on other sites

This topic is 3594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this