# myfirst游戏 **Repository Path**: sky9900/myfirstYouXi ## Basic Information - **Project Name**: myfirst游戏 - **Description**: No description available - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2017-11-23 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # myfirst游戏 #include #include #include #include #include //to use function _getch(); #include #include #define Xmap 25 //地图的宽 #define Ymap 80 //地图的长 #define XXmap 2 //地图的左顶点的x #define YYmap 20 //地图左顶点的y using namespace std; //-----------------控制台函数------------------------- void Setpos(int x, int y) { COORD gb = { x,y }; HANDLE pos = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(pos, gb); } void HideCursor() { CONSOLE_CURSOR_INFO cursor_info = { 1,0 }; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info); } //------------------一些函数-------------------- void pritmap() { system("color 74"); for (int i = YYmap; i <= YYmap + Ymap; ++i) { Setpos(i,XXmap); cout << "-"; Setpos(i,XXmap+Xmap); cout << "-"; } for (int i=XXmap; i <= XXmap+ Xmap; ++i) { Setpos(YYmap, i); cout << "||"; Setpos(YYmap+Ymap, i); cout << "||"; } return; } void mouse() { } void begin() { pritmap(); Setpos(((YYmap + Ymap) / 2 ),((XXmap + Xmap) / 2)); cout << "请按任意键进入游戏" << endl; _getch(); pritmap(); /* Setpos(((YYmap + Ymap) / 2), ((XXmap + Xmap) / 2)); cout << "开始游戏"; Setpos(((YYmap + Ymap) / 2-3), ((XXmap + Xmap) / 2+1)); cout << "用鼠标点击选择难度"; Setpos(((YYmap + Ymap) / 2-3), ((XXmap + Xmap) / 2+2)); cout << "简单 困难 噩梦"; mouse(); */ return; } //-------------------------------------class------------------------------------ class Game { public: COORD enemy[8]; COORD plane; Game(); void priplane(); void moveenemy(); void moveplane(); void initplane(); void initenemy(); void removeplane(COORD a); void removeenemy(COORD a); }; Game::Game() { initenemy(); initplane(); } void Game::initplane() { plane = { XXmap + Xmap - 1,(YYmap + Ymap) / 2 }; priplane(); } void Game::initenemy() { for (int i = 0; i <= 7; ++i) { enemy[i].X= rand() % 3 + XXmap + 1; enemy[i].Y= rand() %80 + YYmap + 1; Setpos(enemy[i].Y - 1, enemy[i].X); cout << "= ="; Setpos(enemy[i].Y, enemy[i].X + 1); cout << "|"; } } void Game::removeplane(COORD a) { Setpos(a.Y - 1, a.X); cout << " "; Setpos(a.Y - 1, a.X - 1); cout << " "; } void Game::removeenemy(COORD a) { Setpos(a.Y - 1, a.X); cout << " "; Setpos(a.Y - 1, a.X + 1); cout << " "; } void Game::priplane() { Setpos(plane.Y - 1, plane.X); cout << "=*="; Setpos(plane.Y, plane.X - 1); cout << "|"; } void Game::moveenemy() { for (int i = 0; i <= 7; ++i) { removeenemy(enemy[i]); enemy[i].X += 1; Setpos(enemy[i].Y - 1, enemy[i].X); cout << "= ="; Setpos(enemy[i].Y, enemy[i].X + 1); cout << "|"; } } void Game::moveplane() { } //-----------------------main------------------------ int main() { srand((int)time(0)); HideCursor(); begin(); system("pause>>NULL"); return 0; }