请你编程一款射击游戏并写出代码
#include <iostream>
#include <string>
using namespace std;
//Enum for different game states
enum GameState { Menu, Playing, GameOver };
//Enum for player actions
enum PlayerAction { Shoot, Reload };
//Global Variables
int ammo = 0; //ammo count
GameState state = Menu; //current game state
void main() {
while (state != GameOver) {
switch (state) {
case Menu:
cout << "Welcome to the shooting game!" << endl;
cout << "Press 1 to start the game" << endl;
int input;
cin >> input;
if (input == 1) state = Playing; break;
case Playing:
cout << "You are in the middle of a shooting match. What do you want to do?" << endl; cout << "Press 1 to shoot"<<endl<<"Press 2 to reload"<<endl;; int actionInput ; cin >> actionInput ; if(actionInput == 1){ PlayerAction action = Shoot ; if(ammo > 0 ){ ammo-- ; cout<<"You shot your gun!"<<endl ; }else{ cout<<"Out of ammo! Please reload."<<endl ; } }else if(actionInput == 2){ PlayerAction action = Reload ; ammo += 5 ; cout<<"Reloaded your gun! You have now " + std::to_string(ammo)+ " bullets."+endl;; } break; } }}
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。