NOGDUS $1670.00 has been donated to NOGDUS!
June 23, 2017, 08:44:20 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: idea in mind  (Read 3753 times)
0 Members and 1 Guest are viewing this topic.
xhunter
Guest
« on: August 14, 2009, 07:27:08 PM »

Hi to all;
So,after 3 days of  reading the cplusplus documentation I've just had an idea in mind , and I started coding something...actually it does nothing for now . So I don't know why am posting this anyway  Huh

Code:
#include<iostream>
#include<string>
#include<sstream>

using namespace std;

#define N "\n";
#define X_HEALTH 100;

using namespace std;

class Knight
{
Knight(); // you had a lowercase k, and needed an uppercase k
Knight(int race, string weapon, int mana, int health);

~Knight;

public:

struct bag
{
int items;
string weapon;
string potions;
string armors;
};

int take_damage(int nb_damage);

//int attack(int damage_value, int *target);
// I assume you wanted to attack another Knight
int attack(int damage_value, Knight& target);

void potions(string potion_name, int value_potion);
void change_weapon(string weapon_name, int damage_value);
int check_health(int health);

private:
int race;
string weapon;
int mana;
int health;
int armor;
string potions;
string armors; // you missed a semi colon, I added it for you
}; // you missed a semi colon, I added it for you


// the attack function
int Knight::take_damage(int nb_damage) // you forgot an int
{
health -= nb_damage;

/*
switch(health)
{
case health<0:
health==0;
case health > X_HEALTH;
health==x_HEALTH;
}
*/

// your code above does not function whatsoever.
// the logic is
// if the health is less than zero, then make it zero

health = (health < 0) ? 0 : health;

// you need to return something. I chose to return health
return health;
}

//Knight::attack(int &target)
int Knight::attack(int damage_value, Knight& target);
{
//&target.take_damage(int nb_damage);
// the code above doesn't work

target.take_damage(int damage_value);
}

void Knight::potions(int value_potion) // you missed a void
{
health += value_potion;

if (health > X_HEALTH)
{
// health == X_HEALTH;
// the above code is a comparison. not an assignment!
health = X_HEALTH;
}
}

/*
getchar();
return 0;
}
*/
// I don't know at all why you have that there...its going to cause an error duh


P.S: If a member of this forum want to edit this or correct me, yo are more than welcom and thanks in advanced  Grin

Good night

(edited by Richard Marks)
Logged
Richard Marks
Administrator
Offline Offline

Respect: 3425
« Reply #1 on: August 14, 2009, 10:35:06 PM »

Looks like you are preparing for a battle type demo.

Good luck!

Learn your syntax more!
Logged

xhunter
Guest
« Reply #2 on: August 15, 2009, 06:37:41 AM »

wow ! your modification was awesome, so as your correction, thanks Richard, you're the best;

Talking about the getchar() , I used it instead of the system("PAUSE") ( I was using devc++ ) otherwise, the application will just terminate



Regards,greyfox
Logged
Richard Marks
Administrator
Offline Offline

Respect: 3425
« Reply #3 on: August 15, 2009, 06:58:44 AM »

You are welcome.

Use this instead of getchar() or system("pause"). It will work on any C++ compiler.

Place this in a header or at the top of your file (before the rest of your code, but after includes)
Code:
void better_pause()
{
    fflush(stdin);
    std::string betterpause;
    std::cout << "Press Enter to Continue...";
    std::getline(std::cin, betterpause);
}

and then when you need to pause, you just call it:
Code:
better_pause();

Much better than using non-portable functions. Wink
Remember, write cross-platform code and you will be writing better code! Cool
Logged

xhunter
Guest
« Reply #4 on: August 15, 2009, 08:40:21 AM »

bright Idea !  Wink

I should have thought about this ^^

Am learning a lot of things from you, thanks Richards
Logged
xhunter
Guest
« Reply #5 on: August 15, 2009, 08:43:24 AM »

by the way, what's the role of the fflush() function, is it important ?
Logged
Richard Marks
Administrator
Offline Offline

Respect: 3425
« Reply #6 on: August 15, 2009, 09:27:24 AM »

Read the fflush() documentation.
Logged

Tags: c++ 
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
.: Theme by Richard Marks :.
Valid XHTML 1.0! Valid CSS!