写一个愤怒小鸟游戏的c++代码
#include <iostream>
#include <string>
using namespace std;
int main() {
int score = 0; // 分数
string userInput; // 用户输入
cout << "欢迎来到愤怒的小鸟游戏!" << endl;
while (true) { // 游戏循环开始
cout << "请输入要发射的力量:"; // 询问用户发射力度大小
cin >> userInput; // 获取用户输入值
if (userInput == "q") { // 如果用户输入 q,则退出循环
break; // 退出循环
} else { // 否则根据用户输入的力量大小来决定是否发射出去并且得分情况。
int power = stoi(userInput); // 将字符串转化为整型数字
if (power >= 10) { // 力量大于 10 才能够发射出去,否则会失去机会。
cout << "你发射了一只愤怒的鸟!" << endl; // 执行正常情况时显示此信息。
score += power * 2; // 计算本次得分情况,2倍加分。
} else { // 力量不够10时显示此信息。
cout << "你的力量不够,你失去了一次机会!"<<endl; } } } cout<<"本局得分:"<<score<<endl ; return 0 ;}
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。