game code help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2004
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

 
0
  #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.

  1. /* Jason Cordes */
  2. /* COMBAT.CPP */
  3. /* 8/95 */
  4.  
  5. #include <stdlib.h> // random, randomize
  6. #include <fstream.h> // file i/o
  7. #include <string.h> // string commands (copy, concatenate, etc...)
  8. #include <ctype.h> // toupper (100 bytes)
  9. #include <conio.h> // clearscr(), getch()
  10.  
  11. int roll(int die=6, int throws=1, int modifier=0)
  12. {
  13. int total=0, index;
  14. for(index=1;index<=throws;index++)
  15. { total += random(die); total++; }
  16. total += modifier;
  17. return(total);
  18. }
  19.  
  20. void main()
  21. {
  22. int hp,mhp,THAC,mTHAC,AC,mAC,hitroll;
  23. int damage,mdamage,ALIVE,temp;
  24.  
  25.  
  26. hp = 32;
  27. mhp = 64;
  28. THAC = 12;
  29. AC = 5;
  30. mTHAC = 15;
  31. mAC = 4;
  32. damage = 10;
  33. mdamage = 8;
  34. ALIVE = 1;
  35.  
  36. randomize();
  37. cout << "\n\nStarting combat...";
  38. do{
  39. cout << "\n\nYour hp: " << hp;
  40. cout << "\nIt's hp: " << mhp << endl << endl;
  41. getch();
  42.  
  43.  
  44. cout << endl << " Attacking...";
  45. hitroll = roll(20);
  46. cout << "\nYou rolled a " << hitroll;
  47. if(hitroll >= (THAC-mAC))
  48. { cout << "\nHIT!";
  49. temp = roll(damage);
  50. mhp -= temp;
  51. cout << " You did " << temp << " point(s) of damage.";
  52. if(mhp <= 0)
  53. { ALIVE = 0;
  54. cout << "\nThe Skeleton is dead. You gain 10 xp.";} }
  55.  
  56. else
  57. { cout << "\nYou missed."; }
  58.  
  59. if(ALIVE != 0)
  60. {
  61. hitroll = roll(20);
  62. cout << "\nIt rolled a " << hitroll;
  63. if(hitroll >= (mTHAC-AC))
  64. { cout << "\n\nThe skeleton swings wildly at you...";
  65. cout << "\nHIT!";
  66. temp = roll(damage);
  67. hp -= temp;
  68. cout << " IT did " << temp << " point(s) of damage.";
  69. if(hp <= 0)
  70. { ALIVE = 0;
  71. cout << "\nYou are dead. Maybe someone will ressurect you.";} }
  72.  
  73. else
  74. cout << "\nIT missed."; }
  75.  
  76.  
  77. }while(hp > 0 && mhp > 0);
  78. cout << "\nHim: " << mhp << " You: " << hp << endl;
  79. }
Last edited by cscgal; Mar 23rd, 2004 at 10:13 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
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

 
0
  #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
  1. (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.
  1. std::cout << ...
or put a
  1. 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 Quick reply to this message  
Join Date: Apr 2008
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

 
0
  #3
Apr 29th, 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 Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC