Go Back   Champions of Regnum > English > The Inn

The Inn A place to gather around and chat about almost any subject

Reply
 
Thread Tools Display Modes
Old 10-27-2010, 02:42 PM   #21
ArcticWolf
Duke
 
ArcticWolf's Avatar
 
Join Date: Nov 2006
Location: 0x00CAFE
Posts: 3,366
ArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of light
Default

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.
ArcticWolf no ha iniciado sesión   Reply With Quote
Old 10-27-2010, 03:20 PM   #22
Znurre
Marquis
 
Join Date: Jan 2007
Location: RA
Posts: 1,897
Znurre will become famous soon enoughZnurre will become famous soon enough
Default

Quote:
Originally Posted by ArcticWolf View Post
P.S.: This would be much better if we used GitHub. :P
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
Znurre no ha iniciado sesión   Reply With Quote
Old 10-28-2010, 05:48 AM   #23
Arafails
Baron
 
Arafails's Avatar
 
Join Date: Nov 2007
Location: Not where it looks like, to either of us.
Posts: 706
Arafails will become famous soon enough
Default

Quote:
Originally Posted by ArcticWolf View Post
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
NEIN! USE GITORIOUS.ORG!!!

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'gerSoul Taker, Imperial Guard of Ignis
Arafails no ha iniciado sesión   Reply With Quote
Old 10-28-2010, 07:30 AM   #24
kidanger
Pledge
 
Join Date: Aug 2007
Location: France
Posts: 4
kidanger is on a distinguished road
Default

Quote:
Originally Posted by Arafails View Post
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?

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 :/
kidanger no ha iniciado sesión   Reply With Quote
Old 10-28-2010, 08:38 AM   #25
Znurre
Marquis
 
Join Date: Jan 2007
Location: RA
Posts: 1,897
Znurre will become famous soon enoughZnurre will become famous soon enough
Default

Quote:
Originally Posted by Arafails View Post
NEIN! USE GITORIOUS.ORG!!!

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?
Meh, references are for whimps
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
Znurre no ha iniciado sesión   Reply With Quote
Old 10-28-2010, 10:10 AM   #26
Arafails
Baron
 
Arafails's Avatar
 
Join Date: Nov 2007
Location: Not where it looks like, to either of us.
Posts: 706
Arafails will become famous soon enough
Default

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'gerSoul Taker, Imperial Guard of Ignis
Arafails no ha iniciado sesión   Reply With Quote
Old 10-28-2010, 10:20 AM   #27
Valkasar
Count
 
Valkasar's Avatar
 
Join Date: Feb 2009
Location: San Martin de los Andes
Posts: 1,090
Valkasar is on a distinguished road
Default

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.
Valkasar no ha iniciado sesión   Reply With Quote
Old 10-28-2010, 05:25 PM   #28
Enitharmon
Initiate
 
Enitharmon's Avatar
 
Join Date: May 2007
Posts: 144
Enitharmon is on a distinguished road
Default

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
weapon.h:
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";
	}
};
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);
   player.describe(std::cout);
}
mob.cpp and mob.h are unchanged from kidanger's last commit.
Enitharmon no ha iniciado sesión   Reply With Quote
Old 10-28-2010, 06:20 PM   #29
A_K_M
Apprentice
 
Join Date: Jul 2008
Location: Virginia
Posts: 67
A_K_M is on a distinguished road
Default

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
A_K_M no ha iniciado sesión   Reply With Quote
Old 10-28-2010, 07:13 PM   #30
Arafails
Baron
 
Arafails's Avatar
 
Join Date: Nov 2007
Location: Not where it looks like, to either of us.
Posts: 706
Arafails will become famous soon enough
Default

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;
}
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;
      }

      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
All other files remain unchanged!
__________________
If you can't detect sarcasm yourself, please pay attention when it's pointed out to you.
Arathael :: Wyrd Sceote :: Gwn M'gerSoul Taker, Imperial Guard of Ignis
Arafails no ha iniciado sesión   Reply With Quote
Reply

Tags
programming code game


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:21 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
NGD Studios 2002-2024 © All rights reserved