Dark Age Games
Home Dark Age EX Dark Age 2 Message Board Fan Art FAQ Kelzar Mage DALpedia MS Forum
Board Index Dark Age General Bug Report Website Off Topic Register User Edit User User List Search

Hey, Xorlak
Posted by: Colin
17:43:36 07-26-2004

I don't really know that much C++ and I'm trying to learn. I was wondering if you could help me with this little thingy:

It crahses when I try and use a var a cout.

<pre>
/*

========================================================
Basic text based battle system
Copyright 2003, Colin James Fitzpatrick
========================================================

Current only one-on-one but could be _easily_ expanded
for more.

*/

/* Inclusions */
#include LESTHANiostreamGREATERTHAN

/* Party definitions */
#define PLAYER_PARTY 1
#define ENEMY_PARTY 2

/* Fighter class  */
class fighter
{

public:

/* Public stats */
int hp;
int mp;
int ap;
int agility;
int level;
int dp;

/* Is it a player? */
bool isPlayer;

/* Damage fighter taking dp into account*/
int damage(int amount)
{
int dealt = 0;
dealt = amount - dp;
hp -= dealt;
return dealt;
}

/*  Heal fighter */
void heal(int amount)
{
hp += amount;
}

};

/* Party class */
class party
{
/* Array of members */
public:fighter members[1];
};

/* Parties */
party parties[2];

/* Misc globals */
bool ranAway = false;

/* Function declarations */
void mainLoop();
void playerTurn(fighter player);
bool fightIsOver();

/* Main entry point */
int main()
{

/* Testing stats */
/* Player */
parties[PLAYER_PARTY].members[1].hp = 10;
parties[PLAYER_PARTY].members[1].dp = 1;
parties[PLAYER_PARTY].members[1].ap = 5;
parties[PLAYER_PARTY].members[1].isPlayer = true;
/* Enemy */
parties[ENEMY_PARTY].members[1].hp = 5;
parties[ENEMY_PARTY].members[1].dp = 4;
parties[ENEMY_PARTY].members[1].ap = 1;

mainLoop();
return 1;

}

void mainLoop()
{

/* ------------------------- */
/* Main fight execution loop */
/* ------------------------- */

bool done = false;
while(!done)
{
/* For each party */
for(int a = 1; a  LESSTHAN= 2; a++)
{
/* For each member in that party */
for(int b = 1; b LESSTHAN= 1; b++)
{

/* Give them a turn */
if(parties[a].members[b].isPlayer)
{
/* Player */
playerTurn(parties[a].members[b]);
}
else
{
/* Enemy */
}

if(fightIsOver())
{
/* Fight has ended */
done = true;
a = 3;
b = 2;
}
}
}
}
}

bool fightIsOver()
{

/* ------------------------- */
/* Determines if the fight   */
/* is over                   */
/* ------------------------- */

bool toRet = false;

/* Did we run away? */
if(ranAway) toRet = true;

return toRet;

}

void playerTurn(fighter player)
{

/* ------------------------- */
/* Handles a player's turn   */
/* ------------------------- */

bool done = false;
while(!done)
{
/* Display choices */
std::cout LESSTHANLESSTHAN "What would you like to do, laddy?"
  LESSTHANLESSTHAN std::endl
  LESSTHANLESSTHAN std::endl
  LESSTHANLESSTHAN "[1] - Fight"
  LESSTHANLESSTHAN std::endl
  LESSTHANLESSTHAN "[2] - Magic"
  LESSTHANLESSTHAN std::endl
  LESSTHANLESSTHAN "[3] - Flee!"
  LESSTHANLESSTHAN std::endl;

char choice;
std::cin GREATERTHANGREATERTHAN choice;
std::cout LESSTHANLESSTHAN std::endl;
done = true;
switch(choice)
{
case('1'):
{
int damage = 0;
damage = parties[ENEMY_PARTY].members[1].damage(player.ap);
std::cout LESSTHANLESSTHAN "You dealt " LESSTHANLESSTHAN damage LESSTHANLESSTHAN " damage!" LESSTHANLESSTHAN std::endl;
break;
}
case('2'):
{
break;
}
case('3'):
{
std::cout LESSTHANLESSTHAN "Woooo! Ran away!" LESSTHANLESSTHAN std::endl;
ranAway = true;
break;
}
default:
{
/* User didn't press a valid key; try again */
done = false;
break;
}
}
}
}

Edit Post