- C++
C++有趣代码/游戏(搬运)第一篇
- @ 2026-5-6 19:20:17
注:代码均为搬运!!! 1.歌曲《起风了》
#include <Windows.h>
#pragma comment(lib,"winmm.lib")
using namespace std;
enum Scale{
Rest=0,C8=108,B7=107,A7s = 106, A7 = 105, G7s = 104, G7 = 103, F7s = 102, F7 = 101, E7 = 100,
D7s = 99, D7 = 98, C7s = 97, C7 = 96, B6 = 95, A6s = 94, A6 = 93, G6s = 92, G6 = 91, F6s = 90, F6 = 89,
E6 = 88, D6s = 87, D6 = 86, C6s = 85, C6 = 84, B5 = 83, A5s = 82, A5 = 81, G5s = 80, G5 = 79, F5s = 78,
F5 = 77, E5 = 76, D5s = 75, D5 = 74, C5s = 73, C5 = 72, B4 = 71, A4s = 70, A4 = 69, G4s = 68, G4 = 67,
F4s = 66, F4 = 65, E4 = 64, D4s = 63, D4 = 62, C4s = 61, C4 = 60, B3 = 59, A3s = 58, A3 = 57, G3s = 56,
G3 = 55, F3s = 54, F3 = 53, E3 = 52, D3s = 51, D3 = 50, C3s = 49, C3 = 48, B2 = 47, A2s = 46, A2 = 45,
G2s = 44, G2 = 43, F2s = 42, F2 = 41, E2 = 40, D2s = 39, D2 = 38, C2s = 37, C2 = 36, B1 = 35, A1s = 34,
A1 = 33, G1s = 32, G1 = 31, F1s = 30, F1 = 29, E1 = 28, D1s = 27, D1 = 26, C1s = 25, C1 = 24, B0 = 23,
A0s = 22, A0 = 21
};
enum Voice{
X1 = C2, X2 = D2, X3 = E2, X4 = F2, X5 = G2, X6 = A2, X7 = B2,
L1 = C3, L2 = D3, L3 = E3, L4 = F3, L5 = G3, L6 = A3, L7 = B3,
M1 = C4, M2 = D4, M3 = E4, M4 = F4, M5 = G4, M6 = A4, M7 = B4,
H1 = C5, H2 = D5, H3 = E5, H4 = F5, H5 = G5, H6 = A5, H7 = B5,
LOW_SPEED = 500, MIDDLE_SPEED = 400, HIGH_SPEED = 300,
_ = 0XFF
};
void Wind(){
HMIDIOUT handle;
midiOutOpen(&handle, 0, 0, 0, CALLBACK_NULL);
int volume = 0x7f;
int voice=0x0;
int sleep=350;
int wind[]={
400,0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,0,L7,M1,M2,M3,300,L2,0,M5,M3,M2,M3,M1,M2,L7,M1,300,L5,0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,0,L7,M1,M2,M3,300,L2,0,M5,M3,M2,M3,M1,M2,L7,M1,300,L5,
0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,0,L7,M1,M2,M3,300,L2,0,M5,M3,M2,M3,M1,M2,L7,M1,300,L5,0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,
0,M6,M3,M2,L6,M3,L6,M2,M3,L6,_,_,_,
M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M1,300,M2,700,0,M1,M2,M3,M2,M1,300,L5,_,
M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M3,300,M2,0,M1,700,300,M2,_,_,_,
M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M3,300,M2,0,M1,700,300,L6,_,
0,M3,M2,M1,M2,300,M1,_,0,M3,M2,M1,M2,300,M1,700,0,L5,M3,M2,M1,M2,300,M1,_,_,_,
M1,M2,M3,M1,M6,0,M5,M6,300,_,700,0,M1,300,M7,0,M6,M7,300,_,_,M7,0,M6,M7,300,_,M3,0,H1,H2,H1,M7,300,M6,M5,M6,0,M5,M6,_,M5,M6,M5,300,M6,0,M5,M2,300,_,0,M5,700,300,M3,_,_,_,
M1,M2,M3,M1,M6,0,M5,M6,300,_,700,0,M1,300,M7,0,M6,M7,300,_,_,M7,0,M6,M7,300,_,M3,0,H1,H2,H1,M7,300,M6,M5,M6,0,H3,H3,300,_,M5,M6,0,H3,H3,300,_,0,M5,700,300,M6,_,_,_,_,_,
H1,H2,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H2,0,H1,M6,300,_,0,H1,H1,300,H2,0,H1,300,M6,700,0,_,300,H1,700,H3,_,0,H3,H4,H3,H2,H3,300,H2,700,
H1,H2,H3,0,H6,H5,_,H6,H5,_,H6,H5,300,_,H3,H3,0,H6,H5,_,H6,H5,_,H6,H5,700,300,H3,700,H2,0,H1,M6,700,300,
H3,700,H2,0,H1,300,M6,700,H1,H1,_,_,_,_,_,
0,M6,300,H3,700,H2,0,H1,M6,700,300,H3,H2,700,300,0,H1,M6,300,700,H1,H1,_,_,
0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,0,L7,M1,M2,M3,300,L2,0,M5,M3,M2,M3,M1,M2,L7,M1,300,L5,0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,
0,M6,M3,M2,L6,M3,L6,M2,M3,L6,_,_,_,
M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M1,300,M2,700,0,M1,M2,M3,M2,M1,300,L5,_,
M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M3,300,M2,0,M1,700,300,M2,_,_,_,
M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M3,300,M2,0,M1,700,300,L6,_,
0,M3,M2,M1,M2,300,M1,_,0,M3,M2,M1,M2,300,M1,700,0,L5,M3,M2,M1,M2,300,M1,_,_,_,
M1,M2,M3,M1,M6,0,M5,M6,300,_,700,0,M1,300,M7,0,M6,M7,300,_,_,M7,0,M6,M7,300,_,M3,0,H1,H2,H1,M7,300,M6,M5,M6,0,M5,M6,_,M5,M6,M5,300,M6,0,M5,M2,300,_,0,M5,700,300,M3,_,_,_,
M1,M2,M3,M1,M6,0,M5,M6,300,_,700,0,M1,300,M7,0,M6,M7,300,_,_,M7,0,M6,M7,300,_,M3,0,H1,H2,H1,M7,300,M6,M5,M6,0,H3,H3,300,_,M5,M6,0,H3,H3,300,_,0,M5,700,300,M6,_,_,_,_,_,
H1,H2,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H2,0,H1,M6,300,_,0,H1,H1,300,H2,0,H1,300,M6,700,0,_,300,H1,700,H3,_,0,H3,H4,H3,H2,H3,300,H2,700,
H1,H2,H3,0,H6,H5,_,H6,H5,_,H6,H5,300,_,H3,H3,0,H6,H5,_,H6,H5,_,H6,H5,700,300,H3,700,H2,0,H1,M6,700,300,
H3,700,H2,0,H1,300,M6,700,H1,H1,_,_,_,_,_,
H1,H2,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H2,0,H1,M6,300,_,0,H1,H1,300,H2,0,H1,300,M6,700,0,_,300,H1,700,H3,_,0,H3,H4,H3,H2,H3,300,H2,700,
H2,H3,0,H6,H5,_,H6,H5,_,H6,H5,300,_,H3,H3,0,H6,H5,_,H6,H5,_,H6,H5,700,300,H3,700,H2,0,H1,M6,700,300,
H3,700,H2,0,H1,300,M6,700,H1,H1,_,_,_,_,_,
H1,H2,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H2,0,H1,M6,300,_,0,H1,H1,300,H2,0,H1,300,M6,700,0,_,300,H1,700,H3,_,0,H3,H4,H3,H2,H3,300,H2,700,
H1,H2,H3,0,H6,H5,_,H6,H5,_,H6,H5,300,_,H3,H3,0,H6,H5,_,H6,H5,_,H6,H5,700,300,H3,700,H2,0,H1,M6,700,300,
H3,700,H2,0,H1,300,M6,700,H1,H1,_,_,_,_,_,
0,M6,300,H3,700,H2,0,H1,M6,700,300,H3,H2,700,300,0,H1,M6,300,700,H1,H1,_,_,_,_,_,_,_,
};
int len=sizeof(wind)/sizeof(wind[0]);
for (int i=0;i<len;i++) {
int val=wind[i];
if(val==0){
sleep = 175;
continue;
}
if(val==700){
Sleep(175);
continue;
}
if(val==300){
sleep = 350;
continue;
}
if (val == _) {
Sleep(350);
continue;
}
voice= (volume << 16) + ((val) << 8) + 0x90;
midiOutShortMsg(handle, voice);
cout << voice << endl;
Sleep(sleep);
}
midiOutClose(handle);
}
int main(){
while(1){
Wind();
Sleep(2246);
}
return 0;
}
2.恶魔轮盘赌
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
using namespace std;
int Your = 6, Other = 6;
string daojuname[] = {"放大镜", "手铐", "小刀", "烟", "饮料"};
double Yourmoney;
int read() {
char ch = _getch();
while (ch>'9'||ch<'0')ch=_getch();
return ch - 48;
}
int shi, kong;
int q[10], qlen; //1 实 2 空
int Rand(int x, int y) {
int A = rand(), B = rand();
return A * 1ll * B % (y - x + 1) + x;
}
int T;//ou->you
int daojulen;
int daoju[10];
int daojulen1;
int daoju1[10];
void build_gun() {
kong = Rand(1, 4);
shi = Rand(1, 4);
qlen = 0;
printf("%d发实弹,%d发空弹\n", shi, kong);
int a1 = kong, a2 = shi;
for (int i = 1; i <= kong + shi; i++) {
// Sleep(50);
int sum = Rand(1, a1 + a2);
if (sum <= a1) {
a1--;
q[++qlen] = 2;
} else {
a2--;
q[++qlen] = 1;
}
}
int maxn = min(4, 8 - daojulen);
printf("你获得了%d个道具:\n", maxn);
daojulen += maxn;
for (int i = 1; i <= maxn; i++) {
// Sleep(50);
int kkk = Rand(0, 4);
daoju[kkk]++;
cout << daojuname[kkk];
if (i != maxn) {
printf(",");
}
}
printf("\n");
maxn = min(4, 8 - daojulen1);
printf("恶魔获得了%d个道具:\n", maxn);
daojulen1 += maxn;
for (int i = 1; i <= maxn; i++) {
int kkk = Rand(0, 4);
daoju1[kkk]++;
cout << daojuname[kkk];
if (i != maxn) {
printf(",");
}
}
printf("\n");
system("pause");
system("cls");
}
void IsOver() {
if (Your <= 0) {
printf("你输了\n");
system("pause");
exit(0);
}
if (Other <= 0) {
printf("你赢了\n你获得了奖金$%.2lf\n", Yourmoney);
system("pause");
exit(0);
}
}
void wait() {
for (int i = 1; i <= 3; i++) {
Sleep(500);
printf(".");
}
Sleep(500);
}
int Hurt = 1;
int shoukao_you;
void Timeyou() {
int x;
while (1) {
printf("你的生命:%d/6\n恶魔生命:%d/6\n", Your, Other);
printf("剩余实弹数:%d 剩余空弹数:%d\n", shi, kong);
printf("你现在拥有的道具:\n");
for (int i = 0; i <= 4; i++) {
cout << daojuname[i];
printf("%d", daoju[i]);
printf("个");
if (i != 4) {
printf(",");
}
}
printf("\n");
printf("恶魔现在拥有的道具:\n");
for (int i = 0; i <= 4; i++) {
cout << daojuname[i];
printf("%d", daoju1[i]);
printf("个");
if (i != 4) {
printf(",");
}
}
printf("\n");
printf("现在是你的回合\n");
printf("你要\n1.向恶魔开枪\n2.向自己开枪\n");
for (int i=0;i<=4;i++){
printf("%d.使用",i+3);
cout<<daojuname[i]<<'\n';
}
x=read();
if(1<=x&&x<=7) break;
printf("输入不合法\n");
Sleep(1145);
system("cls");
}
if(x==1){
printf("你决定向恶魔开枪");
T++;
wait();
if (q[qlen] == 2) {
Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(shi)*1.0/(double)(shi+kong)));
kong--;
qlen--;
Hurt=1;
printf("是空弹\n");
if(shoukao_you==1){
shoukao_you=0;
printf("因为你使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}else{
// printf("((%lf))\n",Yourmoney);
Yourmoney+=(double)(5000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
// printf("{{%lf}}\n",Yourmoney);
shi--;
qlen--;
Other -= Hurt;
Hurt = 1;
printf("是实弹\n");
Sleep(500);
IsOver();
if (shoukao_you == 1) {
shoukao_you = 0;
Yourmoney += 1000.0;
printf("因为你使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}
} else if (x == 2) {
printf("你决定向自己开枪");
wait();
if (q[qlen] == 2) {
Yourmoney += (double)(2000.0 * (Hurt * 1.0) * (1 + (double)(kong) * 1.0 / (double)(shi + kong)));
kong--;
qlen--;
Hurt = 1;
printf("是空弹\n");
} else {
Yourmoney += 5000.0 * (1 + (double)(shi) * 1.0 / (double)(shi + kong));
T++;
shi--;
qlen--;
Your -= Hurt;
Hurt = 1;
printf("是实弹\n");
Sleep(500);
IsOver();
if (shoukao_you == 1) {
shoukao_you = 0;
printf("因为你使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}
} else if (x == 3) { //{"放大镜","手铐","小刀","烟","饮料"};
if (daoju[0]) {
daoju[0]--;
daojulen--;
printf("你使用了放大镜\n");
wait();
printf("\n你看到了");
if (q[qlen] == 1) {
printf("实弹\n");
Yourmoney += 2500.0;
} else {
printf("空弹\n");
}
Sleep(500);
printf("\n");
} else {
printf("你现在没有放大镜\n");
Sleep(1145);
system("cls");
}
} else if (x == 4) {
if (daoju[1]) {
if (!shoukao_you) {
daoju[1]--;
daojulen--;
printf("你使用了手铐\n");
printf("你获得了连开两枪的机会\n");
shoukao_you = 1;
} else {
printf("你已经用过手铐了\n");
}
Sleep(1145);
system("cls");
} else {
printf("你现在没有手铐\n");
Sleep(1145);
system("cls");
}
} else if (x == 5) {
if (daoju[2]) {
if (Hurt == 1) {
daoju[2]--;
daojulen--;
printf("你使用了小刀\n");
printf("若下一发为实弹则伤害+1\n");
Yourmoney += 500.0;
Hurt = 2;
} else {
printf("你已经用过小刀了\n");
}
Sleep(1145);
system("cls");
} else {
printf("你现在没有小刀\n");
Sleep(1145);
system("cls");
}
} else if (x == 6) {
if (daoju[3]) {
if (Your ^ 6) {
daoju[3]--;
daojulen--;
printf("你使用了烟\n");
printf("你回复了一点生命\n");
Yourmoney += 500.0;
Your++;
} else {
printf("你现在不需要烟\n");
}
Sleep(1145);
} else {
printf("你现在没有烟\n");
Sleep(1145);
system("cls");
}
} else {
if (daoju[4]) {
daoju[4]--;
daojulen--;
printf("你使用了饮料\n");
wait();
printf("\n");
printf("你退了一发");
if (q[qlen] == 2) {
printf("空弹");
kong--;
} else {
printf("实弹");
Yourmoney += 500.0;
shi--;
}
qlen--;
Sleep(500);
} else {
printf("你现在没有饮料\n");
Sleep(1145);
system("cls");
}
}
Sleep(1000);
system("cls");
}
int Know;//通过放大镜得知下一发子弹
int shoukaoemo;
void fightyou() {
printf("恶魔决定向你开枪");
T++;
wait();
if (q[qlen] == 2) {
Yourmoney += (double)(2000.0 * (Hurt * 1.0) * (1 + (double)(kong) * 1.0 / (double)(shi + kong)));
kong--;
qlen--;
Hurt = 1;
Know = 0;
printf("是空弹\n");
if (shoukaoemo) {
printf("因为恶魔使用了手铐,所以可以再来一次\n");
T--;
Sleep(500);
shoukaoemo = 0;
}
} else {
Yourmoney += (double)(5000.0 * (Hurt * 1.0) * (1 + (double)(kong) * 1.0 / (double)(shi + kong)));
shi--;
qlen--;
Your -= Hurt;
Hurt = 1;
printf("是实弹\n");
Know = 0;
Sleep(500);
IsOver();
if (shoukaoemo) {
printf("因为恶魔使用了手铐,所以可以再来一次\n");
Yourmoney += 1000.0;
T--;
Sleep(500);
shoukaoemo = 0;
}
}
}
void fightemo() {
printf("恶魔决定向自己开枪");
wait();
if (q[qlen] == 2) {
Yourmoney += 2000.0 * (1 + (double)(shi) * 1.0 / (double)(shi + kong));
kong--;
qlen--;
printf("是空弹\n");
Know = 0;
} else {
Yourmoney += 5000.0 * (1 + (double)(kong) * 1.0 / (double)(shi + kong));
shi--;
T++;
qlen--;
Other -= Hurt;
Hurt = 1;
printf("是实弹\n");
Know = 0;
Sleep(500);
IsOver();
if (shoukaoemo) {
printf("因为恶魔使用了手铐,所以可以再来一次\n");
T--;
Sleep(500);
shoukaoemo = 0;
}
}
}
void Timeother() {
printf("你的生命:%d/6\n恶魔生命:%d/6\n", Your, Other);
printf("剩余实弹数:%d 剩余空弹数:%d\n", shi, kong);
printf("你现在拥有的道具:\n");
for (int i = 0; i <= 4; i++) {
cout << daojuname[i];
printf("%d", daoju[i]);
printf("个");
if (i != 4) {
printf(",");
}
}
printf("\n");
printf("恶魔现在拥有的道具:\n");
for (int i = 0; i <= 4; i++) {
cout << daojuname[i];
printf("%d", daoju1[i]);
printf("个");
if (i != 4) {
printf(",");
}
}
printf("\n");
printf("现在是恶魔的回合\n");
Sleep(1500);
if (Other != 6) {
if (daoju1[3]) {
daoju1[3]--;
daojulen1--;
printf("恶魔使用了烟\n");
printf("恶魔回复了一点生命\n");
Other++;
Yourmoney += 500.0;
Sleep(1145);
system("cls");
return ;
}
}
if (Know == 0 && kong == 0) {
Know = 1;
}
if (Know == 0) {
if (abs(shi - kong) < 2 && kong != 0) {
if (daoju1[0]) {
daoju1[0]--;
daojulen1--;
printf("恶魔使用了放大镜\n");
wait();
printf("\n恶魔看到了");
if (q[qlen] == 1) {
printf("实弹");
Yourmoney += 2500.0;
Know = 1;
} else {
printf("空弹");
Know = 2;
}
Sleep(1145);
system("cls");
return ;
}
}
} else if (Know == 1) {
if (Hurt == 1 && daoju1[2]) {
daoju1[2]--;
daojulen1--;
Hurt++;
printf("恶魔使用了小刀\n");
printf("若下一发为实弹则伤害+1");
Yourmoney += 500.0;
Sleep(1145);
system("cls");
return ;
} else {
if (shi >= kong + 1 && daoju1[1] && shoukaoemo != 1) {
daoju1[1]--;
daojulen1--;
shoukaoemo = 1;
printf("恶魔使用了手铐\n");
printf("恶魔获得了连开两枪的机会\n");
Sleep(1145);
system("cls");
return ;
}
fightyou();
system("cls");
return ;
}
} else {
if (daoju1[4]) {
daoju1[4]--;
daojulen1--;
printf("恶魔使用了饮料\n");
wait();
printf("\n");
printf("恶魔退了一发");
if (q[qlen] == 2) {
printf("空弹");
kong--;
} else {
printf("实弹");
shi--;
}
Know = 0;
qlen--;
Sleep(500);
Sleep(1145);
system("cls");
return ;
} else {
fightemo();
Sleep(1145);
system("cls");
return ;
}
}
if(shi >= kong) fightyou();
else fightemo();
Sleep(1145);
system("cls");
}
void Play() {
while (1) {
if (shi == 0) {
build_gun();
T = 0;
continue;
}
if (T % 2 == 0) {
Timeyou();
} else {
Timeother();
}
}
}
void danrenplay() {
for (int i = 1; i <= 3; i++) {
printf(".");
// Sleep(1000);
}
printf("\n");
printf("又来了一位挑战者...\n");
Sleep(1000);
int x;
while (1) {
printf("准备好参与恶魔的游戏吗?胜者带走奖金,败者将会在此长眠\n1.好的\n2.没问题\n");
x=read();
if (x == 1 || x == 2) {
break;
}
printf("输入不合法\n");
Sleep(1145);
system("cls");
}
while (1) {
printf("你清楚我们的规则吗?\n1.清楚\n2.不清楚\n");
x=read();
if (x == 1 || x == 2) {
break;
}
printf("输入不合法\n");
Sleep(1145);
system("cls");
}
if (x == 1) {
} else {
for (int i = 1; i <= 3; i++) {
printf(".");
Sleep(1000);
}
printf("\n");
printf("规则:\n");
printf("你和恶魔都各有6点生命\n") ;
printf("每一回合开始前,你将知道一共有几发实弹,几发空弹,同时双方都将获得4个道具作为补给(上限为8个)\n");
printf("每一回合,你可以选择对自己开枪,对恶魔开枪或者使用道具\n");
printf("如果你对自己开枪,若为空弹,则可以继续行动,否则,停止行动\n");
printf("如果你对恶魔开枪,无论如何,都将停止行动\n");
printf("道具一览:\n");
printf("放大镜:可以知道下一发子弹是空弹还是实弹\n");
printf("手铐:增加一次本回合的行动次数\n");
printf("小刀:若下一发子弹为实弹,则伤害+1\n");
printf("烟:可以回复1点体力\n");
printf("饮料:可以退一发子弹\n");
system("pause");
system("cls");
}
printf("好吧\n");
Sleep(1145);
printf("游戏将要开始了哦\n");
Sleep(1145);
system("cls");
Play();
}
void IsOver_duo() {
if (Your <= 0) {
printf("玩家B赢了\n玩家B获得了奖金$%.2lf\n", Yourmoney);
system("pause");
exit(0);
} else if (Other <= 0) {
printf("玩家A赢了\n玩家A获得了奖金$%.2lf\n", Yourmoney);
system("pause");
exit(0);
}
}
void build_gun_duo() {
kong = Rand(1, 4);
shi = Rand(1, 4);
qlen = 0;
printf("%d发实弹,%d发空弹\n", shi, kong);
int a1 = kong, a2 = shi;
for (int i = 1; i <= kong + shi; i++) {
// Sleep(50);
int sum = Rand(1, a1 + a2);
if (sum <= a1) {
a1--;
q[++qlen] = 2;
} else {
a2--;
q[++qlen] = 1;
}
}
int maxn = min(2, 8 - daojulen);
printf("玩家A获得了%d个道具:\n", maxn);
daojulen += maxn;
for (int i = 1; i <= maxn; i++) {
// Sleep(50);
int kkk = Rand(0, 4);
daoju[kkk]++;
cout << daojuname[kkk];
if (i != maxn) {
printf(",");
}
}
printf("\n");
maxn = min(2, 8 - daojulen1);
printf("玩家B获得了%d个道具:\n", maxn);
daojulen1 += maxn;
for (int i = 1; i <= maxn; i++) {
int kkk = Rand(0, 4);
daoju1[kkk]++;
cout << daojuname[kkk];
if (i != maxn) {
printf(",");
}
}
printf("\n");
system("pause");
system("cls");
}
void Timeyou_duo() {
int x;
while (1) {
printf("玩家A的生命:%d/4\n玩家B的生命:%d/4\n", Your, Other);
printf("剩余实弹数:%d 剩余空弹数:%d\n", shi, kong);
printf("玩家A现在拥有的道具:\n");
for (int i = 0; i <= 4; i++) {
cout << daojuname[i];
printf("%d", daoju[i]);
printf("个");
if (i != 4) {
printf(",");
}
}
printf("\n");
printf("玩家B现在拥有的道具:\n");
for (int i = 0; i <= 4; i++) {
cout << daojuname[i];
printf("%d", daoju1[i]);
printf("个");
if (i != 4) {
printf(",");
}
}
printf("\n");
printf("现在是玩家A的回合\n");
printf("玩家A要\n1.向玩家B开枪\n2.向自己开枪\n");
for (int i = 0; i <= 4; i++) {
printf("%d.使用", i + 3);
cout << daojuname[i] << '\n';
}
x=read();
if (1 <= x && x <= 7) {
break;
}
printf("输入不合法\n");
Sleep(1145);
system("cls");
}
if (x == 1) {
printf("玩家A决定向玩家B开枪");
T++;
wait();
if (q[qlen] == 2) {
Yourmoney += (double)(2000.0 * (Hurt * 1.0) * (1 + (double)(shi) * 1.0 / (double)(shi + kong)));
kong--;
qlen--;
Hurt = 1;
printf("是空弹\n");
if (shoukao_you == 1) {
shoukao_you = 0;
printf("因为玩家A使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
} else {
// printf("((%lf))\n",Yourmoney);
Yourmoney += (double)(5000.0 * (Hurt * 1.0) * (1 + (double)(kong) * 1.0 / (double)(shi + kong)));
// printf("{{%lf}}\n",Yourmoney);
shi--;
qlen--;
Other -= Hurt;
Hurt = 1;
printf("是实弹\n");
Sleep(500);
IsOver_duo();
if (shoukao_you == 1) {
shoukao_you = 0;
Yourmoney += 1000.0;
printf("因为玩家A使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}
} else if (x == 2) {
printf("玩家A决定向自己开枪");
wait();
if (q[qlen] == 2) {
Yourmoney += (double)(2000.0 * (Hurt * 1.0) * (1 + (double)(kong) * 1.0 / (double)(shi + kong)));
kong--;
qlen--;
Hurt = 1;
printf("是空弹\n");
} else {
Yourmoney += 5000.0 * (1 + (double)(shi) * 1.0 / (double)(shi + kong));
T++;
shi--;
qlen--;
Your -= Hurt;
Hurt = 1;
printf("是实弹\n");
Sleep(500);
IsOver_duo();
if (shoukao_you == 1) {
shoukao_you = 0;
printf("因为玩家A使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}
} else if (x == 3) { //{"放大镜","手铐","小刀","烟","饮料"};
if (daoju[0]) {
daoju[0]--;
daojulen--;
printf("玩家A使用了放大镜\n");
wait();
printf("\n玩家A看到了");
if (q[qlen] == 1) {
printf("实弹\n");
Yourmoney += 2500.0;
} else {
printf("空弹\n");
}
Sleep(500);
printf("\n");
} else {
printf("玩家A现在没有放大镜\n");
Sleep(1145);
system("cls");
}
} else if (x == 4) {
if (daoju[1]) {
if (!shoukao_you) {
daoju[1]--;
daojulen--;
printf("玩家A使用了手铐\n");
printf("玩家A获得了连开两枪的机会\n");
shoukao_you = 1;
} else {
printf("玩家A已经用过手铐了\n");
}
Sleep(1145);
system("cls");
} else {
printf("玩家A现在没有手铐\n");
Sleep(1145);
system("cls");
}
} else if (x == 5) {
if (daoju[2]) {
if (Hurt == 1) {
daoju[2]--;
daojulen--;
printf("玩家A使用了小刀\n");
printf("若下一发为实弹则伤害+1\n");
Yourmoney += 500.0;
Hurt = 2;
} else {
printf("玩家A已经用过小刀了\n");
}
Sleep(1145);
system("cls");
} else {
printf("玩家A现在没有小刀\n");
Sleep(1145);
system("cls");
}
} else if (x == 6) {
if (daoju[3]) {
if (Your ^ 4) {
daoju[3]--;
daojulen--;
printf("玩家A使用了烟\n");
printf("玩家A回复了一点生命\n");
Yourmoney += 500.0;
Your++;
} else {
printf("玩家A现在不需要烟\n");
}
Sleep(1145);
} else {
printf("玩家A现在没有烟\n");
Sleep(1145);
system("cls");
}
} else {
if (daoju[4]) {
daoju[4]--;
daojulen--;
printf("玩家A使用了饮料\n");
wait();
printf("\n");
printf("玩家A退了一发");
if (q[qlen] == 2) {
printf("空弹");
kong--;
} else {
printf("实弹");
Yourmoney += 500.0;
shi--;
}
qlen--;
Sleep(500);
} else {
printf("玩家A现在没有饮料\n");
Sleep(1145);
system("cls");
}
}
Sleep(1000);
system("cls");
}
void Timeother_duo() {
int x;
while (1) {
printf("玩家A的生命:%d/4\n玩家B的生命:%d/4\n", Your, Other);
printf("剩余实弹数:%d 剩余空弹数:%d\n", shi, kong);
printf("玩家A现在拥有的道具:\n");
for (int i = 0; i <= 4; i++) {
cout << daojuname[i];
printf("%d", daoju[i]);
printf("个");
if (i != 4) {
printf(",");
}
}
printf("\n");
printf("玩家B现在拥有的道具:\n");
for (int i = 0; i <= 4; i++) {
cout << daojuname[i];
printf("%d", daoju1[i]);
printf("个");
if (i != 4) {
printf(",");
}
}
printf("\n");
printf("现在是玩家B的回合\n");
printf("玩家B要\n1.向玩家A开枪\n2.向自己开枪\n");
for (int i = 0; i <= 4; i++) {
printf("%d.使用", i + 3);
cout << daojuname[i] << '\n';
}
scanf("%d", &x);
if (1 <= x && x <= 7) {
break;
}
printf("输入不合法\n");
Sleep(1145);
system("cls");
}
if (x == 1) {
printf("玩家B决定向玩家A开枪");
T++;
wait();
if (q[qlen] == 2) {
Yourmoney += (double)(2000.0 * (Hurt * 1.0) * (1 + (double)(shi) * 1.0 / (double)(shi + kong)));
kong--;
qlen--;
Hurt = 1;
printf("是空弹\n");
if (shoukaoemo == 1) {
shoukaoemo = 0;
printf("因为玩家B使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
} else {
// printf("((%lf))\n",Yourmoney);
Yourmoney += (double)(5000.0 * (Hurt * 1.0) * (1 + (double)(kong) * 1.0 / (double)(shi + kong)));
// printf("{{%lf}}\n",Yourmoney);
shi--;
qlen--;
Your -= Hurt;
Hurt = 1;
printf("是实弹\n");
Sleep(500);
IsOver_duo();
if (shoukaoemo == 1) {
shoukaoemo = 0;
Yourmoney += 1000.0;
printf("因为玩家B使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}
} else if (x == 2) {
printf("玩家B决定向自己开枪");
wait();
if (q[qlen] == 2) {
Yourmoney += (double)(2000.0 * (Hurt * 1.0) * (1 + (double)(kong) * 1.0 / (double)(shi + kong)));
kong--;
qlen--;
Hurt = 1;
printf("是空弹\n");
} else {
Yourmoney += 5000.0 * (1 + (double)(shi) * 1.0 / (double)(shi + kong));
T++;
shi--;
qlen--;
Other -= Hurt;
Hurt = 1;
printf("是实弹\n");
Sleep(500);
IsOver_duo();
if (shoukao_you == 1) {
shoukao_you = 0;
printf("因为玩家B使用了手铐,所以可以再来一次\n");
Sleep(500);
T--;
}
}
} else if (x == 3) { //{"放大镜","手铐","小刀","烟","饮料"};
if (daoju1[0]) {
daoju1[0]--;
daojulen1--;
printf("玩家B使用了放大镜\n");
wait();
printf("\n玩家B看到了");
if (q[qlen] == 1) {
printf("实弹\n");
Yourmoney += 2500.0;
} else {
printf("空弹\n");
}
Sleep(500);
printf("\n");
} else {
printf("玩家B现在没有放大镜\n");
Sleep(1145);
system("cls");
}
} else if (x == 4) {
if (daoju1[1]) {
if (!shoukaoemo) {
daoju1[1]--;
daojulen1--;
printf("玩家B使用了手铐\n");
printf("玩家B获得了连开两枪的机会\n");
shoukaoemo = 1;
} else {
printf("玩家B已经用过手铐了\n");
}
Sleep(1145);
system("cls");
} else {
printf("玩家B现在没有手铐\n");
Sleep(1145);
system("cls");
}
} else if (x == 5) {
if (daoju1[2]) {
if (Hurt == 1) {
daoju1[2]--;
daojulen1--;
printf("玩家B使用了小刀\n");
printf("若下一发为实弹则伤害+1\n");
Yourmoney += 500.0;
Hurt = 2;
} else {
printf("玩家B已经用过小刀了\n");
}
Sleep(1145);
system("cls");
} else {
printf("玩家B现在没有小刀\n");
Sleep(1145);
system("cls");
}
} else if (x == 6) {
if (daoju1[3]) {
if (Other ^ 4) {
daoju1[3]--;
daojulen1--;
printf("玩家B使用了烟\n");
printf("玩家B回复了一点生命\n");
Yourmoney += 500.0;
Other++;
} else {
printf("玩家B现在不需要烟\n");
}
Sleep(1145);
} else {
printf("玩家B现在没有烟\n");
Sleep(1145);
system("cls");
}
} else {
if (daoju1[4]) {
daoju1[4]--;
daojulen1--;
printf("玩家B使用了饮料\n");
wait();
printf("\n");
printf("玩家B退了一发");
if (q[qlen] == 2) {
printf("空弹");
kong--;
} else {
printf("实弹");
Yourmoney += 500.0;
shi--;
}
qlen--;
Sleep(500);
} else {
printf("玩家B现在没有饮料\n");
Sleep(1145);
system("cls");
}
}
Sleep(1000);
system("cls");
}
int asdasd;
void duorenplay() {
while (1) {
if (shi == 0) {
build_gun_duo();
T = asdasd;
asdasd++;
continue;
}
if (T % 2 == 0) {
Timeyou_duo();
} else {
Timeother_duo();
}
}
}
int main(){
srand(time(0));
int x;
while(1){
printf("请选择你想要的模式:\n1.单人\n2.双人(此模式中,生命值为4,道具补给为2)\n");
x=read();
if(x==1||x==2) break;
printf("输入不合法\n");
Sleep(1145);
system("cls");
}
system("cls");
if(x==1) danrenplay();
else{
Your=Other=4;
duorenplay();
}
return 0;
}
3.愤怒的小鸟
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
using namespace std;
const double pi = 3.1415926536;
int toint(float a) {
return ((int) (a * 10 + 5)) / 10;
}
void Color (int a) {
if (a == 0 || a == 14 || a == 20) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
} else if (a == 1 || a == 12) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);
} else if (a == 2) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY | FOREGROUND_GREEN);
} else if (a == 3) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE);
} else if (a == 4 || a == 11) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY | FOREGROUND_RED);
} else if (a == 5 || a == 13) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
} else if (a == 7) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_GREEN | FOREGROUND_BLUE);
} else if (a == 15) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
} else if (a == 16) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_GREEN);
} else if (a == 17) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_RED);
} else if (a == 8) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
} else if (a == 6) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY | FOREGROUND_BLUE);
} else if (a == 9) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY | FOREGROUND_RED | BACKGROUND_RED | BACKGROUND_GREEN);
}
}
void SetPos (float x, float y) {
int xx = toint (x), yy = toint (y);
COORD pos;
pos.X = yy * 2;
pos.Y = xx;
SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), pos);
}
struct node {
int W, W2, S, mS;
float X, Y;
float vx, vy;
float ax, ay;
bool go, boom;
} blt[100001], pig[100001], boo[100001];
int T, yX, yY, Xy, put, K, K2, Sle, What;
int Bot, Pit, Blt, Pig, Sco, pigk, scok;
int m[41][41];
void Cout (int a, int x, int y) {
if (a == 1) {
SetPos (x, y);
Color (5);
cout << put << ' ';
}
if (y == 202) {
SetPos (pig[a].X, pig[a].Y);
cout << " ";
if ((pig[a].W == 2 || pig[a].W == 3) && pig[a].X >= 2) {
SetPos (pig[a].X - 2, pig[a].Y);
cout << " ";
SetPos (pig[a].X - 1, pig[a].Y);
cout << " ";
} else if (pig[a].W == 4) {
SetPos (pig[a].X, pig[a].Y - 1);
cout << " ";
} else if (pig[a].W == 5) {
SetPos (pig[a].X - 1, pig[a].Y);
cout << " ";
SetPos (pig[a].X - 1, pig[a].Y - 1);
cout << " ";
}
}
if (a == 2) {
for (int i = 0; i <= 40; i++) {
for (int j = 0; j <= 40; j++) {
if (i <= 18 && m[i][j] == 1) {
SetPos (i, j);
Color (7);
cout << "■";
}
if (m[i][j] >= 2 && m[i][j] <= 19) {
SetPos (i, j);
Color (5);
cout << "█";
m[i][j]++;
}
if (m[i][j] > 19 && m[i][j] <= 29) {
SetPos (i, j);
Color (0);
cout << "█";
m[i][j]++;
if (m[i][j] == 30) {
SetPos (i, j);
Color (0);
cout << " ";
m[i][j] = 0;
}
if (m[i][j] >= 31 && m[i][j] <= 49) {
SetPos (i, j);
Color (0);
cout << "■";
m[i][j]++;
}
if (m[i][j] == 50) {
SetPos (i, j);
Color (7);
cout << "■";
m[i][j] = 1;
}
}
}
}
}
if (y == 666) {
SetPos (blt[a].X, blt[a].Y);
Color (10 + blt[a].W);
cout << "●";
}
Color (0);
}
void Go (int a) {
SetPos (blt[a].X, blt[a].Y);
cout << " ";
blt[a].X += blt[a].vx / 2;
blt[a].Y += blt[a].vy / 2;
blt[a].vx += blt[a].ax / 2;
blt[a].vy += blt[a].ay / 2;
if (blt[a].X >= 20) {
blt[a].X = 19;
}
if (blt[a].X > 20 || blt[a].Y > 38 || blt[a].X < 0 || blt[a].Y <= 0) {
blt[a].go = 1;
}
if (blt[a].W2 == 1 && blt[a].Y >= Xy) {
blt[a].go = 1;
Sle = 0;//地跑鸟
}
if (blt[a].W2 == 0) {
for (int i = 0; i <= blt[a].vx / 2 + 1; i++) {
if (blt[a].vx > 0 && m[toint (blt[a].X) + i][toint (blt[a].Y)] == 1) {
if (blt[a].W != 5) {
blt[a].boom = 1;
}
blt[a].X = toint (blt[a].X) + i - 1;
blt[a].Y += blt[a].vy / 2;
blt[a].vx = -blt[a].vx * 0.4;
blt[a].vy = blt[a].vy * 0.8;
if (blt[a].W == 3) {
blt[a].ax = 0.5;
}
if (blt[a].W == 7) {
blt[a].vx *= 2;
}
if (blt[a].W == 10) {
blt[a].go = 1;
Bot++;
boo[Bot].X = blt[a].X;
boo[Bot].Y = blt[a].Y;
boo[Bot].S = 1;
boo[Bot].mS = 4;
}
}
if (blt[a].vx < 0 && m[toint (blt[a].X) - i][toint(blt[a].Y)] == 1) {
if (blt[a].W != 5) {
blt[a].boom = 1;
}
blt[a].X = toint (blt[a].X) + i + 1;
blt[a].Y += blt[a].vy / 2;
blt[a].vx = -blt[a].vx;
blt[a].vy = blt[a].vy * 0.8;
if (blt[a].W == 3) {
blt[a].ax = 0.5;
}
if (blt[a].W == 7) {
blt[a].vx *= 2;
}
if (blt[a].W == 10) {
blt[a].go = 1;
Bot++;
boo[Bot].X = blt[a].X;
boo[Bot].Y = blt[a].Y;
boo[Bot].S = 1;
boo[Bot].mS = 4;
}
}
}
if (abs (blt[a].vx) <= 0.1 && abs (blt[a].vy) <= 0.1 && abs (blt[a].ay) <= 0.1) {
blt[a].go = 1;
if (blt[a].W == 5) {
Bot++;
boo[Bot].X = blt[a].X;
boo[Bot].Y = blt[a].Y;
boo[Bot].S = 1;
boo[Bot].mS = 4;
blt[a].go = 1;
}
}
}
if (blt[a].go == 0) {
Cout (a, 0, 666);
}
}
void Kill (int a) {
if (pig[a].go == 0 && pig[a].W != 2 && pig[a].W != 3 && pig[a].Y < 16) {
Cout (a, 202, 202);
pig[a].Y = 16;
}
if (pig[a].go == 0 && pig[a].W == 4 && pig[a].Y < 20) {
pig[a].W = 1;
}
int R = rand () % 50;
Cout (a, 202, 202);
//清除猪猪
pig[a].X += pig[a].vx / 2;
pig[a].Y += pig[a].vy / 2;
pig[a].vx += pig[a].ax / 2;
pig[a].vy += pig[a].ay / 2;
for (int i = -2; i <= pig[a].vx / 2 + 1; i++) {
if (m[toint (pig[a].X) + i][toint (pig[a].Y)] == 1) {
pig[a].X = toint (pig[a].X) + i - 1;
pig[a].Y += pig[a].vy / 2;
pig[a].vx = -pig[a].vx * 0.5;
pig[a].vy = pig[a].vy * 0.8;
}
}
for (int i = Blt - 10; i <= Blt; i++) {
if (pig[a].W == 5 && blt[i].go == 0 && abs (pig[a].X - blt[i].X) <= 1
&& abs (pig[a].Y - blt[i].Y) <= 1) {
m[toint (pig[a].X) - 1][toint (pig[a].Y)] = 2;
pig[a].W2++;
Sco += 2;
break;
}
if (pig[a].W == 5 && m[toint (pig[a].X)][toint (pig[a].Y)] >= 2 &&
m[toint (pig[a].X)][toint (pig[a].Y)] < 30) {
m[toint (pig[a].X) - 1][toint (pig[a].Y)] = 2;
pig[a].W2++;
Sco += 2;
break;
}
if (blt[i].go == 0 && abs (pig[a].X - blt[i].X) <= 1 && abs (pig[a].Y - blt[i].Y) <= 1) {
if (pig[a].W == 6) {
Bot++;
boo[Bot].X = pig[a].X;
boo[Bot].Y = pig[a].Y;
boo[Bot].S = 1;
boo[Bot].mS = 4;
blt[i].go = 1;
}
m[toint (pig[a].X)][toint (pig[a].Y)] = 2;
pig[a].go = 1;
Pig--;
Sco += 10;
break;
}
if (m[toint (pig[a].X)][toint (pig[a].Y)] >= 2 &&
m[toint (pig[a].X)][toint (pig[a].Y)] < 30) {
if (pig[a].W == 6) {
Bot++;
boo[Bot].X = pig[a].X;
boo[Bot].Y = pig[a].Y;
boo[Bot].S = 1;
boo[Bot].mS = 4;
}
pig[a].go = 1;
Pig--;
Sco += 10;
break;
}
if ((pig[a].W == 2 || pig[a].W == 3) && blt[i].go == 0 &&
abs (pig[a].X - 2 - blt[i].X) <= 1 && abs (pig[a].Y - blt[i].Y) <= 1) {
m[toint (pig[a].X)][toint (pig[a].Y)] = 2;
pig[a].go = 1;
Pig--;
Sco += 10;
break;
}
if ((pig[a].W == 2 || pig[a].W == 3) &&
m[toint (pig[a].X - 2)][toint (pig[a].Y)] >= 2
&& m[toint (pig[a].X - 2)][toint (pig[a].Y)] < 30) {
pig[a].go = 1;
Pig--;
Sco += 10;
break;
}
}
//弄死猪猪
if (pig[a].go == 0) {
if (pig[a].go == 0 && pig[a].W != 2 && pig[a].W != 3 && pig[a].Y < 16) {
Cout (a, 202, 202);
pig[a].Y = 16;
}
if (pig[a].go == 0 && pig[a].W == 4 && pig[a].Y < 20) {
pig[a].W = 1;
}
int Xx = toint (pig[a].X), Xy = toint (pig[a].Y);
if (pig[a].W == 6) {
SetPos (pig[a].X, pig[a].Y);
Color (9);
cout << "TN";
Color (0);
} else {
SetPos (pig[a].X, pig[a].Y);
Color (2);
cout << "●";
if ((pig[a].W == 2 || pig[a].W == 3) && pig[a].X >= 2) {
SetPos (pig[a].X - 2, pig[a].Y);
Color (0);
cout << "○";
SetPos (pig[a].X - 1, pig[a].Y);
cout << "|";
} else if (pig[a].W == 4) {
SetPos (pig[a].X, pig[a].Y - 1);
Color (2);
cout << "﹃";
} else if (pig[a].W == 5) {
SetPos (pig[a].X - 1, pig[a].Y);
Color (8);
SetPos (pig[a].X - 1, pig[a].Y - 1);
cout << "▁";
if (pig[a].W2 == 0) {
cout << "▅";
} else if (pig[a].W2 == 1) {
cout << "▃";
} else if (pig[a].W2 == 2) {
cout << "▂";
} else if (pig[a].W2 == 3) {
pig[a].W = 1;
pig[a].W2 = 0;
SetPos (pig[a].X - 1, pig[a].Y - 1);
cout << " ";
}
}
}
//输出猪猪
if (pig[a].W == 2 && pig[a].X > pig[a].S) {
pig[a].W = 3;
pig[a].ax = -0.4;
pig[a].vx = 1.5;
} else if (pig[a].W == 3 && pig[a].X <= pig[a].S) {
pig[a].W = 2;
pig[a].ax = 0.4;
pig[a].vx = -1.5;
}
if ((pig[a].W == 2 || pig[a].W == 3) && (pig[a].Y <= 10 || pig[a].Y >= 38)) {
pig[a].vy *= -1;
}
if (pig[a].W == 4 && R == 0 && pig[a].X == 20) {
pig[a].vx = -((rand () % 40) / 10);
}
if (pig[a].W == 4) {
int r = rand () % 20;
for (int i = Blt - 10; i <= Blt; i++) {
if (r <= 5 && blt[i].go == 0 && pig[a].Y - blt[i].Y <= 5 &&
abs (blt[i].X - pig[a].X) <= 1.5 && r < 5) {
r = 0;
break;
}
}
if (r == 0) {
m[toint (pig[a].X)][toint (pig[a].Y) - 2] = 10;
m[toint (pig[a].X)][toint (pig[a].Y) - 3] = 2;
for (int j = toint (pig[a].Y) - 1; j >= toint (pig[a].Y) - 5; j--) {
for (int i = Blt - 10; i <= Blt; i++) {
if (blt[i].go == 0 && !(blt[i].W == 3 && blt[i].boom == 1)
&& blt[i].W2 == 0 && toint (blt[i].Y) == j
&& abs (blt[i].X - pig[a].X) <= 2) {
blt[i].vy = -2;
}
}
for (int i = Pit - 50; i <= Pit; i++) {
if (pig[i].go == 0 && toint (pig[i].Y) == j && abs (pig[i].X - pig[a].X) <= 2) {
pig[i].vy = -1;
}
}
}
}
}
//移动猪猪
if (pig[a].go == 0 && pig[a].W != 2 && pig[a].W != 3 && pig[a].Y < 16) {
Cout (a, 202, 202);
pig[a].Y = 16;
}
if (pig[a].go == 0 && pig[a].W == 4 && pig[a].Y < 20) {
pig[a].W = 1;
}
if (pig[a].X > 20 || pig[a].Y > 38 || pig[a].X < 0 || pig[a].Y <= 0) {
pig[a].go = 1;
Pig--;
Cout (a, 202, 202);
}
//清除猪猪
}
}
void Creat (int a, int p) {
if (a == -1 && p == -1) {
Blt++;
blt[Blt].W = What;
blt[Blt].W2 = 1;
blt[Blt].vy = 1;
blt[Blt].X = 19;
blt[Blt].Y = 0;
blt[Blt].boom = 1;
} else if (a == 0 && p == -1) {
int u = rand () % 7 + 1, U = rand() % 30;
if (u >= 5) {
Pit++;
pig[Pit].Y = rand () % 15 + 20;
pig[Pit].X = 2;
pig[Pit].ax = 0.5;
pig[Pit].W = 1;
} else if (u == 1) {
Pit++;
pig[Pit].Y = rand () % 15 + 20;
pig[Pit].X = 2;
pig[Pit].vy = 0.5;
pig[Pit].ax = 0.5;
pig[Pit].S = rand () % 5 + 7;
pig[Pit].W = 2;
} else if (u == 2) {
Pit++;
pig[Pit].Y = rand () % 15 + 20;
pig[Pit].X = 2;
pig[Pit].ax = 0.5;
pig[Pit].W = 4;
} else if (u == 3) {
Pit++;
pig[Pit].Y = rand () % 15 + 20;
pig[Pit].X = 2;
pig[Pit].ax = 0.5;
pig[Pit].W = 5;
} else if (u == 4) {
Pit++;
pig[Pit].Y = rand () % 15 + 20;
pig[Pit].X = 2;
pig[Pit].ax = 0.5;
pig[Pit].W = 6;
}
if (U == 1) {
Bot++;
boo[Bot].Y = rand () % 13 + 15;
boo[Bot].X = (rand () % 4) * 3 + 8;
boo[Bot].S = 0;
boo[Bot].mS = rand () % 2 + 2;
boo[Bot].W2 = 1;
}
} else {
Blt++;
blt[Blt].W = What;
if (a == 1) {
blt[Blt].X = yX;
blt[Blt].Y = yY;
blt[Blt].ax = 0.5; //抛物线
}
blt[Blt].vx = -3.5 * sin (p * pi / 180);
blt[Blt].vy = 3 * cos (p * pi / 180);
if (p <= 45) {
blt[Blt].vy *= 1 + (0.33 - 0.01 * (45 - p));
}
if (p >= 45) {
blt[Blt].vy *= 1 + (0.33 - 0.01 * (p - 45));
}
if (blt[Blt].W == 6) {
blt[Blt].vy *= 1.2;
blt[Blt].ax = 0.4;
}
}
}
void Boom (int a) {
if (boo[a].W2 == 0) {
int ms = boo[a].mS, s = boo[a].S, x = boo[a].X, y = boo[a].Y;
if (s == ms) {
return ;
}
for (int i = x - s; i <= x + s; i++) {
for (int j = y - s; j <= y + s; j++) {
float k = (i - x) * (i - x) + (j - y) * (j - y) - s * s;
if (k <= s && k >= -s && i <= 20 && j <= 38 && i >= 0 && j > 0 && m[i][j] != 1) {
m[i][j] = 2;
}
}
}
boo[a].S++;
}
if (boo[a].W2 == 1) {
int ms = boo[a].mS, s = boo[a].S, x = boo[a].X, y = boo[a].Y;
if (s == ms) {
return ;
}
if (y - s > 10) {
m[x][y - s] = 31 - 31 * (boo[a].W2 - 1);
}
if (y + s < 40) {
m[x][y + s] = 31 - 31 * (boo[a].W2 - 1);
}
boo[a].S++;
}
}
void Move (int a) {
Color (5);
if (a == -2) {
SetPos (17, Xy);
cout << " ";
SetPos (18, Xy);
cout << " ";
SetPos (19, Xy);
cout << " ";
SetPos (20, Xy);
cout << " ";
}
if (a == -1) {
SetPos (17, Xy);
cout << " ";
SetPos (18, Xy);
cout << " ┃ ┃";
SetPos (19, Xy);
cout << " ╰┳╯";
SetPos (20, Xy);
cout << " ▏";
}
if (a == 0) {
SetPos (18, Xy);
cout << " ┃";
Color (What + 10);
cout << "●";
Color (5);
cout << "┃";
SetPos (19, Xy);
cout << " ╰┳╯";
SetPos (20, Xy);
cout << " ▏";
}
if (a == 1) {
SetPos (18, Xy);
cout << " ";
Color (What + 10);
cout << "●";
Color (5);
cout << " ┃";
SetPos (19, Xy);
cout << " ╰┳╯";
SetPos (20, Xy);
cout << " ▏";
}
if (a == 2) {
SetPos (18, Xy);
Color (What + 10);
cout << "●";
Color (5);
cout << "┃ ┃";
SetPos (19, Xy);
cout << " ╰┳╯";
SetPos (20, Xy);
cout << " ▏";
}
if (a == 3) {
SetPos (18, Xy);
cout << " ┃ ┃";
SetPos (19, Xy);
Color (What + 10);
cout << "●";
Color (5);
cout << "╰┳╯";
SetPos (20, Xy);
cout << " ▏";
}
if (a == 4) {
SetPos (18, Xy);
cout << " ┃ ┃";
SetPos (19, Xy);
cout << " ╰┳╯";
SetPos (20, Xy);
Color (What + 10);
cout << "●";
Color (5);
cout << " ▏";
}
if (a == 5) {
SetPos (18, Xy);
cout << " ┃ ┃";
SetPos (19, Xy);
cout << " ╰┳╯";
SetPos (20, Xy);
cout << " ";
Color (What + 10);
cout << "●";
Color (5);
cout << " ▏";
}
if (a == 6) {
SetPos (18, Xy);
cout << " ┃ ┃";
SetPos (19, Xy);
cout << " ╰┳╯";
SetPos (20, Xy);
cout << " ";
Color (What + 10);
cout << "●";
Color (5);
cout << " ";
}
Color (0);
}
void Start () {
char g;
Color (5);
system ("cls");
SetPos (1, 1);
cout << "------- 愤 怒 的 小 鸟 -------";
Color (0);
SetPos (3, 1);
cout << "空格瞄准,按X触发小鸟技能,←→移动弹弓";
SetPos (5, 1);
cout << "猪猪技能自动触发,空中会有墙出现。";
SetPos (7, 1);
cout << "危险值由命中率,猪的存活时间计算!";
SetPos (9, 1);
cout << "危险值点满后失败!1500分通关!";
SetPos (1, 20);
cout << "-------- 小 鸟 技 能 --------";
SetPos (3, 20);
Color (11);
cout << "●";
Color (0);
cout << ":无技能";
SetPos (5, 20);
Color (12);
cout << "●";
Color (0);
cout << ":分身!不同分身初速度大小相同,";
SetPos(6, 20);
cout << " 方向不同。";
SetPos (7, 20);
Color (13);
cout << "●";
Color (0);
cout << ":加速!以当前速度做匀速直线运动,";
SetPos (8, 20);
cout << " 且免疫狙击猪的冲击。";
SetPos (9, 20);
Color (14);
cout << "●";
Color (0);
cout << ":投蛋!并获得向上速度做匀速直线";
SetPos (10, 20);
cout << " 运动,快达可以穿墙。";
SetPos (11, 20);
Color (15);
cout << "●";
Color (0);
cout << ":爆炸!";
SetPos (13, 20);
Color (16);
cout << "●";
Color (0);
cout << ":回旋!开始做向左加速运动!发射";
SetPos (14, 20);
cout << " 时获得双倍水平速度。";
SetPos (15, 20);
Color (17);
cout << "●";
Color (0);
cout << ":[被动] 弹跳力为普通鸟三倍。发射";
SetPos (16, 20);
cout << " 时获得1.5倍水平、竖直速度。";
SetPos (11, 1);
cout << "-------- 猪 猪 技 能 --------";
SetPos (13, 2);
Color (2);
cout << "●";
Color (0);
cout << ":无技能";
SetPos (14, 1);
Color (8);
cout << "▁▅";
SetPos (15, 2);
Color (2);
cout << "●";
Color (0);
cout << ":防御力为普通猪三倍";
SetPos (16, 2);
cout << "○";
SetPos (17, 2);
cout << "│:做空中简谐运动,受死范围";
SetPos (18, 2);
Color (2);
cout << "●";
Color (0);
cout << " 为普通猪两倍。";
SetPos (19, 2);
cout << " 有几率跳起或发射冲击波,冲";
SetPos (20, 1);
Color (2);
cout << "﹃●";
Color (0);
cout << ":开小鸟与同类,可以引爆TNT!";
SetPos (18, 20);
Color (5);
cout << "按 y 开始游戏!";
A:
if (kbhit ()) {
g = _getch ();
}
if (g != 'y') {
goto A;
}
}
int main () {
system ("mode con cols=79 lines=22");
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cursor_info);
srand ((unsigned)time(NULL));
St:
Start ();
system ("cls");
memset (blt, 0, sizeof (blt));
memset (pig, 0, sizeof (pig));
memset (boo, 0, sizeof (boo));
memset (m, 0, sizeof (m));
T = put = K = K2 = Sle = What = Pig = Sco = 0;
pigk = scok = -1;
Xy = 4;
yX = 18;
yY = 6;
Blt = 20;
Bot = 20;
Pit = 60;
Color (7);
SetPos (19, 14);
cout << "■";
SetPos (20, 13);
cout << " █▍";
m[19][14] = m[20][13] = m[20][14] = 1;
SetPos (21, 0);
for (int i = 0; i < 39; i++) {
cout << "■";
m[21][i] = 1;
}
Color (0);
What = rand () % 5 + 1;
while (1) {
if (Sco >= 1500) {
break;
}
T++;
K = 0;
Color (0);
if (Sco != scok) {
SetPos (1, 1);
cout << "分数:" << Sco << ' ';
}
if (Pig != pigk) {
SetPos (3, 1);
cout << "危险值:";
int aa = min (Sco / 100, 10);
Pig += aa;
SetPos (3, 5);
if (Pig <= 2) {
Color (2);
} else if (Pig <= 4) {
Color (16);
} else if (Pig <= 6) {
Color (7);
} else if (Pig <= 9) {
Color (6);
} else if (Pig <= 12) {
Color (3);
} else if (Pig <= 15) {
Color (17);
} else {
Color (11);
}
for (int i = 1; i <= Pig; i++) {
cout << "■";
}
Color (0);
cout << ' ' << Pig;
for (int i = 1; i <= 5; i++) {
cout << " ";
}
if (Pig > 18) {
break;
}
Pig -= aa;
}
scok = Sco;
pigk = Pig;
if (GetAsyncKeyState (VK_LEFT) & 0x8000 && Xy > 0) {
Move (-2);
Xy--;
K = 1;
}
if (GetAsyncKeyState (VK_RIGHT) & 0x8000 && Xy < 10) {
Move (-2);
Xy++;
K = 1;
}
if (K == 1) {
if (put == 0 && Sle == 0) {
Move (0);
} else {
Move (-1);
}
}
if (kbhit ()) {
char g = _getch ();
if (g == 'x' || g == 'X') {
for (int i = Blt - 10; i <= Blt; i++) {
if (blt[i].go == 0 && blt[i].boom == 0 && blt[i].W != 1 && blt[i].W != 7) {
blt[i].boom = 1;
if (blt[i].W == 2) {
Blt++;
blt[Blt].W = 2;
blt[Blt].vy = blt[i].vy * 1.2;
blt[Blt].vx = blt[i].vx + 1;
blt[Blt].ax = blt[i].ax;
blt[Blt].X = blt[i].X;
blt[Blt].Y = blt[i].Y;
blt[Blt].boom = 1;
Blt++;
blt[Blt].W = 2;
blt[Blt].vy = blt[i].vy * 0.7;
blt[Blt].vx = blt[i].vx - 1;
blt[Blt].ax = blt[i].ax;
blt[Blt].X = blt[i].X;
blt[Blt].Y = blt[i].Y;
blt[Blt].boom = 1;
}
if (blt[i].W == 3) {
blt[i].vy = fmax (blt[i].vy * 1.5, 2.5);
blt[Blt].vx++;
blt[i].ax = 0;
}
if (blt[i].W == 4) {
blt[i].vx = -3;
blt[i].ax = 0.1;
Blt++;
blt[Blt].boom = 1;
blt[Blt].W = 10;
blt[Blt].X = blt[i].X;
blt[Blt].Y = blt[i].Y;
blt[Blt].ax = blt[i].ax;
blt[Blt].vx = 1;
}
if (blt[i].W == 5) {
Bot++;
boo[Bot].X = blt[i].X;
boo[Bot].Y = blt[i].Y;
boo[Bot].S = 1;
boo[Bot].mS = 5;
blt[i].go = 1;
}
if (blt[i].W == 6) {
blt[i].ay = -1;
blt[i].ax = 0.3;
blt[i].vx = min (blt[i].vx / 2, (float)0);
}
break;
}
}
}
}
if (GetAsyncKeyState (' ') & 0x8000 && K == 0 && Sle == 0) {
if (put <= 5) {
Move (1);
yX = 18;
yY = Xy + 1;
} else if (put <= 20) {
Move (2);
yX = 18;
yY = Xy;
} else if (put <= 40) {
Move (3);
yX = 19;
yY = Xy;
} else if (put <= 60) {
Move (4);
yX = 20;
yY = Xy;
} else if (put <= 80) {
Move (5);
yX = 20;
yY = Xy + 1;
} else {
Move (6);
yX = 20;
yY = Xy + 2;
}
if (put == 0) {
K2 = 1;
}
if (put == 90) {
K2 = -1;
}
if (K2 == 1) {
put += min (rand () % 7 + 1, 90 - put);
}
if (K2 == -1) {
put -= min(rand() % 7 + 1, put);
}
Cout (1, 17, Xy + 2);
}
if ((!(GetAsyncKeyState (' ') & 0x8000) && (put != 0)) || (put != 0 && K == 1)) {
Move (-1);
Creat (1, put);
put = 0;
yX = 18;
yY = 5;
Sle = 1;
What = rand () % 7 + 1;
Creat (-1, -1);
Sco = max (Sco - 5, 0);
}
for (int i = Blt - 10; i <= Blt; i++) {
if (blt[i].go == 0) {
Go (i);
}
}
for (int i = Bot - 10; i <= Bot; i++) {
if (boo[i].go == 0) {
Boom (i);
Cout (2, 0, 0);
}
}
for (int i = Pit - 50; i <= Pit; i++) {
if (pig[i].go == 0) {
Kill (i);
}
}
if (Sle != 0) {
Move (-1);
} else if (put == 0) {
Move (0);
}
if (T % 300 == 0) {
system ("cls");
pigk = scok = -1;
}
if (T % 100 == 0) {
Color (7);
for (int i = 0; i <= 18; i++) {
for (int j = 0; j <= 40; j++) {
if (m[i][j] == 1 && T % 100 == 0) {
SetPos (i, j);
cout << "■";
}
}
}
SetPos (19, 14);
cout << "■";
SetPos (20, 13);
cout << " █▍";
SetPos (21, 0);
for (int i = 0; i < 39; i++) {
cout << "■";
Color (0);
}
}
if (T % min (50, (2000 - Sco) / 30) == 0) {
Pig++;
Creat (0, -1);
}
Sleep (30);
}
if (Sco < 1500) {
if (MessageBox (NULL, "很遗憾,您输了,您还想再来一次吗?", "温馨提示", MB_YESNO) == IDYES) {
goto St;
} else {
return 0;
}
} else {
if (MessageBox (NULL, "恭喜您赢了!您还想再来一次吗?", "温馨提示", MB_YESNO) == IDYES) {
goto St;
} else {
return 0;
}
}
return 0;
}
0 条评论
目前还没有评论...