Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cout << "1) Move, 2) Rest, 3) View Stats, 4) Quit: ";
- cin >> selection;
- Monster* monster = 0;
- switch( selection )
- {
- case 1:
- gameMap.movePlayer();
- // Check for a random encounter. This function
- // returns a null pointer if no monsters are
- // encountered.
- monster = gameMap.checkRandomEncounter();
- // 'monster' not null, run combat simulation.
- if( monster != 0 )
- //refering to the once null pointer and now modifies something real?
- monster = new Monster
- 0 = gameMap.checkRandomEncounter();
- 0 = null;
- Monster* Map::checkRandomEncounter()
- {
- int roll = Random(0, 20);
- Monster* monster = 0;
- if( roll <= 5 )
- {
- // No encounter, return a null pointer.
- return 0;
- }
- else if(roll >= 6 && roll <= 10)
- {
- monster = new Monster("Orc", 10, 8, 200, 1,
- "Short Sword", 2, 7);
- cout << "You encountered an Orc!" << endl;
- cout << "Prepare for battle!" << endl;
- cout << endl;
- }
- monster = new Monster();
- Monster* monster = 0;
- // Check for a random encounter. This function
- // returns a null pointer if no monsters are
- // encountered.
- monster = gameMap.checkRandomEncounter();
- // 'monster' not null, run combat simulation.
- if( monster != 0 ) ...
- if( roll <= 5 )
- {
- // No encounter, return a null pointer.
- return 0;
- }
- else if(roll >= 6 && roll <= 10)
- {
- monster = new Monster("Orc", 10, 8, 200, 1,
- "Short Sword", 2, 7);
- cout << "You encountered an Orc!" << endl;
- cout << "Prepare for battle!" << endl;
- cout << endl;
- }
- return monster;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement