//FIGHTING STUFF
void dungeon()
{
srand(GetTickCount());
//BASIC MOVE COMMANDS
char pMove;
int fight();
top:
if (player.pX == 5 && player.pY == 5)
{
fight();
}
cout <<"Your Position is ("<<player.pX<<","<<player.pY<<")"<<endl;
cout <<"---> ";
cin >> pMove;
switch (pMove)
{
case 'l':
player.pX -= 1;
goto top;
case 'r':
player.pX += 1;
goto top;
case 'u':
player.pY += 1;
goto top;
case 'd':
player.pY -= 1;
goto top;
case 'm':
Draw (↦);
goto top;
case 'c':
system("cls");
goto top;
case 'h':
help();
break;
case 'q':
char yn[3];
cout <<"Are you sure your wish to leave? ";
cin >> yn;
if (yn[0] = 'y')
{
system("cls");
Draw (&tag);
return;
}
else
{
goto top;
}
default:
cout <<" ------INVALID COMMAND------\n";
goto top;
}
}
//BASIC MOVE COMMADS
Under invalid command it repeats continously until you close it or until the computer crashes..Also
class PERSON
{
public:
int pX;
int pY;
char pName[8], pClass[8];
int strength, energy, dex, armor, vit, gold, dam, wep, kills, kill;
};
NEED HELP WITH THIS CODE
I am writting a text game and I am fairly far along. But I have a problem with my fighting sim.
This is another file a header or part of it. I want to define in this file, that when kill == 5 you gain a level and every five kills after that. It will increase your stats(That I can do easily) But I don know how to define what kill does
Thank you for the help [/source]
[edited by - betrayer_of_code on January 11, 2003 1:01:48 PM]
BoC HomepageLuck is a Horse to ride like any other...Luckily im not a gambler, I dont know how to ride.
I think you should use break; after each case: statement, i dont know if thats the problem tough
invalid command it repeats continously until you close it or until the computer crashes..Also
hey this is only a text why didn''t you put a // before
hey this is only a text why didn''t you put a // before
It''s not easy to figure out what you want, but if i got it
right, you want kill to be a function? So kill() ?
then define it as int kill(); in the class,
and to write the function, use
int Person::kill()
{
//your code here
}
I really think you should aim for writing a bit
more structured code
//Junior
--
MFC is sorta like the swedish police... It''''s full of crap, and nothing can communicate with anything else.
right, you want kill to be a function? So kill() ?
then define it as int kill(); in the class,
and to write the function, use
int Person::kill()
{
//your code here
}
I really think you should aim for writing a bit
more structured code
//Junior
--
MFC is sorta like the swedish police... It''''s full of crap, and nothing can communicate with anything else.
// I believe you want to do either this: if(kill = 5) { kill = 0; // reset kill /* update player statistics */ }// or this: if((kill%5) == 0) { /* update player statistics */ }
Also, I rewrote your code and got rid of the gotos, cause even people who say "gotos aren''t that bad" would probably agree they aren''t remotely necessary in your code.
void dungeon() { // your dungeon function, modified for better structure char pMove; char yn[4] = "yes"; // you had 3, but it should be 4(room for "yes" and null zero) int fight(); // this doesn''t look right.... // a do-while lood does what you want, just a little differently do { if (player.pX == 5 && player.pY == 5) { fight(); } cout << "Your Position is (" << player.pX << "," << player.pY << ")" << endl; cout << "---> "; cin >> pMove; switch (pMove) { case ''l'': player.pX -= 1; break; // note the breaks case ''r'': player.pX += 1; break; case ''u'': player.pY += 1; break; case ''d'': player.pY -= 1; break; case ''m'': Draw (↦); break; case ''c'': system("cls"); break; case ''h'': help(); break; // why did you put break here and nowhere else? case ''q'': cout <<"Are you sure your wish to leave? "; cin >> yn; if (yn[0] = ''y'') { system("cls"); Draw (&tag); return; } // don''t need an else with that return break; default: cout <<" ------INVALID COMMAND------\n"; break; } }}
C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!
person is the class and kill is a member that is what I wanted but will that work in a class instead of a function?
Oh. My code is fairly structured, these are just small snippets of it. If you look at the whole thing it is fairly organized
Oh. My code is fairly structured, these are just small snippets of it. If you look at the whole thing it is fairly organized
BoC HomepageLuck is a Horse to ride like any other...Luckily im not a gambler, I dont know how to ride.
person is the class and kill is a member that is what I wanted but will that work in a class instead of a function?
Oh. My code is fairly structured, these are just small snippets of it. If you look at the whole thing it is fairly organized
Oh. My code is fairly structured, these are just small snippets of it. If you look at the whole thing it is fairly organized
BoC HomepageLuck is a Horse to ride like any other...Luckily im not a gambler, I dont know how to ride.
1.Go here
2.Check "did you double post?"
3.Hit "make modifications"
[edited by - evil sausage on January 11, 2003 5:56:14 PM]
[edited by - evil sausage on January 11, 2003 5:57:03 PM]
2.Check "did you double post?"
3.Hit "make modifications"
[edited by - evil sausage on January 11, 2003 5:56:14 PM]
[edited by - evil sausage on January 11, 2003 5:57:03 PM]
And so, the evil religion thread stole the wonderful "What the Heck?" thread's throne. Truly a sad day for gamedev.
quote: person is the class and kill is a member that is what I wanted but will that work in a class instead of a function?
Oh. My code is fairly structured, these are just small snippets of it. If you look at the whole thing it is fairly organized
Well, as long as some is organized, it's okay
As for whether you can have functions in a class, the answer is ABSOLUTELY! I'm still not sure exactly on what you want kill() to do, though. Assuming it is to increase kills by one and check if kills is a multiple of five(and if so, update player stats), this is what could do:
class PERSON{ public: int pX; int pY; char pName[8], pClass[8]; int strength, energy, dex, armor, vit, gold, dam, wep, kills; void kill(void); // just like a normal function(so far)};...// later, perhaps after mainvoid PERSON::kill(void) { kill++; // you killed something! if((kill % 5) == 0) { // if kill is a multiple of 5 strength += 3; // in a member function, you don't need to say class.variable, just variable // update everything here } // do anything else you want}
there's a LOT more you can do with member functions, but that's a start. You could rewrite a lot of code to take advantage of methods(another word for member functions). For example, instead of player.pX -= 1 you could do player.left() and have the method do the code. When your game gets large, you could also add boundary checking. Or when asking for the players name, you could call player.getName() and do the code there.
There's a lot more you can do with classes than that, but I'd wait until you're done with your current project before you delve too deeply in that subject.
EDIT: formatting
[edited by - nobodynews on January 13, 2003 1:40:18 PM]
C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!
Hey guys,(and gals)
Thank you for the help. I am planing on revising it tomorrow, in the mean time check out my site, I have a copy and paste-able verson of the code at my site
HERE
So I would love it if you played around with the code or even played the game. I love Feed back
(Sorry your gonna need to compile it youself)
Betrayer_of_Code
Thank you for the help. I am planing on revising it tomorrow, in the mean time check out my site, I have a copy and paste-able verson of the code at my site
HERE
So I would love it if you played around with the code or even played the game. I love Feed back
(Sorry your gonna need to compile it youself)
Betrayer_of_Code
BoC HomepageLuck is a Horse to ride like any other...Luckily im not a gambler, I dont know how to ride.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement