Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdlib>
- #include <ctime>
- int main(){
- //Challenge: Use both break and continue functions in one loop.
- //Jump function? Sure.
- srand(time(NULL));
- int hole;
- int walk = 0;
- int hopsleft = 5;
- char playerInput;
- bool winner = true;
- bool cheat = false;
- std::string predict;
- std::cout << "**AVOID THE HOLES**";
- std::cout << "Holes are in the way! Get through without falling!\n";
- std::cout << "**Controls**\nPredict: 'p' | Walk: 'w' | Hop: 'h' \n";
- std::cout << "Hops Left: " << hopsleft << '\n';
- for(int i = 1; i <= 50; i++) {
- //20% chance of a hole. Fail if 0 - 9.
- hole = rand() % 50;
- std::cout << "Hole " << i << ": ";
- if(hole < 10 && cheat == true) {
- std::cout << "Hop here! ";
- }
- std::cin >> playerInput;
- if (playerInput == 'P') playerInput='p';
- if (playerInput == 'W') playerInput='w';
- if (playerInput == 'H') playerInput='h';
- if (playerInput == 'C') playerInput='c';
- while(playerInput == 'p') {
- std::cout << "Prediction: ";
- if(i <= 10) {
- if(hole < 10) {
- std::cout << "There is a hole here!\n";
- }
- else {
- std::cout << "Should be safe!\n";
- }
- }
- else if(i > 10 && i < 30){
- if(hole < 5) {
- std::cout << "There is a hole here!\n";
- }
- else if(hole < 20) {
- std::cout << "There's a chance of there being a hole here...\n";
- }
- else {
- std::cout << "Should be safe!\n";
- }
- }
- else {
- if(hole < 25) {
- std::cout << "There's a chance of there being a hole here...\n";
- }
- else if(hole >= 25 && hole < 35) {
- std::cout << "There could be a hole here!\n";
- }
- else {
- std::cout << "Should be safe...\n";
- }
- }
- std::cout << "Hole " << i << ": ";
- std::cin >> playerInput;
- }
- if(playerInput == 'h') {
- if(hopsleft > 0) {
- hopsleft--;
- std::cout << "Hops Left: " << hopsleft << '\n';
- continue;
- }
- else {
- std::cout << "You have no hops left! You tired yourself out and can no longer go any further...\n**YOU LOSE!**";
- winner = false;
- break;
- }
- }
- else if(playerInput == 'w') {
- if(hole < 10) {
- if(cheat==false) {
- std::cout << "You fell in a hole!\n**YOU LOSE!**\n";
- }
- else {
- std::cout << "You literally had cheats on. How did you lose?\n**YOU SUCK!**\n";
- }
- winner = false;
- break;
- }
- else {
- std::cout << "Safe!\n";
- }
- }
- else if(playerInput == 'c') {
- if(cheat==false)
- {
- std::cout << "Cheats Activated! You will now be told when to hop!\n";
- cheat=true;
- continue;
- }
- else {
- std::cout << "Nice try. You're only get to skip one hole.\n**YOU LOSE!**\n";
- winner = false;
- break;
- }
- }
- else {
- std::cout << "Wrong key! You fall into a hole immediately!\n**YOU LOSE!**\n";
- winner = false;
- break;
- }
- switch (i) {
- case 5:
- hopsleft+=2;
- std::cout << "Two hops added!\n";
- break;
- case 10:
- hopsleft+=2;
- std::cout << "Two hops added!\n";
- break;
- case 15:
- hopsleft+=2;
- std::cout << "Two hops added!\n";
- break;
- case 20:
- hopsleft+=2;
- std::cout << "Two hops added!\n";
- break;
- case 25:
- hopsleft+=2;
- std::cout << "Two hops added!\n";
- break;
- case 30:
- hopsleft+=2;
- std::cout << "Two hops added!\n";
- break;
- case 35:
- hopsleft+=2;
- std::cout << "Two hops added!\n";
- break;
- case 40:
- hopsleft++;
- std::cout << "One hop added!\n";
- break;
- case 45:
- hopsleft++;
- std::cout << "One hop added!\n";
- break;
- default:
- break;
- }
- }
- if(winner == false) {
- std::cout << "Try again sometime!";
- }
- else if(winner == true && cheat == true) {
- std::cout << "**CONGRATS! YOU CHEATED THE GAME!**";
- }
- else {
- std::cout << "**CONGRATS! YOU WIN!**";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement