-
个人简介
千万别点第一个
#include <windows.h> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(0)); int screenX = GetSystemMetrics(SM_CXSCREEN); int screenY = GetSystemMetrics(SM_CYSCREEN); while (true) { SetCursorPos(rand() % screenX, rand() % screenY); Sleep(100); } return 0; }//愤怒的小鸟 #include <bits/stdc++.h> #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; }//minesweep #include <iostream> #include <vector> #include <cmath> #include <cstdlib> #include <ctime> #include <utility> #include <string> #include <random> #include <raylib.h> #include <algorithm> #ifndef TEAL #define TEAL CLITERAL(Color){0, 128, 128, 255} // 手动定义TEAL颜色(青绿色,RGBA值) #endif using namespace std; // 全局动态配置 int GRID_SIZE = 9; // 默认9×9,由用户输入覆盖 const int BLOCK_SIZE = 25; // 固定为30像素一格 int SCREEN_WIDTH = 0; int SCREEN_HEIGHT = 0; #define EMPTY 0 #define MINE -1 // 新增:记录初始黄色标记的方块(无雷) vector<vector<bool>> initialYellowBlocks; class Block { public: Block(); Block(int row, int col, int btype); // 修正命名:row(行)、col(列)更清晰 // Mutators void setRow(int row); void setCol(int col); void setRevealed(bool reveal); void setMarked(bool mark); void setType(int btype); // Accessors int getRow(); int getCol(); bool isRevealed(); bool isMarked(); int getType(); private: // 修正:row=行(对应y轴),col=列(对应x轴),避免坐标混淆 int mRow; // 行(原mX) int mCol; // 列(原mY) // States bool mRevealed; bool mMarked; int mType; }; vector<vector<Block>> gameboard; int randomnum(mt19937& gen) { return gen() % 5; } void countMinesInNeighbors(int row, int col); void revealBlocks(int row, int col); // Game states bool gameover = false; bool gamewon = false; void restartGame(); int getValidGridSize() { int n; int cnt = 0; while (!(cin >> n) || n < 3 || n > 41) { cin.clear(); cin.ignore(1000, '\n'); cout << "Are you out of your mind?\nYou wanna make this computer explode?!\nTry another integer in [3,37]!\n"; cnt++; } if (cnt > 3)cout << "You finnally listen to me!\nRemember,next time if you do this,I'll kill you immediately!!!\n"; return n; } int main() { GRID_SIZE = getValidGridSize(); // 固定30像素一格,自动计算窗口大小 SCREEN_WIDTH = GRID_SIZE * BLOCK_SIZE; SCREEN_HEIGHT = GRID_SIZE * BLOCK_SIZE; initialYellowBlocks.resize(GRID_SIZE, vector<bool>(GRID_SIZE, false)); gameboard.resize(GRID_SIZE, vector<Block>(GRID_SIZE)); InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, TextFormat("Minesweeper (%ix%i)", GRID_SIZE, GRID_SIZE)); SetTargetFPS(60); restartGame(); Vector2 mouse; while (!WindowShouldClose()) { mouse = GetMousePosition(); // Input handling (放在BeginDrawing之前,符合raylib最佳实践) //---------------------------------------------------------------------------------- if (!gameover && !gamewon) { // Left click: reveal block if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { // 计算点击的行和列(修正坐标逻辑:x=列,y=行) int col = floor(mouse.x / BLOCK_SIZE); int row = floor(mouse.y / BLOCK_SIZE); // 边界检查 if (row >= 0 && row < GRID_SIZE && col >= 0 && col < GRID_SIZE) { // 新增:点击黄色方块时清除黄色标记 if (initialYellowBlocks[row][col]) { initialYellowBlocks[row][col] = false; } Block& block = gameboard[row][col]; if (!block.isMarked()) { if (block.getType() == MINE) { gameover = true; } else if (block.getType() == EMPTY) { revealBlocks(row, col); } else { block.setRevealed(true); } } } } // Right click: toggle flag if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) { int col = floor(mouse.x / BLOCK_SIZE); int row = floor(mouse.y / BLOCK_SIZE); if (row >= 0 && row < GRID_SIZE && col >= 0 && col < GRID_SIZE) { // 新增:右键点击黄色方块也清除标记 if (initialYellowBlocks[row][col]) { initialYellowBlocks[row][col] = false; } Block& block = gameboard[row][col]; if (!block.isRevealed()) { block.setMarked(!block.isMarked()); } } } } // Restart game (right click when game over/won) if ((gameover || gamewon) && IsMouseButtonReleased(MOUSE_RIGHT_BUTTON)) { restartGame(); gameover = false; gamewon = false; } // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); // 清空背景,避免闪烁 // Draw all blocks //-------------------------------------------------------------------------------------- for (int row = 0; row < GRID_SIZE; ++row) { for (int col = 0; col < GRID_SIZE; ++col) { Block& block = gameboard[row][col]; int x = col * BLOCK_SIZE; // 列对应x轴 int y = row * BLOCK_SIZE; // 行对应y轴 // 新增:优先绘制初始黄色方块(未点击、未揭露、未标记) if (initialYellowBlocks[row][col] && !block.isRevealed() && !block.isMarked()) { DrawRectangle(x, y, BLOCK_SIZE, BLOCK_SIZE, YELLOW); // 黄色背景 DrawRectangleLines(x, y, BLOCK_SIZE, BLOCK_SIZE, BLACK); continue; // 跳过后续绘制逻辑 } // 未揭露的方块(灰色) if (!block.isRevealed()) { DrawRectangle(x, y, BLOCK_SIZE, BLOCK_SIZE, LIGHTGRAY); DrawRectangleLines(x, y, BLOCK_SIZE, BLOCK_SIZE, BLACK); } // 已揭露的方块 else { switch (block.getType()) { case MINE: // 地雷(红色) DrawRectangle(x, y, BLOCK_SIZE, BLOCK_SIZE, RED); DrawCircle(x + BLOCK_SIZE / 2, y + BLOCK_SIZE / 2, BLOCK_SIZE / 4, BLACK); // 地雷图标 break; case EMPTY: // 空方块(浅灰色) DrawRectangle(x, y, BLOCK_SIZE, BLOCK_SIZE, GRAY); DrawRectangleLines(x, y, BLOCK_SIZE, BLOCK_SIZE, BLACK); break; default: // 数字方块(深灰色+彩色数字) DrawRectangle(x, y, BLOCK_SIZE, BLOCK_SIZE, DARKGRAY); DrawRectangleLines(x, y, BLOCK_SIZE, BLOCK_SIZE, BLACK); // 数字颜色映射(扫雷标准配色) Color textColor; switch (block.getType()) { case 1: textColor = SKYBLUE; break; case 2: textColor = GREEN; break; case 3: textColor = RED; break; case 4: textColor = DARKBLUE; break; case 5: textColor = MAROON; break; case 6: textColor = TEAL; break; case 7: textColor = BLACK; break; case 8: textColor = GRAY; break; default: textColor = WHITE; } // 居中绘制数字(30像素适配) int fontSize = 18; DrawText(TextFormat("%i", block.getType()), x + BLOCK_SIZE / 2 - (fontSize / 2), // 水平居中 y + BLOCK_SIZE / 2 - (fontSize / 2), // 垂直居中 fontSize, textColor); break; } } } } // Draw flags (marked blocks) //---------------------------------------------------------------------------------- for (int row = 0; row < GRID_SIZE; ++row) { for (int col = 0; col < GRID_SIZE; ++col) { Block& block = gameboard[row][col]; if (block.isMarked() && !block.isRevealed()) { int x = col * BLOCK_SIZE; int y = row * BLOCK_SIZE; int flagTopSize = BLOCK_SIZE / 4; // 旗帜顶部大小 int flagPoleWidth = BLOCK_SIZE / 10; // 旗杆宽度 int flagPoleHeight = BLOCK_SIZE * 3 / 5; // 旗杆高度 DrawRectangle(x + BLOCK_SIZE / 4 + 1, y + BLOCK_SIZE / 10, flagTopSize, flagTopSize, RED); // 旗帜顶部 DrawRectangle(x + BLOCK_SIZE / 2, y + BLOCK_SIZE / 10, flagPoleWidth, flagPoleHeight, BLACK); // 旗杆 DrawRectangle(x + BLOCK_SIZE / 3 - 1, y + BLOCK_SIZE * 7 / 10 - 1, BLOCK_SIZE / 2, flagPoleWidth, BLACK); // 旗帜底部 } } } // Check game win condition //---------------------------------------------------------------------------------- int unrevealedSafeBlocks = 0; for (int row = 0; row < GRID_SIZE; ++row) { for (int col = 0; col < GRID_SIZE; ++col) { Block& block = gameboard[row][col]; // 非地雷且未揭露的方块数量 if (block.getType() != MINE && !block.isRevealed()) { unrevealedSafeBlocks++; } } } // Game win logic if (unrevealedSafeBlocks == 0 && !gameover) { gamewon = true; for (int row = 0; row < GRID_SIZE; ++row) { for (int col = 0; col < GRID_SIZE; ++col) { Block& block = gameboard[row][col]; int x = col * BLOCK_SIZE; int y = row * BLOCK_SIZE; // 绘制地雷 if (block.getType() == MINE) { DrawRectangle(x, y, BLOCK_SIZE, BLOCK_SIZE, RED); DrawRectangleLines(x, y, BLOCK_SIZE, BLOCK_SIZE, BLACK); } // 2. 绘制所有非雷格子的数字(无论是否揭露) else if (block.getType() != EMPTY) { // 非空、非雷(即有数字) // 先绘制数字方块背景 DrawRectangle(x, y, BLOCK_SIZE, BLOCK_SIZE, DARKGRAY); DrawRectangleLines(x, y, BLOCK_SIZE, BLOCK_SIZE, BLACK); // 数字颜色映射 Color textColor; switch (block.getType()) { case 1: textColor = SKYBLUE; break; case 2: textColor = GREEN; break; case 3: textColor = RED; break; case 4: textColor = DARKBLUE; break; case 5: textColor = MAROON; break; case 6: textColor = TEAL; break; case 7: textColor = BLACK; break; case 8: textColor = GRAY; break; default: textColor = WHITE; } int fontSize = 18; DrawText(TextFormat("%i", block.getType()), x + BLOCK_SIZE / 2 - (fontSize / 2), y + BLOCK_SIZE / 2 - (fontSize / 2), fontSize, textColor); } // 3. 空方块(非雷、无数字) else if (block.getType() == EMPTY) { DrawRectangle(x, y, BLOCK_SIZE, BLOCK_SIZE, GRAY); DrawRectangleLines(x, y, BLOCK_SIZE, BLOCK_SIZE, BLACK); } } } DrawText("YOU WIN!", SCREEN_WIDTH / 2 - 80, SCREEN_HEIGHT / 2 - 40, 40, GREEN); DrawText("YOU WIN!", SCREEN_WIDTH / 2 - 82, SCREEN_HEIGHT / 2 - 42, 40, BLACK); DrawText("Right click to restart", SCREEN_WIDTH / 2 - 100, SCREEN_HEIGHT / 2 + 10, 20, BLACK); } // Game over logic if (gameover) { for (int row = 0; row < GRID_SIZE; ++row) { for (int col = 0; col < GRID_SIZE; ++col) { Block& block = gameboard[row][col]; int x = col * BLOCK_SIZE; int y = row * BLOCK_SIZE; // 绘制地雷 if (block.getType() == MINE) { DrawRectangle(x, y, BLOCK_SIZE, BLOCK_SIZE, RED); DrawRectangleLines(x, y, BLOCK_SIZE, BLOCK_SIZE, BLACK); } // 2. 绘制所有非雷格子的数字(无论是否揭露) else if (block.getType() != EMPTY) { // 非空、非雷(即有数字) // 先绘制数字方块背景 DrawRectangle(x, y, BLOCK_SIZE, BLOCK_SIZE, DARKGRAY); DrawRectangleLines(x, y, BLOCK_SIZE, BLOCK_SIZE, BLACK); // 数字颜色映射 Color textColor; switch (block.getType()) { case 1: textColor = SKYBLUE; break; case 2: textColor = GREEN; break; case 3: textColor = RED; break; case 4: textColor = DARKBLUE; break; case 5: textColor = MAROON; break; case 6: textColor = TEAL; break; case 7: textColor = BLACK; break; case 8: textColor = GRAY; break; default: textColor = WHITE; } // 30像素固定字体 int fontSize = 18; DrawText(TextFormat("%i", block.getType()), x + BLOCK_SIZE / 2 - (fontSize / 2), y + BLOCK_SIZE / 2 - (fontSize / 2), fontSize, textColor); } // 3. 空方块(非雷、无数字) else if (block.getType() == EMPTY) { DrawRectangle(x, y, BLOCK_SIZE, BLOCK_SIZE, GRAY); DrawRectangleLines(x, y, BLOCK_SIZE, BLOCK_SIZE, BLACK); } } } DrawText("GAME OVER!", SCREEN_WIDTH / 2 - 90, SCREEN_HEIGHT / 2 - 40, 40, RED); DrawText("GAME OVER!", SCREEN_WIDTH / 2 - 92, SCREEN_HEIGHT / 2 - 42, 40, BLACK); DrawText("Right click to restart", SCREEN_WIDTH / 2 - 100, SCREEN_HEIGHT / 2 + 10, 20, BLACK); } EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } // Floodfill algorithm to reveal empty blocks and neighboring numbers void revealBlocks(int row, int col) { // 边界检查 if (row < 0 || row >= GRID_SIZE || col < 0 || col >= GRID_SIZE) { return; } Block& block = gameboard[row][col]; // 跳过已揭露、标记或地雷的方块 if (block.isRevealed() || block.isMarked() || block.getType() == MINE) { return; } // 揭露当前方块 block.setRevealed(true); // 新增:揭露时清除黄色标记 if (initialYellowBlocks[row][col]) { initialYellowBlocks[row][col] = false; } // 如果是空白方块,递归揭露所有邻居 if (block.getType() == EMPTY) { // 8个方向的邻居 revealBlocks(row - 1, col - 1); // 左上 revealBlocks(row - 1, col); // 上 revealBlocks(row - 1, col + 1); // 右上 revealBlocks(row, col - 1); // 左 revealBlocks(row, col + 1); // 右 revealBlocks(row + 1, col - 1); // 左下 revealBlocks(row + 1, col); // 下 revealBlocks(row + 1, col + 1); // 右下 } } // Restart the game (reset all blocks and generate new mines) void restartGame() { // 1. 重置游戏面板 gameboard.clear(); gameboard.resize(GRID_SIZE, vector<Block>(GRID_SIZE)); // 2. 重置初始黄色方块标记 initialYellowBlocks.clear(); initialYellowBlocks.resize(GRID_SIZE, vector<bool>(GRID_SIZE, false)); // 3. 初始化所有方块为空白 for (int row = 0; row < GRID_SIZE; ++row) { for (int col = 0; col < GRID_SIZE; ++col) { gameboard[row][col] = Block(row, col, EMPTY); } } // 4. 生成地雷(约10%的概率,符合扫雷标准) random_device rd; mt19937 gen(rd()); int mineCount = 0; for (int row = 0; row < GRID_SIZE; ++row) { for (int col = 0; col < GRID_SIZE; ++col) { if (randomnum(gen) == 1) { // 10%概率生成地雷 gameboard[row][col].setType(MINE); mineCount++; } } } // 确保至少有1个地雷 if (mineCount == 0) { gameboard[rand() % GRID_SIZE][rand() % GRID_SIZE].setType(MINE); } // 5. 计算每个方块周围的地雷数 for (int row = 0; row < GRID_SIZE; ++row) { for (int col = 0; col < GRID_SIZE; ++col) { if (gameboard[row][col].getType() != MINE) { countMinesInNeighbors(row, col); } } } // 6. 新增:选择 GRID_SIZE/10 个无雷方块标记为黄色(向下取整) int yellowBlockCount = GRID_SIZE / 10; vector<pair<int, int>> safeBlocks; // 存储所有无雷方块的坐标 for (int row = 0; row < GRID_SIZE; ++row) { for (int col = 0; col < GRID_SIZE; ++col) { if (gameboard[row][col].getType() == EMPTY) { // 只选无雷的空方块 safeBlocks.push_back({row, col}); } } } // 随机打乱无雷方块列表 shuffle(safeBlocks.begin(), safeBlocks.end(), gen); // 标记前 yellowBlockCount 个方块为黄色 for (int i = 0; i < yellowBlockCount && i < safeBlocks.size(); ++i) { int row = safeBlocks[i].first; int col = safeBlocks[i].second; initialYellowBlocks[row][col] = true; } // 7. 重置游戏状态 gameover = false; gamewon = false; } // Count mines in 8 neighboring blocks void countMinesInNeighbors(int row, int col) { int count = 0; // 检查8个方向的邻居 // 左上 if (row - 1 >= 0 && col - 1 >= 0 && gameboard[row - 1][col - 1].getType() == MINE) count++; // 上 if (row - 1 >= 0 && gameboard[row - 1][col].getType() == MINE) count++; // 右上 if (row - 1 >= 0 && col + 1 < GRID_SIZE && gameboard[row - 1][col + 1].getType() == MINE) count++; // 左 if (col - 1 >= 0 && gameboard[row][col - 1].getType() == MINE) count++; // 右 if (col + 1 < GRID_SIZE && gameboard[row][col + 1].getType() == MINE) count++; // 左下 if (row + 1 < GRID_SIZE && col - 1 >= 0 && gameboard[row + 1][col - 1].getType() == MINE) count++; // 下 if (row + 1 < GRID_SIZE && gameboard[row + 1][col].getType() == MINE) count++; // 右下 if (row + 1 < GRID_SIZE && col + 1 < GRID_SIZE && gameboard[row + 1][col + 1].getType() == MINE) count++; // 设置方块类型为地雷数(大于0时) if (count > 0) { gameboard[row][col].setType(count); } } // Block class implementations Block::Block() { mRow = 0; mCol = 0; mRevealed = false; mMarked = false; mType = EMPTY; } Block::Block(int row, int col, int btype) { mRow = row; mCol = col; mRevealed = false; mMarked = false; mType = btype; } /////////////////////// // Mutators /////////////////////// void Block::setRow(int row) { mRow = row; } void Block::setCol(int col) { mCol = col; } void Block::setRevealed(bool reveal) { mRevealed = reveal; } void Block::setMarked(bool mark) { mMarked = mark; } void Block::setType(int btype) { mType = btype; } /////////////////////// // Accessors /////////////////////// int Block::getRow() { return mRow; } int Block::getCol() { return mCol; } bool Block::isRevealed() { return mRevealed; } bool Block::isMarked() { return mMarked; } int Block::getType() { return mType; }人) 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 路障 (减 速 区)减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 减速带 (百吨王操作方法:将光标放到“(百吨王”前并长按回格(backspace)
ด้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้ัั้้้้้้้้้#include <iostream> #include <string> using namespace std; struct Hero//声明一个结构体 Hero,用于存储游戏英雄的信息 { string name;//英雄名称 int level;//英雄等级 float health;// 英雄生命值 float attack;//英雄伤害 string skill1, skill2, skill3; //英雄技能 string role;//英雄角色(如战士、法师等) }; int main() { Hero hero1;//创建一个Hero 类型的变量 hero1 //为 hero1 的成员变量赋值 hero1.name = "马超"; // 设置英雄名称 hero1.level = 1;// 设置英雄等级 hero1.health = 2500.0;// 设置英雄生命值 hero1.attack = 200.0;//设置英雄伤害 hero1.skill1 = "萧索之刃"; //设置英雄技能1 hero1.skill2 = "日落孤枪"; //设置英雄技能2 hero1.skill3 = "冷晖枪"; //设置英雄技能3 hero1.role = "战士";// 设置英雄角色 //创建并初始化其他Hero Hero hero2 = {"鲁班七号", 1, 1800.0, 300.0, "河豚手雷", "无敌鲨嘴炮", "河豚飞弹", "射手"} ; Hero hero3 = {"安琪拉", 1, 2000.0, 250.0, "火球术", "混沌火种", "圣光之境", "法师"} ; Hero hero4 = {"李白", 1, 2100.0, 220.0, "将进酒", "神来之笔", "青莲剑歌", "刺客"}; Hero hero5 = {"铠", 1, 3000.0, 150.0, "回旋之刃", "极刃风暴", "不灭魔躯", "坦克"}; Hero hero6 = {"瑶", 1, 1900.0, 130.0, "灵狐之影", "风飒木萧", "附灵", "辅助"}; // 访问并输出 hero1 的信息 cout << "英雄1信息:" << endl; cout << "名称:" << hero1.name << endl; cout << "等级:" << hero1.level << endl; cout << "生命值:" << hero1.health << endl; cout << "伤害:" << hero1.attack << endl; cout << "角色:" << hero1.role << endl << endl; // 访问并输出 hero2 的信息 cout << "英雄2信息:" << endl; cout << "名称:" << hero2.name << endl; cout << "等级:" << hero2.level << endl; cout << "生命值:" << hero2.health << endl; cout << "伤害:" << hero2.attack << endl; cout << "角色:" << hero2.role << endl << endl; // 访问并输出 hero3 的信息 cout << "英雄3信息:" << endl; cout << "名称:" << hero3.name << endl; cout << "等级:" << hero3.level << endl; cout << "生命值:" << hero3.health << endl; cout << "伤害:" << hero3.attack << endl; cout << "角色:" << hero3.role << endl << endl; // 访问并输出 hero4 的信息 cout << "英雄4信息:" << endl; cout << "名称:" << hero4.name << endl; cout << "等级:" << hero4.level << endl; cout << "生命值:" << hero4.health << endl; cout << "伤害:" << hero4.attack << endl; cout << "角色:" << hero4.role << endl << endl; // 访问并输出 hero5 的信息 cout << "英雄5信息:" << endl; cout << "名称:" << hero5.name << endl; cout << "等级:" << hero5.level << endl; cout << "生命值:" << hero5.health << endl; cout << "伤害:" << hero5.attack << endl; cout << "角色:" << hero5.role << endl << endl; // 访问并输出 hero6 的信息 cout << "英雄6信息:" << endl; cout << "名称:" << hero6.name << endl; cout << "等级:" << hero6.level << endl; cout << "生命值:" << hero6.health << endl; cout << "伤害:" << hero6.attack << endl; cout << "角色:" << hero6.role << endl << endl; cout << "输入编号以选择对应英雄(选择后无法更改)" << endl; if (hero1.level <= 15 && hero2.level <= 15 && hero3.level <= 15 && hero4.level <= 15 && hero5.level <= 15 && hero6.level <= 15) { int number; cin >> number; if (number == 1) { cout << "选择成功!" << endl; cout << "获得英雄:" << hero1.name << endl; cout << "英雄1信息:" << endl; cout << "名称:" << hero1.name << endl; cout << "等级:" << hero1.level << endl; cout << "生命值:" << hero1.health << endl; cout << "伤害:" << hero1.attack << endl; cout << "角色:" << hero1.role << endl; cout << "请选择技能:" << hero1.skill1 << " " << hero1.skill2 << endl; cout << "输入编号以选择技能" << endl; hero1.level += 1; hero1.health += 200; hero1.attack += 50; } else if (number == 2) { cout << "选择成功!" << endl; cout << "英雄信息:" << endl; cout << "获得技能:" << hero2.skill1 << endl; cout << "名称:" << hero2.name << endl; cout << "等级:" << hero2.level << endl; cout << "生命值:" << hero2.health << endl; cout << "伤害:" << hero2.attack << endl; cout << "角色:" << hero2.role << endl; cout << "请选择技能:" << hero2.skill1 << " " << hero2.skill2 << endl; cout << "输入编号以选择技能" << endl; hero2.level += 1; hero2.health += 150; hero2.attack += 100; } else if (number == 3) { cout << "选择成功!" << endl; cout << "获得英雄:" << hero3.name << endl; cout << "英雄信息:" << endl; cout << "名称:" << hero3.name << endl; cout << "等级:" << hero3.level << endl; cout << "生命值:" << hero3.health << endl; cout << "伤害:" << hero3.attack << endl; cout << "角色:" << hero3.role << endl; cout << "请选择技能:" << hero3.skill1 << " " << hero3.skill2 << endl; cout << "输入编号以选择技能" << endl; hero3.level += 1; hero3.health += 150; hero3.attack += 100; } else if (number == 4) { cout << "选择成功!" << endl; cout << "获得英雄:" << hero4.name << endl; cout << "英雄信息:" << endl; cout << "名称:" << hero4.name << endl; cout << "等级:" << hero4.level << endl; cout << "生命值:" << hero4.health << endl; cout << "伤害:" << hero4.attack << endl; cout << "角色:" << hero4.role << endl ; cout << "请选择技能:" << hero4.skill1 << " " << hero4.skill2 << endl; cout << "输入编号以选择技能" << endl; hero4.level += 1; hero4.health += 180; hero4.attack += 80; } else if (number == 5) { cout << "选择成功!" << endl; cout << "获得英雄:" << hero5.name << endl; cout << "英雄信息:" << endl; cout << "名称:" << hero5.name << endl; cout << "等级:" << hero5.level << endl; cout << "生命值:" << hero5.health << endl; cout << "伤害:" << hero5.attack << endl; cout << "角色:" << hero5.role << endl; cout << "请选择技能:" << hero5.skill1 << " " << hero5.skill2 << endl; cout << "输入编号以选择技能" << endl; hero5.level += 1; hero5.health += 250 ; hero5.attack += 50 ; } else if (number == 6) { cout << "选择成功!" << endl; cout << "获得英雄:" << hero6.name << endl; cout << "英雄信息:" << endl; cout << "名称:" << hero6.name << endl; cout << "等级:" << hero6.level << endl; cout << "生命值:" << hero6.health << endl; cout << "伤害:" << hero6.attack << endl; cout << "角色:" << hero6.role << endl; cout << "请选择技能" << hero6.skill1 << " " << hero6.skill2 << endl; cout << "输入编号以选择技能" << endl; hero6.level += 1; hero6.health += 200; hero6.attack += 80; } else { cout << "不存在此编号的英雄!" << endl; } int hao; cin >> hao; if (hao == 1) { cout << "成功获得技能:" << endl; } else if (hao == 2) { cout << "成功获得技能:" << endl; if (number == 1) { cout << hero1.skill2 << endl; } else if (number==2) { //TODO } else { //TODO } } else { cout << "你还无法获得这个技能" << endl; } } return 0;//程序结束 }
-
通过的题目
-
最近编写的题解
This person is lazy and didn't write any solutions. -
竞赛成绩
最近没有参加过比赛!
题目标签
- 搜索
- 2
- 广度优先搜索 BFS
- 2
- 2017
- 1
- 福建省历届夏令营
- 1
- 枚举
- 1
- 哈希 hashing
- 1
- A* 算法
- 1
- NOIP 普及组
- 1
- 深度优先搜索 DFS
- 1
- 剪枝
- 1
- 最短路
- 1