1 Attachment(s)
Need help on my first Text Adventure game
Hello guys and gals, I have been in my computer science class for about 3 weeks, I'm trying to create a Text Adventure but i seem to have hit a bug, could anyone help? Its a bit long, but the part i need help with is in the bottom, under my spiderfight custom function, i put a comment for you guys after the while loop i made.
Code:
#include <stdio.h>
#include <stdlib.h>
void displayhealth(int);
void spiderfight(int, int, char, int, int, int);
int main()
{
/* Monsters */
int spider = 100;
int troll = 150;
/* Players */
int playerhealth = 100;
char player = 'c';
char pinput;
/* Locations */
char Cave = 'C';
char Hill = 'H';
char Bridge = 'B';
char Forest = 'F';
/* Skills */
int Punchdmg = 10;
int Kickdmg = 25;
int Bitedmg = 35;
printf("Chapter I: Amnesia\n\n");
printf("Location: Dark Forest\n\n");
displayhealth(playerhealth);
printf("You awaken in a dark forest, your leg is badly wounded with what\nlooks like a fang stuck in it. You seem to be undergoing amnesia and dont know\nwhere you are, you check inside your pocket and find a credit card with the nameKevin Chen on it. Ahead there is a fork in the path.\n");
printf("\nChoose a path\n\nCave (C)\nHill (H)\nBridge (B)\n");
scanf("%c", &player);
while(player == 'C' || player == 'c' || player == 'B' || player == 'b' || player == 'H' || player == 'h')
{
if(player == 'C' || player == 'c') /* <-- I would like to later change this to a string "Cave", how would i do that? */
{
getchar();
system("cls");
printf("Location: Creepy Cave\n\nA dark and ominous walk, you arrive at the entrance of the Cave. There are\nthick stands of Silk hanging off the perimeter of the entrance and you get\nan eerie feel that hundreds of eyes are watching you.\n\n");
printf("Would you like to enter the Creepy Cave? Y/N\n");
scanf("%c", &player);
if(player == 'Y' || player == 'y')
{
spiderfight(spider, playerhealth, pinput, Punchdmg, Kickdmg, Bitedmg);
}
else if(player == 'N' || player == 'n')
{
getchar();
system("cls");
printf("Location: Dark Forest\n");
printf("You arrive back at the Dark forest after fleeing from the Dark Cave\nChoose a path\n\nCave (C)\nHill (H)\nBridge (B)\n");
scanf("%c", &player);
}
}
else if(player == 'H' || player == 'h')
{
getchar();
printf("Not yet written");
break;
}
if(player == 'B' || player == 'b')
{
getchar();
system("cls");
printf("Location: Bridge\nYou made it to the bridge in one piece, somewhere underneath the bridge, the\nsnoring of something big is being emitted, looking under the bridge you find\nyourself face to face with a sleeping troll. Shaken with fear, you try to cross the bridge as quickly as possible, you take a step...\n\nPress Enter\n");
getchar();
printf("*CREAK*\n\nDamnit, why did the boards have to be creaky.\nThe Troll was awaken!\nTROLL: Your going to have to pay a toll to get across MY bridge!\nTROLL: I think your head would suffice!\n");
printf("Run? Or FIGHT! R/F\n");
scanf("%c", &player);
if(player == 'R' || player == 'r')
{
printf("TROLL: HEY! Come back here!\n\nYou got away safely");
getchar();
system("cls");
printf("Location: Dark Forest\n");
printf("You arrive back at the Dark forest after fleeing from the Dark Cave\nChoose a path\n\nCave (C)\nHill (H)\nBridge (B)\n");
scanf("%c", &player);
}
else if(player == 'F' || player == 'f')
{
printf("Hello");
}
}
}
return 0;
}
void spiderfight(int spider2, int playerhealth2, char pinput2, int punchdmg2, int kickdmg2, int bitedmg2)
{
getchar();
system("cls");
while(playerhealth2 > 1 || spider2 > 1) /* Im trying to make it so that it will repeat until either you, or the spider dies. But ATM, it will keep repeating even if the spider is past 0 health, also it prints the Choose a move option twice every turn. And yes i do realize i haven't made a way for the player to die yet */
{
printf("Kevin's Health: %i -- Spider Health: %i\n\n", playerhealth2, spider2);
printf("Choose a Move\nA. Punch B. Kick\nC. Bite D. ----\n\n");
scanf("%c", &pinput2);
if(pinput2 == 'A' || pinput2 == 'a')
{
printf("Kevin used Punch!\n");
spider2 = spider2 - punchdmg2;
}
if(pinput2 == 'B' || pinput2 == 'b')
{
printf("Kevin used Kick!\n");
spider2 = spider2 - kickdmg2;
}
if(pinput2 == 'C' || pinput2 == 'c')
{
printf("Kevin used Bite! - Gross... Did you really just bite a spider?\n");
spider2 = spider2 - bitedmg2;
}
}
}
void displayhealth(int playerhealth3)
{
printf("\nHealth: [%i] Status: ", playerhealth3);
if(playerhealth3 <= 10)
{
printf("DANGEROUSLY LOW\n\n", playerhealth3);
}
if(playerhealth3 >= 11 && playerhealth3 < 30)
{
printf("LOW\n\n", playerhealth3);
}
if(playerhealth3 >= 30 && playerhealth3 < 50)
{
printf("MODERATE\n\n", playerhealth3);
}
if(playerhealth3 >= 50 && playerhealth3 <= 75)
{
printf("GOOD\n\n");
}
if(playerhealth3 > 75 && playerhealth3 <= 100)
{
printf("GREAT\n\n");
}
}
Attachment 13270