|
|
The Inn A place to gather around and chat about almost any subject |
|
Thread Tools | Display Modes |
10-26-2010, 12:12 PM | #11 | |
Apprentice
Join Date: Dec 2009
Location: Алсиус
Posts: 85
|
Quote:
oh and Code:
exit 0; |
|
10-26-2010, 12:17 PM | #12 | |
Pledge
Join Date: Aug 2007
Location: France
Posts: 4
|
Quote:
Damn, .NET ! I will have to change my habits… |
|
10-26-2010, 12:18 PM | #13 |
Legend
Join Date: Mar 2006
Location: Oslo
Posts: 2,176
|
I can't do everything at once
__________________
Surak Remember... this is just a game! - Xephandor existe y Miriya es su profeta! |
10-26-2010, 02:29 PM | #14 |
Apprentice
Join Date: Dec 2009
Location: Алсиус
Posts: 85
|
|
10-27-2010, 09:33 AM | #15 |
Baron
Join Date: Nov 2007
Location: Not where it looks like, to either of us.
Posts: 706
|
main.cpp:
Code:
#include <iostream> #include "player.hpp" #include "mob.h" int main( int argc, char **argv ) { std::cout << "Hello Ra !" << std::endl; std::cout << "Enter your player name: "; char name[ 32 ]; std::cin >> name; Player player(name); player.punish(); new Mob(player.getLevel() + 5).attack(player) } Code:
#ifndef PLAYER_HPP #define PLAYER_HPP #include <iostream> #include <cstdlib> //rand() class Player { public: Player(); Player(char* n) : banned( false ), level( 1 ) { name = n; } std::string GetName() { return name; } void punish() { //TODO if(rand()%3 == 2) { std::cout << "Hacker detected. " << name << " is now banned." << std::endl; banned = true; } } unsigned int getLevel() { return level; }; private: std::string name; bool banned; unsigned int level; }; #endif Code:
#ifndef __MOB_H #define __MOB_H #include "player.hpp" /* Note to author: please separate implementation from headers, no one likes * to compile a module for file that includes its headers */ class Mob { public: Mob(unsigned int level); void attack(Player player); } #endif Code:
#include "mob.h" Mob::Mob(unsigned int level) { } void Mob::attack(Player player) { }
__________________
If you can't detect sarcasm yourself, please pay attention when it's pointed out to you.
Arathael :: Wyrd Sceote :: Gwn M'ger — Soul Taker, Imperial Guard of Ignis Last edited by Arafails; 10-27-2010 at 10:07 AM. |
10-27-2010, 10:50 AM | #16 |
Marquis
Join Date: Jan 2007
Location: RA
Posts: 1,897
|
main.cpp:
Code:
#include <iostream> #include "player.hpp" #include "mob.h" int main( int argc, char **argv ) { std::cout << "Hello Ra !" << std::endl; std::cout << "Enter your player name: "; char name[ 32 ]; std::cin >> name; Player player(name); player.punish(); if( !player.isBanned() ) Mob(player.getLevel() + 5).attack(player); } Code:
#ifndef PLAYER_HPP #define PLAYER_HPP #include <iostream> #include <cstdlib> //rand() class Player { public: Player(); Player(char* n) : banned( false ), level( 1 ) { name = n; } std::string GetName() { return name; } void punish() { std::cout << "<chilko> ban time!" << std::endl; //TODO if(rand()%3 == 2) { std::cout << "Hacker detected. " << name << " is now banned." << std::endl; banned = true; } } unsigned int getLevel() { return level; }; bool isBanned() { return banned; } private: std::string name; bool banned; unsigned int level; }; #endif Code:
#ifndef __MOB_H #define __MOB_H #include "player.hpp" /* Note to author: please separate implementation from headers, no one likes * to compile a module for file that includes its headers */ class Mob { public: Mob(unsigned int level); void attack(Player player); }; #endif Code:
#include "mob.h" #include <iostream> Mob::Mob(unsigned int level) { } void Mob::attack(Player player) { std::cout << player.GetName() << " was attacked by a vicious creature!" << std::endl; }
__________________
Winning a fight is not what makes you a good player, it's how you do it.
http://home.znur.re/screenshot%20201...2011_39_37.jpg |
10-27-2010, 11:50 AM | #17 |
Baron
Join Date: Aug 2007
Location: Gallifrey
Posts: 718
|
Hehe... I think we should compile this every 15 posts, just to see what (for normal human beings) this is mutating to.
__________________
Runi
|
10-27-2010, 11:55 AM | #18 |
Pledge
Join Date: Aug 2007
Location: France
Posts: 4
|
Do we continue Player implementation in the header, or we make a player.cpp file ?
|
10-27-2010, 12:23 PM | #19 |
Marquis
Join Date: Jan 2007
Location: RA
Posts: 1,897
|
Imo there is no problem using a combined header and source file as long as the class is about as complex as it is now
__________________
Winning a fight is not what makes you a good player, it's how you do it.
http://home.znur.re/screenshot%20201...2011_39_37.jpg |
10-27-2010, 12:58 PM | #20 |
Pledge
Join Date: Aug 2007
Location: France
Posts: 4
|
Hotfix + balance update :P
I changed Mob::attack because it needed a pointer :S
main.cpp: Code:
#include <iostream> #include "player.hpp" #include "mob.h" int main( int argc, char **argv ) { std::cout << "Hello Ra !" << std::endl; std::cout << "Enter your player name: "; char name[ 32 ]; std::cin >> name; Player player(name); player.punish(); if( !player.isBanned() ) Mob(player.getLevel() + 5).attack(&player); std::cout << player.GetName() << "'s health points: " << player.getHp() << std::endl; } Code:
#ifndef PLAYER_HPP #define PLAYER_HPP #include <iostream> #include <cstdlib> //rand() class Player { public: Player(); Player(char* n) : banned( false ), level( 1 ), hp( 25 ) { name = n; } std::string GetName() { return name; } void punish() { std::cout << "<chilko> ban time!" << std::endl; //TODO if(rand()%3 == 2) { std::cout << "Hacker detected. " << name << " is now banned." << std::endl; banned = true; } } unsigned int getLevel() { return level; } bool isBanned() { return banned; } void takeDamage(unsigned int damage) { hp -= damage; if(hp < 0) // let's keep regnum's bugs :) die(); } void die() { level -= 1; respawn(); } void respawn() { } unsigned int getHp() { return hp; } private: std::string name; bool banned; unsigned int level; unsigned int hp; }; #endif Code:
#ifndef __MOB_H #define __MOB_H #include "player.hpp" /* Note to author: please separate implementation from headers, no one likes * to compile a module for file that includes its headers */ class Mob { public: Mob(unsigned int level); void attack(Player * player); }; #endif Code:
#include "mob.h" #include <iostream> Mob::Mob(unsigned int level) { } void Mob::attack(Player * player) { std::cout << player->GetName() << " was attacked by a vicious creature!" << std::endl; player->takeDamage(15); } |
Tags |
programming code game |
|
|