aiaiask.com©

开花即结果 提问即答案

写一个愤怒小鸟游戏的c++代码
原始问题:

写一个愤怒小鸟游戏的c++代码

include

include

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 ;}
写一个愤怒小鸟游戏的c++代码
https://www.aiaiask.com/ask/14517.html
AI / 模型Siliconflow
时间 / DATEApril 19, 2023, 11:44 PM
语言zh-CN
IP / 区域湖北 武汉