|
|
The Inn A place to gather around and chat about almost any subject |
|
Thread Tools | Display Modes |
10-27-2010, 02:42 PM | #21 |
Duke
Join Date: Nov 2006
Location: 0x00CAFE
Posts: 3,366
|
Ohhh my! I love this thread!
Unfortunately, I'm a bit busy right now, so I'll post something useful later. P.S.: This would be much better if we used GitHub. :P
__________________
I don't have a solution, but I admire the problem. |
10-27-2010, 03:20 PM | #22 |
Marquis
Join Date: Jan 2007
Location: RA
Posts: 1,897
|
Of course, but that would be too easy :P
__________________
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-28-2010, 05:48 AM | #23 | |
Baron
Join Date: Nov 2007
Location: Not where it looks like, to either of us.
Posts: 706
|
Quote:
Geez, who wants version control anyway.… On a more serious note, kidanger you surprise me. Most C++ programmers would prefer references over pointers, because they like to pretend they don't care where it's actually the same object or not. Maybe you're really a C programmer?
__________________
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 |
|
10-28-2010, 07:30 AM | #24 | |
Pledge
Join Date: Aug 2007
Location: France
Posts: 4
|
Quote:
I'm not a "real" programmer. I've used Python for about 2 years, and I've just started to learn C++. I still have a lot to learn… Did it be a good or a bad surprise ? I didn't know references exists, did I have to use it ? EDIT: I used pointer because when I tested, the player didn't lose health, player was just copied :/ |
|
10-28-2010, 08:38 AM | #25 | |
Marquis
Join Date: Jan 2007
Location: RA
Posts: 1,897
|
Quote:
Personally I always use pointers except for storage classes like QList and QString, it gives another level of flexibility.
__________________
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-28-2010, 10:10 AM | #26 |
Baron
Join Date: Nov 2007
Location: Not where it looks like, to either of us.
Posts: 706
|
It really depends on where you enter C++ from. C and assembly programmers will tend towards pointers because we're used to them (and oftern understand how the memory is sorted at least logically if not physically). Java programmers are used to everything being passed by reference already. Python.… What little Python I've done suggests something similar to Java, but I'll admit I'm not very experienced with it.
It was a surprising surprise. Znurre, I'm not sure I agree with you. I dislike references because they're a bit too deferential, and it's not immediately obvious whether someone has used them wrong or not (unlike pointers, which lightly tap you across the face for forgetting a * or &, or actually punch you if you didn't do it on a pointer to a pointer).
__________________
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 |
10-28-2010, 10:20 AM | #27 |
Count
Join Date: Feb 2009
Location: San Martin de los Andes
Posts: 1,090
|
you programmers are strange... i like it! keep goin keep goin!
(they made a game ten times as complex than RO)
__________________
Poptart, caza 53. Omlette, conju 50. Strawberry, barbaro en ascenso, Haven, Alsius. Van SacKK. |
10-28-2010, 05:25 PM | #28 |
Initiate
Join Date: May 2007
Posts: 144
|
My apologies if this commit is too large!
player.hpp: Code:
#ifndef PLAYER_HPP #define PLAYER_HPP #include <iostream> #include <cstdlib> //rand() #include "weapon.h" class Player { public: Player(); Player(char* n) : name(n), banned( false ), level( 1 ), hp( 25 ), weapon( new WoodenSpoon() ) {} 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; } void describe(std::ostream &out) { out << "A weary traveller, bearing the name of " << GetName() << "." << std::endl; if (level <= 1) { out << " He seems fragile enough that a feeble fly could " << "probably squash him easily." << std::endl; } if (weapon) { out << " In his hand, he wields " << weapon->GetDisplayName() << "." << std::endl; } out << " Health points: " << getHp() << std::endl; } private: std::string name; bool banned; unsigned int level; unsigned int hp; Weapon *weapon; }; #endif Code:
#pragma once class Weapon { // Something that can be utilized for slaying something else! public: virtual ~Weapon() {} // Damage yielded by this weapon when wielded by the provided object virtual unsigned int GetDamage(void *) const = 0; virtual std::string GetName() const = 0; virtual std::string GetDisplayName() const { return "a " + GetName(); } }; class EgoWeapon : public Weapon { // A type of weapon there only exists one instance of. public: virtual std::string GetDisplayName() const { return "The " + GetName(); } }; class WoodenSpoon : public Weapon { public: virtual unsigned int GetDamage(void *) const { return 1; } virtual std::string GetName() const { return "wooden spoon"; } }; class StaffOfGonorrhea : public EgoWeapon { public: virtual unsigned int GetDamage(void *) const { return 999; } virtual std::string GetName() const { return "Great Staff of Gonorrhea"; } }; 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); player.describe(std::cout); } |
10-28-2010, 06:20 PM | #29 |
Apprentice
Join Date: Jul 2008
Location: Virginia
Posts: 67
|
I dont know guys... When I go to compile it, it has a bunch of errors. I belive I am missing files...I have: weapon.h, player.h, mob.h, mob.cpp, main.cpp. Is there a weapon.cpp? Im still new at this so dont flame me too hard
__________________
Horus: AKM lvl 50 Conjurer, Chiller lvl 42 Warlock, MAK lvl 50 Knight, A K M lvl 45 Hunter |
10-28-2010, 07:13 PM | #30 |
Baron
Join Date: Nov 2007
Location: Not where it looks like, to either of us.
Posts: 706
|
Works for me.… How are you compiling?
Anyway. Hacky operator goodness! 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; } Code:
#ifndef PLAYER_HPP #define PLAYER_HPP #include <iostream> #include <cstdlib> //rand() #include "weapon.h" class Player { public: Player(); Player(char* n) : name(n), banned( false ), level( 1 ), hp( 25 ), weapon( new WoodenSpoon() ) {} 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; } void describe(std::ostream &out) { out << "A weary traveller, bearing the name of " << GetName() << "." << std::endl; if (level <= 1) { out << " He seems fragile enough that a feeble fly could " << "probably squash him easily." << std::endl; } if (weapon) { out << " In his hand, he wields " << weapon->GetDisplayName() << "." << std::endl; } out << " Health points: " << getHp() << std::endl; } friend std::ostream& operator << (std::ostream& out, Player& player) { player.describe(out); return out; } private: std::string name; bool banned; unsigned int level; unsigned int hp; Weapon *weapon; }; #endif
__________________
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 |
Tags |
programming code game |
|
|