Help with C++

Grab your favourite IDE and tinker with the innards of game engines

Postby zombie@computer on Wed Apr 04, 2007 1:00 pm

easiest would be to get each type of soldier a class, eg

Code: Select all
#include <cstdlib>
#include <iostream>

using namespace std;

class CSoldiers {
   public:
     int m_iCount;
     char * m_szType;

     //constructor
     CSoldiers(int iCount, const char* szType) {
        m_iCount=iCount;
        m_szType=new char[strlen(szType)+1];
        strcpy(m_szType, szType);
     }
     //deconstructor
     ~CSoldiers() {
        delete [] m_szType;
     }
   
     //killer
     void kill(int iDice) {
        int lost = rand() % iDice;
        if (lost > m_iCount) lost=m_iCount;
        m_iCount -= lost;
        cout << "lost " << lost << " " << m_szType;
     }

     //status
     void status( void ) {
        cout << m_iCount << " " << m_szType;
     }
};
int main(int argc, char* argv[]) {
    CSoldiers * army[5]; //our army has 5 types of soldiers:
    army[0]= new CSoldiers(500, "Irish...");
    army[1]= new CSoldiers(1000, "footman");
    army[2]= new CSoldiers(100, "welch bowmen");
    army[3]= new CSoldiers(1000, "french conscripts");
    army[4]= new CSoldiers(1, "Mel Gibson");
   
    int dices[] = { 100, 1000, 50, 10000, 2};
   
    srand ( time(NULL) );

    cout << "\nYou are the leader of the scots rebelling against england.";
    cout << "\nYour army constists of\n";
    for (int x=0;x<5;x++) {
        army[x]->status();
        cout << "\n";
    }
    cout << "\n===========================================\n";

    int battles=-1;

    while (army[4]->m_iCount!=0) {
        cout << "\nYou did some fighting and \n";
        for (int x=0;x<5;x++) {
            army[x]->kill( dices[x] );
            cout << "\n";
        }
        battles++;
        if (army[4]->m_iCount!=0) cout << "\nYou defeated the army!!!!\n";
    }
    cout << "\nOh no, you lost Mel Gibson!";
    cout << "\nThe scots lasted " << battles << " battles";
    cout << "\nYou lost you twat";
    system("pause");
    return 1;
}
Heh, this is pretty lol :P
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Postby Dead-Inside on Wed Apr 04, 2007 1:18 pm

"Mel Gibson" made me laugh SO HARD.

Oh. My. God.

And thansk for showing how proper coding is done. Use variables.
Image
User avatar
Dead-Inside
Veteran
Veteran
 
Joined: Wed Jan 05, 2005 4:15 pm
Location: Sweden (It's just as cold as you think it is)

Postby Forceflow on Wed Apr 04, 2007 1:29 pm

army[2]= new CSoldiers(100, "welch bowmen");
army[3]= new CSoldiers(1000, "french conscripts");
army[4]= new CSoldiers(1, "Mel Gibson");

I rofl'd.
User avatar
Forceflow
1337 p0st3r
1337 p0st3r
 
Joined: Sun Jul 16, 2006 12:13 pm
Location: Belgium

Postby zombie@computer on Wed Apr 04, 2007 1:37 pm

its not historically accurate since all of those people fought at the english side but meh, atleast mel did :D
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Postby Forceflow on Wed Apr 04, 2007 1:54 pm

Too bad mel dies so much. I have played the game for hours now, and he keeps on dying. He'll probably blame the jews for it, though.

Just out of interest: why all the hocus pocus with the char* pointers ? I'd use the string (it's C++, not vanilla C) :) Correct me if I'm wrong though.
User avatar
Forceflow
1337 p0st3r
1337 p0st3r
 
Joined: Sun Jul 16, 2006 12:13 pm
Location: Belgium

Postby zombie@computer on Wed Apr 04, 2007 3:58 pm

strings are for gay people. Real men use chars. That, and, its good practice, and ive accidentally corrupted toe string.h header and cba to redownload it :-D
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Postby Forceflow on Wed Apr 04, 2007 4:35 pm

zombie@computer wrote:strings are for gay people. Real men use chars. That, and, its good practice, and ive accidentally corrupted toe string.h header and cba to redownload it :-D
How ... convenient. :)
User avatar
Forceflow
1337 p0st3r
1337 p0st3r
 
Joined: Sun Jul 16, 2006 12:13 pm
Location: Belgium

Postby DarkMortar on Thu Apr 05, 2007 4:37 am

its the year 2007, get wif the times bro and utilize strings!!! :-D :-D :-D :-D
Image
DarkMortar wrote:If you copied and pasted this in notepad, you may be a nerd. If you just highlighted this, you may be intelligent. If you read this like it is, you may become blind.
User avatar
DarkMortar
Senior Member
Senior Member
 
Joined: Wed Feb 09, 2005 12:19 am
Location: California, US.

Postby Sauce on Thu Apr 05, 2007 5:57 am

not gonna read ur code but it sounds like you are changing the amount of gold in a private variable within a function. either use pointers to a global variable or tell your function to return that variable to a global one.
Image
Blink wrote:Do you watch porn and decide you don't need to have sex because you've seen the ending? :-D

zombie@computer wrote:what retarded countries measure in stones anyway?
or feet? or inches? Your dick is a lot longer in cms
User avatar
Sauce
Senior Member
Senior Member
 
Joined: Sat Nov 26, 2005 4:36 am
Location: Australia

Postby Sauce on Sat Apr 07, 2007 1:17 pm

Blink wrote:Done! ;-)

so when someone ELSE suggests it, it gets done...

shame on you blink! this should have happend a long time ago when I first suggested it!
Image
Blink wrote:Do you watch porn and decide you don't need to have sex because you've seen the ending? :-D

zombie@computer wrote:what retarded countries measure in stones anyway?
or feet? or inches? Your dick is a lot longer in cms
User avatar
Sauce
Senior Member
Senior Member
 
Joined: Sat Nov 26, 2005 4:36 am
Location: Australia

Postby Psy on Sat Apr 07, 2007 1:22 pm

Did you say something Sauce?

j/k heh
User avatar
Psy
Veteran
Veteran
 
Joined: Sat Dec 03, 2005 5:41 pm
Location: United Kingdom

Postby Mr. Happy on Sat Apr 07, 2007 7:24 pm

Forceflow wrote:Too bad mel dies so much. I have played the game for hours now, and he keeps on dying. He'll probably blame the jews for it, though.

Just out of interest: why all the hocus pocus with the char* pointers ? I'd use the string (it's C++, not vanilla C) :) Correct me if I'm wrong though.


So its finished? Can I play?
Image
-You've just been happified!?
User avatar
Mr. Happy
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Sat Dec 30, 2006 9:20 am
Location: Flyin' thru "da cloud" in the MotherShip

Postby zombie@computer on Sat Apr 07, 2007 7:51 pm

DarkMortar wrote:its the year 2007, get wif the times bro and utilize strings!!! :-D :-D :-D :-D
its like with cars. Real men drive stick, gheys drive automatics.
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Postby jaddorii on Sat Apr 07, 2007 8:51 pm

Okay Im getting help from a guy whos professional (^_^) but he hasn't been online for a while (about 2 days xD) so I haven't been doing to much with the code. But I was wondering if any1 knows Graphic Coding. I kinda wanna know how to make a stickfigure move when u press A,D,S,W and stuff. Any1 knows how? I will probably finish the other code first but it's good to know. :D

ThAnKs!
Dom Dom Dom... another one bites de_dust
User avatar
jaddorii
1337 p0st3r
1337 p0st3r
 
Joined: Sun Jul 16, 2006 10:24 am

Postby BlekksPoncho on Sat Apr 07, 2007 9:06 pm

That's a whole new can of worms there jaddori, get normal C/C++ coding sorted, then try some Windows programming (If you want to use DirectX for the graphic coding) THEN go onto DirectX. Don't rush into a DirectX tutorial without really knowing what is going on, work your way up.
-----------------------
I'm not drunk, I always eat plastic.
User avatar
BlekksPoncho
Sir Post-a-lot
Sir Post-a-lot
 
Joined: Sat Apr 01, 2006 10:48 pm
Location: England - UK
PreviousNext

Return to Programming

Who is online

Users browsing this forum: No registered users