多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > 貪吃蛇,c,c++

貪吃蛇,c,c++

來源:程序員人生   發布時間:2015-01-09 08:20:34 閱讀次數:2648次
學了c++半個學期了,自己動手做了1個游戲。(有甚么不好的地方,歡迎指出<img alt="大笑" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif" />)
#include <windows.h> #include <conio.h> #include <ctime> #include <iostream> #include <cmath> #include <mmsystem.h> #include<stdio.h> #include <stdlib.h> # pragma comment (lib, "Winmm.lib")//導入Winmm.lib庫 using namespace std; int node; //蛇的節數 int life; //生命,0活著,1死亡 int Q;//控制食品色彩 int fa,fb;//食品坐標 int q;//控制上下左右 int ti=0,ti1=0;//time int nd=0;//難度 char k; int a[4][2]={{⑴,0},{1,0},{0,⑴},{0,1}}; // 上下左右 struct food { int f1; int f2; int need; }f; struct she { int x; int y; }s[1000],t; HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE); //光標定位 COORD coord; void hide() //隱藏光標 { CONSOLE_CURSOR_INFO cursor_info={1,0}; SetConsoleCursorInfo(hout, &cursor_info); } void gotoxy(int x, int y) { CONSOLE_SCREEN_BUFFER_INFO cs; HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hConsoleOut, &cs); cs.dwCursorPosition.X = y; cs.dwCursorPosition.Y = x; SetConsoleCursorPosition(hConsoleOut, cs.dwCursorPosition); } void color(int a)//色彩函數 { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a); } void weiqiang(void)//圍圈 { color(14); int a=25,b=20,c=25,d=20; while(a--) { cout << '-'; } cout << endl; while(b--) { cout << '|'; cout << endl; } while(d--) { gotoxy(20-d,24); cout << '|'; cout << endl; } while(c--) { cout << '-'; } cout << endl; gotoxy(1,1); } void food1(void)//食品 { f.f1=5; f.f2=5; int i; srand((unsigned)time(NULL)); while (1) { loop:f.f1=rand()%19;//隨機數 f.f2=rand()%24; for (i=0;i<node;i++) { if (f.f1==s[i].x||f.f2==s[i].y) { goto loop; } } if (f.f1==0||f.f2==0)//避免超越框框 { continue; } else { break; } } if(f.need==0) { fa=f.f1;fb=f.f2;//f.f1,f.f2賦值給全局變量 gotoxy(f.f1,f.f2); while (1) { Q=rand()%16; if (Q>9) { break; } } color(Q); cout << "*"; } } int died(void)//判斷死亡 { int i,flag=0; for (i=1;i<node;i++) { if (s[0].x==s[i].x&&s[0].y==s[i].y) { flag=1; } } if ((s[0].x==0||s[0].x==21||s[0].y==0||s[0].y==24)||flag==1) { return 0; } else { return 1; } } void tyd(char c) { if (abs(c-k)!=3&&abs(c-k)!=4&&abs(c-k)!=0)//控制蛇頭走身體后面 { if(c=='a') { q=2; } else if (c=='s') { q=1; } else if (c=='w') { q=0; } else if (c=='d') { q=3; } } s[0].x+=a[q][0]; s[0].y+=a[q][1]; } void yd(void)//移動方向 { char c='d'; int i,a=200; s[0].x=1; s[0].y=1; node=2; do { ti+=1;//必須將其重新歸0,不然游戲會出錯 ti1+=ti; if (ti>1000) { ti=0; } if (ti%150==0) { if (a>25) { nd++; a-=25; } } food1(); t.x=s[node⑴].x;//保存最后1個* t.y=s[node⑴].y; for (i=node⑴;i>0;i--)//身體移動 { s[i].x=s[i⑴].x; s[i].y=s[i⑴].y; } for (i=1;i<node;i++) { color(13); gotoxy(s[i].x,s[i].y); cout << "*" ; } gotoxy(t.x,t.y);//消去最后那個* cout << " "; if (_kbhit())//接受鍵盤輸入的上下左右,并以此改變方向 { k=c; c=_getch(); } tyd(c);//移動 gotoxy(s[0].x,s[0].y);//頭移動 cout << "#"; if (s[0].x==fa&&s[0].y==fb)//控制食品每次只能有1個 { f.need=0; node++; } else { f.need=1; } Sleep(a); if(died()==0)//判斷是不是 { system("cls");//清屏 break; } color(12); gotoxy(22,0); cout << "食品統計: " << node⑵ ; gotoxy(1,27); color(11); cout << "游戲難度: " << nd; }while(1); } void jieshu(void) { color(12); cout << "花費時間:" << ti1/60 << " s" << endl; cout << " o(
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 国产欧美性综合视频性刺激 | 九九热在线免费视频 | 亚洲国产成人综合 | 国产精品一区伦免视频播放 | 免费观看美女的网站 | 欧美成人中文字幕dvd | 最近最好的中文字幕免费 | 中国欧美一级毛片免费 | 亚洲 欧美 中文字幕 | 国产精品久久久久久久y | free性欧美极度另类3d | 国产精品ⅴ视频免费观看 | 欧美性高清极品猛交 | 伊人伊人| 伊人影院视频 | 精品日韩欧美国产一区二区 | 国产第3页 | 欧美大片天天免费看视频 | 国产福利写真视频在线观看 | 天天在线欧美精品免费看 | 国产精品亚洲一区二区三区久久 | 亚洲免费人成在线视频观看 | 免费高清a级毛片在线播放 免费高清不卡毛片在线看 免费高清国产 | 亚洲国产成人久久综合一区77 | 尤物在线视频 | 亚洲图片欧美 | 波多野结衣久久精品 | 99heicom视频| 最近最新手机中文字幕在线看 | 成人午夜大片免费视频77777 | 能免费看的黄色网址 | 国产欧美精品区一区二区三区 | 羞羞视频免费观看入口 | 国产午夜精品一区二区三区 | 一级做性色a爰片久久毛片 一级做性色a爰片久久毛片免费 | 一区二区三区四区视频 | 在线看国产视频 | 成人精品第一区二区三区 | 欧美 日韩 国产在线 | 国产精品久久久久毛片 | 欧美成人综合视频 |