Thread: game code help
View Single Post
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