Secret agent game stuck

Description:

Develop a secret agent game. The player will play the part of some famous secret agent (James Bond, Austin Powers, Sherlock Holmes, etc…) – or you may make up an agent of your own choosing. The job of the agent is to track down the hideout of his crafty foe (Goldfinger, Dr. Evil, Moriarty, etc..). Use comic book heroes if you wish -- be creative. Other themes you might choose to use could be a Warrior and a Dragon in a cave, etc…

The Rules:

* The game takes place in a city that is 8 blocks wide and 8 blocks high.
* The hero (the player) starts in the northwest corner of the city.
* The enemy starts in any of the other 63 squares, randomly placed.
* There are from 0-8 ambushes that the enemy has set for the hero in the remaining 62 squares, randomly placed.
* On a turn, the hero may move north, east, south, or west or call in the police. The hero can not move diagonally.
* The hero must not be allowed to leave the city.
* If the hero walks into an ambush, he loses.
* If the hero walks into the enemy's hideout, he loses.
* If the hero calls in the police, he must the specify a direction, north, east, south, or west (of his current position). If the enemy is located in the square next to the player in that direction, the hero wins. If the enemy is not located there, he escapes, and the hero loses.
* If the hero is in a city block next to an ambush (diagonal does not count), the player should be given a message indicating an ambush is near. The player must not be told which direction the ambush is in.
* If the hero is in a city block next to the enemy's hideout (diagonal does not count), the player should be told he or she is near the enemy's hideout. The message should be different from the ambush message. The player must not be told which direction the hideout is.
* You should display the grid for each move the player makes. The positions of the ambushes or the enemy hideout should never be shown on this grid, only the position of the player.
* The user should type w to move north, d to move east, x to move south, and a to move west. Typing c means the player wants to call the police. A player who wants to call the police should then type w, d, x, or a to indicate which direction the police should go.




Sample Output: (Bold indicates user input)

Help Spider Man track down the Green Goblin!
Your spider sense will tingle when you're near an ambush,
and you'll smell a strange gas when near the Green Goblin's hideout!

H A e e e e e e ****NOTE****
e e e e e A e e Ambushes and Hideout
e e e e e e e e should NOT show. They
e e e e A e e e are shown here only to
e e e e e e e A aid in understanding the
e e A e e e e e rules.
e e e e e E e e
e e e e e e e e

Your spider sense is tingling.
What do you want to do? d

The Green Goblin swoops down on you, knocking you out with a pumpkin bomb!
You lose.

Play again? y

H A e e e e e e ****NOTE****
e e e e e A e e Ambushes and Hideout
e e e e e e e e should NOT show. They
e e e e A e e e are shown here only to
e e e e e e e A aid in understanding the
e e A e e e e e rules.
e e e e e E e e
e e e e e e e e

Your spider sense is tingling.
What do you want to do? x

e A e e e e e e ****NOTE****
H e e e e A e e Ambushes and Hideout
e e e e e e e e should NOT show. They
e e e e A e e e are shown here only to
e e e e e e e A aid in understanding the
e e A e e e e e rules.
e e e e e E e e
e e e e e e e e

Nothing unusual here.
What do you want to do? d

e A e e e e e e ****NOTE****
e H e e e A e e Ambushes and Hideout
e e e e e e e e should NOT show. They
e e e e A e e e are shown here only to
e e e e e e e A aid in understanding the
e e A e e e e e rules.
e e e e e E e e
e e e e e e e e

Your spider sense is tingling.
What do you want to do?

<time warp>

e A e e e e e e ****NOTE****
e e e e e A e e Ambushes and Hideout
e e e e e e e e should NOT show. They
e e e e A e e e are shown here only to
e e e e e e e A aid in understanding the
e e A e H e e e rules.
e e e e e E e e
e e e e e e e e

Nothing unusual here.
What do you want to do? d

e A e e e e e e ****NOTE****
e e e e e A e e Ambushes and Hideout
e e e e e e e e should NOT show. They
e e e e A e e e are shown here only to
e e e e e e e A aid in understanding the
e e A e e H e e rules.
e e e e e E e e
e e e e e e e e

You smell a strange gas!
What do you want to do? c

The police are coming! Which way to lead them? w

You lead the police into a warehouse, and they think you're trying to rob it. The Green Goblin gets away.

Play again? y

H A e e e e e e ****NOTE****
e e e e e A e e Ambushes and Hideout
e e e e e e e e should NOT show. They
e e e e A e e e are shown here only to
e e e e e e e A aid in understanding the
e e A e e e e e rules.
e e e e e E e e
e e e e e e e e

Your spider sense is tingling.
What do you want to do? s
.
.
.
after moving about a bit...
.
.
.

e A e e e e e e ****NOTE****
e e e e e A e e Ambushes and Hideout
e e e e e e e e should NOT show. They
e e e e A e e e are shown here only to
e e e e e e e A aid in understanding the
e e A e e H e e rules.
e e e e e E e e
e e e e e e e e

You smell a strange gas!
What do you want to do? c

The police are coming! Which way to lead them? x

You lead the police into the Green Goblin's hideout! They capture the Green Goblin, and take all the credit. Oh well.

You win!

Play again?


Again, your output does not have to look exactly like this, as long as it follows guidelines. Remember, the locations of the ambushes and hideout should NOT be shown.

Additional restrictions.

* You must use a two-dimensional array to represent the city map.
* You should be able to handle (gracefully) illegal inputs in all situations.
Last edited on
Hey guy.... have fun completing your task:)...
Last edited on
Wow that's a neat project, good to hear you have it....what was your question again?
my question is how do i display the array onto the screen. and how do i make the player move around.(i was thinking about if the player wants to move right it should say column +1, if they wanted to move to the left then it should say column -1, and so forth) i am stuck on how to display the array of the city map(8 by 8 grid) and how i place the ambushes in the game.

Please help me i don't know where to start.

thanks
if you're using the console, either you use nested for loops to print it out, or just loop through the number of rows in your map and cout it.

For example:

1
2
3
4
for(int row = 0; row < 8; ++row)
{
     cout << map[row] << endl;
}


Nested loop example:

1
2
3
4
5
6
7
8
for(int row = 0; row < 8; ++row)
{
     for(int col = 0; col < 8; ++col)
     {
          cout << map[row][col];
     }
     cout << "\n";
}


though I think you don't want to show all those e's, and the location of the ambushes. So you may want to use the nested for loops and add some if statements to check whether you'll display the character or not. Anyways I think it's better if you try to implement the game map as an object, but it's probably not required in your computer science class.
Last edited on
no its a beginning computer programming class so i dont think we learned about objects yet. but thanks for the info. ill come back here if i have any more questions
bump.
ill come back here if i have any more questions
bump.
Is that supposed to mean that you have more questions?
ok thank you Dacster13, the code worked. i made a couple adjustments to it just for asthetic appeal to my eyes, but it is still your code. so thanks again for that.

now to my next question. I was wondering what do i do to move the character around using the WASD keys and if the user performs an illegal move (tries to go out of the array) then it should give an error.

thanks
wasd? I thought it was wdxa...
Anyway, try this:
1
2
3
4
5
6
7
char my_input; //whatever char the user entered
switch(my_input){
    case 'w':
        if(hero_y > 1) hero_y --;
        else cout << "error\n";
    //and so on...
}
got code to work, thanks guys!!
Topic archived. No new replies allowed.