-
个人简介
<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=1459037632&auto=1&height=66"></iframe>//扫雷 #include <iostream> #include <cstdlib> #include <ctime> #include <windows.h> #include <queue> #define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) using namespace std; bool l[25][25]; int v[25][25]; int map[25][25] , dx[8] = {1 , -1 , 0 , 0 , 1 , 1 , -1 , -1} , dy[8] = {0 , 0 , 1 , -1 , 1 , -1 , 1 , -1}; struct node { int x , y; }; POINT p; HWND h=GetForegroundWindow(); int main () { int n = 20 , m = 20; HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); DWORD mode; GetConsoleMode(hStdin, &mode); mode &= ~ENABLE_QUICK_EDIT_MODE; SetConsoleMode(hStdin, mode); for (int i = 1; i <= n; i ++) { srand (time (0) + rand ()); l[i][rand () % m + 1] = 1; srand (time (0) + rand ()); while (l[i][rand () % m + 1]) srand (time (0) + rand ()); l[i][rand () % m + 1] = 1; srand (time (0) + rand ()); while (l[i][rand () % m + 1]) srand (time (0) + rand ()); l[i][rand () % m + 1] = 1; } for (int i = 1; i <= n; i ++) { for (int j = 1; j <= m; j ++) { map[i][j] = l[i - 1][j] + l[i + 1][j] + l[i][j - 1] + l[i][j + 1] + l[i - 1][j - 1] + l[i + 1][j - 1] + l[i - 1][j + 1] + l[i + 1][j + 1]; if (l[i][j]) map[i][j] = -1; } } while (true) { if (KEY_DOWN(VK_LBUTTON)) { GetCursorPos(&p); ScreenToClient(h,&p); int x = p.y , y = p.x; x /= 16 , x ++; y /= 16 , y ++; if (x < 1 || y < 1 || x > n || y > m); else if (v[x][y] == 0) { if (map[x][y] == -1) { system ("cls"); printf ("<BOOM> Game Over!"); return 0; } queue <node> qq; qq.push({x , y}); while (!qq.empty ()) { node now = qq.front (); v[now.x][now.y] = 1; qq.pop (); if (map[now.x][now.y] > 0) continue; for (int i = 0; i < 8; i ++) { int nx = now.x + dx[i]; int ny = now.y + dy[i]; if (nx < 1 || ny < 1 || nx > n || ny > m) continue; if (v[nx][ny]) continue; qq.push ({nx , ny}); } } } else if (v[x][y] == 2) v[x][y] = 0; system ("cls"); int cnt = 0; for (int i = 1; i <= n; i ++) { for (int j = 1; j <= m; j ++) { if (v[i][j] == 0) printf ("█"); else if (v[i][j] == 1) if (map[i][j] == -1) printf ("█"); else if (map[i][j] == 0) { printf (" "); cnt ++; } else { printf (" %d" , map[i][j]); cnt ++; } else printf (" P"); } printf ("\n"); } if (cnt == 340) { printf ("You Win!"); return 0; } } if (KEY_DOWN(VK_MBUTTON)) { GetCursorPos(&p); ScreenToClient(h,&p); int x = p.y , y = p.x; x /= 16 , x ++; y /= 16 , y ++; if (v[x][y] == 0) v[x][y] = 2; system ("cls"); int cnt = 0; for (int i = 1; i <= n; i ++) { for (int j = 1; j <= m; j ++) { if (v[i][j] == 0) printf ("█"); else if (v[i][j] == 1) if (map[i][j] == -1) printf ("█"); else if (map[i][j] == 0) { printf (" "); cnt ++; } else { printf (" %d" , map[i][j]); cnt ++; } else printf (" P"); } printf ("\n"); } if (cnt == 340) { printf ("You Win!"); return 0; } } } return 0; }
变色
#include <iostream> #include <windows.h> using namespace std; void rgb_init () { HANDLE hIn = GetStdHandle (STD_INPUT_HANDLE); HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE); DWORD dwInMode , dwOutMode; GetConsoleMode (hIn , &dwInMode); GetConsoleMode (hOut , &dwOutMode); dwInMode |= 0x0200; dwOutMode |= 0x0004; SetConsoleMode (hIn , dwInMode); SetConsoleMode (hOut , dwOutMode); } void rgb_set (int wr , int wg , int wb , int br , int bg , int bb) { printf ("\033[38;2;%d;%d;%dm\033[48;2;%d;%d;%dm" , wr , wg , wb , br , bg , bb); }