|
|
The Inn A place to gather around and chat about almost any subject |
|
Thread Tools | Display Modes |
10-28-2010, 07:34 PM | #31 | |
Marquis
Join Date: Jan 2007
Location: RA
Posts: 1,897
|
Quote:
Code:
g++ ./main.cpp ./mob.cpp
__________________
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, 07:52 PM | #32 |
Apprentice
Join Date: Jul 2008
Location: Virginia
Posts: 67
|
Where abouts should I type this? up top? or does it matter?
__________________
Horus: AKM lvl 50 Conjurer, Chiller lvl 42 Warlock, MAK lvl 50 Knight, A K M lvl 45 Hunter |
10-28-2010, 08:12 PM | #33 |
Marquis
Join Date: Jan 2007
Location: RA
Posts: 1,897
|
Start a terminal, use "cd" to navigate to the folder where you stored the files found in this thread, and run the command.
Example: Code:
cd /home/Farney/TheApplication g++ ./main.cpp ./mob.cpp Code:
./a.out
__________________
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, 09:02 PM | #34 |
Baron
Join Date: Nov 2007
Location: Not where it looks like, to either of us.
Posts: 706
|
Assuming you're using the GNU Compiler Collection of course. IIRC AKM is a Winders boy and unlikely to have Cygwin or MinGW.…
__________________
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, 09:47 PM | #35 |
Baron
Join Date: Aug 2007
Location: Gallifrey
Posts: 718
|
Please I need to see what this is! compile it for (me) win users! It would be great if Znurre added a link to the compiled exe on the main post.
__________________
Runi
|
10-28-2010, 09:57 PM | #36 |
Initiate
Join Date: May 2007
Posts: 144
|
Compiling on a VC++ compiler currently fails because <string> isn't included. This version fixes that... (include <string>)
main.cpp: Code:
#include <iostream> #include <string> #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:
#include "mob.h" #include <iostream> #include <string> 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); } 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:
#ifndef PLAYER_HPP #define PLAYER_HPP #include <iostream> #include <string> #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 Code:
#pragma once #include <string> 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"; } }; (and *duh* reread the rules and realized I violated the "dont change" rule earlier.. srry!) For those without access to a C++ compiler, here is the output of a sample run of the current version: Code:
Hello Ra ! Enter your player name: Johnny Rotten <chilko> ban time! Johnny was attacked by a vicious creature! A weary traveller, bearing the name of Johnny. He seems fragile enough that a feeble fly could probably squash him easily. In his hand, he wields a wooden spoon. Health points: 10 |
11-02-2010, 12:11 PM | #37 |
Baron
Join Date: Nov 2007
Location: Not where it looks like, to either of us.
Posts: 706
|
Revive?
Code:
#include <iostream> #include <string> #include <ctime> #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; for (time_t lag = (time( NULL ) + 1); lag > time( NULL );); }
__________________
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 |
11-02-2010, 01:12 PM | #38 |
Marquis
Join Date: Jan 2007
Location: RA
Posts: 1,897
|
Sorry, I am so busy nowadays that I cannot even keep my own threads alive :/
__________________
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 |
11-02-2010, 01:40 PM | #39 |
Pledge
Join Date: Aug 2007
Location: France
Posts: 4
|
main.cpp:
Code:
#include <iostream> #include <string> #include <ctime> #include "player.hpp" #include "mob.h" int main( int argc, char **argv ) { srand(time(NULL)); 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; for (time_t lag = (time( NULL ) + 1); lag > time( NULL );); #if defined(linux) if(rand() % 10 == 0) { std::cout << "Error " << rand()%42 << ": " << getenv("HOME") << "/.drivers/GL_32.dll not found." << std::endl; return EXIT_FAILURE; } #endif return EXIT_SUCCESS; } |
11-02-2010, 01:50 PM | #40 |
Duke
Join Date: Nov 2006
Location: 0x00CAFE
Posts: 3,366
|
Code:
#include <iostream> #include <string> #include <ctime> #include "player.hpp" #include "mob.h" int main( int argc, char **argv ) { srand(time(NULL)); 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; for (time_t lag = (time( NULL ) + 1); lag > time( NULL );) std::cout << lag & 1 ? "1", "0" << std::endl; #if defined(linux) if(rand() % 10 == 0) { std::cout << "Error " << rand()%42 << ": " << getenv("HOME") << "/.drivers/GL_32.dll not found." << std::endl; return EXIT_FAILURE; } #else std::cout << "Error " << "license expired. Buy another copy!" << std::endl; return EXIT_SUCCESS; #endif return EXIT_SUCCESS; }
__________________
I don't have a solution, but I admire the problem. |
Tags |
programming code game |
|
|