小游戏:
C++#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
string name;
long long troops = 3, event, Goldcoin = 100, commodity, quantity, price, programme;
bool die = 0;
void Executionevent(long long x)
{
if (x == 1)
{
cout << "欢迎来到商店!";
Sleep(1000);
cout << endl << "你要买什么?" << endl << "1.蓝月 50金币" << endl << "2.退出 0金币" << endl << "(输入序号)" << endl;
cin >> commodity;
Sleep(1000);
if (commodity == 1)
{
cout << "要买几个?" << endl;
cin >> quantity;
price = quantity * 50;
Sleep(1000);
if (Goldcoin >= price)
{
troops += quantity;
Goldcoin -= price;
cout << "你有" << troops << "个蓝月" << endl;
Sleep(1000);
cout << "还剩" << Goldcoin << "金币" << endl;
}
else
{
cout << "钱不够, 下次再来吧" << endl;
}
}
else if (commodity == 2)
{
return;
}
else
{
cout << "不要乱选啊!" << endl;
}
}
else if (x == 2)
{
srand(time(NULL));
long long enemy = rand() % (troops + 5) + 1;
cout << "有" << enemy << "个好渴鹅过来了!";
Sleep(1000);
cout << endl << "你要:" << endl << "1.战斗" << endl;
cin >> programme;
Sleep(1000);
if (programme == 1)
{
troops -= (long long)(enemy / 1.5);
cout << "一番大战后";
Sleep(500);
if (troops > 0)
{
cout << " 你还有" << troops << "个蓝月" << endl;
Sleep(1000);
long long bonus = rand() % max((long long)(enemy * 2), (long long)100) + enemy;
Goldcoin += bonus;
cout << "你获得了" << bonus << "个金币" << endl;
Sleep(1000);
cout << "你还有" << Goldcoin << "个金币" << endl;
}
else
{
cout << " 你的蓝月全部阵亡" << endl;
Sleep(800);
cout << "你死了";
did = 1;
}
}
else
{
cout << "你什么都没干";
Sleep(1000);
cout << " 你死了(谁教你啥都不干的?)";
did = 1;
}
}
else if (x == 3)
{
}
else if (x == 4)
{
cout << "你死了!(都说了不要选)";
die = 1;
}
else
{
cout << "不要乱选啊!" << endl;
}
}
int main()
{
Sleep(2000);
cout << "欢迎来到徐俊朗的游戏:好渴鹅大战" << endl;
Sleep(1500);
cout << "你的名字是:";
cin >> name;
if (name == "徐俊朗")
{
Goldcoin = 999999999;
troops = 999999999;
}
Sleep(500);
cout << name;
Sleep(1000);
cout << " 你好!" << endl;
Sleep(2000);
cout << "游戏开始" << endl;
Sleep(2000);
while (1)
{
cout << name << " 你要干嘛?" << endl << "1.商店" << endl << "2.战斗" << endl << "3.小游戏" << endl << "4.不要选" << endl << "(输入序号)" << endl;
cin >> event;
Sleep(1000);
Executionevent(event);
if (die)
{
Sleep(2000);
return 0;
}
Sleep(1000);
}
}