strings
Hejsajeg er ved at lave et spil i vc++
til det har jeg en class:
// monsters.h
// grundtrækkene for et monster
#include <stdio.h>
#include <string.h>
class Monster {
char *_ID; // id for monsteret
char *_name; // Navnet
int _xpos, _ypos;
int _move;
int _life;
public:
Monster() {
_ID=\"\";
_name=\"\";
_xpos=0;
_ypos=0;
_life=0;
_move=0;
}
Monster( char *ID, char *name, const int xpos, const int ypos, const int move, const int life) {
_ID=ID;
_name=name;
_xpos=xpos;
_ypos=ypos;
_move=move;
_life=life;
}
void setPos( const int xpos, const int ypos) {
_xpos = xpos;
_ypos = ypos;
}
char movePos( const int dx, const int dy) {
if (_move*_move >= dx*dx+dy*dy){
_xpos+= dx;
_ypos+= dy;
return 1;
} else
{
return 0;
}
}
int getXpos() { return _xpos; }
int getYpos() { return _ypos; }
char *getName() { return _name;}
~Monster() {}
};
problemet er at jeg åbenbart ikke ka finde ud af at arbejde med \"strenge\"
min cpp fil ser sådan her ud:
/* TEST2.cpp */
/* Creates some bad guys and show their params */
#include <stdio.h>
#include <iostream.h>
#include \"monsters.h\"
Monster amonster(\"ID002002\",\"ORGRE\",25,20,4,32);
void main() {
cout << amonster.getName() << endl;
cout << amonster.getXpos() << \"\\n\" << amonster.getYpos() << endl;
amonster.setPos(10,30);
cout << amonster.getXpos() << \"\\n\" << amonster.getYpos() << endl;
if (amonster.movePos(-2,4))
cout << amonster.getXpos() << \"\\n\" << amonster.getYpos() << endl;
else
cout << \"could not move\" << endl;
}
den udskriver ikke noget ved getName() :/
