RSS Forums RSS

game code help

Please support our C++ advertiser: Programming Forums
Reply
Posts: 12
Reputation: popo_prince is an unknown quantity at this point 
Solved Threads: 0
popo_prince popo_prince is offline Offline
Newbie Poster

game code help

  #1  
Mar 23rd, 2004
i found this off some site and when i build it in vis c++, the errors are with the two random functions. will someone tell me why and how i can fix this. the random on line 15 and randomize on line 36. undeclared identifiers.

/* Jason Cordes */
/* COMBAT.CPP */
/* 8/95 */
 
#include <stdlib.h> // random, randomize
#include <fstream.h> // file i/o
#include <string.h> // string commands (copy, concatenate, etc...)
#include <ctype.h> // toupper (100 bytes)
#include <conio.h> // clearscr(), getch()
 
int roll(int die=6, int throws=1, int modifier=0)
{
int total=0, index;
for(index=1;index<=throws;index++)
{ total += random(die); total++; }
total += modifier;
return(total);
}
 
void main()
{
int hp,mhp,THAC,mTHAC,AC,mAC,hitroll;
int damage,mdamage,ALIVE,temp;
 
 
hp = 32;
mhp = 64;
THAC = 12;
AC = 5;
mTHAC = 15;
mAC = 4;
damage = 10;
mdamage = 8;
ALIVE = 1;
 
randomize();
cout << "\n\nStarting combat...";
do{
cout << "\n\nYour hp: " << hp;
cout << "\nIt's hp: " << mhp << endl << endl;
getch();
 
 
cout << endl << " Attacking...";
hitroll = roll(20);
cout << "\nYou rolled a " << hitroll;
if(hitroll >= (THAC-mAC))
{ cout << "\nHIT!";
temp = roll(damage);
mhp -= temp;
cout << " You did " << temp << " point(s) of damage.";
if(mhp <= 0)
{ ALIVE = 0;
cout << "\nThe Skeleton is dead. You gain 10 xp.";} }
 
else
{ cout << "\nYou missed."; }
 
if(ALIVE != 0)
{
hitroll = roll(20);
cout << "\nIt rolled a " << hitroll;
if(hitroll >= (mTHAC-AC))
{ cout << "\n\nThe skeleton swings wildly at you...";
cout << "\nHIT!";
temp = roll(damage);
hp -= temp;
cout << " IT did " << temp << " point(s) of damage.";
if(hp <= 0)
{ ALIVE = 0;
cout << "\nYou are dead. Maybe someone will ressurect you.";} }
 
else
cout << "\nIT missed."; }
 
 
}while(hp > 0 && mhp > 0);
cout << "\nHim: " << mhp << " You: " << hp << endl;
}
Last edited by cscgal : Mar 23rd, 2004 at 9:13 pm.
AddThis Social Bookmark Button
Reply With Quote  
Posts: 11
Reputation: Steu is an unknown quantity at this point 
Solved Threads: 2
Steu Steu is offline Offline
Newbie Poster

Re: game code help

  #2  
Mar 23rd, 2004
Just a few things about this code, whoever wrote doesn't really understand completely what is going on. The header fstream is for file i/o, which isn't used in this program at all, also cout, and cin are used so the iostream header must be included. For the random functions I think what is needed is randomize = srand (seed the random number generator) and random(die) can be reproduced from
(rand() % die) + 1

Also some compilers don't care about this, but some do, cout, and cin are contained in the namespace std, so you may need to fully qualify them i.e.
std::cout << ...
or put a
using namespace std;
at the top of your program.

Doing this, I still could not get it to compile because VS.net 2003 gives a fatal compile error.
Reply With Quote  
Posts: 1
Reputation: JasonCordes is an unknown quantity at this point 
Solved Threads: 0
JasonCordes JasonCordes is offline Offline
Newbie Poster

Re: game code help

  #3  
Apr 28th, 2008
As the author of the code, I would offer in my own self defense that this code was written in 1994 before C++ was ansi compliant.

if anyone has questions about this code, 1. delete it and ask me what you really want to do and I'll give you something much cleaner to look at.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 3752 | Replies: 2 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:28 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC