Jump to content

check it out


Lights Out

Recommended Posts

#include <iostream.h>#include <math.h>#include <ctype.h>void cloverHillWelcome(void);void cloverHillDisplay(int x, int y);int moveStudent(int &x, int &y, int &keep_going);void mathClass(void);double findThePower(double x, double y);void scienceClass(void);int mixThemUp(int liquid1, int liquid2);/*void englishClass(void);void famousQuote(char[])void socialStudiesClass(void);void getPopulation(char countryCode, int&x);void talkToAFriend(void);*///prototypingint main(void){	int x, y;	int keep_going = 1;	x = y = 0;	//starting location is (0, 0)	cloverHillWelcome();	//welcome the person	do	{  moveStudent(x, y, keep_going);  cloverHillDisplay(x, y);	}	while(keep_going);	//cloverHillDisplay(0, 0);	return 0;}void cloverHillWelcome(void){	cout << "_ _ _ ____ _    ____ ____ _  _ ____    ___ ____" << endl;	cout << "| | | |___ |    |    |  | |\\/| |___     |  |  |" << endl;	cout << "|_|_| |___ |___ |___ |__| |  | |___     |  |__|" << endl;	cout << "\n";	cout << "____ _    ____ _  _ ____ ____    _  _ _ _    _    |" << endl;	cout << "|    |    |  | |  | |___ |__/    |__| | |    |    |" << endl;	cout << "|___ |___ |__|  \\/  |___ |  \\    |  | | |___ |___ ." << endl; 	cout << "Directions: \n When prompted for direction to move, press either N, S, E, W, or Q to quit." << endl;	cout << "N will move you 1 space up, E for 1 space right, and so on. There will be 4 \nrooms";	cout<< " that you will able to visit -- Math, Science, English, and Social Studies." << endl;	char you[] = " O\n\\|/\n{ }\n/-\\";	char fr1end[] = " X\n\\|/\n{ }\n/-\\";	cout << "This is YOU:" << endl;	cout << you << ", but you will be displayed as 'O'";	cout << "\n\nThis is YOUR FRIEND:" << endl;	cout << fr1end << ", but he/she will be displayed as 'X'" << endl;	//display initial hallway where you are @ (0, 0)	cout << "\n\n         |             |         |              |" << endl;	cout << "---------|    Math     |---------|   English    |-----------" << endl;	cout << "\nO                                           X\n" << endl;	cout << "---------|             |---------|                  |-------" << endl;	cout << "         |   Science   |         |  Social Studies  |" << endl;}//cloverHillWelcomevoid cloverHillDisplay(int x, int y){	int num_spaces = 0;	//number of spaces to put in front of 0, as well as number of    	//spaces to delete in front of X	char backspace = 8;	//backspace character	char space = 32;	//space character	//                                           X	cout << "\n\n         |             |         |              |" << endl;	cout << "---------|    Math     |---------|   English    |-----------" << endl;	cout << "\n";		//determine how many spaces to put in front of O and how many to take away in front of X	switch(x)	{  case 5:  	num_spaces = 4;  	break;  case 10:  	num_spaces = 9;  	break;  case 15:  	num_spaces = 16;  	break;  case 20:  	num_spaces = 23;  	break;  case 25:  	num_spaces = 28;  	break;  case 30:  	num_spaces = 34;  	break;  case 35:  	num_spaces = 42;  	break;  case 40:  	num_spaces = 49;  	break;  case 45:  	num_spaces = 55;  	break;  case 50:  	num_spaces = 62;  default:  	num_spaces = 0;  	break;	}	//OUTPUT	for(int i = 1; i <= num_spaces; i++)  cout << space;	//spaces in front of O	cout << "O";	for(int k = 1; k <= 43; k++)  cout << space;	//original number of spaces in front of X ( 43 )	for(int j = 1; j <= num_spaces; j++)  cout << backspace;	//remove spaces according to amount of 	cout << "X\n" << endl;		cout << "---------|             |---------|                  |-------" << endl;	cout << "         |   Science   |         |  Social Studies  |" << endl;}//cloverHillDisplayint moveStudent(int &x, int &y, int &keep_going){	//return 0 on failure	//return 1 on success	char direction;	cout << "Where would you like to move? ";	cin >> direction;	direction = toupper(direction);		//MOVE THE PERSON	switch(direction)	{  case 'N':  	y += 5;	//move 1 spot right  	break;  case 'S':  	y -= 5;	//move 1 spot left...  	break;  case 'E':  	x += 5;  	break;  case 'W':  	x -= 5;  	break;  case 'Q':  	keep_going = 0;	//Q for quit, the do...while terminates iteration in main()  	return 0;	//MOVE WAS UNSUCCESSFUL...QUITTED  	break;  default:  	cout << "\n<------Not a valid direction.------>\n";  	return 0;	//NOT A VALID DIRECTION, MOVE WAS UNSUCCESSFUL  	break;	}	//TEST IF LOCATION IS POSSIBLE	//test if too far left or right ( off the map )	if((x < 0) || (x > 60))	{  cout << "You have moved too far down the hall, restart." << endl;  x = y = 0;	//reset to (0, 0)  return 0;	}	//SEE IF A WALL IS HIT	//if the person hits a wall before the math or science room	if( ( (y >= 1) || (y <= -1) ) && (x <= 10))	{  cout << "You hit a wall. Try again.";  x = y = 0;	//respawn to closest checkpoint (0, 0)  return 0;	}	//if the person hits a wall after the math/sci rooms and before the english/ss	else if( ((y >= 1) || (y <= -1)) && ((x >= 24) && (x <= 34)) )	{  cout << "You hit a wall. Try again.";  x = 25;  y = 0;	//respawn to closest checkpoint (25, 0)  return 0;	}	//if the person hits the wall after the english room	else if( (y >= 1) && ((x >= 49) && (x <= 60)) )	{  cout << "You have hit a wall. Try again.";  x = 50;  y = 0;	//respawn to the closest checkpoint (50, 0)  return 0;	}	//if the person hits the wall after the SS room	else if( (y <= -1) && ((x >= 55) && (x <= 60)) )	{  cout << "You have hit a wall. Try again.";  x = 54;  y = 0;	//respawn to the closest checkpoint (54, 0)  return 0;	}	//SEE IF A ROOM IS ENTERED	//if the person enters the math room	if( (y >= 1) && ((x >= 11) && (x <= 23)) )	{  mathClass();  return 1;	}	//if the person enters the science class	else if( (y <= -1) && ((x >= 11) && (x <= 23)) )	{  scienceClass();  return 1;	}	//if the person enters the english class	else if( (y >= 1) && ((x >= 35) && (x <= 48)) )	{  //englishClass();  return 1;	}	//if the person enters the social studies class	else if( (y >= -1) && ((x >= 35) && (x <= 52)) )	{  //socialStudiesClass();  return 1;	}	else	{  return 0;	//IF NOTHING APPLICABLE GIVEN, QUIT	}	}//moveStudentvoid mathClass(void){	int baseX, expY;	cout << "\n\n--------------------------" << endl;	cout << "You have entered math class. Greetings from Mr. Hayes!" << endl;	cout << "This room allows you to calculate any number to the power of anything." << endl;	cout << "What is the base number? ";	cin >> baseX;	cout << "What is the exponent? ";	cin >> expY;	cout << "The result is " << findThePower(baseX, expY) << endl;}double findThePower(double baseX, double expY){	double answer;	answer = pow(baseX, expY);	//answer is baseX ^ expY	return answer;}void scienceClass(void){	int liquid1, liquid2;	//number representing liquids	liquid1 = liquid2 = 0;	//initialize	cout << "You have entered science class. Greetings from Mrs. Ameen!" << endl;	cout << "This room allows you to  combine 2 liquids to create a brand new concoction." << endl;	cout << "1 - Soda\n2 - Water\n3 - Cough medicine\n4 - Oil" << endl;	cout << "What liquids would you like to combine?" << endl;	cout << "Liquid 1: ";	cin >> liquid1;	cout << "Liquid 2: ";	cin >> liquid2;	//determine concoction name	mixThemUp(liquid1, liquid2);}int mixThemUp(int x, int y)	//1 on success, 2 on failure{	int sum = x + y;	//sum of the two liquids		cout << "\nYour new concoction is ";	switch(sum)	{  case 3:  	cout << "H2soda";  	return 1;  	break;  case 4:  	cout << "H2cough";  	return 1;  	break;  case (5):  	if((x == 2) && (y == 3))  	{    cout << "Water medicine" << endl;  	}  	else if((x == 1) && (y == 4))  	{    cout << "OilCO2" << endl;  	}  	return 1;  	break;  case 6:  	cout << "H2oil" << endl;  	return 1;  	break;  case 7:  	cout << "Cough oil" << endl;  	return 1;  	break;  default:  	cout << "Incorrect numbers given" << endl;  	return 0;  	break;	}}/*void englishClass(void){	//contents}void famousQuote(char[] quote){	//content}void socialStudiesClass(void){	//content}void getPopulation(int countryCode, int &x){	const long int USA = 296832191;	const long int SPAIN = 40341000;	const long int MEXICO = 107254702;	const long int EGYPT = 78369461;	const long int CANADA = 32865910;	cout << "You can get the population of 1 of 5 countries:" << endl;	cout << "1 for USA" << endl;	cout << "2 for Spain" << endl;	cout << "3 for Mexico" << endl;	cout << "4 for Egypt" << endl;	cout << "5 for Canada" << endl;	cout << "Choice: ";	cin >> countryCode;	switch(countryCode)	{  case 1:  	cout << "Population of USA is " << USA << endl;  	x = USA;  	break;  case 2:  	cout << "Population of Spain is " << SPAIN << endl;  	x = SPAIN;  	break;  case 3:  	cout << "Population of Mexico is " << MEXICO << endl;  	x = MEXICO;  	break;  case 4:  	cout << "Population of Egypt is " << EGYPT << endl;  	x = EGYPT;  	break;  case 5:  	cout << "Population of Canada is " << CANADA << endl;  	x = CANADA;  	break;  default:  	cout << "You did not enter a correct choice." << endl;  	break;	}}void talkToAFriend(void){	//content}*/

it's not finished yet

Link to comment
Share on other sites

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
×
×
  • Create New...