c++全套流水账——写点游戏?!
2020-07-26 17:32
489 查看
c++——写点游戏
肯定有些同学想用c++写点游戏,今天,cht就来说说这个(必须有Windows处理器或电脑,Linux不支持)。
关于acwing
一、准备
1、必备算法
(1)高精度
(2)DFS(或BFS)
(3)递推与递归
(4)字符串运算
(5)位运算
(6)部分STL(sort,swap……)
2、头文件
(1)#include<bits/stdc++.h>//万能头文件
(2)#include<conio.h>//getch()
(3)#include<stdlib.h>//system()
(4)#include<ctime>
二、模板与语法
1、getch();
用法:可以在不打换行的前提下输入一个字符(要用conio.h)。
模板
char op; op = getch(); while(op == ' '/*条件*/) { op = getch(); }
事例(按空格键继续):
#include<bits/stdc++.h> #include<conio.h> using namespace std; int main() { cout << "空格继续" << endl; char op; op = getch(); while(op != ' ') { op = getch(); } cout << "再见" << endl; return 0; }
效果:
2、system()
这个函数对应的头文件是:#include<stdlib.h>
具体语法:
(1)、system("cls")//清空屏幕
(2)、
system("color *F);//这里的*可以填0-7。
*的具体填法(写个system("color 10F")
就能出来):
(3)、system("mode con cols=100 lines=40");//初始化缓冲区大小
3、读入读出句柄与字体设置
读入读出句柄是这行:
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);//获取标准输出句柄(写在using namespace std后面) CloseHandle(hOut);//关闭标准输出句柄(写在return 0前面)
就是这么设置(后面的均用这个句柄)。
那它能干什么呢?
(1)、字体颜色:
蓝色:
void blue_border() { WORD blue=FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN;//设置字体颜色、背景颜色 SetConsoleTextAttribute(hOut,blue);//字体样式 }
白色:
void white_back() { WORD white=FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY; SetConsoleTextAttribute(hOut,white); }
青色:
void cyan_choose() { WORD cyan=FOREGROUND_GREEN|FOREGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_BLUE; SetConsoleTextAttribute(hOut,cyan); }
不太好的红色和橙色(其实都是可以自己做的,有兴趣的小伙伴不妨试试):
void red_choose() { WORD red=FOREGROUND_RED|FOREGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_BLUE; SetConsoleTextAttribute(hOut,red); } void orange_choose() { WORD orange=FOREGROUND_RED|FOREGROUND_INTENSITY|BACKGROUND_BLUE|BACKGROUND_BLUE; SetConsoleTextAttribute(hOut,orange); }
自己做的例子:
void on_Select() { WORD select=FOREGROUND_GREEN|FOREGROUND_INTENSITY|BACKGROUND_RED; SetConsoleTextAttribute(hOut,select); }
(2)、输出的位置(光标):
游戏里最常用的函数。
pos(x,y);
代码:
void pos(int x,int y) { COORD posPoint = {x,y}; //设置坐标 SetConsoleCursorPosition(hOut,posPoint); }
(4)、blahblahblah
要写标题请加这行(引号里写标题):
SetConsoleTitle("");
三、游戏事例
1、小程序:一元一次方程神器:
#include <bits/stdc++.h>//C++万能头 #include<windows.h>//控制台编程主要头文件Sleep(); #include<conio.h>//getch()函数 #include<stdlib.h>//system()函数 using namespace std; void pos(int x,int y);//确定光标位置 void blue_border();//蓝色字体 void white_back();//还原亮白色字体 void cyan_choose();//青色字体 void on_Select();//被选中时的样式 void onChoose(int x,int y);//确定所选中的位置 void star();//初始化界面 struct node { double a, b; }; int priority(char c) { if (c == '*' || c == '/') return 2; if (c == '+' || c == '-') return 1; return 0; } void calc(stack <char> &op, stack <node> &num) { node bb = num.top(); num.pop(); node aa = num.top(); num.pop(); node temp_node; switch (op.top()) { case '+': temp_node.a = aa.a + bb.a; temp_node.b = aa.b + bb.b; num.push(temp_node); break; case '-': temp_node.a = aa.a - bb.a; temp_node.b = aa.b - bb.b; num.push(temp_node); break; case '*': temp_node.a = aa.a * bb.b + aa.b * bb.a; temp_node.b = aa.b * bb.b; num.push(temp_node); break; case '/': temp_node.a = aa.a / bb.b; temp_node.b = aa.b / bb.b; num.push(temp_node); break; } op.pop(); } void d() { cyan_choose(); pos(31,14); cout << "欢迎来到一元一次方程神器!"; Sleep(1000);//等待 system("cls"); system("color 2F"); blue_border(); int x=25,y=10; char sel; sel=getch(); while(sel!=' ') { pos(x,y); onChoose(x,y); sel=getch(); } system("cls"); system("color 3F"); cyan_choose(); pos(25,23); cout << "请输入方程:" ; while (1) { string str, str_l, str_r; cin >>str; for (int i = 0; i < str.size(); ++ i) { if (str[i] == '=') { str_l = str.substr(0, i); str_r = str.substr(i + 1, str.size()); } } stack <node> num_l; stack <node> num_r; stack <char> op_l; stack <char> op_r; int len_l = str_l.size(); int len_r = str_r.size(); for (int i = 0; i < len_l; ++ i) { if (isdigit(str_l[i])) { node temp_node; double temp = atof(&str_l[i]); while (isdigit(str_l[i]) || str_l[i] == '.') ++ i; if (str_l[i] == 'x') { temp_node.a = temp; temp_node.b = 0; num_l.push(temp_node); } else { temp_node.a = 0; temp_node.b = temp; num_l.push(temp_node); -- i; } } else if (str_l[i] == 'x') { node temp_node; temp_node.a = 1; temp_node.b = 0; num_l.push(temp_node); } else if (str_l[i] == '(') { op_l.push(str_l[i]); } else if (str_l[i] == ')') { while (op_l.top() != '(') calc(op_l, num_l); op_l.pop(); } else if (op_l.empty()) { op_l.push(str_l[i]); } else if (priority(op_l.top()) < priority(str_l[i])) { op_l.push(str_l[i]); } else if (priority(op_l.top()) >= priority(str_l[i])) { while (!op_l.empty() && priority(op_l.top()) >= priority(str_l[i])) calc(op_l, num_l); op_l.push(str_l[i]); } } for (int i = 0; i < len_r; ++ i) { if (isdigit(str_r[i])) { node temp_node; double temp = atof(&str_r[i]); while (isdigit(str_r[i]) || str_r[i] == '.') ++ i; if (str_r[i] == 'x') { temp_node.a = temp; temp_node.b = 0; num_r.push(temp_node); } else { temp_node.a = 0; temp_node.b = temp; num_r.push(temp_node); -- i; } } else if (str_r[i] == 'x') { node temp_node; temp_node.a = 1; temp_node.b = 0; num_r.push(temp_node); } else if (str_r[i] == '(') { op_r.push(str_r[i]); } else if (str_r[i] == ')') { while (op_r.top() != '(') calc(op_r, num_r); op_r.pop(); } else if (op_r.empty()) { op_r.push(str_r[i]); } else if (priority(op_r.top()) < priority(str_r[i])) { op_r.push(str_r[i]); } else if (priority(op_r.top()) >= priority(str_r[i])) { while (!op_r.empty() && priority(op_r.top()) >= priority(str_r[i])) calc(op_r, num_r); op_r.push(str_r[i]); } } while (!op_l.empty()) calc(op_l, num_l); while (!op_r.empty()) calc(op_r, num_r); double x1 = num_l.top().a, y1 = num_l.top().b; double x2 = num_r.top().a, y2 = num_r.top().b; system("cls"); system("color 3F"); pos(20,20); printf("%.3lf\n", (y2 - y1) / (x1 - x2)); Sleep(2000); pos(20,21); cout << "要继续吗?" << endl; char op; op = getch(); while(op != ' ') { op = getch(); } system("cls"); system("color 3F"); pos(20,20); cout << "谢谢使用,再见!"; Sleep(2000); return; } } HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);//获取标准输出句柄 int main() { system("color 7F");//设置控制台界面背景颜色和前景颜色 system("mode con cols=100 lines=40");//初始化缓冲区大小 SetConsoleTitle("一元一次方程神器");//设置控制台窗口标题 cyan_choose(); cout<<"w,a,s,d 控制光标选择;空格 确定"<<endl; blue_border(); pos(5,5); cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";//上边框 pos(5,25); cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";//下边框 for(int i=5,j=6; j<25; j++) //左边框 { pos(i,j); cout<<"*"; } for(int i=85,j=6; j<25; j++) //右边框 { pos(i,j); cout<<"*"; } cyan_choose(); pos(65,10);//指定位置输出 cout<<"2. 选择 "; pos(25,20); cout<<"3. 继续 "; pos(65,20); cout<<"4. 退出 "; on_Select(); pos(25,10); cout<<"1. 开始 "; //wsad控制光标对进行自由选择 int x=25,y=10; char sel; sel=getch();//和cin相比,不需要按enter键 while(sel!=' ') { star(); switch(sel) { case 'w': y=y-10; break; case 's': y=y+10; break; case 'a': x=x-40; break; case 'd': x=x+40; break; } //防止超出范围 if(x>=65) { x=65; } if(y>=20) { y=20; } if(x<=25) { x=25; } if(y<=10) { y=10; } pos(x,y); onChoose(x,y); sel=getch();//刷新sel } pos(0,30); system("cls"); system("color 5F"); blue_border(); pos(5,5); pos(5,25); cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";//下边框 for(int i=5,j=6; j<25; j++) //左边框 { pos(i,j); cout<<"*"; } for(int i=85,j=6; j<25; j++) //右边框 { pos(i,j); cout<<"*"; } d(); cyan_choose(); CloseHandle(hOut);//关闭标准输出句柄 return 0; } //设置光标位置 void pos(int x,int y) { COORD posPoint = {x,y}; //设置坐标 SetConsoleCursorPosition(hOut,posPoint); }void blue_border() { WORD blue=FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN;//设置字体颜色、背景颜色 SetConsoleTextAttribute(hOut,blue);//字体样式 }void white_back() { WORD white=FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY; SetConsoleTextAttribute(hOut,white); }void cyan_choose() { WORD cyan=FOREGROUND_GREEN|FOREGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_BLUE; SetConsoleTextAttribute(hOut,cyan); }void on_Select() { WORD select=FOREGROUND_GREEN|FOREGROUND_INTENSITY|BACKGROUND_RED; SetConsoleTextAttribute(hOut,select); }void onChoose(int x,int y) { if(x==25&&y==10) { on_Select(); cout<<"1. 开始 "; } else if(x==25&&y==20) { on_Select(); cout<<"3. 继续 "; } else if(x==65&&y==10) { on_Select(); cout<<"2. 选择 "; } else if(x==65&&y==20) { on_Select(); cout<<"4. 退出 "; } } void star() { cyan_choose(); pos(25,10); cout<<"1. 开始 "; pos(65,10); cout<<"2. 选择 "; pos(25,20); cout<<"3. 继续 "; pos(65,20); cout<<"4. 退出 "; }
2、画图小程序(bug多多的):
#include<bits/stdc++.h> #include<stdlib.h> #include<windows.h> #include<conio.h> using namespace std; int x[3][2]; int y[4][2]; int x2[3][2]; int y2[4][2]; int x3[3][2]; int y3[4][2]; int x4[4][2]; int y4[4][2]; HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE); void pos(int x,int y) { COORD posPoint = {x,y}; //设置坐标 SetConsoleCursorPosition(hOut,posPoint); } int main() { system("color 3F"); system("color AF"); system("mode con cols=100 lines=40"); SetConsoleTitle("画图神器"); cout << "欢迎来到画图神器" << endl; Sleep(1000); cout << "1键退出" << endl; Sleep(1000); cout << "a,b,c,d,z键画图" << endl; Sleep(1000); x[0][0] = 0;//**** x[0][1] = 3; x[1][0] = 0;//**** x[1][1] = 3; x[2][0] = 1;// ** x[2][1] = 2; y[0][0] = 0;//** y[0][1] = 1; y[1][0] = 0;//*** y[1][1] = 2; y[2][0] = 0;//*** y[2][1] = 2; y[3][0] = 0;//** y[3][1] = 1; x2[0][0] = 1; x2[0][1] = 2; x2[1][0] = 0; x2[1][1] = 3; x2[2][0] = 0; x2[2][1] = 3; y2[0][0] = 1; y2[0][1] = 2; y2[1][0] = 0; y2[1][1] = 2; y2[2][0] = 0; y2[2][1] = 2; y2[3][0] = 1; y2[3][1] = 2; x3[0][0] = 0; x3[0][1] = 1; x3[1][0] = 0; x3[1][1] = 3; x3[2][0] = 0; x3[2][1] = 3; y3[0][0] = 0; y3[0][1] = 2; y3[1][0] = 0; y3[1][1] = 2; y3[2][0] = 1; y3[2][1] = 2; y3[3][0] = 1; y3[3][1] = 2; x4[0][0] = 0; x4[0][1] = 1; x4[1][0] = 0; x4[1][1] = 3; x4[2][0] = 0; x4[2][1] = 3; x4[3][0] = 2; x4[3][1] = 3; y4[0][0] = 0; y4[0][1] = 2; y4[1][0] = 1; y4[1][1] = 2; y4[2][0] = 1; y4[2][1] = 2; y4[3][0] = 1; y4[3][1] = 3; char a; for(int i = 0;;i ++) { cout << endl <<"请按任意键继续" << endl; char op; op = getch(); while(op == ' ') { op = getch(); } system("cls"); system("color 3F"); system("color AF"); a = getch(); while(a == ' ') { a = getch(); } if(a == 'a') { for(int i = 0;i <= 2; i ++) { for(int j = x[i][0]; j <= x[i][1]; j ++) { pos(j,i); cout << "*"; } cout << endl; } for(int i = 0;i <= 3; i ++) { for(int j = y[i][0]; j <= y[i][1]; j ++) { pos(i,j); cout << "*"; } cout << endl; } } else if(a == 'b') { for(int i = 0;i <= 2; i ++) { for(int j = x2[i][0]; j <= x2[i][1]; j ++) { pos(j,i); cout << "*"; } cout << endl; } for(int i = 0;i <= 3; i ++) { for(int j = y2[i][0]; j <= y2[i][1]; j ++) { pos(i,j); cout << "*"; } cout << endl; } } else if(a == 'c') { for(int i = 0;i <= 2; i ++) { for(int j = x3[i][0]; j <= x3[i][1]; j ++) { pos(j,i); cout << "*"; } cout << endl; } for(int i = 0;i <= 3; i ++) { for(int j = y3[i][0]; j <= y3[i][1]; j ++) { pos(i,j); cout << "*"; } cout << endl; } } else if(a == '1') { break; } else if(a == 'd') { for(int i = 0;i <= 3; i ++) { for(int j = x4[i][0]; j <= x4[i][1]; j ++) { pos(j,i); cout << "*"; } cout << endl; } for(int i = 0;i <= 3; i ++) { for(int j = y4[i][0]; j <= y4[i][1]; j ++) { pos(i,j); cout << "*"; } cout << endl; } } else if(a == 'z') { char op; cout << "好的,按wasd控制线条" << endl; int i = 0,j = 0; system("cls"); system("color 3F"); system("color AF"); pos(i,j); cout << "*"; op = getch(); for(;;) { op = getch(); if(op == 'a') { if(i != 0)pos(i - 1,j); cout << "*"; i -= 1; } else if(op == 's'){ if(j != 0)pos(i, j + 1); cout << "*"; j -= 1; } else if(op == 'd') { pos(i,j - 1); cout << "*"; i += 1; } else if(op == 'w'){ pos(i + 1,j); cout << "*"; j += 1; } else if(op == 'e') { break; } } } Sleep(1000); } Sleep(1000); cout << "谢谢使用,再见!" << endl; Sleep(4000); CloseHandle(hOut); return 0; }
3、跑酷天堂(网上改的):
#include <bits/stdc++.h> #include <windows.h> #include <conio.h> using namespace std; char mmp[1001][1001] = {" ", " ", " ### ", " ", " ## ##### ", " ## ", " ", " ", " ## ", " ", " ", " ## ### ", " ## #### ", " ### #### ", " ### ## ", " ", " O ", "##### ", "##### ", "####################################################################################################" };//20 * 50; char putmmp[20][16]; int jump[20] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, -1, 0, -1, 0, -1, 0, -1}; int main() { char ch; bool t = 1; int x = 16, y = 2, delayjump = 0; system("color 3F"); system("mode con cols=100 lines=40"); SetConsoleTitle("跑酷天堂 l1"); while (1) { Sleep(30); if (y - 7 < 0) { for (register int i = 0; i < 20; i++) { for (register int j = 0; j < 15; j++) { putmmp[i][j] = mmp[i][j]; } putmmp[i][15] = '\n'; } } else if (y + 7 > 99) { for (register int i = 0; i < 20; i++) { int k = 14; for (register int j = 99; j >= 85; j--, k--) { putmmp[i][k] = mmp[i][j]; } putmmp[i][15] = '\n'; } } else { for (register int i = 0; i < 20; i++) { int k = 0; for (register int j = y - 7; j <= y + 7; j++, k++) { putmmp[i][k] = mmp[i][j]; } putmmp[i][15] = '\n'; } } system("cls"); system("color 3F"); fwrite(putmmp, 1, 20 * 16, stdout); if (delayjump > 0) { if (delayjump > 8 && (x + jump[delayjump] == 20 || mmp[x + jump[delayjump]][y] == '#')) { delayjump = 5; } else { if (delayjump <= 8 && (x + jump[delayjump] == -1 || mmp[x + jump[delayjump]][y] == '#')) { delayjump = 0; } else { mmp[x][y] = ' '; x += jump[delayjump]; mmp[x][y] = 'O'; delayjump--; } } } if (!delayjump) { if (mmp[x + 1][y] == ' ' && x < 19 && t) { t = !t; mmp[x][y] = ' '; x++; mmp[x][y] = 'O'; } else { t = !t; } } if (kbhit()) { ch = getch(); switch(ch) { case 27 : exit(0); break; case -32 : ch = getch(); switch(ch) { case 75 : if (y > 0 && mmp[x][y - 1] == ' ') { mmp[x][y] = ' '; y--; mmp[x][y] = 'O'; } break; case 77 : if (y < 99 && mmp[x][y + 1] == ' ') { mmp[x][y] = ' '; y++; mmp[x][y] = 'O'; } break; case 72 : if (!delayjump) { delayjump = 18; } break; } break; } } } return 0; }
4、飞翔的小鸟(网上转载的):
#include <ctime> #include<cstdio> #include <string> #include <cstdlib> #include <conio.h> #include <windows.h> using namespace std; int h,w,c=0; int score=0;//得分 int xn_x,xn_y,b1,b2,b3; char asd; void data(){ h=15; w=25; xn_x=0; xn_y=w/3; b3=w; b1=h/4; b2=h/2; } void page(){ int i,j; char dad ; if(c==0){ system("color 0C"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" =======================================\n"); printf(" = --->飞翔的小鸟<--- =\n"); printf(" = =\n"); printf(" = 空格控制小鸟移动 =\n"); printf(" = 5键暂停继续 =\n"); printf(" = =\n"); printf(" = =\n"); printf(" = 闪屏纯属正常 =\n"); printf(" = ----朱 * * =\n"); printf(" =======================================\n"); c++; dad=getch(); } system("cls"); system("color 02"); for(i=0;i<h;i++){ for(j=0;j<=w;j++){ if(i==xn_x && j==xn_y){ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),14); printf("卐"); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),2); } else if(j==b3&&(i<=b1||i>=b2)){ if(i==xn_x && j>xn_y){ printf("▓"); } else printf(" ▓"); } else printf(" "); } printf("\n"); } SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),9); printf("================================================================================\n"); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),11); printf(" ------------------> 当前得分:%d <------------------\n\n\n",score); } void no(){ int randx; if(xn_y==b3){ if(xn_x>b1&&xn_x<b2) score++; else{ system("color F0"); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),252); printf(" ------> the end <------\n"); c=3; asd=getch(); } } xn_x++; if(b3==0){ b3=w; b1=rand()%(h-5); randx=b1; b2=randx+h/4+2; } else b3--; Sleep(120); } void yes(){ char input; if(kbhit()){ input=getch(); if(input==' ') xn_x-=3; if(input=='5') while(getch()!='5'){};//暂停继续 } } int main(){ system("title 飞翔的小鸟 2.0版 ---朱 * *"); data();//加载数据 while(1){ page();//页面 no();//与用户无关变量 yes();//与用户有关变量 if(c==3)break; } return 0; }
5、迷宫(网上的):
#include <stdio.h> #include <conio.h> #include <windows.h> #include <time.h> /* *迷宫的高度 */ #define Height 23 /* *迷宫的宽度 */ #define Width 39 #define Esc 5 #define Up 1 #define Down 2 #define Left 3 #define Right 4 #define Wall 1 #define Road 0 #define Start 2 #define End 3 int map[Height+2][Width+2]; /* *随机生成迷宫 */ void create(int x,int y) { int c[4][2]={0,1,1,0,0,-1,-1,0}; /*四个方向*/ int i,j,t; /* *将方向打乱 */ for(i=0;i<4;i++) { j=rand()%4; t=c[i][0];c[i][0]=c[j][0];c[j][0]=t; t=c[i][1];c[i][1]=c[j][1];c[j][1]=t; } map[x][y]=Road; for(i=0;i<4;i++) if(map[x+2*c[i][0]][y+2*c[i][1]]==Wall) { map[x+c[i][0]][y+c[i][1]]=Road; create(x+2*c[i][0],y+2*c[i][1]); } } /* *移动坐标 */ void gotoxy(int x,int y) { COORD coord; coord.X=x; coord.Y=y; SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord ); } /* *隐藏光标 */ void hidden() { HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cci; GetConsoleCursorInfo(hOut,&cci); cci.bVisible=0;/*赋1为显示,赋0为隐藏*/ SetConsoleCursorInfo(hOut,&cci); } void paint(int x,int y) { gotoxy(2*y-2,x-1); switch(map[x][y]) { case Start: printf("进");break; /*画入口*/ case End: printf("出");break; /*画出口*/ case Wall: printf("■");break; /*画墙*/ case Road: printf(" ");break; /*画路*/ } } /* *接收按键 */ int get_key() { char c; while(c=getch()) { if(c==27) return Esc; /*Esc*/ // if(c!=-32)continue; // c=getch(); if(c==72) return Up; /*上*/ if(c==80) return Down; /*下*/ if(c==75) return Left; /*左*/ if(c==77) return Right; /*右*/ } return 0; } /* *画迷宫 */ void game() { int x=2,y=1; /*玩家当前位置,刚开始在入口处*/ int c; /*用来接收按键*/ while(1) { gotoxy(2*y-2,x-1); printf("★"); /*画出玩家当前位置*/ if(map[x][y]==End) /*判断是否到达出口*/ { gotoxy(30,24); printf("到达终点,按任意键结束"); getch(); break; } c=get_key(); if(c==Esc) { gotoxy(0,24); break; } switch(c) { case Up: /*向上走*/ if(map[x-1][y]!=Wall) { paint(x,y); x--; } break; case Down: /*向下走*/ if(map[x+1][y]!=Wall) { paint(x,y); x++; } break; case Left: /*向左走*/ if(map[x][y-1]!=Wall) { paint(x,y); y--; } break; case Right: /*向右走*/ if(map[x][y+1]!=Wall) { paint(x,y); y++; } break; } } } int main() { int i,j; system("color 2b"); srand((unsigned)time(NULL)); /*初始化随即种子*/ hidden(); /*隐藏光标*/ for(i=0;i<=Height+1;i++) for(j=0;j<=Width+1;j++) if(i==0||i==Height+1||j==0||j==Width+1) /*初始化迷宫*/ map[i][j]=Road; else map[i][j]=Wall; create(2*(rand()%(Height/2)+1),2*(rand()%(Width/2)+1)); /*从随机一个点开始生成迷宫*/ for(i=0;i<=Height+1;i++) /*边界处理*/ { map[i][0]=Wall; map[i][Width+1]=Wall; } for(j=0;j<=Width+1;j++) /*边界处理*/ { map[0][j]=Wall; map[Height+1][j]=Wall; } map[2][1]=Start; /*给定入口*/ map[Height-1][Width]=End; /*给定出口*/ for(i=1;i<=Height;i++) for(j=1;j<=Width;j++) /*画出迷宫*/ paint(i,j); game(); /*开始游戏*/ return 0; }
如果大家会工程还可以看看这几个:
1、贪吃蛇(网上的):
main.cpp:
#include<windows.h> #include<algorithm> #include<iostream> #incldue<cstring> #include<cstdio> #include<cmath> #include<queue> #include<vector> #include<map> #include"people.h" using namespace std; int main() { system("pause"); return 0; }
snake.cpp:
#include <windows.h> #include <ctime> #include <iostream> #include "snake.h" using namespace std; //测试成功 void Csnake::InitInstance() { snakeMap.resize(line); // snakeMap[竖坐标][横坐标] for(int i=0;i<line;i++) { snakeMap[i].resize(row); for(int j=0;j<row;j++) { snakeMap[i][j]=' '; } } for(int m=1;m<maxSize+1;m++) { //初始蛇身 snakeMap[line/2][m]='@'; //将蛇身坐标压入队列 snakeBody.push(Cmp(m,(line/2))); //snakeBody[横坐标][竖坐标] } //链表头尾 firstSign=snakeBody.back(); secondSign.setPoint(maxSize-1,line/2); } //测试成功 int Csnake::GetDirections()const { if(GetKeyState(VK_UP)<0) return 1; //1表示按下上键 if(GetKeyState(VK_DOWN)<0) return 2; //2表示按下下键 if(GetKeyState(VK_LEFT)<0) return 3; //3表示按下左键 if(GetKeyState(VK_RIGHT)<0)return 4; //4表示按下右键 return 0; } bool Csnake::UpdataGame() { //----------------------------------------------- //初始化得分0 static int score=0; //获取用户按键信息 int choice; choice=GetDirections(); cout<<"分数: "<<score<<endl; //随机产生食物所在坐标 int r,l; //开始初始已经吃食,产生一个食物 static bool eatFood=true; //如果吃了一个,才再出现第2个食物 if(eatFood) { do { //坐标范围限制在(1,1)到(line-2,row-2)对点矩型之间 srand(time(0)); r=(rand()%(row-2))+1; //横坐标 l=(rand()%(line-2))+1;//竖坐标 //如果随机产生的坐标不是蛇身,则可行 //否则重新产生坐标 if(snakeMap[l][r]!='@') {snakeMap[l][r]='*';} }while (snakeMap[l][r]=='@'); } switch (choice) { case 1://向上 //如果蛇头和社颈的横坐标不相同,执行下面操作 if(firstSign.rSign!=secondSign.rSign)nextSign.setPoint(firstSign.rSign,firstSign.lSign-1); //否则,如下在原本方向上继续移动 else nextSign=firstSign+(firstSign-secondSign); break; case 2://向下 if(firstSign.rSign!=secondSign.rSign)nextSign.setPoint(firstSign.rSign,firstSign.lSign+1); else nextSign=firstSign+(firstSign-secondSign); break; case 3://向左 if(firstSign.lSign!=secondSign.lSign)nextSign.setPoint(firstSign.rSign-1,firstSign.lSign); else nextSign=firstSign+(firstSign-secondSign); break; case 4://向右 if(firstSign.lSign!=secondSign.lSign)nextSign.setPoint(firstSign.rSign+1,firstSign.lSign); else nextSign=firstSign+(firstSign-secondSign); break; default: nextSign=firstSign+(firstSign-secondSign); } //---------------------------------------------------------- if(getSymbol(nextSign)!='*' && !isDead(nextSign)) //如果没有碰到食物(且没有死亡的情况下),删除蛇尾,压入新的蛇头 { //删除蛇尾 lastSign=snakeBody.front(); snakeMap[lastSign.lSign][lastSign.rSign]=' '; snakeBody.pop(); //更新蛇头 secondSign=firstSign; //压入蛇头 snakeBody.push(nextSign); firstSign=snakeBody.back(); snakeMap[firstSign.lSign][firstSign.rSign]='@'; //没有吃食 eatFood=false; return true; } //-----吃食----- else if(getSymbol(nextSign)=='*' && !isDead(nextSign)) { secondSign=firstSign; snakeMap[nextSign.lSign][nextSign.rSign]='@'; //只压入蛇头 snakeBody.push(nextSign); firstSign=snakeBody.back(); eatFood=true; //加分 score+=20; return true; } //-----死亡----- else {cout<<"Dead"<<endl;cout<<"Your last total score is "<<score<<endl; return false;} } void Csnake::ShowGame() { for(int i=0;i<line;i++) { for(int j=0;j<row;j++) cout<<snakeMap[i][j]; cout<<endl; } Sleep(1); system("cls"); }
snake.h:
#include <vector> #include <queue> using namespace std; #ifndef SNAKE_H #define SNAKE_H class Cmp { friend class Csnake; int rSign; //横坐标 int lSign; //竖坐标 public: // friend bool isDead(const Cmp& cmp); Cmp(int r,int l){setPoint(r,l);} Cmp(){} void setPoint(int r,int l){rSign=r;lSign=l;} Cmp operator-(const Cmp &m)const { return Cmp(rSign-m.rSign,lSign-m.lSign); } Cmp operator+(const Cmp &m)const { return Cmp(rSign+m.rSign,lSign+m.lSign); } }; const int maxSize = 5; //初始蛇身长度 class Csnake { Cmp firstSign; //蛇头坐标 Cmp secondSign;//蛇颈坐标 Cmp lastSign; //蛇尾坐标 Cmp nextSign; //预备蛇头 int row; //列数 int line; //行数 int count; //蛇身长度 vector<vector<char> > snakeMap;//整个游戏界面 queue<Cmp> snakeBody; //蛇身 public: int GetDirections()const; char getSymbol(const Cmp& c)const //获取指定坐标点上的字符 { return snakeMap[c.lSign][c.rSign]; } Csnake(int n) //初始化游戏界面大小 { if(n<20)line=20+2; else if(n>30)line=30+2; else line=n+2; row=line*3+2; } bool isDead(const Cmp& cmp) { return ( getSymbol(cmp)=='@' || cmp.rSign == row-1 || cmp.rSign== 0 || cmp.lSign == line-1 || cmp.lSign == 0 ); } void InitInstance(); //初始化游戏界面 bool UpdataGame(); //更新游戏界面 void ShowGame(); //显示游戏界面 }; #endif // SNAKE_H
2、赛车(网上大佬写的)
stdafx.cpp
//Download by http://www.NewXing.com // stdafx.cpp : source file that includes just the standard includes // race.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include "stdafx.h" // TODO: reference any additional headers you need in STDAFX.H // and not in this file
stdafx.h
// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently //// Download by http://www.NewXing.com #if !defined(AFX_STDAFX_H__00EFDC91_4920_4CF9_9DB3_D28255687406__INCLUDED_) #define AFX_STDAFX_H__00EFDC91_4920_4CF9_9DB3_D28255687406__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include <stdio.h> // TODO: reference additional headers your program requires here //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_STDAFX_H__00EFDC91_4920_4CF9_9DB3_D28255687406__INCLUDED_)
race.cpp
//***************************************************************** // Silple Race Ver 0.1 // Made by 'k-net 9th' Jae-Dong // E-Mail: pjd@kw.ac.kr // Download by http://www.NewXing.com //***************************************************************** #include "stdafx.h" #include <stdlib.h> #include <time.h> #include <conio.h> #include <math.h> #include <windows.h> //******************* // 惑荐 急攫 //******************* #define CONSOL_WIDTH 80 #define CONSOL_HEIGHT 24 #define EXT_KEY 0xffffffe0 //犬厘虐 牢侥蔼 #define KEY_LEFT 0x4b #define KEY_RIGHT 0x4d //******************* // 备炼眉 急攫 //******************* struct CAR{ char name[16]; int max_spd; int energy; int accel; }; //******************* //傈开 函荐 急攫 //******************* char player_name[20]={"NoName"}; float player_score=0; int player_energy=99; double player_speed=1; int player_carnum=9; //风橇柳涝阑 困窍咯 檬扁蔼阑 瘤沥窃 float player_accel; struct CAR cardata[5]; int road_index,next_index; int player_carpos=20; //泅犁 磊悼瞒狼 困摹 char video_buf[CONSOL_HEIGHT][CONSOL_WIDTH+1]; //橇肺弊伐俊辑绰 捞 硅凯俊 函版且 拳搁阑 盎脚茄促. int speed_counter=0; //何调洒瘤 臼绊 柳青窍绰瘤 眉农窍扁困窃 static char road[22][2]={15,30,15,30,15,30,15,30,15,30,15,30,15,30,15,30,15,30,15,30,15,30,15,30, 15,30,15,30,15,30,15,30,15,30,15,30,15,30,15,30,15,30,15,30}; //road[?][0]捞 left, road[?][1]捞 right char car[5][5][9]={".-TTTT-.", "0-++++-0", " I⑺I ", "[]+--+[]", " Y--Y ", "._|__|_.", "()ΥΣ()", " IスI ", "(||)(||)", " ^ ^ ", " ΤΤ ", "[]ΧΧ[]", " [ノ] ", "⒛::::⑴", " ≡≡ ", "ΞΜΜΟ", "⒎ ⒐", "⒎ ≥ ⒐", "⒏ ⒑", "Ρ←←Π", " ∧Ω∧ ", "⑷$℃⑷", " [≮] ", "⑷∽∽⑷", " ⒆① ",}; //********************* //窃荐 proto type 急攫 //********************* int init(); int video_refresh(); int show_logo(); int show_car(int move); //霸烙吝 拳搁俊 磊悼瞒甫 钎矫茄促. -1篮 哭率栏肺 1篮 坷弗率栏肺 int show_carxy(int carnum,int x,int y); int show_gameframe(); //霸烙拳搁狼 寇胞急阑 弊赴促. int show_stat(); //霸烙拳搁狼 痢荐客 加档客 俊呈瘤甫 盎脚且锭 荤侩 int show_road(); int show_count(); int show_gameover(); int gotoxy(int x,int y); int input_player_data(); int strike_check(); //磊悼瞒客 档肺客 面倒沁绰瘤 八荤窍绊 面倒矫 面倒何盒阑 拳搁俊 免仿 int main(int argc, char* argv[]) { double delay; int frame=0; int i; char key_temp; init(); show_logo(); input_player_data(); system("cls"); player_energy = cardata[player_carnum].energy; show_gameframe(); show_stat(); show_count(); player_accel = (float) cardata[player_carnum].accel/10; for(i=0;i<=200000;i++) //霸烙矫累 { if(kbhit()) { key_temp = getche(); if(key_temp == EXT_KEY) { key_temp = getche(); gotoxy(0,24); putchar(' '); switch(key_temp) { case KEY_LEFT: show_car(-1); player_speed -=1; strike_check(); break; case KEY_RIGHT: show_car(1); player_speed -=1; strike_check(); break; } } strike_check(); } if(player_speed < 100) player_speed += 2.7; if(speed_counter > 6) { if(player_speed < 100) { player_speed = player_speed + (7.6 * player_accel); }else if(player_speed < 200) { player_speed = player_speed + (1.2 * player_accel ); }else if(player_speed < 300) { player_speed = player_speed + ( 0.3 * player_accel ); }else if(player_speed < 315) { player_speed = player_speed + ( 0.1 * player_accel ); }else { player_speed = player_speed + ( 0.06 * player_accel ); } if(player_speed>cardata[player_carnum].max_spd) player_speed = cardata[player_carnum].max_spd; } delay = 350 - (351 * (1-exp(-player_speed/70))); if(delay<0) delay=0.01; if(i%5==0) { player_score = (float)((player_score + player_speed/50)* 1.0003); show_stat(); show_car(0); show_road(); strike_check(); speed_counter++; } show_stat(); if(player_energy <=0) { show_gameover(); fflush(stdin); scanf("%d",&i); break; } gotoxy(10,24); printf("delay: %10.2f",(float)delay); gotoxy(0,24); Sleep((unsigned int)delay); } gotoxy(2,2); //抛胶飘侩 return 0; } int show_logo() { int i; int logo_delay=5; system("cls"); gotoxy(4,2); for(i=4;i<76;i++) { printf("*"); Sleep(logo_delay); } for(i=3;i<8;i++) { gotoxy(75,i);printf("*"); Sleep(logo_delay); } for(i=75;i>=4;i--) { gotoxy(i,7); printf("*"); Sleep(logo_delay); } for(i=7;i>=3;i--) { gotoxy(4,i);printf("*"); Sleep(logo_delay); } Sleep(80); gotoxy(32,4); printf("≠ Simple Race ≠"); Sleep(80); gotoxy(8,6); printf("Ver 0.1"); Sleep(80); gotoxy(56,6); printf("Made By Jae-Dong"); show_carxy(0,13,15); Sleep(200); show_carxy(1,27,15); Sleep(200); show_carxy(2,41,15); Sleep(200); show_carxy(3,55,15); Sleep(1000); gotoxy(28,21); printf("Please Press Any Key!"); getchar(); return 0; } int show_gameframe() { int i; gotoxy(0,0); printf("ΞΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΤΜΜΜΜΜΜΜΜΜΜΟ"); for(i=1;i<CONSOL_HEIGHT-1;i++) { gotoxy(0,i); printf("Ν"); gotoxy(56,i); printf("Ν"); gotoxy(78,i); printf("Ν"); } gotoxy(0,CONSOL_HEIGHT-1); printf("ΡΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΦΜΜΜΜΜΜΜΜΜΜΠ"); gotoxy(58,1); printf(" Simple Racing"); gotoxy(58,2); printf(" Ver 0.1"); gotoxy(58,3); printf("ΜΜΜΜΜΜΜΜΜΜ"); gotoxy(58,4); printf(" Name:"); gotoxy(58,5); printf(" %17s",player_name); gotoxy(58,6); printf("ΜΜΜΜΜΜΜΜΜΜ"); gotoxy(58,7); printf(" Score:"); gotoxy(58,9); printf("ΜΜΜΜΜΜΜΜΜΜ"); gotoxy(58,10); printf(" Energy:"); gotoxy(58,12); printf("ΜΜΜΜΜΜΜΜΜΜ"); gotoxy(58,13); printf(" Speed:"); gotoxy(58,14); printf(" km/h "); gotoxy(58,15); printf(" RPM:"); gotoxy(58,17); printf("ΜΜΜΜΜΜΜΜΜΜ"); gotoxy(61,18); printf("--Car Info--"); gotoxy(59,19); printf("Model :%s",cardata[player_carnum].name); gotoxy(59,20); printf("Max Spd: %d Km/h",cardata[player_carnum].max_spd); gotoxy(59,21); printf("Energy : %d",cardata[player_carnum].energy); gotoxy(59,22); printf("Accel : %d",cardata[player_carnum].accel); return 0; } int show_stat() { int i,j; static int recent_energy = 999,recent_rpm = 999,recent_speed = 999; //score gotoxy(58,8); printf("%19.0f",player_score); gotoxy(58,11); if(recent_energy !=player_energy) //蔼俊 函拳啊 乐阑锭父 拳搁俊 盎脚 { for(i=0,j=player_energy;i<10;i++) { if(j>=10) printf("♂"); else printf("∴"); j-=10; } } if(recent_speed != player_speed) { gotoxy(58,14); printf("%12.0f",player_speed); } //RPM gotoxy(58,16); j= (int) ((player_speed * 10) / cardata[player_carnum].max_spd ); if(j != recent_rpm) //蔼俊 函拳啊 乐阑锭父 拳搁俊 盎脚 { for(i=0;i<10;i++) { if(j>i) printf("♂"); else printf("∴"); } } recent_rpm = j; recent_energy = player_energy; return 0; } int init() { int i,j; road_index = 0; next_index = 0; for(i=0;i<CONSOL_HEIGHT;i++) for(j=0;j<CONSOL_WIDTH;j++) video_buf[i][j]=32; video_refresh(); for(i=0;i<CONSOL_HEIGHT-1;i++) //拳搁免仿 付瘤阜 沫俊 new line内靛 火涝 video_buf[i][CONSOL_WIDTH]=(char)0x0d; video_buf[i][CONSOL_WIDTH]=NULL; //磊悼瞒 单捞磐 涝仿 sprintf(cardata[0].name,"Laser"); cardata[0].max_spd=350; cardata[0].energy=70; cardata[0].accel=7; sprintf(cardata[1].name,"Fire"); cardata[1].max_spd=320; cardata[1].energy=90; cardata[1].accel=8; sprintf(cardata[2].name,"Shot Gun"); cardata[2].max_spd=290; cardata[2].energy=70; cardata[2].accel=9; sprintf(cardata[3].name,"Monster"); cardata[3].max_spd=295; cardata[3].energy=40; cardata[3].accel=6; sprintf(cardata[4].name,"K-Machine"); cardata[4].max_spd=320; cardata[4].energy=100; cardata[4].accel=10; //罚待 seed蔼 檬扁拳 srand((unsigned)time(NULL)); return 0; } int video_refresh() { system("cls"); printf("%s",video_buf[0]); return 0; } int gotoxy(int x,int y) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); COORD pos; pos.Y=y; pos.X=x; SetConsoleCursorPosition(hConsole, pos); return 0; } int show_carxy(int carnum,int x,int y) { static int i; i=y; for(;i<=y+4;i++) { gotoxy(x-1,i); printf(" %8s ",car[carnum][i-y]); } return 0; } int input_player_data() { int i,j,k; fflush(stdin); system("cls"); gotoxy(3,3); printf("Name? :"); gotoxy(3,7); printf("Select Your Car. [1-4]:"); show_carxy(0,15,10); show_carxy(1,33,10); show_carxy(2,51,10); show_carxy(3,69,10); gotoxy(12,9); printf(" [ 1 ] [ 2 ] [ 3 ] [ 4 ] "); gotoxy(2,16); printf("Model Name:"); gotoxy(2,18); printf("MAX Speed :"); gotoxy(2,20); printf("Energy :"); gotoxy(2,22); printf("Accelation:"); for(i=16,j=0;j<4;i+=18,j++) { gotoxy(i,16); printf("%s",cardata[j].name); } for(i=16,j=0;j<4;i+=18,j++) { gotoxy(i,18); printf("%d Km/h",cardata[j].max_spd); } for(i=16,j=0;j<4;i+=18,j++) { gotoxy(i,20); for(k=cardata[j].energy/10;k>0;k--) printf("*"); } for(i=16,j=0;j<4;i+=18,j++) { gotoxy(i,22); for(k=cardata[j].accel ;k>0;k--) printf("*"); } gotoxy(11,3); scanf("%s",player_name); while( (player_carnum < 0) || (player_carnum > 4)) { gotoxy(27,7); scanf("%d",&player_carnum); player_carnum--; } return 0; } int show_road() { int i,j; int rand_num; static int road_left=15,road_right=32; gotoxy(road[(road_index+1)%22][0],1); printf(" "); gotoxy(road[(road_index+1)%22][1],1); printf(" "); for(j=2,i=road_index+1;j<23;i++,j++) { i =i%22; if(road[(i+1)%22][0] != road[i][0]) { gotoxy(road[(i+1)%22][0],j); printf(" "); gotoxy(road[(i+1)%22][1],j); printf(" "); } } //罚待栏肺 档肺 积己 0:哭率滴沫 1,2:哭率茄沫 3,4,5,6:流柳 7,8:坷弗率茄沫 9:坷弗率滴沫 //rand_num=rand()%10; rand_num=rand()%8; rand_num++; switch(rand_num) { case 0: if(road[(road_index+1)%22][0] <=4 ) { road[next_index][0] = road[(road_index+1)%22][0]; road[next_index][1] = road[(road_index+1)%22][1]; break; } road[next_index][0] =road[(road_index+1)%22][0]-2; road[next_index][1] =road[(road_index+1)%22][1]-2; break; case 1: case 2: if(road[(road_index+1)%22][0] <=3 ) { road[next_index][0] = road[(road_index+1)%22][0]; road[next_index][1] = road[(road_index+1)%22][1]; break; } road[next_index][0] =road[(road_index+1)%22][0]-1; road[next_index][1] =road[(road_index+1)%22][1]-1; break; case 7: case 8: if(road[(road_index+1)%22][1] >=55 ) { road[next_index][0] = road[(road_index+1)%22][0]; road[next_index][1] = road[(road_index+1)%22][1]; break; } road[next_index][0] =road[(road_index+1)%22][0]+1; road[next_index][1] =road[(road_index+1)%22][1]+1; break; case 9: if(road[(road_index+1)%22][1] >=54 ) { road[next_index][0] = road[(road_index+1)%22][0]; road[next_index][1] = road[(road_index+1)%22][1]; break; } road[next_index][0] =road[(road_index+1)%22][0]+2; road[next_index][1] =road[(road_index+1)%22][1]+2; break; default: road[next_index][0] = road[(road_index+1)%22][0]; road[next_index][1] = road[(road_index+1)%22][1]; break; } road_index=next_index; if( road_index == 0) next_index = 21; else next_index = road_index-1; for(j=1,i=road_index;j<23;i++,j++) { i = i%22; gotoxy(road[i][0],j); printf("["); gotoxy(road[i][1],j); printf("]"); } road_index=next_index; return 0; } int show_car(int move) { player_carpos = player_carpos + move; if( player_carpos <2) player_carpos = 2; if( player_carpos >48) player_carpos = 48; show_carxy(player_carnum,player_carpos,18); return 0; } int strike_check() //磊悼瞒客 档肺客 面倒沁绰瘤 八荤窍绊 面倒矫 面倒何盒阑 拳搁俊 免仿 { int i; for(i=18;i<=19;i++) { if( road[road_index][0]>=player_carpos) { show_car(1); player_carpos++; player_speed -= 7+(player_speed/50); if(player_speed <0) player_speed = 0; player_energy -= 5; if(player_energy <0) player_energy = 0; speed_counter = 0; gotoxy(road[road_index][0],i); printf("*"); break; } if( road[road_index][1]<=player_carpos+7) { show_car(-1); player_carpos--; player_speed -= 7+(player_speed/50); if(player_speed <0) player_speed = 0; player_energy -= 5; if(player_energy <0) player_energy = 0; speed_counter = 0; gotoxy(road[road_index][1],i); printf("*"); break; } } return 0; } int show_gameover() { gotoxy(12,8); printf("ΞΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΟ"); gotoxy(12,9); printf("Ν********************************Ν"); gotoxy(12,10); printf("Ν* GAME OVER *Ν"); gotoxy(12,11); printf("Ν********************************Ν"); gotoxy(12,12); printf("ΡΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΠ"); return 0; } int show_count() { int i,j,k; gotoxy(16,5); printf("ΞΜΜΜΜΜΜΜΜΜΜΟ"); gotoxy(16,6); printf("Ν ♂♂♂ Ν"); gotoxy(16,7); printf("Ν ♂ ♂ Ν"); gotoxy(16,8); printf("Ν ♂ Ν"); gotoxy(16,9); printf("Ν ♂ Ν"); gotoxy(16,10); printf("Ν ♂♂ Ν"); gotoxy(16,11); printf("Ν ♂ Ν"); gotoxy(16,12); printf("Ν ♂ ♂ Ν"); gotoxy(16,13); printf("Ν ♂ ♂ Ν"); gotoxy(16,14); printf("Ν ♂♂♂ Ν"); gotoxy(16,15); printf("ΣΜΜΜΜΜΜΜΜΜΜΥ"); gotoxy(16,16); printf("Ν $ : Move Left Ν"); gotoxy(16,17); printf("Ν ℃ : Move Right Ν"); gotoxy(16,18); printf("ΡΜΜΜΜΜΜΜΜΜΜΠ"); gotoxy(0,23); Sleep(1000); gotoxy(16,5); printf("ΞΜΜΜΜΜΜΜΜΜΜΟ"); gotoxy(16,6); printf("Ν ♂♂♂ Ν"); gotoxy(16,7); printf("Ν ♂ ♂ Ν"); gotoxy(16,8); printf("Ν ♂ Ν"); gotoxy(16,9); printf("Ν ♂ Ν"); gotoxy(16,10); printf("Ν ♂ Ν"); gotoxy(16,11); printf("Ν ♂ Ν"); gotoxy(16,12); printf("Ν ♂ Ν"); gotoxy(16,13); printf("Ν ♂ Ν"); gotoxy(16,14); printf("Ν ♂♂♂♂♂♂ Ν"); gotoxy(0,23); Sleep(1000); gotoxy(16,5); printf("ΞΜΜΜΜΜΜΜΜΜΜΟ"); gotoxy(16,6); printf("Ν ♂ Ν"); gotoxy(16,7); printf("Ν ♂♂ Ν"); gotoxy(16,8); printf("Ν ♂ Ν"); gotoxy(16,9); printf("Ν ♂ Ν"); gotoxy(16,10); printf("Ν ♂ Ν"); gotoxy(16,11); printf("Ν ♂ Ν"); gotoxy(16,12); printf("Ν ♂ Ν"); gotoxy(16,13); printf("Ν ♂ Ν"); gotoxy(16,14); printf("Ν ♂♂♂ Ν"); gotoxy(0,23); Sleep(1000); gotoxy(16,5); printf("ΞΜΜΜΜΜΜΜΜΜΜΟ"); gotoxy(16,6); printf("Ν ♂♂♂ Ν"); gotoxy(16,7); printf("Ν ♂ ♂ Ν"); gotoxy(16,8); printf("Ν ♂ ♂ Ν"); gotoxy(16,9); printf("Ν ♂ ♂♂ Ν"); gotoxy(16,10); printf("Ν ♂ ♂ ♂ Ν"); gotoxy(16,11); printf("Ν ♂♂ ♂ Ν"); gotoxy(16,12); printf("Ν ♂ ♂ Ν"); gotoxy(16,13); printf("Ν ♂ ♂ Ν"); gotoxy(16,14); printf("Ν ♂♂♂ Ν"); for(j=16,k=40;j<=41;j++,k--) { for(i=5;i<18;i+=2) { gotoxy(j-1,i); printf(" "); if(j!=41) { printf("*"); } gotoxy(k,i+1); if(k!=13) { printf("*"); } printf(" "); } Sleep(80); } return 0; }
好了,第四期咱们就说到这里,这是前三期:
下期见!bye!
相关文章推荐
- C++游戏开发需要阅读的书籍
- 【iOS-cocos2d-X 游戏开发之十四】cocos2dx(c++)中访问object函数
- C++赌博游戏
- 使用C++与SFML编写一个简单的撞球游戏Part2——创建游戏窗口
- C++抽象编程——回溯算法(4)——回溯在游戏中的应用
- 【iOS-Cocos2d游戏开发之十二】浅析使用C++/C/OC进行iOS游戏混编出现“failed with exit”问题与小结;
- C++编写简单的打靶游戏
- c++打字母游戏
- C++ DirectX 游戏开发初级视频教程 17 资源下载链接
- Unity结合C++开发服务器实现多人游戏(一)
- C++面向对象游戏模型
- C++ 生命游戏
- 基于C++和JavaScript的全平台全栈式游戏开发解决方案的思考
- 【贪吃蛇,C++实现】,由简单游戏开始学习OOP,的编程新手
- Cocos2d-x游戏移植到WP8之路 -- c++和c#交互
- GFX游戏引擎衔接文件简述(一)c++代码部分
- 用C++实现跨平台游戏开发之Irrlicht引擎(2)
- c++游戏开发中使用json
- 贪吃蛇游戏(C++实现)
- plain framework 1(简约框架)一款主要用于网络(游戏)开发的C/C++框架 即将开源发布