Finish it if you want, or not. This was for praciticing with classes and function. I'm moving on now.
Code:#include "stdafx.h" #include <iostream> #include <string> #include <stdlib.h> using namespace std; #define stop system("PAUSE") #define clear system("cls") //Player information against skeleton class player { private: int playerhp, playerexp, playerlvl; public: int Losehp () { playerhp=10; playerhp-=2; return playerhp; } int Gainhp () { playerhp++; return playerhp; } int Gainexp () { playerexp=+2; return playerexp; } int Gainlvl () { if(playerexp <= 3) { playerlvl=+1; return playerlvl; } } int Playeratacckingskele() { int Choice2, Choice3; cin >> Choice2, Choice3; int attack = 1; int run = 2; if(Choice2 == run) { cout << "Merlin: You may not run from this battle!" << endl; cout << "Merlin: Choose again!" << endl; return Playeratacckingskele(); } if(Choice2 == attack) { clear; cout << "*You battle the skeleton and are victorious!*\n\n"; cout << "Merlin: I will now relay your stats, and I will do this after every battle.\n"; cout << "Your hp is" <<" " << Losehp () << " " << "your exp is" <<" " << Gainexp () << " " << "your level is" <<" " << Gainlvl () << endl << endl; return 0; } } }; // hehe function to choose weapon. int choose() { string Choice; cin >> Choice; cout << endl << endl; string Bow, bow, Staff, staff, Sword, sword; Bow = "Bow", bow = "bow", Staff = "Staff", staff = "staff", Sword = "Sword", sword = "sword"; // or "||" doesn't seem to work o.o? if (Choice == Bow) { clear; cout << "Merlin: A bow man EH? Well here is your weapon master Archer \n."; cout << "*Merlin hands you your weapon.*\n\n"; return 0; } if (Choice == bow) { clear; cout << "Merlin: A bowman Eh? Well here is your weapon master Archer.\n"; cout << "*Merlin hands you your weapon.*\n\n"; return 0; } if (Choice == Staff) { clear; cout << "Merlin: Oh-ho? A fellow magician? I will help you in your quest to master\nthe dark arts!\n"; cout << "*Merlin hands you your weapon.*\n\n"; return 0; } if (Choice == staff) { clear; cout << "Merlin: Oh-ho? A fellow magician? I will help you in your quest to master the\ndark arts!\n"; cout << "*Merlin hands you your weapon.*\n\n"; return 0; } if (Choice == Sword) { clear; cout << "Merlin: There is no opponet to the mighty blade!\n"; cout << "*Merlin hands you your weapon.*\n\n"; return 0; } if (Choice == sword) { clear; cout << "Merlin: There is no opponet to the mighty blade!\n"; cout << "*Merlin hands you your weapon.* \n\n"; return 0; } } int main () { cout << "Hello adventurer and welcome to the world of Cytonia! Before we begin type in\n" << "the username you wish to have below.\n\n"; //variables for the username string Playername; cin >> Playername; cout << endl << endl; cout << "So your name is" << " " << Playername << "?" << " " << "Great name! My name is Merlin and I'm here to help you\n" << "throughout your journey. Before we begin, you must select your weapon!\n\n"; cout <<"Choose from: \n" << "Bow" << endl << "Staff" << endl << "Sword\n\n"; choose(); // don't have to recall cout to make a new line O:!!! cout << "Merlin: Now that you are properly geared, I will teach you about combat in\nCytonia. When faced against one of the many enimes in Cytonia, you will have a\nchoice to either Attack or Run. Attacking will make you lose HP but give you exp. For every 3 exp you get you gain one level, once your HP gets to 0 the game is over. You begin with 10hp and each level you gain, I heal you to full hp.\n\n"; cout << "Merlin: Lets practice this concept, I will summon a skeleton from the gates of\nhell to battle with you.\n\n"; cout << "*Merlin gently taps his staff against the ground and a skeleton runs toward you* what will you do? *SELECT A NUMBER ONLY!*\n\n"; cout << "1.)Attack" << endl << "2.)Run" << endl << endl; player a; a.Playeratacckingskele(); cout << "Ah, I see you are very skilled in combat."; stop; return 0; }
Results 1 to 10 of 10
- 01 May. 2010 04:18pm #1
c++ sloppy little console game (not done)
- 01 May. 2010 05:40pm #2
Wouldn't LoseHP() always return 8? Since you're assigning the value of 10 to playerhp every time you call the function.
- 01 May. 2010 05:49pm #3
Yerp, but the program is only fighting one enemy and that's the skeleton. In the project assign that's all it asked for, so I went half ass on it. Brand new at function and classes.
- 01 May. 2010 05:52pm #4
- 01 May. 2010 05:56pm #5
- 01 May. 2010 11:59pm #6
Its a great thing.
Chad showed me that.
I remember when I made my Pirate bot, I had loads of if's and stuff.
After a while I fixed it up with a switch/case.
Cut the loading time down a bit.Shh, I'm watching My little pony.
- 02 May. 2010 12:41am #7
Having trouble trying to use a lot of chars with switch. Can someone give me an example?
- 02 May. 2010 06:23am #8
- 02 May. 2010 04:15pm #9
The book I'm reading decides to wait until I wrote all of that before telling me about the constructor. Wow.
- 25 Jun. 2010 03:48pm #10
In C++ it would be:
Code:switch (Variable_to_test) { case 'choice_1': { cout<<"Hi"; break; } case 'choice_2': { cout<<"bye"; break; } case 'choice_3': { cout<<"Hi again"; break; }