need help
Posted: Sun Aug 28, 2011 2:00 am
ok so my problem is when a user enters a number from choices well it works fine the problem is if they enter a character it gets stuck in a continues loop of what was last outputed on the screen
so lets say you enter w at the first cin/scanf it goes you are in a dark room what do you do press 1. to look around FOREVER
Code: Select all
// Text Adventure.cpp : main project file.
#include "stdafx.h"
#include <cstdlib>
#include <cstdio>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits>
using namespace System;
using namespace std;
int main(array<System::String ^> ^args)
{
int choice = 0;
int monster_crit;
int attack = 1;
int level = 1;
int abp = 1;
int real_damage;
int just_leveled = 1;
int strength = 1;
int exp = 0;
int store1_potions = 10;
int store1_Fire_Swords = 1;
int store1_strength_ups = 1;
int in_shop = 0;
int sword = 0;
int looked = 0;
int health = 100;
int damage = 10;
int world = 1;
int gold = 15;
int torch_lit = 0;
int world_1_swords = 1;
int trout_of_Auzur_hp = 2000;
int trout_of_Auzur = 1;
int potions = 3;
int Dead_Trout_of_Auzur_hp = 999999;
int Dead_Trout_of_Auzur = 1;
int just_killed = 1;
for(;;)
{
void leveling(int choice, int attack, int level, int abp, int just_leveled, int strength, int exp);
if(world == 1)
{
printf("you are in a dark room what do you do \n 1.Look around \n");
if(looked == 1)
{
if(torch_lit == 0)
{
printf(" 2.Light the torch \n");
}
if(world_1_swords == 1)
{
printf(" 3.Pickup the sword \n");
}
}
if(torch_lit == 1)
{
printf(" 4.Leave the room \n");
}
cin >> choice;
if (choice == 1)
{
}
if(choice == 1)
{
if(sword == 0)
{
printf("You see a sword\n");
}
if(sword == 1)
{
}
if(torch_lit == 0)
{
printf("You see a torch\n\n");
}
if(torch_lit == 1)
{
printf("You see a lit torch\n\n");
}
looked = 1;
}
else if(choice == 2)
{
printf("You light the torch you now see a door would you like to enter it 1.Yes 2.No \n");
torch_lit = 1;
scanf("%d", &choice);
if(choice == 1)
{
world = 2;
}
else if(choice == 2)
{
printf("You stay in the room \n\n");
world = 1;
}
else
{
printf("invalid command\n");
}
}
else if(choice == 3)
{
if(world_1_swords == 1)
{
printf("You have obtained a sword\n\n");
sword = 1;
damage = 100;
world_1_swords = 0;
}
}
else if(choice == 4)
{
if(torch_lit == 1)
{
world = 2;
}
}
}
if(world == 2)
{
if(trout_of_Auzur == 1)
{
printf("Old Man: Werdo your there I have a favor to ask will you go to the lake and kill the Trout of Auzur please\n1.Yes\n2.No\n");
scanf("%d", &choice);
if(choice == 1)
{
while(trout_of_Auzur == 1)
{
if(trout_of_Auzur_hp <=0)
{
trout_of_Auzur = 0;
exp += 100;
}
if(trout_of_Auzur == 1)
{
printf("1.Attack\n2.use potion\n");
scanf("%d", &choice);
if(choice == 1)
{
srand ( time(NULL) );
real_damage = rand() % (damage *2) + damage + (strength*2) + (strength*2);
monster_crit = rand() % 2 + 1;
if(monster_crit == 1)
{
health -= rand() % (10 + 8) *2;
}
else if(monster_crit == 2)
{
health -= rand() % 10 + 8;
}
else
{
}
trout_of_Auzur_hp -= real_damage;
}
if(choice == 2)
{
if(potions >= 1)
{
health += 75;
monster_crit = rand() % 2 + 1;
if(monster_crit == 1)
{
health -= rand() % (10 + 8) *2;
}
else if(monster_crit == 2)
{
health -= rand() % 10 + 8;
}
else
{
}
potions --;
}
if(potions <= 0)
{
}
}
else
{
}
cout << "Trout of Auzur hp: " <<trout_of_Auzur_hp << endl;
cout << "Your hp: " << health << endl;
if(health <= 0)
{
return 0;
}
}
}
}
else if(choice == 2)
{
}
}
if(trout_of_Auzur == 0 && Dead_Trout_of_Auzur == 1)
{
if(just_killed == 1)
{
potions += 10;
printf("Old Man: GREAT JOB WERDO!\n");
printf("Trout of Azuar: HISSSSS!\n");
printf("You have been ATTACKED!\n");
just_killed ++;
}
if(Dead_Trout_of_Auzur == 1)
{
if(Dead_Trout_of_Auzur_hp >= 1)
{
if(health >= 1)
{
cout << "Dead Trout of Auzur health: " << Dead_Trout_of_Auzur_hp << endl << "Your Health: " << health << endl;
printf("Press 1. to attack\nPress 2. to use a potion\n");
scanf("%d", &choice);
if(choice == 1)
{
Dead_Trout_of_Auzur_hp -= 0;
health -= 500;
}
if(choice == 2)
{
printf("The Trout stops you from using the potion\n");
Dead_Trout_of_Auzur_hp -= 0;
health -= 500;
}
}
if(health <= 0)
{
printf("Dead Trout of Auzur: you fool you should have never come here now you die\n");
printf("The old man jumps in front of the trouts magic and saves your life\n at the cost of his own ");
printf("After the Dead Trout of Auzur casts his last magic\nhe explodes and dies ");
printf("Right before the old man dies he casts a heal spell on you\n\n");
health += 461;
Dead_Trout_of_Auzur_hp -= 9999999;
}
}
if(Dead_Trout_of_Auzur_hp <= 0)
{
Dead_Trout_of_Auzur --;
world = 3;
}
}
while(world == 3)
{
if(in_shop == 0)
{
printf("You have managed to find your way to the town square what would you like to do\n 1. shop\n 2. leave\n");
scanf("%d", &choice);
if(choice == 1)
{
in_shop = 1;
while(in_shop == 1)
{
printf("press 4 to exit the store\n");
cout << "You have " << gold << " gold" << endl;
if(store1_potions >= 1)
{
cout << "I have " << store1_potions << " potions press 1 to buy a Potion for 15 gold\n";
}
if(store1_potions <= 0)
{
printf("I am very sorry to inform you that i have no more Potions\n");
}
if(store1_Fire_Swords >= 1)
{
cout << "I have " << store1_Fire_Swords << " Fire Swords press 2 to buy 1 for 500 gold\n";
}
if(store1_Fire_Swords <= 0)
{
printf("I am very sorry to inform you that i have no more Fire Swords\n");
}
if(store1_strength_ups >= 1)
{
cout << "I have " << store1_strength_ups << " Strength ups in stock press 3 to buy 1 for 1000 gold\n";
}
if(store1_strength_ups <= 0)
{
printf("I am very sorry to inform you that i have no more Strength ups\n");
}
scanf("%d", &choice);
if(choice == 4)
{
in_shop = 0;
world = 3;
}
else if(choice == 1)
{
if(gold >= 15)
{
store1_potions --;
potions ++;
gold -= 15;
}
else if(gold <= 14)
{
printf("Not enough gold\n");
potions += 0;
gold -= 0;
}
else
{
printf("HOW");
}
}
else
{
printf("Invalid command\n");
}
}
}
else if(choice == 2)
{
world = 4;
}
else
{
printf("Invalid Command");
}
}
}
if(world == 4)
{
printf("how?");
}
}
}
}
return 0;
}