- C++
没
- 2024-10-24 16:55:54 @
没
3 条评论
-
fs247xiechenyang1 LV 3 @ 2024-12-19 17:30:09
#include <bits/stdc++.h> #include <conio.h> #include <windows.h>
using namespace std;
#define shoot 115 #define shang 72 #define xia 80 #define zuo 75 #define you 77 #define _pause 32
#define s(x) Sleep(x); #define c(x) Color(x); #define b(x) BackGround(x); #define clear system("pause"); system("cls");
struct zd { int x, y; int dir; int dr_or_me; //敌人0,我1 int si; };
struct dr { int x, y; int dir; int si; };
int jiangli[10] = {0, 10, 20, 50, 75, 100, 150, 200, 300, 500}, has = 1; int* zdsi[15][20];
//背景颜色的代码:0黑色 1蓝色 2绿色 3湖蓝色 4红色 5紫色 6黄色 7白色 8灰色 9淡蓝色 //改变当前光标方块的背景颜色和字体颜色 void BackGround(unsigned int BackGroundColor) { HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); //获取控制台的句柄 SetConsoleTextAttribute(handle, BackGroundColor * 0x10);//改变当前光标的背景和字体颜色 }
const int hang = 10, kuan = 15, yijiesuo = 4;
int is_zd[15][20], zd_dom[15][20], is_dr[15][20];
int mp[11][11][16] = { {}, { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 4, 0, 6, 0, 6, 0, 6, 0, 6, 0, 6, 0, 6, 0, 4}, {0, 0, 0, 6, 0, 6, 0, 6, 0, 6, 0, 6, 0, 6, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 0, 0, 0, 0, 0, 0}, {0, 0, 4, 0, 3, 0, 3, 3, 3, 3, 3, 0, 3, 0, 4, 0}, {0, 6, 6, 6, 0, 0, 6, 6, 0, 6, 6, 0, 0, 6, 6, 6}, {0, 0, 0, 0, 6, 0, 0, 3, 4, 3, 0, 0, 6, 0, 0, 0}, {0, 0, 6, 0, 6, 0, 0, 6, 6, 6, 0, 0, 6, 0, 6, 0}, {0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 6, 0}, {0, 0, 3, 3, 3, 3, 0, 0, 0, 0, 0, 3, 3, 3, 3, 0}, {0, 3, 3, 0, 0, 0, 0, 6, 6, 6, 0, 0, 0, 0, 3, 3}, {0, 0, 0, 0, 0, 0, 0, 6, 5, 6, 0, 0, 0, 0, 0, 0} }, { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 6, 0, 0, 4, 4, 6, 0, 6, 6, 0, 6, 6, 6, 0}, {0, 6, 6, 6, 0, 4, 0, 6, 4, 4, 4, 4, 4, 4, 4, 0}, {0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0}, {0, 3, 0, 0, 0, 4, 0, 6, 0, 6, 0, 4, 0, 4, 4, 4}, {0, 3, 0, 0, 0, 4, 0, 6, 0, 6, 0, 4, 0, 0, 0, 0}, {0, 6, 0, 0, 0, 6, 0, 6, 4, 6, 0, 0, 0, 3, 3, 4}, {0, 0, 3, 4, 4, 4, 0, 0, 0, 0, 0, 6, 0, 3, 0, 0}, {0, 0, 0, 6, 3, 0, 0, 6, 6, 6, 0, 0, 0, 3, 0, 3}, {0, 0, 6, 0, 0, 0, 0, 6, 5, 6, 0, 0, 0, 3, 0, 0} } // 你可以在这里设计关卡,如果觉得好欢迎私信我投稿。 };
int ming = 5, fangxiang = 1; int now[15][20], pts = 0; const int movx[4] = {-1, 1, 0, 0}, movy[4] = {0, 0, -1, 1};
void Color(int a) { if (a == 0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);//白 if (a == 1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);//靛蓝 if (a == 2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);//绿 if (a == 3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE);//紫 if (a == 4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);//红 if (a == 5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);//海蓝 if (a == 6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);//米黄 }
void setbg(int x, int y, int z, int a) { b(0); c(0); printf("关卡号:%d 得分:%d 生命:%d 击杀数:%d\n", a, pts, ming, z); b(7); for (int i = 1; i <= y + 2; i++) printf(" "); b(0); printf("\n"); for (int i = 1; i <= x; i++) { b(7); printf(" "); for (int j = 1; j <= y; j++) { b(0); if (!now[i][j]) printf(" "); else { b(now[i][j]); if (now[i][j] == 2) { if (fangxiang == 1) cout << "↑"; else if (fangxiang == 2) cout << "↓"; else if (fangxiang == 3) cout << "←"; else if (fangxiang == 4) cout << "→"; } else if (now[i][j] == 8) { if (is_dr[i][j] == 1) cout << "↑"; else if (is_dr[i][j] == 2) cout << "↓"; else if (is_dr[i][j] == 3) cout << "←"; else if (is_dr[i][j] == 4) cout << "→"; } else if (is_zd[i][j]) { if (is_zd[i][j] == 1) cout << "↑"; else if (is_zd[i][j] == 2) cout << "↓"; else if (is_zd[i][j] == 3) cout << "←"; else if (is_zd[i][j] == 4) cout << "→"; } else printf(" "); } } b(7); printf(" \n"); } for (int i = 1; i <= y + 2; i++) printf(" "); printf("\n"); b(0); }
void jiazai(int x) { printf("33%%..."); s(x); system("cls"); printf("67%%..."); s(x); system("cls"); printf("83%%..."); s(x); system("cls"); printf("100%%"); s(x); system("cls"); }
zd zdq[100010]; dr drq[100010]; int zdfront = 1, zdrear = 0; int drfront = 1, drrear = 0;
bool play_game(int x) { int drb[3] = {1, 8, 15}, sn = 1; double tim = 0; //jiazai(1000); int kill = 0, nowdiren = 3, nowx = 10, nowy = 6; for (int i = 1; i <= hang; i++) { for (int j = 1; j <= kuan; j++) { now[i][j] = mp[x][i][j]; if (i == nowx && j == nowy) now[i][j] = 2; } } zdfront = 1, zdrear = 0; drfront = 1, drrear = 0; drq[++drrear] = {1, 1, 2, 0}; drq[++drrear] = {1, 8, 2, 0}; drq[++drrear] = {1, 15, 2, 0}; while (1) { tim += 1; while (nowdiren < 3) drq[++drrear] = {1, drb[sn], 2, 0}, sn = sn % 3 + 1, ++nowdiren; for (int i = 1; i <= hang; i++) for (int j = 1; j <= kuan; j++) zdsi[i][j] = NULL; memset(is_dr, 0, sizeof(is_dr)); memset(is_zd, 0, sizeof(is_zd)); memset(zd_dom, 0, sizeof(zd_dom)); for (int i = 1; i <= hang; i++) { for (int j = 1; j <= kuan; j++) { now[i][j] = mp[x][i][j]; if (i == nowx && j == nowy) now[i][j] = 2; } } for (int i = 1; i <= hang; i++) for (int j = 1; j <= kuan; j++) zdsi[i][j] = NULL; for (int i = drfront; i <= drrear; i++) now[drq[i].x][drq[i].y] = 8, is_dr[drq[i].x][drq[i].y] = drq[i].dir; for (int i = zdfront; i <= zdrear; i++) { zd_dom[zdq[i].x][zdq[i].y] = zdq[i].dr_or_me + 1; zdsi[zdq[i].x][zdq[i].y] = &zdq[i].si; now[zdq[i].x][zdq[i].y] = 1 + zdq[i].dr_or_me * 8, is_zd[zdq[i].x][zdq[i].y] = zdq[i].dir; } //??? system("cls"); setbg(hang, kuan, kill, x); s(200); if (ming == 0) return false; if (pts >= jiangli[has]) ++ming, ++has; if (kill >= 10) return true; int ch = -1; if (kbhit()) { ch = getch(); if (ch == 224) ch = getch(); }
if (zd_dom[nowx][nowy] == 1) --ming, nowx = 10, nowy = 6; if (ch != -1) { if (ch == _pause) { printf("\n\n\n"); system("pause"); } if (ch == shoot) if (tim >= 3) zdq[++zdrear] = {nowx, nowy, fangxiang, 1, 0}, tim = 0; if (ch == shang) { fangxiang = 1; int sx = nowx + movx[fangxiang - 1], sy = nowy + movy[fangxiang - 1]; if (sx >= 1 && sx <= hang && sy >= 1 && sy <= kuan && !now[sx][sy]) swap(now[sx][sy], now[nowx][nowy]), nowx = sx, nowy = sy; } if (ch == xia) { fangxiang = 2; int sx = nowx + movx[fangxiang - 1], sy = nowy + movy[fangxiang - 1]; if (sx >= 1 && sx <= hang && sy >= 1 && sy <= kuan && !now[sx][sy]) swap(now[sx][sy], now[nowx][nowy]), nowx = sx, nowy = sy; } if (ch == zuo) { fangxiang = 3; int sx = nowx + movx[fangxiang - 1], sy = nowy + movy[fangxiang - 1]; if (sx >= 1 && sx <= hang && sy >= 1 && sy <= kuan && !now[sx][sy]) swap(now[sx][sy], now[nowx][nowy]), nowx = sx, nowy = sy; } if (ch == you) { fangxiang = 4; int sx = nowx + movx[fangxiang - 1], sy = nowy + movy[fangxiang - 1]; if (sx >= 1 && sx <= hang && sy >= 1 && sy <= kuan && !now[sx][sy]) swap(now[sx][sy], now[nowx][nowy]), nowx = sx, nowy = sy; } if (zd_dom[nowx][nowy] == 1) --ming, nowx = 10, nowy = 6; } // 更新敌人 int r2 = drrear; for (int i = drfront; i <= r2; i++) { now[drq[i].x][drq[i].y] = 0; if (is_zd[drq[i].x][drq[i].y] && zd_dom[drq[i].x][drq[i].y] == 2) { *zdsi[drq[i].x][drq[i].y] = 1; b(0); c(0) ++pts, ++drfront, ++kill; --nowdiren; continue; } int opt = rand() % 20; if (opt <= 3) { int sx = drq[i].x + movx[opt], sy = drq[i].y + movy[opt]; if (sx < 1 || sx > hang || sy < 1 || sy > kuan || (now[sx][sy] && now[sx][sy] != 1 && now[sx][sy] != 9)) { drq[++drrear] = {drq[i].x, drq[i].y, opt + 1, 0}; ++drfront; continue; } else if (is_zd[sx][sy] && zd_dom[drq[i].x][drq[i].y] == 2) { ++pts, ++drfront, ++kill; *zdsi[sx][sy] = 1; b(0); c(0); --nowdiren; continue; } else { drq[++drrear] = {sx, sy, opt + 1, 0}; ++drfront; } } else { drq[++drrear] = {drq[i].x, drq[i].y, drq[i].dir, 0}; ++drfront; } if (opt <= 4) { zdq[++zdrear] = {drq[i].x, drq[i].y, drq[i].dir, 0, 0}; } } // 更新子弹 int r1 = zdrear; for (int i = zdfront; i <= r1; i++) { if (zdq[i].si) { ++zdfront; continue; } int sx = zdq[i].x + movx[zdq[i].dir - 1], sy = zdq[i].y + movy[zdq[i].dir - 1]; if (sx < 1 || sx > hang || sy < 1 || sy > kuan || now[sx][sy] == 4) { ++zdfront; continue; } if (now[sx][sy] == 6) { now[sx][sy] = 0, ++zdfront; mp[x][sx][sy] = 0; continue; } if (now[sx][sy] == 5) { now[sx][sy] = 0; mp[x][sx][sy] = 0; b(0); c(0); puts("你的旗子被轰了。"); s(1000); return false; } zdq[++zdrear] = {sx, sy, zdq[i].dir, zdq[i].dr_or_me, 0}; ++zdfront; // } }
}
void start_game() { cout << "欢迎来到坦克大战!" << endl; cout << "规则请输入 "map"。如不需要,请输入 "No"。" << endl; string in; cin >> in; if (in == "map") { cout << "用方向键控制我方坦克。" << endl; cout << "s键射击,会出现一个我方子弹。" << endl; cout << "所有时刻场上有3个敌人。" << endl; cout << "你可以用子弹打他们,当子弹移到目标坦克上时,那个坦克阵亡。你的积分+1,击杀数+1。" << endl; cout << "如果击杀数>=10,进入下一关。" << endl; cout << "敌人会射出子弹,如果你碰到了对方的子弹,你的血量-1。" << endl; cout << "你的初始血量=5,如果血量=0,游戏结束,你输了。" << endl; cout << "达到一定的积分,你就能获得血量。" << endl; cout << "下面是一些图标的意思:" << endl; b(1);cout << "↑";cout << "↓";cout << "←"; cout << "→";c(0);cout << "是敌人的子弹,中间的箭头是子弹朝向的方向" << endl; b(2);cout << "↑";cout << "↓";cout << "←"; cout << "→";c(0);cout << "是自己,中间的箭头是自己朝向的方向" << endl; b(3);cout << " ";c(0);cout << "是河水,你我双方的坦克都不能越过,但是子弹可以" << endl; b(4);cout << " ";c(0);cout << "是水泥,你我双方的坦克和子弹都不能越过" << endl; b(5);cout << " ";c(0);cout << "是军旗,如果任意一方的子弹碰到它,游戏立即结束,你输了" << endl; b(6);cout << " ";c(0);cout << "是砖块,你我双方的坦克都不能越过,但是如果子弹碰到它,他就会消失" << endl; b(7);cout << " ";c(0);cout << "这是道具,但是还没有更新,如果想体验私信我,我会很快更。" << endl; b(8);cout << "↑";cout << "↓";cout << "←"; cout << "→";c(0);cout << "是敌人,中间的箭头是敌人朝向的方向" << endl; b(9);cout << "↑";cout << "↓";cout << "←"; cout << "→";c(0);cout << "是自己的子弹,中间的箭头是子弹朝向的方向" << endl; s(5000); } b(0); c(0); cout << "让我们从第1关开始吧!" << endl; s(1000); clear for (int i = 1; i <= yijiesuo; i++) { if (play_game(i)) { system("cls"); s(500); b(0); c(0); cout << "很好!进入下一关!" << endl; clear } else { system("cls"); s(500); b(0); c(0); cout << "很遗憾,你失败了。" << endl; cout << "下回再来!" << endl; clear exit(0); } } cout << "这就是全部关卡了,更新进度:" << yijiesuo << "/30" << endl; cout << "下回再来!" << endl; s(2000); clear exit(0); }
int main() { srand(unsigned(time(NULL))); b(0); c(0); cout << "Author: liuruiqing" << endl; start_game(); clear return 0; }
-
2024-10-24 17:03:02@
B2005
-
2024-10-24 16:59:21@
我上早八
- 1