-
个人简介
陈冕 1.猜数字
#include <iostream> #include <cstdlib> int main() { srand(time(0)); int secretNumber = rand() % 100 + 1; int guess = 0; int attempts = 0; std::cout << "猜数字游戏!我已经选择了一个1到100之间的数字。\n"; while (guess != secretNumber) { std::cout << "请输入你的猜测:"; std::cin >> guess; attempts++; if (guess < secretNumber) { std::cout << "太小了!再试一次。\n"; } else if (guess > secretNumber) { std::cout << "太大了!再试一次。\n"; } else { std::cout << "恭喜你!你猜对了!数字是 " << secretNumber << "。\n"; std::cout << "你总共尝试了 " << attempts << " 次。\n"; } } return 0; }
2.井字棋
#include <cstdio> #include <iostream> #include <algorithm> #include <cstdlib> #include <ctime> using namespace std; int s[5][5] = {}; // 网格上的小盒子 0 无 -1 电脑 +1 玩家 下同 int m[5][5] = {}; // 网格上的中盒子 int l[5][5] = {}; // 网格上的大盒子 int p1[4] = {0, 2, 2, 2}, p2[4] = {0, 2, 2, 2}; // 电脑和玩家的①小②中③大盒个数 int p[5][5] = {}; // 当前网格被谁占据 int px[2][5], py[2][5], bx[3], by[3]; struct node { int x, y, h; } aa[15]; bool cmp(node a, node b) { return a.h > b.h; } // 输出当前网格 void showSquare() { // 计算当前网格被谁的盒子占据 int a[5][5] = {}; // 当前网格上的盒子 + - 表示角色 数字表示箱子大小 for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { if (l[i][j] != 0) { a[i][j] = l[i][j] * 3; } else if (m[i][j] != 0) { a[i][j] = m[i][j] * 2; } else { a[i][j] = s[i][j] * 1; } } } // 绘制网格 string border[4] = {"", "┌────┬────┬────┐", "├────┼────┼────┤", "├────┼────┼────┤"}; for (int i = 1; i <= 3; i++) { cout << border[i] << endl; cout << "│"; for (int j = 1; j <= 3; j++) { if (a[i][j] > 0) { cout << " +" << a[i][j] << " │"; } else if (a[i][j] < 0) { cout << " " << a[i][j] << " │"; } else { cout << " │"; } } cout << endl; } cout << "└────┴────┴────┘" << endl; } // 对行、列、对角线求和,若和为3则玩家胜利返回1,若和为-3则电脑胜利返回-1,否则返回0继续游戏 int findWinner() { // 计算当前网格被谁占据,只记录角色-1 +1,不记录箱子大小 int b[5][5] = {}; // 当前网格被谁占据 for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { if (l[i][j] != 0) { b[i][j] = l[i][j]; } else if (m[i][j] != 0) { b[i][j] = m[i][j]; } else { b[i][j] = s[i][j]; } } } // 检查行 for (int i = 1; i <= 3; i++) { int sum = 0; for (int j = 1; j <= 3; j++) { sum += b[i][j]; } if (sum == 3) return 1; if (sum == -3) return -1; } // 检查列 for (int j = 1; j <= 3; j++) { int sum = 0; for (int i = 1; i <= 3; i++) { sum += b[i][j]; } if (sum == 3) return 1; if (sum == -3) return -1; } // 检查对角线 int diag1 = 0, diag2 = 0; for (int i = 1; i <= 3; i++) { diag1 += b[i][i]; diag2 += b[i][4-i]; } if (diag1 == 3 || diag2 == 3) return 1; if (diag1 == -3 || diag2 == -3) return -1; return 0; } // 角色q把size箱子放到x行y列的位置 bool place(int x, int y, int size, int q) { if (x < 1 || x > 3 || y < 1 || y > 3) return false; if (q == -1) { printf("电脑试图在(%d,%d)下%d\n", x, y, size); } if (size == 3) { if (l[x][y] != 0) return false; l[x][y] = q; } if (size == 2) { if (l[x][y] != 0 || m[x][y] != 0) return false; m[x][y] = q; } if (size == 1) { if (l[x][y] != 0 || m[x][y] != 0 || s[x][y] != 0) return false; s[x][y] = q; } return true; } // 角色q把size箱子从x1行y1列转移到x2行y2列 bool move(int x1, int y1, int x2, int y2, int size, int q) { if (x1 < 1 || x1 > 3 || y1 < 1 || y1 > 3) return false; if (x2 < 1 || x2 > 3 || y2 < 1 || y2 > 3) return false; if (q == -1) { cout << "电脑试图将(" << x1 << "," << y1 << ")" << "转移到(" << x2 << "," << y2 << ")" << endl; } if (size == 3) { if (l[x1][y1] != q || l[x2][y2] != 0) return false; l[x1][y1] = 0; l[x2][y2] = q; } if (size == 2) { if (l[x1][y1] != 0 || l[x2][y2] != 0 || m[x1][y1] != q || m[x2][y2] != 0) return false; m[x1][y1] = 0; m[x2][y2] = q; } if (size == 1) { if (l[x1][y1] != 0 || l[x2][y2] != 0 || m[x1][y1] != 0 || m[x2][y2] != 0 || s[x1][y1] != q || s[x2][y2] != 0) return false; s[x1][y1] = 0; s[x2][y2] = q; } return true; } int winning(int x) { // 计算当前网格被谁占据 for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { if (l[i][j] != 0) p[i][j] = l[i][j]; else if (m[i][j] != 0) p[i][j] = m[i][j]; else p[i][j] = s[i][j]; } } int a = 0; if (x == 1) a = 1; for (int i = 1; i <= 3; i++) px[a][i] = py[a][i] = 0; bx[a] = by[a] = 0; for (int i = 1; i <= 3; i++) for (int j = 1; j <= 3; j++) if (p[i][j] == x) { px[a][i]++; py[a][j]++; if (i == j) bx[a]++; if (i + j == 4) by[a]++; } int s = bx[a] >= 2; s += by[a] >= 2; for (int i = 1; i <= 3; i++) { s += px[a][i] >= 2; s += py[a][i] >= 2; } return s; } int fill(int x, int y, int size) //电脑至少用size大小的棋子占领x行y列 { // cout << "电脑试图在" << x << ',' << y << "下棋" << endl; if (l[x][y] == 1) return 0; for (int k = size; k <= 3; k++) if (p1[k] && place(x, y, k, -1)) { p1[k]--; return 1; } if (s[x][y] == 1) size = max(size, 2); if (m[x][y] == 1) size = 3; if (size == 1) { for (int i = 1; i <= 3; i++) for (int j = 1; j <= 3; j++) if (s[i][j] == -1 && move(i, j, x, y, 1, -1)) { if (winning(1) == 0) return 1; move(x, y, i, j, 1, -1); } } if (size <= 2) { for (int i = 1; i <= 3; i++) for (int j = 1; j <= 3; j++) if (m[i][j] == -1 && move(i, j, x, y, 2, -1)) { if (winning(1) == 0) return 1; move(x, y, i, j, 2, -1); } } if (size <= 3) { for (int i = 1; i <= 3; i++) for (int j = 1; j <= 3; j++) if (l[i][j] == -1 && move(i, j, x, y, 3, -1)) { if (winning(1) == 0) return 1; move(x, y, i, j, 3, -1); } } return 0; } void computer() { if (winning(-1) > 0) { cout << "电脑认为自己快赢了" << endl; for (int i = 1; i <= 3; i++) for (int j = 1; j <= 3; j++) if (p[i][j] != -1 && (px[0][i] == 2 || py[0][j] == 2)) { if (fill(i, j, 1)) return; } if (bx[0] == 2) { for (int i = 1; i <= 3; i++) if (p[i][i] != -1 && fill(i, i, 1)) return ; } if (by[0] == 2) { for (int i = 1; i <= 3; i++) if (p[i][4 - i] != -1 && fill(i, 4 - i, 1)) return ; } } if (winning(1) > 0) { cout << "电脑认为你快赢了" << endl; int cnt = 0; for (int i = 1; i <= 3; i++) for (int j = 1; j <= 3; j++) { int w = (px[1][i] == 2) + (py[1][j] == 2); if (i == j && bx[1] == 2) w++; if (i + j == 4 && by[1] == 2) w++; if (w == 0) continue; aa[++cnt].x = i; aa[cnt].y = j; aa[cnt].h = w; } sort(aa + 1, aa + cnt + 1, cmp); for (int i = 1; i <= cnt; i++) { // printf("电脑想在%d,%d阻止你,w=%d\n",aa[i].x,aa[i].y,aa[i].h); if (p2[3] > 0) { if (fill(aa[i].x, aa[i].y, 3)) return ; else continue; } if (p2[2] > 0) { if (fill(aa[i].x, aa[i].y, 2)) return ; else continue; } if (p2[1] > 0) { if (fill(aa[i].x, aa[i].y, 1)) return ; else continue; } } } if (l[2][2] == 0) { cout << "电脑决定占领中心" << endl; if (p1[3] > 0) { p1[3]--; place(2, 2, 3, -1); return; } if (fill(2, 2, 3)) return ; if (fill(2, 2, 2)) return ; } int cnt = 0; for (int i = 1; i <= 3; i++) for (int j = 1; j <= 3; j++) if (p[i][j] != -1) { if (l[i][j] > 0) continue; int t = p[i][j]; p[i][j] = -1; aa[++cnt].x = i; aa[cnt].y = j; aa[cnt].h = winning(-1); p[i][j] = t; } sort(aa + 1, aa + cnt + 1, cmp); int j = 1; for (int i = 1; i <= cnt; i++) { if (aa[i].h == aa[j].h) j = i; else break; } j = rand() % j + 1; if (fill(aa[j].x, aa[j].y, 1)) return; for (int i = 1; i <= cnt; i++) if (fill(aa[i].x, aa[i].y, 1)) return; } int game() { srand((unsigned int)time(NULL)); while (true) { cout << "请选择 ① 放一个盒子 还是 ② 移动一个盒子 (输入数字)" << endl; int choice, size, x1, y1, x2, y2; cin >> choice; if (choice == 1) { cout << "你现在有盒子 小:" << p2[1] << " 中:" << p2[2] << " 大:" << p2[3] << endl; cout << "请选择盒子的大小 ① 小 ② 中 ③ 大 (输入数字)" << endl; cin >> size; if (size > 3 || size < 1) {cout << "非法输入" << endl; continue;} if (p2[size] <= 0) {cout << "盒子没了" << endl; continue;} cout << "请输入放置的位置(输入两个整数,如:1 1)" << endl; cin >> x1 >> y1; if (!place(x1, y1, size, 1)) {cout << "放置失败" << endl; continue;} cout << "放置成功" << endl; p2[size]--; showSquare(); } else if (choice == 2) { cout << "请输入移走的位置(输入两个整数,如:1 1)" << endl; cin >> x1 >> y1; cout << "请输入放置的位置(输入两个整数,如:1 1)" << endl; cin >> x2 >> y2; // 判断移动的箱子 if (l[x1][y1] == 1) size = 3; else if (m[x1][y1] == 1 && l[x1][y1] == 0) size = 2; else if (s[x1][y1] == 1 && l[x1][y1] == 0 && m[x1][y1] == 0) size = 1; else {cout << "没有可以移动的盒子" << endl; continue;} if (!move(x1, y1, x2, y2, size, 1)) {cout << "移动失败" << endl; continue;} showSquare(); } else continue; int winner = findWinner(); if (winner != 0) { return winner; } computer(); cout << "电脑下棋" << endl; showSquare(); winner = findWinner(); if (winner != 0) { return winner; } } } void showWinner(int winner) { if (winner == 1) { cout << "玩家胜利" << endl; } else { cout << "电脑胜利" << endl; } } void intro() { cout << "玩家和电脑各拥有大中小号盒子各2个," << endl; cout << "双方轮流在九宫格的棋盘中放入或移动一个盒子,每个盒子都可盖住任意比他小的盒子。" << endl; cout << "若你方团队的盒子率先在棋盘上连成一条直线则挑战成功,否则挑战失败。" << endl; cout << "用正数表示玩家的盒子,负数表示电脑的盒子,1、2、3表示盒子的小中大。" << endl; cout << "开始吧!" << endl; showSquare(); } int main() { intro(); int winner = game(); showWinner(winner); return 0; }
3.汉诺塔
#include <bits/stdc++.h> #include <conio.h> #include <windows.h> using namespace std; const int COLUMN[4] = { 0, 2, 5, 8 }; const int DISC_CNT_MAX = 10; const int ROW_OP_CNT = 2, COL_OP_CNT = 16; const int ROW_MESSAGE = 3, COL_MESSAGE = 16; const int ROW_HELP = 15, COL_HELP = 1; const int ROW_MAX = 30, COL_MAX = 120; const int BLUE = 1; const int GREEN = 2; const int CYAN = 3; const int AQUA = 3; const int RED = 4; const int PURPLE = 5; const int YELLOW = 6; const int WHITE = 7; int n; stack<int> rod[4]; int sz[4] = { 0 }; int pos1, pos2; int key; bool prev_key_is_esc; int op_cnt; bool is_moving; int moved_disc; template <typename T> inline T read() { T x = 0; T multiplier = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') { multiplier = -1; } ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch & 15); ch = getchar(); } return x * multiplier; } void set_caret_pos(int row = 1, int col = 1) { COORD pos; pos.X = col - 1; pos.Y = row - 1; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); } int get_caret_row() { CONSOLE_SCREEN_BUFFER_INFO info; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); return info.dwCursorPosition.Y + 1; } int get_caret_col() { CONSOLE_SCREEN_BUFFER_INFO info; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); return info.dwCursorPosition.X + 1; } pair<int, int> get_caret_pos() { CONSOLE_SCREEN_BUFFER_INFO info; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); return make_pair(info.dwCursorPosition.Y + 1, info.dwCursorPosition.X + 1); } void set_foreground_color(int x, bool intensity = false) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x | (intensity << 3)); } void set_cursor_visibility(bool visibility = true) { CONSOLE_CURSOR_INFO cc_info; cc_info.bVisible = visibility; cc_info.dwSize = 1; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cc_info); } void disp_init_state(int n) { for (int i = 1; i <= n; i++) { set_caret_pos(i, COLUMN[1]); printf("%d", i); } for (int i = 1; i <= 3; i++) { set_caret_pos(n + 1, COLUMN[i] - 1); printf("---"); set_caret_pos(n + 2, COLUMN[i]); putchar('A' + i - 1); } set_caret_pos(ROW_OP_CNT, COL_OP_CNT); printf("0"); } void disp_help() { set_caret_pos(ROW_HELP, COL_HELP); printf("如何玩:\n" "数字表示光盘的尺寸.\n" "将A杆上圆盘移动到C杆上,每次一个.\n" "每个杆上的圆盘必须按大小升序堆叠.\n" "使用左右箭头键选择杆.\n" "按Enter键拾取选定杆上的顶部圆盘.\n" "然后使用左右键移动.\n" "按ESC取消当前移动.\n" "再次按Enter键可将圆盘放置.\n" "按R重新启动.\n" "按ESC键两次退出.\n"); } void disp_pos(int pos1, int pos2 = 0) { for (int i = 1; i <= 3; i++) { set_caret_pos(n + 3, COLUMN[i]); printf(" "); } set_caret_pos(n + 3, COLUMN[pos1]); printf("^"); if (pos2) { set_caret_pos(n + 3, COLUMN[pos2]); set_foreground_color(GREEN, true); printf("^"); set_foreground_color(WHITE); } } void clear() { for (int i = 1; i <= DISC_CNT_MAX + 3; i++) { for (int j = 1; j <= COL_MAX; j++) { set_caret_pos(i, j); putchar(' '); } } } void moving_disc(int pos1, int pos2) { int x = rod[pos1].top(); set_caret_pos(n + 1 - sz[pos1], COLUMN[pos1]); set_foreground_color(RED, true); printf("%d", x); set_foreground_color(WHITE); set_caret_pos(n - sz[pos2] + (pos1 == pos2), COLUMN[pos2]); set_foreground_color(GREEN, true); printf("%d", x); set_foreground_color(WHITE); } void update_discs(int pos1, int pos2) { int x = rod[pos1].top(); set_caret_pos(n + 1 - sz[pos1], COLUMN[pos1]); printf(" "); rod[pos1].pop(); sz[pos1]--; rod[pos2].push(x); sz[pos2]++; set_caret_pos(n + 1 - sz[pos2], COLUMN[pos2]); printf("%d", x); } void remove_temp_disc(int pos) { set_caret_pos(n - sz[pos], COLUMN[pos]); printf(" "); } void update_op_cnt() { op_cnt++; set_caret_pos(ROW_OP_CNT, COL_OP_CNT); printf("%d", op_cnt); } int main() { printf("输入光盘数量(不超过 %d): ", DISC_CNT_MAX); n = min(read<int>(), DISC_CNT_MAX); set_cursor_visibility(false); disp_help(); for (; n <= DISC_CNT_MAX; n++) { clear(); for (int i = 1; i <= 3; i++) { while (!rod[i].empty()) { rod[i].pop(); } sz[i] = 0; } for (int i = n; i >= 1; i--) { rod[1].push(i); } sz[1] = n; is_moving = false; pos1 = 1; op_cnt = 0; prev_key_is_esc = false; disp_init_state(n); disp_pos(1); while (true) { if (sz[3] == n) { set_caret_pos(ROW_MESSAGE, COL_MESSAGE); if (op_cnt != (1 << n) - 1) { printf("你用%d个动作完成了谜题.",op_cnt); } else { printf("祝贺你用最少的动作完成了谜题 " ); } Sleep(2000); break; } key = getch(); if (key == 224) { key = getch(); if (!is_moving) { if (key == 75) { // Left arrow key pos1 = (pos1 + 1) % 3 + 1; } else if (key == 77) { // Right arrow key pos1 = pos1 % 3 + 1; } disp_pos(pos1); } else { remove_temp_disc(pos2); if (key == 75) { // Left arrow key pos2 = (pos2 + 1) % 3 + 1; } else if (key == 77) { // Right arrow key pos2 = pos2 % 3 + 1; } moving_disc(pos1, pos2); disp_pos(pos1, pos2); } } else if (key == 13) { // Enter key if (!is_moving) { if (rod[pos1].empty()) { continue; } is_moving = true; moved_disc = rod[pos1].top(); pos2 = pos1; moving_disc(pos1, pos2); disp_pos(pos1, pos2); } else { if (!rod[pos2].empty() && rod[pos2].top() < moved_disc) { set_caret_pos(ROW_MESSAGE, COL_MESSAGE); printf("提示:光盘未按升序堆叠在棒上。"); continue; } is_moving = false; update_discs(pos1, pos2); update_op_cnt(); pos1 = pos2; disp_pos(pos1); } } else if (key == 27) { // Escape key if (prev_key_is_esc) { // Double ESC break; } if (is_moving) { is_moving = false; remove_temp_disc(pos2); update_discs(pos1, pos1); disp_pos(pos1); } else { prev_key_is_esc = true; } } else if (key == 'R' || key == 'r') { n--; break; } } if (prev_key_is_esc && key == 27) { // Double ESC break; } } set_caret_pos(ROW_MAX - 1, 1); return 0; }
4.贪吃蛇
#include <iostream> #include <cstdio> #include <cstdlib> #include <ctime> #include <conio.h> #include <cmath> #include <windows.h> using namespace std; HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE); COORD coord; void locate(int x,int y){ coord.X=y; coord.Y=x; SetConsoleCursorPosition(hout,coord); }; void hide(){ CONSOLE_CURSOR_INFO cursor_info={1,0}; SetConsoleCursorInfo(hout, &cursor_info); } double random(double start, double end){ return start+(end-start)*rand()/(RAND_MAX + 1.0); } int m=25,n=40; struct node{ int x,y; }snake[1000]; int snake_length,dir; node food; int direct[4][2]={{-1,0},{1,0},{0,-1},{0,1}}; void print_wall(){ cout<<" "; for(int i=1;i<=n;i++)cout<<"-"; cout<<endl; for (int j=0;j<=m-1;j++){ cout<<"|"; for(int i=1;i<=n;i++)cout<<" "; cout<<"|"<<endl; } cout<<" "; for(int i=1;i<=n;i++)cout<< "-"; } void print_snake(){ locate(snake[0].x,snake[0].y); cout<<"@"; for(int i=1;i<=snake_length-1;i++) { locate(snake[i].x,snake[i].y); cout << "*"; } } bool is_correct(){ if (snake[0].x==0 || snake[0].y==0 || snake[0].x==m+1 || snake[0].y==n+1) return 0; for(int i=1;i<=snake_length-1;i++)if(snake[0].x==snake[i].x&&snake[0].y==snake[i].y)return 0; return 1; } bool print_food(){ srand((unsigned)time(0)); bool e; while (1) { e=true; int i=(int)random(0,m)+1,j=(int)random(0,n)+1; food.x=i;food.y=j; for (int k=0;k<=snake_length-1;k++){ if(snake[k].x==food.x && snake[k].y==food.y) { e=false; break; } } if(e)break; } locate(food.x,food.y); cout<<"$"; return true; } bool go_ahead(){ node temp; bool e=false; temp=snake[snake_length-1]; for(int i=snake_length-1;i>=1;i--)snake[i]=snake[i-1]; snake[0].x+=direct[dir][0]; snake[0].y+=direct[dir][1]; locate(snake[1].x,snake[1].y); cout << "*"; if(snake[0].x==food.x&&snake[0].y==food.y) { snake_length++; e=true; snake[snake_length-1]=temp; } if (!e) { locate(temp.x,temp.y); cout << " "; } else print_food(); locate(snake[0].x,snake[0].y); cout<<"@"; if (!is_correct()) { system("cls"); cout << "You lose!" << endl << "Length: " << snake_length << endl; return false; } return true; } int main() { cout<<"--------------------贪吃蛇---------------------"<<endl; cout<<"请注意窗口大小,以免发生错位.建议将窗口调为最大."<<endl; cout<<"先选择难度.请在1-10中输入1个数,1最简单,10则最难"<<endl; cout<<"然后进入游戏画面,以方向键控制方向.祝你游戏愉快!"<<endl; cout<<"-----------------------------------------------"<<endl; if(m<10||n<10||m>25||n>40){ cout<<"ERROR"<<endl; system("pause"); return 0; } int hard; cin>>hard; if(hard<=0||hard>100){ cout<<"ERROR"<<endl; system("pause"); return 0; } snake_length=5; clock_t a,b; char ch; double hard_len; for(int i=0;i<=4;i++){ snake[i].x=1; snake[i].y=5-i; } dir=3; system("cls"); hide(); print_wall(); print_food(); print_snake(); locate(m+2,0); cout<<"Now length: "; while (1) { hard_len=(double)snake_length/(double)(m*n); a=clock(); while (1) { b=clock(); if(b-a>=(int)(400-30*hard)*(1-sqrt(hard_len)))break; } if(kbhit()) { ch=getch(); if(ch==-32) { ch=getch(); switch(ch) { case 72: if(dir==2||dir==3) dir=0; break; case 80: if(dir==2||dir==3) dir=1; break; case 75: if(dir==0||dir==1) dir=2; break; case 77: if(dir==0||dir==1) dir=3; break; } } } if(!go_ahead())break; locate(m+2,12); cout<<snake_length; } system("pause"); return 0; }
5.打怪
#include<bits/stdc++.h> #include <conio.h> #include <windows.h> using namespace std; const int N=1e2+10; const int INF=0x3f3f3f3f; bool YOU_DIED=0,YOU_WON=0; int EXP_TO_LOVE[25]={0,20,25,30,40,50,60,70,80,94,115,120,130,150,167,189,190,200,200,230,1000000}; struct Ploblems{ string pr; int ans,spd; }p[N]; struct Things{ string name; int help_atk,help_def,help_hp; int Much_Buy,G,Kind_Of;//1武器2防具3药 }tg[N]; struct Monsters{ int Max_HP,ATK,HP,DEF,Mercy_Time,Shot; string name,Speak; }m[N]; struct Frisk{ int Max_HP,ATK,HP,DEF; int LV,EXP,G,Stage; int Drug_Bag[N],ATK_Bag[N],DEF_Bag[N]; int Have_Drug,Have_ATK,Have_DEF; int knife,shield; string name; }y; void slowsay(string a,int speed=39) { int alen=a.size(); for(int i=0;i<alen;i++){ Sleep(speed); cout<<a[i]; } } void Shop_Draw(int l) { printf("-----------------------------------\n"); l==1?printf(">>提米薄片 40G\n"):printf(" 提米薄片 40G\n"); l==2?printf(">>传说英雄 280G\n"):printf(" 传说英雄 280G\n"); l==3?printf(">>蜘蛛蛋糕 400G\n"):printf(" 蜘蛛蛋糕 400G\n"); l==4?printf(">>平底锅 500G\n"):printf(" 平底锅 500G\n"); l==5?printf(">>提米盔甲!! 1700G\n"):printf(" 提米盔甲!! 1700G\n"); l==6?printf(">>甜甜圈套餐 9999G\n"):printf(" 甜甜圈套餐 9999G\n"); l==7?printf(">>退出商店\n"):printf(" 退出商店\n"); printf("-----------------------------------\n"); if(l==1)printf("*防具 防御+20\n*不用担心防御,轻轻松松地战斗\n"); if(l==2)printf("*药品 HP+40\n*很好吃的三明治\n"); if(l==3)printf("*药品 HP+60\n*有奇效的蛋糕\n"); if(l==4)printf("*防具 防御+30,攻击+10\n*神器\n"); if(l==5)printf("*防具 防御+?\n*你等着瞧叭,看看它多厉害!\n"); if(l==6)printf("*?? \n*奸商!!!\n"); if(l==7)printf("*按'k'键退出\n"); printf("-----------------------------------\n"); } void Buy_Things_From_Shop() { system("cls"); slowsay("*你吼,我素提米!欢迎来到TEMMY SHOP!!\n"); Sleep(200); BUY_AGAIN: system("cls"); printf("*你吼,我素提米!欢迎来到TEMMY SHOP!!\n"); int HREAT_LINE=1; Shop_Draw(HREAT_LINE); while(1) { Sleep(10); if(kbhit()) { char x=_getch(); if(x=='k' && HREAT_LINE==7) { system("cls"); slowsay("欢银下次光临!"); return; } else if(x=='w') { system("cls"); printf("*你吼,我素提米!欢迎来到TEMMY SHOP!!\n"); Shop_Draw(HREAT_LINE==1?1:--HREAT_LINE); } else if(x=='s') { system("cls"); printf("*你吼,我素提米!欢迎来到TEMMY SHOP!!\n"); Shop_Draw(HREAT_LINE==7?7:++HREAT_LINE); } else if(x=='k') { system("cls"); if(y.G>=tg[HREAT_LINE].G && tg[HREAT_LINE].Much_Buy>=1) { slowsay("*购买成功!\n"); if(HREAT_LINE==6) { Sleep(1000); slowsay("*提米偷偷嗦:介个家伙素不素有钱没地方花..."); } y.G-=tg[HREAT_LINE].G; tg[HREAT_LINE].Much_Buy-=1; if(tg[HREAT_LINE].Kind_Of==1) { y.ATK_Bag[++y.Have_ATK]=HREAT_LINE; } if(tg[HREAT_LINE].Kind_Of==2) { y.DEF_Bag[++y.Have_DEF]=HREAT_LINE; } if(tg[HREAT_LINE].Kind_Of==3) { y.Drug_Bag[++y.Have_Drug]=HREAT_LINE; } } else if(y.G<tg[HREAT_LINE].G) { slowsay("*你好像没有足够哒钱钱\n"); } else if(tg[HREAT_LINE].Much_Buy<1) { slowsay("*啊哦,今天售罄了...\n"); } Sleep(500); goto BUY_AGAIN; } } } return; } void Main_Draw(int l) { printf("-----------------------------------\n"); l==1?printf(">>商店\n"):printf(" 商店\n"); l==2?printf(">>存档\n"):printf(" 存档\n"); l==3?printf(">>查看\n"):printf(" 查看\n"); l==4?printf(">>战斗\n"):printf(" 战斗\n"); l==5?printf(">>退出\n"):printf(" 退出\n"); printf("-----------------------------------\n"); printf("操作方式:w上 s下 k确认\n"); printf("-----------------------------------"); return; } void File() { system("cls"); int c=y.G; int atk=y.ATK; int def=y.DEF; int mh=y.Max_HP; int hp=y.HP; int exp=y.EXP; int lv=y.LV; int hd=y.Have_Drug,ha=y.Have_ATK,hde=y.Have_DEF; FILE*fp=fopen("./undertale_cundang.txt","w"); fprintf(fp,"%d %d %d %d %d %d %d %d %d %d %d ",c,atk,def,mh,hp,exp,lv,hd,ha,hde,y.Stage); for(int i=1;i<=y.Have_Drug;++i) { fprintf(fp,"%d ",y.Drug_Bag[i]); } for(int i=1;i<=y.Have_ATK;++i) { fprintf(fp,"%d ",y.ATK_Bag[i]); } for(int i=1;i<=y.Have_DEF;++i) { fprintf(fp,"%d ",y.DEF_Bag[i]); } fclose(fp); for(int i=1;i<10;i++) { system("cls"); if(i%3==0)cout<<"正在存档中..."; if(i%3==1)cout<<"正在存档中."; if(i%3==2)cout<<"正在存档中.."; Sleep(300); } system("cls"); cout<<"存档成功!"; Sleep(2000); system("cls"); return; } void Frisk_Define() { y.ATK=18; y.DEF=0; y.EXP=0; y.G=10000; y.Have_Drug=0; y.HP=20; y.LV=1; y.Max_HP=20; y.name="Frisk"; y.Stage=1; } void Monster_Define() { m[1].ATK=19,m[1].DEF=0,m[1].HP=25,m[1].Max_HP=25,m[1].name=" 小花 ";m[1].Speak="*杀或被杀\n"; m[2].ATK=6,m[2].DEF=8,m[2].HP=20,m[2].Max_HP=20,m[2].name=" 蛙吉特 ";m[2].Speak="*第一个对手\n"; m[3].ATK=10,m[3].DEF=3,m[3].HP=18,m[3].Max_HP=18,m[3].name=" 独眼怪 ";m[3].Speak="*样子怪怪的\n"; m[4].ATK=8,m[4].DEF=5,m[4].HP=30,m[4].Max_HP=30,m[4].name=" 小幽灵 ";m[4].Speak="*时常哭泣\n"; m[5].ATK=12,m[5].DEF=2,m[5].HP=31,m[5].Max_HP=31,m[5].name=" 爵士虫 ";m[5].Speak="*飘渺的对手\n"; m[6].ATK=9,m[6].DEF=8,m[6].HP=50,m[6].Max_HP=50,m[6].name=" 蛙吉特 ";m[6].Speak="*再见面\n"; m[7].ATK=2,m[7].DEF=10,m[7].HP=180,m[7].Max_HP=180,m[7].name=" 托丽尔 ";m[7].Speak="*亲爱的守护者\n"; m[8].ATK=19,m[8].DEF=32,m[8].HP=320,m[8].Max_HP=320,m[8].name=" 盾狗 ";m[8].Speak="*憨憨的模样\n"; m[9].ATK=46,m[9].DEF=41,m[9].HP=1020,m[9].Max_HP=1020,m[9].name=" 帕派瑞斯 ";m[9].Speak="*小天使\n"; m[10].ATK=5,m[10].DEF=184,m[10].HP=10089,m[10].Max_HP=10089,m[10].name=" 不灭的安黛因 ";m[10].Speak="*真正的女英雄\n"; m[11].ATK=1,m[11].DEF=1,m[11].HP=1,m[11].Max_HP=1,m[11].name=" 衫斯 ";m[11].Speak="*最简单的敌人\n*只能承受1点伤害\n"; } void Things_Define() { tg[1].help_atk=0,tg[1].help_def=20,tg[1].help_hp=0,tg[1].Much_Buy=1,tg[1].name="提米薄片",tg[1].G=40,tg[1].Kind_Of=2; tg[2].help_atk=0,tg[2].help_def=0,tg[2].help_hp=40,tg[2].Much_Buy=INF,tg[2].name="传说英雄",tg[2].G=280,tg[2].Kind_Of=3; tg[3].help_atk=0,tg[3].help_def=0,tg[3].help_hp=60,tg[3].Much_Buy=INF,tg[3].name="蜘蛛蛋糕",tg[3].G=400,tg[3].Kind_Of=3; tg[4].help_atk=10,tg[4].help_def=30,tg[4].help_hp=0,tg[4].Much_Buy=1,tg[4].name="平底锅",tg[4].G=500,tg[4].Kind_Of=2; tg[5].help_atk=0,tg[5].help_def=0,tg[5].help_hp=0,tg[5].Much_Buy=1,tg[5].name="提米盔甲",tg[5].G=1700,tg[5].Kind_Of=2; tg[6].help_atk=0,tg[6].help_def=0,tg[6].help_hp=0,tg[6].Much_Buy=INF,tg[6].name="甜甜圈套餐",tg[6].G=9999,tg[6].Kind_Of=3; } void Ploblems_Define() { p[1].pr="1&1",p[1].ans=1,p[1].spd=2; p[2].pr="1|1",p[2].ans=1,p[2].spd=3; p[3].pr="1^1",p[3].ans=0,p[3].spd=3; p[4].pr="0&1",p[4].ans=0,p[4].spd=3; p[5].pr="0&0",p[5].ans=0,p[5].spd=3; p[6].pr="1|0",p[6].ans=1,p[6].spd=2; p[7].pr="0^0",p[7].ans=0,p[7].spd=3; p[8].pr="1^0",p[8].ans=1,p[8].spd=3; p[9].pr="1&1^1",p[9].ans=0,p[9].spd=2; p[10].pr="0|1|0",p[10].ans=1,p[10].spd=2; } void Get_File() { system("cls"); FILE *fp=fopen("./undertale_cundang.txt","r"); Monster_Define(); Things_Define(); Ploblems_Define(); if(fp) { slowsay("检测到有存档,是否读档?(1/0):\n"); int aorpo; cin>>aorpo; if(aorpo) { for(int i=1;i<10;i++) { system("cls"); if(i%3==0)cout<<"正在读取存档中..."; if(i%3==1)cout<<"正在读取存档中."; if(i%3==2)cout<<"正在读取存档中.."; Sleep(300); } int c,atk,def,mh,hp,exp,lv,st,hd,ha,hde; fscanf(fp,"%d%d%d%d%d%d%d%d%d%d%d",&c,&atk,&def,&mh,&hp,&exp,&lv,&hd,&ha,&hde,&st); for(int i=1;i<=hd;++i) { fscanf(fp,"%d",&y.Drug_Bag[i]); } for(int i=1;i<=ha;++i) { fscanf(fp,"%d",&y.ATK_Bag[i]); } for(int i=1;i<=hde;++i) { fscanf(fp,"%d",&y.DEF_Bag[i]); } fclose(fp); y.ATK=atk,y.DEF=def,y.EXP=exp,y.G=c,y.Have_Drug=hd;y.Have_ATK=ha; y.LV=lv,y.Max_HP=mh,y.name="Frisk";y.HP=hp;y.Stage=st;y.Have_DEF=hde; slowsay("读取成功!"); Sleep(1000); return; } } Frisk_Define(); } void Check_Kit_Draw(int li,int lj) { printf("-----------------------------------\n\n"); bool flag=0; if(li==1) { printf("[武器] 防具\n\n"); for(int i=1;i<=y.Have_ATK;++i) { lj==i?printf(">>"):printf(" "); cout<<tg[y.ATK_Bag[i]].name<<'\n'; } lj==y.Have_ATK+1?printf(">>退出\n"):printf(" 退出\n"); } else { flag=1; printf(" 武器 [防具]\n\n"); for(int i=1;i<=y.Have_DEF;++i) { lj==i?printf(">>"):printf(" "); cout<<tg[y.DEF_Bag[i]].name<<'\n'; } lj==y.Have_DEF+1?printf(">>退出\n"):printf(" 退出\n"); } printf("-----------------------------------\n"); if((!flag && lj!=y.Have_ATK+1)||(flag && lj!=y.Have_DEF+1)) { li==1?printf("*武器\n"):printf("*防具\n"); printf("*攻击+%d 防御+%d 血量+%d\n",tg[y.DEF_Bag[lj]].help_atk,tg[y.DEF_Bag[lj]].help_def,tg[y.DEF_Bag[lj]].help_hp); printf("*输入k确认装备\n"); } printf("-----------------------------------\n"); return; } void Drug_Draw(int lj) { printf("-----------------------------------\n"); int d=y.Have_Drug; for(int i=1;i<=d;++i) { lj==i?printf(">>"):printf(" "); cout<<tg[y.Drug_Bag[i]].name<<endl; } lj==d+1?printf(">>退出\n"):printf(" 退出\n"); printf("-----------------------------------\n"); printf("*药品 血量+%d\n",tg[y.Drug_Bag[lj]].help_hp); printf("按k键丢弃\n"); printf("-----------------------------------\n"); return; } void Check_Yourself() { system("cls"); printf("-----------------------------------\n"); printf("Frisk:\n"); printf("LV(等级):%d EXP(经验):%d\n",y.LV,y.EXP); printf("Max_HP(血量上限):%d\n",y.Max_HP); printf("ATK(攻击):%d\n",y.ATK); printf("DEF(防御):%d\n",y.DEF); printf("HP(当前血量):%d\n",y.HP); printf("CN(金币):%d\n",y.G); cout<<"武器:"<<tg[y.knife].name<<" 防具:"<<tg[y.shield].name<<endl; printf("BAG(背包):%d/10\n",y.Have_Drug); for(int i=1;i<=y.Have_Drug;++i) { cout<<tg[y.Drug_Bag[i]].name<<" "; } printf("\n-----------------------------------\n输入1查看装备,2查看背包,3退出:"); int Your_Choose; cin>>Your_Choose; if(Your_Choose==1) { CHECK_AGAIN: system("cls"); int HREAT_LINE=1,HREAT_ROW=1; Check_Kit_Draw(HREAT_ROW,HREAT_LINE); while(1) { Sleep(10); if(kbhit()) { char x=_getch(); if(x=='w') { system("cls"); Check_Kit_Draw(HREAT_ROW,HREAT_LINE==1?1:--HREAT_LINE); } else if(x=='s') { system("cls"); Check_Kit_Draw(HREAT_ROW,HREAT_ROW==1?(HREAT_LINE==y.Have_ATK+1?y.Have_ATK+1:++HREAT_LINE):(HREAT_LINE==y.Have_DEF+1?y.Have_DEF+1:++HREAT_LINE)); } else if(x=='a') { system("cls"); HREAT_LINE=1; Check_Kit_Draw(HREAT_ROW==1?1:--HREAT_ROW,1); } else if(x=='d') { system("cls"); HREAT_LINE=1; Check_Kit_Draw(HREAT_ROW==2?2:++HREAT_ROW,1); } else if(x=='k' && ((HREAT_ROW==1&&HREAT_LINE==y.Have_ATK+1)||((HREAT_ROW==1&&HREAT_LINE==y.Have_DEF+1))) ) { return; } else if(x=='k') { system("cls"); cout<<"装备成功!\n"; Sleep(1700); if(HREAT_ROW==1)y.knife=y.ATK_Bag[HREAT_LINE]; if(HREAT_ROW==2)y.shield=y.DEF_Bag[HREAT_LINE]; goto CHECK_AGAIN; } } } } if(Your_Choose==2) { CHECK_AGAIN2: system("cls"); int HREAT_LINE=1; Drug_Draw(HREAT_LINE); while(1) { Sleep(10); if(kbhit()) { char x=_getch(); if(x=='w') { system("cls"); Drug_Draw(HREAT_LINE==1?1:--HREAT_LINE); } else if(x=='s') { system("cls"); Drug_Draw(HREAT_LINE==y.Have_Drug+1?HREAT_LINE:++HREAT_LINE); } else if(x=='k' && HREAT_LINE==y.Have_Drug+1 ) { return; } else if(x=='k') { system("cls"); cout<<"丢弃成功!\n"; Sleep(1700); y.Drug_Bag[HREAT_LINE]=0; for(int i=HREAT_LINE+1;i<=y.Have_Drug;++i) { y.Drug_Bag[i-1]=y.Drug_Bag[i]; } y.Have_Drug--; goto CHECK_AGAIN2; } } } } else { return; } } void ITEM_Draw(int lj) { system("cls"); printf("-----------------------------------\n"); int d=y.Have_Drug; for(int i=1;i<=d;++i) { lj==i?printf(">>"):printf(" "); cout<<tg[y.Drug_Bag[i]].name<<endl; } lj==d+1?printf(">>退出\n"):printf(" 退出\n"); printf("-----------------------------------\n"); } void M_FIGHT() { system("cls"); cout<<"*怪物攻击!"<<endl; Sleep(500); int k=m[y.Stage].ATK,r=rand()%5+1; while(r--) { int a=rand()%10+1; int t=p[a].spd*1000,flag=0; cout<<endl<<p[a].pr<<endl; while(t>0) { t-=100; Sleep(100); if(kbhit()) { char x=_getch(); int my_ans=x-'0'; if(my_ans!=p[a].ans) { flag=2; cout<<"回答错误!\n"; Sleep(200); break; } else { flag=1; cout<<"回答正确!\n"; Sleep(200); break; } } } if(flag!=1) { if(flag==0)cout<<"超时!\n"; y.HP-=k; } Sleep(1000); } } void FIGHT() { double k=y.ATK+tg[y.knife].help_atk+tg[y.shield].help_atk; system("cls"); //for循环1~100再到1攻击力 double r=rand()%100+50; k=floor(k*r/100.0); if(m[y.Stage].name!="衫斯") { m[y.Stage].HP-=max(0,(int)k-m[y.Stage].DEF); printf("你对怪物造成了 %d 点伤害!",max(0,(int)k-m[y.Stage].DEF)); } else { printf("你对怪物造成了 0 点伤害!"); } if(m[y.Stage].HP<=0) { YOU_WON=1;int s=rand()%30+10,w=rand()%30+15; Sleep(500); slowsay("\n*你胜利了!"); printf("\n*你获得了 %d 点EXP和 %d 金币!\n",s,w); y.EXP+=s;y.G+=w; if(y.EXP>=EXP_TO_LOVE[y.LV]) { y.EXP-=EXP_TO_LOVE[y.LV]; y.LV++; Sleep(200); slowsay("*你升级了!\n"); y.Max_HP+=5; y.ATK+=2; y.DEF+=1; } } Sleep(1000); } void ACT() { system("cls"); printf("-----------------------------------\n"); slowsay("*");slowsay(m[y.Stage].name);slowsay(" ");cout<<m[y.Stage].ATK; slowsay(" ATK ");cout<<m[y.Stage].DEF;slowsay(" DEF\n"); slowsay(m[y.Stage].Speak); printf("-----------------------------------\n"); Sleep(500); printf("按任意键继续:"); char o; cin>>o; return; } void ITEM() { system("cls"); int HREAT_LINE=1; ITEM_Draw(HREAT_LINE); while(1) { Sleep(10); if(kbhit()) { char x=_getch(); if(x=='w') { system("cls"); ITEM_Draw(HREAT_LINE==1?1:--HREAT_LINE); } else if(x=='s') { system("cls"); ITEM_Draw(HREAT_LINE==y.Have_Drug+1?HREAT_LINE:++HREAT_LINE); } else if(x=='k' && HREAT_LINE==y.Have_Drug+1) { return; } else if(x=='k') { system("cls"); slowsay("*你吃掉了 ");slowsay(tg[y.Drug_Bag[HREAT_LINE]].name); slowsay(" !\n*你恢复了");printf("%d",tg[y.Drug_Bag[HREAT_LINE]].help_hp);slowsay("点HP!"); Sleep(1700); y.HP=min(y.Max_HP,y.HP+tg[y.Drug_Bag[HREAT_LINE]].help_hp); y.Drug_Bag[HREAT_LINE]=0; for(int i=HREAT_LINE+1;i<=y.Have_Drug;++i) { y.Drug_Bag[i-1]=y.Drug_Bag[i]; } y.Have_Drug--; system("cls"); return; } } } } void MERCY() { system("cls"); int y=rand()%4+1; if(y==4) { slowsay("你胜利了!"); slowsay("\n你获得了 0 点EXP和 0 金币!"); Sleep(1000); YOU_WON=1; } else { slowsay("怪物拒绝了!"); Sleep(1000); } return; } void Fight_Draw() { YOU_WON=0; system("cls"); int s=y.Stage,hl; slowsay("*");slowsay(m[s].name);slowsay("发起战斗!\n"); Sleep(300); FIGHT_AGAIN: if(YOU_WON==1) { y.Stage++; return; } if(y.HP<=0) { system("cls"); printf("*(心碎)\n"); Sleep(2200); slowsay("GAME OVER\n"); Sleep(2000); slowsay("*你是我们的希望...\n"); Sleep(1000); slowsay("*Frisk,保持你的决心!"); Sleep(2000); YOU_DIED=1; return; } system("cls"); cout<<m[s].name<<" "<<m[s].HP<<"/"<<m[s].Max_HP<<endl; printf("-----------------------------------\n"); slowsay("*尽管攻击!\n"); printf("FRISK %d / %d\n",y.HP,y.Max_HP); printf("-----------------------------------\n"); hl=1; hl==1?printf(">>[战斗] "):printf(" [战斗] "); hl==2?printf(">>[行动] "):printf(" [行动] "); hl==3?printf(">>[物品] "):printf(" [物品] "); hl==4?printf(">>[仁慈] "):printf(" [仁慈] "); while(1) { Sleep(10); if(kbhit()) { char x=_getch(); if(x=='a') { system("cls"); hl==1?hl=1:hl--; cout<<m[s].name<<" "<<m[s].HP<<"/"<<m[s].Max_HP<<endl; printf("-----------------------------------\n"); printf("*尽管攻击!\n"); printf("FRISK %d / %d\n",y.HP,y.Max_HP); printf("-----------------------------------\n"); hl==1?printf(">>[战斗] "):printf(" [战斗] "); hl==2?printf(">>[行动] "):printf(" [行动] "); hl==3?printf(">>[物品] "):printf(" [物品] "); hl==4?printf(">>[仁慈] "):printf(" [仁慈] "); } else if(x=='d') { system("cls"); hl==4?hl=4:hl++; cout<<m[s].name<<" "<<m[s].HP<<"/"<<m[s].Max_HP<<endl; printf("-----------------------------------\n"); printf("*尽管攻击!\n"); printf("FRISK %d / %d\n",y.HP,y.Max_HP); printf("-----------------------------------\n"); hl==1?printf(">>[战斗] "):printf(" [战斗] "); hl==2?printf(">>[行动] "):printf(" [行动] "); hl==3?printf(">>[物品] "):printf(" [物品] "); hl==4?printf(">>[仁慈] "):printf(" [仁慈] "); } else if(x=='k') { if(hl==1)FIGHT(); if(hl==2)ACT(); if(hl==3)ITEM(); if(hl==4)MERCY(); if(YOU_WON!=1) { M_FIGHT(); } goto FIGHT_AGAIN; } } } } void Start_Fight() { system("cls"); cout<<"当前关数:"<<y.Stage<<" "<<m[y.Stage].name<<endl; Sleep(200); slowsay("\nENTER K TO START!:"); char ys; cin>>ys; if(ys=='k' || ys=='K') { Fight_Draw(); } else { return; } } int main() { srand(time(0)); Get_File(); system("cls"); Sleep(3000); slowsay("U N D E R T A L E"); Sleep(1000); slowsay("\nby lingzai\n"); Sleep(2000); cout<<"按任意键开始:"; char cin_to_start;int HREAT_LINE=1; cin>>cin_to_start; AGAIN: if(YOU_DIED) { return 0; } system("cls"); Main_Draw(HREAT_LINE); while(1) { Sleep(10); if(kbhit()) { char x=_getch(); if(x=='w') { system("cls"); Main_Draw(HREAT_LINE==1?1:--HREAT_LINE); } else if(x=='s') { system("cls"); Main_Draw(HREAT_LINE==5?5:++HREAT_LINE); } else if(x=='k') { if(HREAT_LINE==1)Buy_Things_From_Shop(); else if(HREAT_LINE==2)File(); else if(HREAT_LINE==3)Check_Yourself(); else if(HREAT_LINE==4)Start_Fight(); else if(HREAT_LINE==5) { system("cls"); Sleep(3000); slowsay("U N D E R T A L E"); Sleep(1000); slowsay("\n感谢游玩!\n"); return 0; } goto AGAIN; } } } return 0; }
植姜
#include<bits/stdc++.h> #include<windows.h> using namespace std; int b[5][100]; int d[5][100]; void print(string a,string c){ for(int i=0;i<a.size();i++){ cout<<a[i]; Sleep(1); } cout<<c; } void printg(int ty){ cout<<"|"; for(int i=1;i<=20;i++){ if(b[ty][i]==1) print("?",""); else if(b[ty][i]==2) print("@",""); else if(b[ty][i]==3) print(">",""); else print(" ",""); } cout<<"|"<<endl; } int main(){ print(" ----植物大战僵尸---- ","\n"); print(">是双向射手","\n"); print("@是向日葵","\n"); print("?是僵尸","\n"); Sleep(400); system("cls"); print("开始游戏","\n"); memset(b,0,sizeof(b)); while(true){ system("cls"); print(" ----植物大战僵尸---- ","\n"); printg(1); printg(2); printg(3); printg(4); printg(5); print(" -------------------- ","\n"); int x,y,z; cin>>x>>y>>z; b[x][y]=z; if(b[x][y]==1) d[x][y]=100; for(int i=1;i<=5;i++){ for(int j=1;j<=20;j++){ if(b[i][j]==1){ b[i][j]=0; b[i][j-1]=1; d[i][j-1]=d[i][j]; d[i][j]=0; } } } for(int i=1;i<=5;i++){ for(int j=1;j<=100;j++){ if(b[i][j]==3){ for(int k=1;k<=100;k++){ if(b[i][k]==1){ d[i][k]-=35; if(d[i][k]<=0) b[i][k]=0; break; } } } } } for(int i=1;i<=5;i++){ b[i][20]=1; } } return 0; }
-
通过的题目
-
最近活动
- 少年宫周日晚上高级C1C2班(2025/03/09)【张正标】 作业
- 少年宫周日晚上高级C1班开学测试 IOI
- 少年宫周日晚上C2班期末测试 IOI
- 少年宫周日晚上班(20241222)【张正标】 作业
- 少年宫周日下午C2班 IOI
- 少年宫周日晚上班(20241215)【张正标】 作业
- 少年宫周日晚上班(20241110)【张正标】 作业
- 少年宫周日晚上班【张正标】(20241103) 作业
- 少年宫周日晚上班test1 IOI
- sng周日下午班期末 IOI
- 2024少年宫周日19:10-20:30高级班期末考核 IOI
- 第三届小云雀杯入门组比赛 OI
- 少年宫周日下午班test IOI
- 少年宫周日晚上班(20240519)【张正标】 作业
- 少年宫周日晚上班(20240512)【张正标】 作业
- 少年宫周日晚上班(20240414)【张正标】 作业
- 少年宫周日晚上班test IOI
- 少年宫周日晚上班(2024/03/24)【张正标】 作业
- 少年宫周日晚上班(2024/03/17)【张正标】 作业
- 2023少年宫周日晚上5点班期末测试 IOI
- 少年宫周日晚上5点班 IOI
- +++少年宫周日下午晚上班【张正标】(20231203) 作业
- +++少年宫周日下午晚上班【张正标】(20231126) 作业
- +++少年宫周日下午晚上班【张正标】(20231112) 作业
- +++少年宫周日下午晚上班【张正标】(20231105) 作业
- +++少年宫周日下午晚上班【张正标】(20231029) 作业
- +++少年宫周日下午晚上班【张正标】(20231022) 作业
- +++少年宫周日下午晚上班【张正标】(20231015) 作业
- 少年宫模拟测试1题解 难度从J到S- OI
- 少年宫秋季周日晚上班开学测 IOI
- 少年宫秋季周日下午班开学测 IOI
- 少年宫周三班test IOI
- +++少年宫周日5点7点(20230528)+++ 作业
- ===少年宫周日下午5点初级1班(20230521)=== 作业
- ++++【少年宫周日下午5点7点班】++++(20230514) 作业
- 少年宫周日初级1班(20230507) 作业
- 第二届小云雀杯决赛(初级组) OI
- 第二届小云雀杯初级组 IOI
- 周日晚初级c1,c2班摸底测试 IOI
- 2022年天河区创意编程C++小学组 OI
-
最近编写的题解
题目标签
- 语言基础
- 53
- 循环语句
- 22
- 其他
- 17
- 竞赛
- 16
- NOIP
- 14
- 搜索
- 12
- 一维数组
- 10
- 基础语法
- 8
- 位运算
- 8
- 普及组
- 8
- 字符串
- 8
- 选择语句
- 8
- 递归
- 7
- 贪心
- 6
- 递推
- 6
- 二维数组
- 6
- 字符数组
- 6
- DFS
- 5
- 年份
- 5
- 模拟
- 4