#include <stdio.h>
int main() {
    char A;
    char B;
    char C;
    char Start;
    printf("Welcome to the game! Please press 1 to start.\n");
    scanf(" %c", &Start);
    if (Start == '1') {
        printf("You wake up in a forest.");
        printf("There 3 paths leading to different places. Where would like to go?\n");
        printf("A. Go to the cabin?\n");
        printf("B. Go inside the cave?\n");
        printf("C. Go to the old well?\n");
        scanf(" %c", &A);
        scanf(" %c", &B);
        scanf(" %c", &C);
        //Option A//
        if (A == 'A') {
            printf("You went up to cabin. But no one is home.\n");
            printf("What will you do now?\n");
            printf("A. Knock on the door?\n");
            printf("B. Break a nearby window?\n");
            scanf(" %c", &A);
	          scanf(" %c", &B);
            if (A == 'A') {
              printf("You knocked on the door and no one answered. You decided to break the glass of a nearby window. You sneaked in. What will you do now?\n");
              printf("A. Check the drawers.\n");
              printf("B. Check the closet.\n");
              printf("C. Check the cabinets.\n");
              char choice;
              do {
                scanf(" %c", &choice);
                if (choice == 'A') {
                    printf("You checked the drawer and found an emerald. You found treasure.\n");
                    printf("You got: Ending 1\n");
                    break;
                } else if (choice == 'B') {
                    printf("You checked the closet and found nothing.\n");
                    printf("Choose another option:\n");
                } else if (choice == 'C') {
                    printf("You checked the cabinet and found nothing.\n");
                    printf("Choose another option:\n");
                } else {
                    printf("Please choose again:\n");
                }
              } while (choice != 'A');
          } else if (B == 'B'){
              printf("You decided to break the glass of a nearby window. You sneaked in. What will you do now?\n");
              printf("A. Check the drawers.\n");
              printf("B. Check the closet.\n");
              printf("C. Check the cabinets.\n");
              char choice;
              do {
                scanf(" %c", &choice);
                if (choice == 'A') {
                    printf("You checked the drawer and found an emerald. You found treasure.\n");
                    printf("You got: Ending 1\n");
                    break;
                } else if (choice == 'B') {
                    printf("You checked the closet and found nothing.\n");
                    printf("Choose another option:\n");
                } else if (choice == 'C') {
                    printf("You checked the cabinet and found nothing.\n");
                    printf("Choose another option:\n");
                } else {
                    printf("Please choose again:\n");
                }
              } while (choice != 'A');
          }
      }
      //Option B//
      else if (B == 'B') {
        printf("It's very dark in here. Let's keep exploring.\n");
        printf("A. Go straight.\n");
        printf("B. Go right.\n");
        scanf(" %c", &A);
        scanf(" %c", &B);
        if (A == 'A') {
            printf("You continue going straight. As you move forward, you stumble across a deadend. You looked around and saw nothing in your surrounds other than rocks.\n");
            printf("You've found absolutely nothing. You wasted your time and effort just to get this ending.\n");
            printf("You got: Ending 2\n");
        } else if (B == 'B') {
            printf("You decided to take the right path instead. As you continue, you stumble across a pit full of spikes.\n");
            printf("You see a ledge across the other side of the pit. However, the distance to the ledge seems a bit far.\n");
            printf("Are you willing to take the risk to jump to the other side?\n");
            printf("A. Yes, I want to jump across.\n");
            printf("B. No, I fear death.\n");
            scanf(" %c", &A);
            scanf(" %c", &B);
            if (A == 'A') {
                printf("You decided to jump across, however, the distance was simply too far.\n");
                printf("You fall into the pit, and the spikes pierces through your entire body. You died.\n");
                printf("You got: Ending 3\n");
            } else if (B == 'B') {
                printf("You made the decision to not jump across the pit. You decided to leave the cave and didn't bother going back.\n");
                printf("You successfully avoided the danger of the pit, but you are left emptyhanded.\n");
                printf("You got: Ending 4\n");
            }
        }
    }  
    //Option C//
    else if (C == 'C') {
        printf("You looked around the old, abandoned well. You can see some water at the bottom of it.\n"); 
        printf("Upon further inspection, you desire of jumping into the well increases.\n");
        printf("A. Jump into the well?\n");
        scanf(" %c", &A);
        if (A == 'A') {
            printf("You jumped into the well. Lucklily, the well wasn't as deep as you thought it was. You see a entrance to what looks like a hallway. Continue forward?\n");
            printf("A. Go through the dark hallway?\n");
            scanf(" %c", &A);
            if (A == 'A') {
                printf("The hallway splits into two directions. Left or right. Which way will you go?\n");
                printf("A. Go left.\n");
                printf("B. Go right.\n");
                scanf(" %c,", &A);
                scanf(" %c", &B);
                if (A == 'A') {
                    printf("You went left and stumble a giant room filled with chests and gold spilling out of them. You found treasure.\n");
                    printf("You got Ending 5\n");
                } else if (B == 'B') {
                    printf("You went right. You stumb across a bottomless pit with what it seems a diamond across the other side.\n");
                    printf("You realize there was no rope to get out of the well. There's no turning back now. Will you jump across and risk your life for the diamond?\n");
                    printf("A. Jump across.\n");
                    printf("B. Do nothing.\n");
                    scanf(" %c", &A);
                    scanf(" %c", &B);
                    if (A == 'A') {
                        printf("You decided to jump across, however, the distance was simply too far. You continously fall and fall and fall.\n");
                        printf("You got: Ending 6\n");
                    } else if (B == 'B') {
                        printf("You decided to do absolutely nothing. What is wrong with you will? You are giving up. You are going to die of thirst and hunger.\n");
                        printf("You eventually stopped thinking.\n");
                        printf("You got: Ending 7\n");
                    }
                }
            }
        }
    }
  } else if(Start != '1') {
        printf("You are a pathetic being. All you had to do was press 1.\n");
        printf("You got: Ending ?\n");
    }
    else {
        printf("Invalid.\n");
    }
    return 0;
}
