/* * *TEQUILA* 2 * as coded by Shiv. */ #include #include #include #include #include #include #include #include #include //FUNCTION PROTOTYPES int TequilaHeader(); int TequilaQuit(); int SoundGame(); int NumberGuess(); int MaxDrink(); int Text(); int Marquee(); // subsequent three functions are int TextScroll(); // accessed by master function int TextBounce(); // Text(). int TextQuit(); int Worm(); void Scenery(); //called by function Worm() Obstacle(int &horizontal, int &vertical); Goal(int &goalX, int &goalY, int &horizontal, int &vertical, int &kill); main() { int selection; int choice; int endVar; do //begin main program loop { //set opening requirements clrscr(); randomize(); textcolor(LIGHTGRAY); textbackground(BLACK); selection = TequilaHeader(); //call preliminary function if (selection == 1) //main function calls { selection = SoundGame(); } else if (selection == 2) { selection = NumberGuess(); } else if (selection == 3) { selection = MaxDrink(); } else if (selection == 4) { do { //required to loop the Text() choice = Text(); //functions together if (choice == 1) { choice = Marquee(); } else if (choice == 2) { choice = TextScroll(); } else if (choice == 3) { choice = TextBounce(); } choice = TextQuit(); } while (choice != 1); } else if (selection == 5) { selection = Worm(); } endVar = TequilaQuit(); //call closing function } while (endVar != 1); //end main program loop return 0; //return a 0 to the OS } //PROGRAM FUNCTIONS //*************************************************************** //Tequila Header function int TequilaHeader() { int selection; cout << "\n"; cout << " *TEQUILA*TEQUILA*TEQUILA*TEQUILA*TEQUILA*TEQUILA*TEQUILA*TEQUILA*TEQUILA*\n"; cout << " *TEQUILA*TEQUILA*TEQUILA*TEQUILA*TEQUILA*TEQUILA*TEQUILA*TEQUILA*TEQUILA*\n\n"; cout << " Welcome to Tequila. Type the number of the selection you want to try and \n"; cout << " hit enter to begin.\n\n"; cout << " #1 ----- Sound Game\n"; cout << " #2 ----- Number Guess\n"; cout << " #3 ----- Maximum Drink\n"; cout << " #4 ----- Text Molestation\n"; cout << " #5 ----- Worm\n\n"; cout << "Type the number now: "; cin >> selection; return(selection); } //*************************************************************** //Sound Game Function int SoundGame() { int selection; int soundEndVar; int soundnum; int numLoops; int pitchStart; int pitchEnd; int pitchRaise; int pitchDelay; int LCV; int LCV2; do //begin main sound game loop { clrscr(); cout << "How many times do you want the sound loop to repeat?\n"; cout << "(probably won't want more than five) >> "; cin >> numLoops; //reads number of times sound sequence will loop cout << "\nWhere would you like the pitch to start?\n"; cout << "(recommended minmum of 20) >> "; cin >> pitchStart; //reads where the sequence will start cout << "\nWhere would you like the pitch to end?\n"; cout << "(speaker conks out about 3000 - recommended max of 1000) >> "; cin >> pitchEnd; //reads where the sequence ends cout << "\nBy what interval would you like the pitch to go up and down?\n"; cout << "(goes very fast - probably no more than five or ten) >> "; cin >> pitchRaise; //reads what interval the sounds will go up by cout << "\nWhat would you like the delay between sounds to be?\n"; cout << "(goes very fast - probably no more than 5) >> "; cin >> pitchDelay; //reads the delay between sounds soundnum = pitchStart; //unneeded, but makes code easier to understand LCV = 0; //initialize variables LCV2 = 1; while (LCV < numLoops) //begin main sound loop { do //begin upscale loop { sound(soundnum); //outputs set sound soundnum += pitchRaise; //increments sound delay(pitchDelay); //pauses for the delay nosound(); //stops sound gotoxy(1,16); cout << "+"; LCV2++; //increments counter variable } while (soundnum <= pitchEnd); //end upscale loop do { //begin downscale loop sound(soundnum); //outputs set sound soundnum -= pitchRaise; //decrements sound delay(pitchDelay); //pauses for the delay nosound(); //stops sound gotoxy(1,16); cout << "-"; } while (soundnum >= pitchStart); //end downscale loop LCV++; //increments counter variable cout << "\nLoop " << LCV << " completed."; //outputs status } //end main sound loop cout << "\n\nDo you want to quit? 1 for yes and 0 for no. "; cin >> soundEndVar; } //closing brace for main sound loop while (soundEndVar != 1); return(selection); } //final closing brace //*************************************************************** //Number Guess function int NumberGuess() { int selection; int numguessEndVar; int secondNum; int answerNum; int guess; int numGuesses; int LCV; do //begin main number guess loop { clrscr(); cout << "The number will be between 1 and 'n.' Please choose what you'd like \n'n' to be: "; cin >> secondNum; //designates 'n' answerNum = random(secondNum); //picks the number cout << "\nHow many guesses do you want to have? "; cin >> numGuesses; //designates number of guesses cout << "\nOkay, to recap, your goal is to guess a number between 1 and " << secondNum << ", and you have " << numGuesses << " guess/guesses to do so."; cout << "\nTry and guess the number between 1 and " << secondNum << ". "; cin >> guess; LCV = 1; do //begin guessing loop { if (guess > answerNum) //executes if guess is higher than the answer { cout << "\nWrong. Try lower. "; cin >> guess; LCV += 1; } if (guess < answerNum) //executes if guess lower than the answer { cout << "\nWrong. Try higher. "; cin >> guess; LCV += 1; } if (guess == answerNum) //executes if they're right { cout << "\nBingo!"; secondNum = LCV; //assignment statement required to keep track LCV = numGuesses; //of # guesses } } while (LCV != numGuesses); LCV = secondNum; //reset LCV value to original state (God I //hate C++) if (guess == answerNum) //output results { cout << "\nYou win!"; cout << "\nThe number was " << answerNum << ", and it took you " << LCV << " tries to get it."; } else { cout << "\nYou lose! Haha!"; cout << "\nThe number was " << answerNum << ", and it took you " << LCV << " tries to LOSE."; } cout << "\n\nDo you want to quit? 1 for yes and 0 for no. "; cin >> numguessEndVar; } //closing brace for main number guess loop while (numguessEndVar != 1); return(selection); } //final closing brace //*************************************************************** //Maximum Drink function int MaxDrink() { int selection; int age; char gender; int weight; char diabetes; int maxDrink; int endVar; do { clrscr(); maxDrink = 0; //initialize variables gender = 'x'; weight = 0; diabetes = 'n'; cout << "This game calculates the maximum amount of alcohol you could consume\n"; cout << "without vomiting. Press any key to continue..."; getch(); clrscr(); cout << "\nHow old are you? "; cin >> age; cout << "\nAre you male or female? (m or f) "; cin >> gender; toupper(gender); //convert to upper case cout << "\nHow much do you weigh? (lbs) "; cin >> weight; cout << "\nAre you diabetic? (y or n) "; cin >> diabetes; toupper(diabetes); //convert to upper case cout << "\n\nThanks. I'm going to stalk you now (just kidding)."; getch(); if (gender == 'M') //determine output maxDrink = 4; else maxDrink = 3; if (age < 10) maxDrink += 1; else if (age < 15) maxDrink += 3; else if (age <= 17) maxDrink += 4; else if (age >= 18) maxDrink += 5; else if (age > 30) maxDrink = 0; if (weight < 150) maxDrink += 1; else if (weight < 180) maxDrink += 3; else if (weight < 220) maxDrink += 5; else if (weight < 275) maxDrink += 10; else if (weight > 275) maxDrink += 15; if (diabetes == 'Y') maxDrink = 2; //output results cout << "\n\nIt has been tabulated that you can hold " << maxDrink << " drinks before vomiting."; getch(); cout << "\n\nDo you want to quit? 1 for yes, 0 for no. "; cin >> endVar; } while (endVar != 1); return(selection); } //*************************************************************** //Text function int Text() { int choice; clrscr(); //determines which text function to execute cout << "Please choose which option you'd like to try: "; cout << "\n #1 - Marquee Simulator"; cout << "\n #2 - Text Scroller"; cout << "\n #3 - Text Bouncer"; gotoxy (47,1); cin >> choice; return(choice); } //*************************************************************** //Marquee function int Marquee() { int choice; char phrase[81]; int speed; int screen; int repeats; int LCV; int horizontal; int vertical; int endVar; do { clrscr(); cout << "Enter the phrase to scroll across the screen (80 letters max).\n"; cin.getline(phrase, 80); //required to clear buffer cin.getline(phrase, 80); cout << "How many times do you want it to repeat? \n"; cin >> repeats; cout << "How much of a delay do you want? (recommended minimum of 20) "; cin >> speed; screen = 80 - (strlen(phrase)); //determines length of screen LCV = 0; clrscr(); do { //begin marquee emulation horizontal = screen; vertical = random(24 + 1); //correct if vertical is 0 gotoxy(screen,vertical); //go to designated position while (horizontal > 1) //loop until phrase hits { //left side of screen cout << phrase; delay(speed); delline(); //delete outputted line gotoxy(horizontal,vertical); horizontal--; //decrement counter variable } LCV++; //increment counter variable } while (repeats != LCV); clrscr(); gotoxy(1,1); //corrects cursor position cout << "Do you want to quit? (1 for yes, 0 for no) "; cin >> endVar; } while (endVar != 1); return(choice); } //*************************************************************** //Text Scroll function int TextScroll() { int choice; char phrase[81]; int bounces; int speed; int screen; int LCV; int horizontal; int endVar; do { clrscr(); cout << "Enter the phrase to scroll across the screen (80 letters max).\n"; cin.getline(phrase, 80); //required to clear buffer cin.getline(phrase, 80); screen = 80 - (strlen(phrase)); //determines length of screen cout << "How many times do you want it to bounce back and forth? "; cin >> bounces; cout << "How much of a delay do you want? (recommended minimum of 20) "; cin >> speed; horizontal = 1; LCV = 0; clrscr(); do { while (horizontal < screen) //loops until phrase hits right { //edge of screen cout << phrase; delay(speed); //sets delay delline(); //deletes line gotoxy(horizontal,10); horizontal++; //increments counter variable } while (horizontal > 1) //loops until phrase hits left { //edge of screen cout << phrase; delay(speed); delline(); gotoxy(horizontal,10); horizontal--; //decrements counter variable } LCV++; //increments main counter variable } while (bounces != LCV); clrscr(); gotoxy(1,1); cout << "Do you want to quit? (1 for yes, 0 for no) "; cin >> endVar; } while (endVar != 1); return(choice); } //*************************************************************** //Text Bounce function int TextBounce() { int choice; char phrase[81]; int bounces; int speed; int screen; int LCV; int horizontal; int vertical; int endVar; do { clrscr(); cout << "Enter the phrase to scroll across the screen (80 letters max).\n"; cin.getline(phrase, 80); //required to clear buffer cin.getline(phrase, 80); screen = 80 - (strlen(phrase)); //determine screen length cout << "How many times do you want it to bounce back and forth? "; cin >> bounces; cout << "How much of a delay do you want? (recommended minimum of 20) "; cin >> speed; horizontal = 1; vertical = 1; LCV = 0; clrscr(); do { horizontal = random(screen); //set horizontal value vertical = random(24 + 1); //set vertical value while ((horizontal < screen) && (vertical < 25)) { cout << phrase; //loops until phrase hits delay(speed); //bottom of screen delline(); gotoxy(horizontal,vertical); horizontal++; //increment counters vertical++; } while ((horizontal < screen) && (vertical > 1)) { cout << phrase; //loops until phrase hits delay(speed); //right side of screen delline(); gotoxy(horizontal,vertical); horizontal++; //increment horizontal vertical--; //decrement vertical } horizontal = random(screen); //once loop is completed, vertical = random(24 + 1); //reset horiz and vert while ((horizontal < screen) && (vertical < 25)) { cout << phrase; //loops until phrase hits delay(speed); //bottom of screen delline(); gotoxy(horizontal,vertical); horizontal--; //increment horizontal vertical++; //increment vertical } while ((horizontal > 1) && (vertical > 1)) { cout << phrase; //loops until phrase hits delay(speed); //left side of screen delline(); gotoxy(horizontal,vertical); horizontal--; //decrement counters vertical--; } LCV++; //increment main counter } while (bounces != LCV); clrscr(); gotoxy(1,1); //correct cursor position cout << "Do you want to quit? (1 for yes, 0 for no) "; cin >> endVar; } while (endVar != 1); return(choice); } //*************************************************************** //TextQuit function int TextQuit() { int textEnd; clrscr(); cout << "Do you want to quit molesting text? 1 for yes, 0 for no. "; cin >> textEnd; return(textEnd); } //*************************************************************** //Worm function int Worm() { int selection; char keypress; int horizontal; int vertical; int direction; int goalX; int goalY; int kill; int length; int reset; int endVar; do { clrscr(); //shows how control scheme works cout << "\nThe following is how the worm control works:\n\n"; cout << " (7) (8) (9) \n"; cout << " \\\\ || // \n"; cout << " (4) === === (6) \n"; cout << " // || \\\\ \n"; cout << " (1) (2) (3) \n\n"; cout << "To quit, hit a lowercase 'x'. Press enter to continue. "; getch(); horizontal = 39; //initialize variables, vertical = 12; //perform prelims reset = 7; length = 1; direction = 0; goalX = 1; goalY = 1; kill = 1; textbackground(BLUE); clrscr(); goalX = random(79 + 1); goalY = random(19 + 1); gotoxy(goalX, goalY); putch('*'); while (keypress != 120) { //begin inner loop Scenery(); //run function to create background //run function to set the goal Goal(goalX, goalY, horizontal, vertical, kill); textcolor(BLACK); //reset colors textbackground(BLUE); gotoxy(horizontal, vertical); if (direction == 0) //output worm character putch('Ü'); else if (direction == 1) putch('Û'); else putch('Ü'); gotoxy(horizontal,vertical); keypress = getch(); //reads users keypress gotoxy(horizontal, vertical); switch (keypress) //determines direction { //cardinal directions case (50) : { vertical++; //up (8) direction = 1; break; } case (52) : { horizontal--; //left (4) direction = 0; break; } case (54) : { horizontal++; //right (6) direction = 0; break; } case (56) : { vertical--; //down (2) direction = 1; break; } /* * It was impossible to represent the keypad numbers using * anything other than their ASCII values. This brought * about several additional bugs, and with the slanted * directions, certain directional manipulations responded * to the incorrect ASCII values. This is why the following * code may seem mixed up, or incorrect. */ //slanted directions case (49) : { horizontal--; //down and left (1) vertical++; direction = 2; break; } case (51) : { horizontal++; //down and right (3) vertical++; direction = 2; break; } case (55) : { horizontal--; //up and left (7) vertical--; direction = 2; break; } case (57) : { horizontal++; //up and right (9) vertical--; direction = 2; break; } } //end switch statement if (horizontal < 1) //corrects if user attempts to horizontal++; //go outside screen else if (horizontal > 80) horizontal--; else if (vertical < 1) vertical++; else if (vertical > 25) vertical--; Obstacle(horizontal, vertical); //calls obstacle function length++; //adjusts the length of the worm if (length >= reset) { length = 0; clrscr(); } } //end inner loop clrscr(); keypress = 'c'; //resets variable textbackground(BLACK); //resets color textcolor(LIGHTGRAY); cprintf("Do you want to quit? 1 for yes, 0 for no. "); cin >> endVar; } while (endVar != 1); return(selection); } //*************************************************************** //Goal function Goal(int &goalX, int &goalY, int &horizontal, int &vertical, int &kill) { textcolor(WHITE); textbackground(BLUE); if ((horizontal == goalX) && (vertical == goalY)) { kill = 1; } if (kill == 1) { goalX = random(79 + 1); goalY = random(19 + 1); clrscr(); Scenery(); gotoxy(goalX, goalY); textcolor(WHITE); textbackground(BLUE); putch('*'); kill = 0; } if (kill == 0) { gotoxy(goalX, goalY); putch('*'); gotoxy(horizontal, vertical); } return 0; } //*************************************************************** //Scenery function void Scenery() { //scenery declaration textcolor(LIGHTGRAY); textbackground(RED); //top left 'L' shape gotoxy(5,3); cprintf("ÉÍÍÍÍÍÍÍÍ͵"); //only way I know to output gotoxy(5,4); //colored text without additional cprintf("º"); gotoxy(5,5); cprintf("Ð"); //top right 'L' shape gotoxy(65,3); cprintf("ÆÍÍÍÍÍÍÍÍ»"); gotoxy(74,4); cprintf("º"); gotoxy(74,5); cprintf("Ð"); //bottom left 'L' shape gotoxy(5,22); cprintf("ÈÍÍÍÍÍÍÍ͵"); gotoxy(5,21); cprintf("º"); gotoxy(5,20); cprintf("Ò"); //bottom right 'L' shape gotoxy(65,22); cprintf("ÆÍÍÍÍÍÍÍͼ"); gotoxy(74,21); cprintf("º"); gotoxy(74,20); cprintf("Ò"); //central box textcolor(GREEN); textbackground(BROWN); gotoxy(34,10); cprintf("ÉÍÍÍ"); gotoxy(41,10); cprintf("ÍÍÍ»"); gotoxy(34,14); cprintf("ÈÍÍÍ"); gotoxy(41,14); cprintf("ÍÍͼ"); gotoxy(34,11); cprintf("º"); gotoxy(34,13); cprintf("º"); gotoxy(44,11); cprintf("º"); gotoxy(44,13); cprintf("º"); } //end scenery declaration function //*************************************************************** //Obstacle function Obstacle(int &horizontal, int &vertical) { /* Okay, this is gonna be a pretty big bunch of IF statement. */ //top left 'L' watcher if (((horizontal == 5) && (vertical == 3)) || ((horizontal == 6) && (vertical == 3)) || ((horizontal == 7) && (vertical == 3)) || ((horizontal == 8) && (vertical == 3)) || ((horizontal == 9) && (vertical == 3)) || ((horizontal == 10) && (vertical == 3)) || ((horizontal == 11) && (vertical == 3)) || ((horizontal == 12) && (vertical == 3)) || ((horizontal == 13) && (vertical == 3)) || ((horizontal == 14) && (vertical == 3)) || ((horizontal == 15) && (vertical == 3)) || ((horizontal == 16) && (vertical == 3)) || ((horizontal == 5) && (vertical == 4)) || ((horizontal == 5) && (vertical == 5))) { clrscr(); horizontal = 39; vertical = 12; gotoxy(39,12); sound(500); delay(80); nosound(); } //top right 'L' watcher if (((horizontal == 65) && (vertical == 3)) || ((horizontal == 66) && (vertical == 3)) || ((horizontal == 67) && (vertical == 3)) || ((horizontal == 68) && (vertical == 3)) || ((horizontal == 69) && (vertical == 3)) || ((horizontal == 70) && (vertical == 3)) || ((horizontal == 71) && (vertical == 3)) || ((horizontal == 72) && (vertical == 3)) || ((horizontal == 73) && (vertical == 3)) || ((horizontal == 74) && (vertical == 3)) || ((horizontal == 74) && (vertical == 4)) || ((horizontal == 74) && (vertical == 5))) { clrscr(); horizontal = 39; vertical = 12; gotoxy(39,12); sound(500); delay(80); nosound(); } //bottom left 'L' watcher if (((horizontal == 5) && (vertical == 22)) || ((horizontal == 6) && (vertical == 22)) || ((horizontal == 7) && (vertical == 22)) || ((horizontal == 8) && (vertical == 22)) || ((horizontal == 9) && (vertical == 22)) || ((horizontal == 10) && (vertical == 22)) || ((horizontal == 11) && (vertical == 22)) || ((horizontal == 12) && (vertical == 22)) || ((horizontal == 13) && (vertical == 22)) || ((horizontal == 14) && (vertical == 22)) || ((horizontal == 15) && (vertical == 22)) || ((horizontal == 5) && (vertical == 21)) || ((horizontal == 5) && (vertical == 20))) { clrscr(); horizontal = 39; vertical = 12; gotoxy(39,12); sound(500); delay(80); nosound(); } //bottom right 'L' watcher if (((horizontal == 65) && (vertical == 22)) || ((horizontal == 66) && (vertical == 22)) || ((horizontal == 67) && (vertical == 22)) || ((horizontal == 68) && (vertical == 22)) || ((horizontal == 69) && (vertical == 22)) || ((horizontal == 70) && (vertical == 22)) || ((horizontal == 71) && (vertical == 22)) || ((horizontal == 72) && (vertical == 22)) || ((horizontal == 73) && (vertical == 22)) || ((horizontal == 74) && (vertical == 22)) || ((horizontal == 75) && (vertical == 22)) || ((horizontal == 65) && (vertical == 21)) || ((horizontal == 65) && (vertical == 20))) { clrscr(); horizontal = 39; vertical = 12; gotoxy(39,12); sound(500); delay(80); nosound(); } //central box watcher if (((horizontal == 34) && (vertical == 10)) || ((horizontal == 35) && (vertical == 10)) || ((horizontal == 36) && (vertical == 10)) || ((horizontal == 37) && (vertical == 10)) || ((horizontal == 34) && (vertical == 11)) || ((horizontal == 41) && (vertical == 10)) || ((horizontal == 42) && (vertical == 10)) || ((horizontal == 43) && (vertical == 10)) || ((horizontal == 44) && (vertical == 10)) || ((horizontal == 44) && (vertical == 11)) || ((horizontal == 34) && (vertical == 14)) || ((horizontal == 35) && (vertical == 14)) || ((horizontal == 36) && (vertical == 14)) || ((horizontal == 37) && (vertical == 14)) || ((horizontal == 34) && (vertical == 13)) || ((horizontal == 41) && (vertical == 14)) || ((horizontal == 42) && (vertical == 14)) || ((horizontal == 43) && (vertical == 14)) || ((horizontal == 44) && (vertical == 14)) || ((horizontal == 44) && (vertical == 13))) { clrscr(); horizontal = 39; vertical = 12; gotoxy(39,12); sound(500); delay(80); nosound(); } return 0; } //*************************************************************** //Tequila Quit function int TequilaQuit() { int endVar; clrscr(); cout << "Do you want to quit Tequila? Enter 1 for yes and 0 for no. "; cin >> endVar; return(endVar); }