qcode
  • 创作工场专业版,一问多答!更智能、更完整、更原创
  • 这是一个超强内容创作平台,它会写文章、做设计、绘图、敲代码,有问必答!
🔥点击使用-免登录深度版🔥

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

时间2023-05-21 17:00:08 提问来自 山东省枣庄市 的网友 分类创作 浏览398
#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; } }}

不满意?免费深度重写!

免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。

上一篇 请你写出任意一款游戏的代码 下一篇 发条橙 A Clockwork Orange影评