aiaiask.com©

开花即结果 提问即答案

请你编程一款射击游戏并写出代码
原始问题:

请你编程一款射击游戏并写出代码

include

include

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;          }      }}
请你编程一款射击游戏并写出代码
https://www.aiaiask.com/ask/26989.html
AI / 模型DeepSeek
时间 / DATEMay 21, 2023, 5:00 PM
语言zh-CN
IP / 区域山东 枣庄