Hey all, I'm using Visual C++. This code is updated, no errors but it always reads choice 1 except on traveln.
Code:
#include <iostream>
// Functions
int stats();
int traveltown();
int traveln();
int ynbeer();
int shop();
int outside();
// Global Variables (This is bad code - work to fix it on your own)
bool alive = true;
char location[4] = "T";
int bosses, kills, maxlife, life, damage, gold; // Everything is initilized to NULL initally. This basically equals 0. No need to redeclare in main().
// Code
int main()
{
life = 100;
maxlife = 100;
damage = 3;
gold = 1000;
std::cout << "Welcome to ShortSword!" << std::endl;
while (alive == true)
{
traveltown();
}
return(0);
}
int stats()
{
std::cout << "\n" << std::endl;
if (strcmp(location, "T") == 0)
{
std::cout << "You are in The Town" << std::endl;
}
else if (strcmp(location, "B") == 0)
{
std::cout << "You are in The Bar." << std::endl;
}
else if (strcmp(location, "S") == 0)
{
std::cout << "You are in The Store." << std::endl;
}
std::cout << "Your have killed " << bosses <<" bosses" << std::endl;
std::cout << "You have " << kills << " kills" << std::endl;
std::cout << "You have " << life << "/"<< maxlife << " life" << std::endl;
std::cout << "You do " << damage << " damage" << std::endl;
std::cout << "You have " << gold << " gold" << std::endl;
std::cout << "Stats appear every time you kill a monster or boss, go into town, go inside a store, or buy something" << std::endl;
std::cout << "\n" << std::endl;
if (strcmp(location, "T") == 0)
{
traveltown();
}
else if (strcmp(location, "B") == 0)
{
ynbeer();
}
else if (strcmp(location, "S") == 0)
{
shop();
}
return(0);
}
int traveltown()
{
std::cout << "Where do you want to travel too?" << std::endl;
std::cout << "The Bar - 1" << std::endl;
std::cout << "The Shop - 2" << std::endl;
std::cout << "Outside - 3" << std::endl;
std::cout << "\n" << std::endl;
traveln();
return(0);
}
int traveln()
{
int choice;
std::cin >> choice;
if (choice == 1)
{
ynbeer();
(strcmp(location, "B") == 0);
}
else if (choice == 2)
{
shop();
(strcmp(location, "S") == 0);
}
else if (choice == 3)
{
outside();
}
else
{
std::cout << "Invalid input. Please put in a correct character" << std::endl;
traveln();
}
stats();
return(0);
}
int ynbeer()
{
int choice;
std::cout << "Bartender: Watcha want, kid? We got some mighty fine beer on sale. It'll fix ya right on up! It's only 100 gold! You want some?" << std::endl;
std::cout << "Yes - 1" << std::endl;
std::cout << "No, I just want to look around - 2" << std::endl;
std::cout << "No, I'm leaving! - 3" <<std::endl;
std::cin >> choice;
if (choice = 1)
{
std::cout << "Aye, lad! Good choice! Here ya go!" << std::endl;
life = maxlife;
gold = gold-250;
stats();
}
else if (choice = 2)
{
std::cout << "Fine then! See that I care!" << std::endl;
stats();
}
else if (choice = 3)
{
std::cout << "See ya later!" << std::endl;
traveltown();
}
else
{
std::cout << "Ummm, please choose somethin' matey!" << std::endl;
ynbeer();
}
return(0);
}
int shop()
{
int chooseshop;
std::cout << "Clerk: What can I get for you today?" << std::endl;
std::cout << "Healing Potion Cost: 100 gold. Heals you 75 life. - 1" << std::endl;
std::cout << "Armor Cost: 500 gold. Less chance of being hurt. - 2" << std::endl;
std::cout << "I don't want anything. - 3" << std::endl;
std::cin>>chooseshop;
if (chooseshop = 1)
{
std::cout << "One healing potion coming right up!" << std::endl;
life = life+75;
shop();
}
else if (chooseshop = 2)
{
std::cout << "Armor, eh? Here ya go! Now you have a 25% less chance of being hit!" <<std::endl;
// not finished yet
shop();
}
else
{
std::cout << "Come back any time!" <<std::endl;
shop();
}
return(0);
}
int outside()
{
std::cout << "Under Construction" << std::endl;
return(0);
}