Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. cout << "1) Move, 2) Rest, 3) View Stats, 4) Quit: ";
  2. cin >> selection;
  3.  
  4. Monster* monster = 0;
  5. switch( selection )
  6. {
  7. case 1:
  8. gameMap.movePlayer();
  9.  
  10. // Check for a random encounter. This function
  11. // returns a null pointer if no monsters are
  12. // encountered.
  13. monster = gameMap.checkRandomEncounter();
  14.  
  15. // 'monster' not null, run combat simulation.
  16. if( monster != 0 )
  17.  
  18. //refering to the once null pointer and now modifies something real?
  19. monster = new Monster
  20.  
  21. 0 = gameMap.checkRandomEncounter();
  22.  
  23. 0 = null;
  24.  
  25. Monster* Map::checkRandomEncounter()
  26. {
  27. int roll = Random(0, 20);
  28.  
  29. Monster* monster = 0;
  30.  
  31. if( roll <= 5 )
  32. {
  33. // No encounter, return a null pointer.
  34. return 0;
  35. }
  36. else if(roll >= 6 && roll <= 10)
  37. {
  38. monster = new Monster("Orc", 10, 8, 200, 1,
  39. "Short Sword", 2, 7);
  40.  
  41. cout << "You encountered an Orc!" << endl;
  42. cout << "Prepare for battle!" << endl;
  43. cout << endl;
  44. }
  45.  
  46. monster = new Monster();
  47.  
  48. Monster* monster = 0;
  49.  
  50. // Check for a random encounter. This function
  51. // returns a null pointer if no monsters are
  52. // encountered.
  53. monster = gameMap.checkRandomEncounter();
  54.  
  55. // 'monster' not null, run combat simulation.
  56. if( monster != 0 ) ...
  57.  
  58. if( roll <= 5 )
  59. {
  60. // No encounter, return a null pointer.
  61. return 0;
  62. }
  63.  
  64. else if(roll >= 6 && roll <= 10)
  65. {
  66. monster = new Monster("Orc", 10, 8, 200, 1,
  67. "Short Sword", 2, 7);
  68.  
  69. cout << "You encountered an Orc!" << endl;
  70. cout << "Prepare for battle!" << endl;
  71. cout << endl;
  72. }
  73.  
  74. return monster;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement