軟件工程俄羅斯方塊_第1頁
軟件工程俄羅斯方塊_第2頁
軟件工程俄羅斯方塊_第3頁
軟件工程俄羅斯方塊_第4頁
軟件工程俄羅斯方塊_第5頁
已閱讀5頁,還剩45頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

課程實(shí)驗(yàn)報(bào)告課程名稱:軟件工程計(jì)算機(jī)科學(xué)與技術(shù)學(xué)院目錄軟件名稱:俄羅斯方塊軟件定義.............................3問題定義...........................3可行性研究..........................3需求分析...........................4設(shè)計(jì)棋盤.........................5設(shè)計(jì)棋子.........................6按鍵功能設(shè)置(上下左右)....................7棋子落下的動畫實(shí)現(xiàn)以及越界檢測................9Morefunctions......................11俄羅斯方塊的DFD圖.......................12需求分析建模–數(shù)據(jù)字典......................13代碼..............................14俄羅斯方塊編譯環(huán)境Codeblocks編譯器用C語言在window8下軟件定義問題定義額,俄羅斯方塊不用定義了吧。。相信大家都知道。俄羅斯方塊(Tetris,俄文:Тетрис)是一款風(fēng)靡全球的電視游戲機(jī)和掌上游戲機(jī)游戲,它由俄羅斯人阿列克謝·帕基特諾夫發(fā)明,故得此名。俄羅斯方塊的基本規(guī)則是移動、旋轉(zhuǎn)和擺放游戲自動輸出的各種方塊,使之排列成完整的一行或多行并且消除得分。由于上手簡單、老少皆宜,從而家喻戶曉,風(fēng)靡世界。2014年2月22日,英國心理學(xué)家發(fā)現(xiàn),減肥者通過玩俄羅斯方塊,可以降低對富含脂肪的食物和零食的心理需求;嘗試戒煙者的煙癮也能得到遏制??尚行匝芯慷砹_斯方塊是曾經(jīng)風(fēng)靡全球的一款游戲。如今看來,雖然與其他手游相比,編碼簡單,但對于現(xiàn)階段的我們,還是有一定的難度,因而做出俄羅斯方塊的代碼,是一個很能鍛煉自我的任務(wù),因此我選擇了寫俄羅斯方塊。通過大一對C語言和這學(xué)期數(shù)據(jù)結(jié)構(gòu)的學(xué)習(xí),已經(jīng)基本掌握了俄羅斯方塊編程的需要,因此是可行的。需求分析設(shè)計(jì)棋盤設(shè)計(jì)棋子按鍵功能設(shè)置(上下左右)棋子落下的動畫實(shí)現(xiàn)以及越界檢測軟件設(shè)計(jì)設(shè)計(jì)棋盤設(shè)計(jì)出棋盤的高和寬:#defineCHESS_WIDTH12*2#defineCHESS_HIGHT1出來的效果應(yīng)該是這樣的:設(shè)計(jì)棋子用一個二維數(shù)組表示棋子:x,y(4,1)chara[4][4]a[0][0]=1,a[0][1]=1,a[1][0],a[1][1]=1;出來的效果:按鍵功能設(shè)置(上下左右,暫停)按鍵功能分別由下面幾個函數(shù)實(shí)現(xiàn):voidClearChess(chess_datachess)清屏voidMoveDown(chess_data*Chess)下移voidMoveLeft(chess_data*Chess)左移voidMoveRight(chess_data*Chess)右移然后這兒呢,會出現(xiàn)一個bug,即出現(xiàn)越界現(xiàn)象,所以需要寫函數(shù)來判斷是否越界。棋子落下的動畫實(shí)現(xiàn)以及越界檢測越界檢測:intCheckLeftBorder(chess_dataChess)檢查左右邊界intCheckDownBorder(chess_dataChess)檢查下邊界Morefunctions游戲難度控制添加聲音效果還未研發(fā)出來….俄羅斯方塊的DFD圖第0層:第1層:需求分析建模–數(shù)據(jù)字典數(shù)據(jù)流名:玩家可用鍵說明:玩家在玩游戲是可以用到的鍵數(shù)據(jù)流來源:玩家數(shù)據(jù)流去向:系統(tǒng)處理數(shù)據(jù)流組成:Y/N+上下左右數(shù)據(jù)元素詞條 Y/N=“Y”“N” 上下左右=“↑”“↓”“←”“→”程序代碼#include<stdio.h>#include<stdlib.h>#include<string.h>#include<ctype.h>#include<stdarg.h>#include<time.h>#include"hello.h"#include<share.h>#include<Windows.h>#include"gameproc.h"http://#definevar333;//移動光標(biāo)位置voidgotoxy(intx,inty){ COORDxy; HANDLEhstdout; hstdout=GetStdHandle(STD_OUTPUT_HANDLE); xy.X=x; xy.Y=y; SetConsoleCursorPosition(hstdout,xy); //CloseHandle(hstdout);}voidfillchar(chara,intcharlen){ COORDxy={0}; HANDLEhstdout; longbyw; hstdout=GetStdHandle(STD_OUTPUT_HANDLE); FillConsoleOutputCharacter(hstdout,a,charlen,xy,&byw); CloseHandle(hstdout);}#defineX20#defineY6//繪制邊框voiddrawM(void){ inti; //上邊 gotoxy(X,Y); prt("┏"); for(i=1;i<=13;i++) { prt("━"); } prt("┓");//左邊 for(i=1;i<=16;i++) {gotoxy(X,Y+i); prt("┃"); } //右邊 for(i=1;i<=16;i++) { gotoxy(X+28,Y+i); prt("┃"); } //下邊 gotoxy(X,Y+17); prt("┗"); for(i=1;i<=13;i++) { prt("━"); } prt("┛"); return;}//drawmenuvoiddrawmenu(void){ gotoxy(X+3,Y+3); prt("1->菜單選項(xiàng)一");gotoxy(X+3,Y+3+2); prt("菜單選項(xiàng)二"); gotoxy(X+3,Y+3+2+2); prt("退出"); gotoxy(0,0);}intselmenu_Num=0;intselmenu(void){//0,1,2//如果按下↓selmenu_Num++;如果>2selmenu_Num=0;//如果按下↑selmenu_Num--;如果<0selmenu_Num=2; intch=0; while(1) { ch=getch(); //gotoxy(0,0); //prt("%d",ch); if(ch==13) { returnselmenu_Num; } switch(ch) { case72://上光標(biāo) selmenu_Num--; if(selmenu_Num<0) { selmenu_Num=2; } break; case80://下光標(biāo) selmenu_Num++; if(selmenu_Num>2) { selmenu_Num=0; } break; }gotoxy(0,0); //prt("selmenu_num=%d",selmenu_Num); //動態(tài)菜單 switch(selmenu_Num) { case0: gotoxy(X+3,Y+3); prt("1->"); gotoxy(X+3,Y+3+2); prt(""); gotoxy(X+3,Y+3+2+2); prt(""); gotoxy(0,0); break; case1: gotoxy(X+3,Y+3); prt(""); gotoxy(X+3,Y+3+2); prt("2->"); gotoxy(X+3,Y+3+2+2); prt(""); gotoxy(0,0); break; case2: gotoxy(X+3,Y+3); prt(""); gotoxy(X+3,Y+3+2); prt(""); gotoxy(X+3,Y+3+2+2); prt("3->"); gotoxy(0,0); break; } }//endwhile returnselmenu_Num;}//doMenuvoiddoMenu(void){intsel;sel= selmenu();switch(sel){case0://菜單一 gotoxy(0,0); prt("\n菜單一功能\n"); break;case1: gotoxy(0,0); prt("\n菜單二功能\n"); break;case2://退出 exit(1); break;}}DWORDWINAPIThreadProc1( LPVOIDlpParameter//接收CreateThread的第4個參數(shù) ){inti=0;while(1) //添加線程代碼{i++;EnterCriticalSection(&cs);gotoxy(0,1);printf("OKOKi=%d",i);//下移一格棋子if(CheckDownBorder(oneChess)||CheckDownChess(oneChess)){ Add1Chess(oneChess); ShowChessBoard(); //重新賦值OneChess進(jìn)行新的一輪棋子掉落 //隨機(jī)初始化 rx=rand()%5; ry=0; oneChess=DownChessData[rx][ry]; oneChess.rx=rx; oneChess.ry=ry; ShowChess(oneChess);}else{ MoveDown(&oneChess);}LeaveCriticalSection(&cs);Sleep(speed);} return1;}DWORDWINAPIThreadProc2( LPVOIDlpParameter//接收CreateThread的第4個參數(shù) ){while(1)//添加線程代碼{//隨機(jī)初始化rx=rand()%2;ry=rand()%4;Sleep(100);}return1;}intmain(void){ //Y行X列//fillchar('',3000); InitializeCriticalSection(&cs); InitializeCriticalSection(&cs_puts); system("color0a"); system("titleQQ150330575");/*drawM(); drawmenu(); doMenu();*/ SetWindowPos(HWND_BOTTOM,HWND_NOTOPMOST,133,100,800,600,SWP_SHOWWINDOW); DrawChessMap(); //開始游戲 th1=CreateThread(NULL,0,ThreadProc1,NULL,0,NULL); //創(chuàng)建線程 //CreateThread(NULL,0,ThreadProc2,NULL,0,NULL); //創(chuàng)建線程 playgame(); getch(); prt("22222222222"); getch(); return0;}//宏定義#defineCHESS_X28#defineCHESS_Y8#defineCHESS_WIDTH12*2#defineCHESS_HIGHT18charChessBoard[12][18]={0};//12*18的二維數(shù)組表示棋盤數(shù)據(jù)有黑格子的地方置1其它地方置0unsignedintrx,ry;externvoidgotoxy(int,int);intPointNum=0;intspeed=1000;HANDLEth1;//線程1句柄voidShowChessBoard();typedefstruct_chess_data{ charrx;//5種類型0..4 charry;////4種形態(tài)0..3 chardata[4][4];//數(shù)據(jù) COORDxy;//位置POINT}chess_data;chess_dataoneChess;CRITICAL_SECTIONcs;CRITICAL_SECTIONcs_puts;voidprt(char*s){//進(jìn)入臨界區(qū) EnterCriticalSection(&cs_puts); puts(s); LeaveCriticalSection(&cs_puts); //離開臨界區(qū)}//畫棋盤voidDrawChessMap(void){ inti; //U型 //左邊 for(i=0;i<CHESS_HIGHT;i++){ gotoxy(CHESS_X,CHESS_Y+i); prt("┃");} //右邊 for(i=0;i<CHESS_HIGHT;i++) { gotoxy(CHESS_X+CHESS_WIDTH,CHESS_Y+i); prt("┃"); } //底部轉(zhuǎn)角gotoxy(CHESS_X,CHESS_Y+CHESS_HIGHT); prt("┗"); gotoxy(CHESS_X+CHESS_WIDTH,CHESS_Y+CHESS_HIGHT); prt("┛"); //底部橫線 for(i=1;i<CHESS_WIDTH/2;i++) { gotoxy(CHESS_X+i*2,CHESS_Y+CHESS_HIGHT); prt("━"); } return;}//20種不成形態(tài)的棋子chess_dataDownChessData[5][4]={0};voidInitChessData(void){ //□□ //□□類型0狀態(tài)0 DownChessData[0][0].xy.X=CHESS_X+4; DownChessData[0][0].xy.Y=CHESS_Y+0; DownChessData[0][0].data[0][0]=1; DownChessData[0][0].data[1][0]=1; DownChessData[0][0].data[0][1]=1; DownChessData[0][0].data[1][1]=1; //狀態(tài)1-3=狀態(tài)0 DownChessData[0][1]=DownChessData[0][2]=DownChessData[0][3]=DownChessData[0][0]; //□□□ //□類型1狀態(tài)0 DownChessData[1][0].xy.X=CHESS_X+4; DownChessData[1][0].xy.Y=CHESS_Y+0; DownChessData[1][0].data[0][0]=1; DownChessData[1][0].data[1][0]=1; DownChessData[1][0].data[2][0]=1; DownChessData[1][0].data[1][1]=1; //□ //□□ //□類型1狀態(tài)1 DownChessData[1][1].xy.X=CHESS_X+4; DownChessData[1][1].xy.Y=CHESS_Y+0; DownChessData[1][1].data[1][0]=1; DownChessData[1][1].data[1][1]=1; DownChessData[1][1].data[1][2]=1; DownChessData[1][1].data[0][1]=1; //□類型1狀態(tài)2 //□□□ DownChessData[1][2].xy.X=CHESS_X+4; DownChessData[1][2].xy.Y=CHESS_Y+0; DownChessData[1][2].data[1][0]=1; DownChessData[1][2].data[0][1]=1; DownChessData[1][2].data[1][1]=1; DownChessData[1][2].data[2][1]=1; //□類型1狀態(tài)3 //□□ //□ DownChessData[1][3].xy.X=CHESS_X+4; DownChessData[1][3].xy.Y=CHESS_Y+0; DownChessData[1][3].data[0][0]=1; DownChessData[1][3].data[0][1]=1; DownChessData[1][3].data[0][2]=1; DownChessData[1][3].data[1][1]=1; //□ //□ //□ //□ DownChessData[2][0].xy.X=CHESS_X+4; DownChessData[2][0].xy.Y=CHESS_Y+0; DownChessData[2][0].data[1][0]=1; DownChessData[2][0].data[1][1]=1; DownChessData[2][0].data[1][2]=1; DownChessData[2][0].data[1][3]=1; DownChessData[2][2]=DownChessData[2][0]; //□□□□ DownChessData[2][3].xy.X=CHESS_X+4; DownChessData[2][3].xy.Y=CHESS_Y+0; DownChessData[2][3].data[1][2]=1; DownChessData[2][3].data[2][2]=1; DownChessData[2][3].data[3][2]=1; DownChessData[2][3].data[0][2]=1; DownChessData[2][1]=DownChessData[2][3]; //□□ //□□ DownChessData[3][0].xy.X=CHESS_X+4; DownChessData[3][0].xy.Y=CHESS_Y+0; DownChessData[3][0].data[0][1]=1; DownChessData[3][0].data[0][2]=1; DownChessData[3][0].data[1][2]=1; DownChessData[3][0].data[1][3]=1; DownChessData[3][2]=DownChessData[3][0]; //□ //□□ //□ DownChessData[3][1].xy.X=CHESS_X+4; DownChessData[3][1].xy.Y=CHESS_Y+0; DownChessData[3][1].data[0][0]=1; DownChessData[3][1].data[1][0]=1; DownChessData[3][1].data[1][1]=1; DownChessData[3][1].data[2][1]=1; DownChessData[3][3]=DownChessData[3][1]; //□ //□ //□□ DownChessData[4][0].xy.X=CHESS_X+4; DownChessData[4][0].xy.Y=CHESS_Y+0; DownChessData[4][0].data[1][0]=1; DownChessData[4][0].data[1][1]=1; DownChessData[4][0].data[1][2]=1; DownChessData[4][0].data[2][2]=1; //□□□ //□ DownChessData[4][1].xy.X=CHESS_X+4; DownChessData[4][1].xy.Y=CHESS_Y+0; DownChessData[4][1].data[0][2]=1; DownChessData[4][1].data[1][2]=1; DownChessData[4][1].data[2][2]=1; DownChessData[4][1].data[0][3]=1; //□□ //□ //□ DownChessData[4][2].xy.X=CHESS_X+4; DownChessData[4][2].xy.Y=CHESS_Y+0; DownChessData[4][2].data[0][0]=1; DownChessData[4][2].data[1][0]=1; DownChessData[4][2].data[1][1]=1; DownChessData[4][2].data[1][2]=1; //□ //□□□ DownChessData[4][3].xy.X=CHESS_X+4; DownChessData[4][3].xy.Y=CHESS_Y+0; DownChessData[4][3].data[3][1]=1; DownChessData[4][3].data[1][2]=1; DownChessData[4][3].data[2][2]=1; DownChessData[4][3].data[3][2]=1;}//顯示某個下落的棋子voidShowChess(chess_datachess){ intx,y; for(x=0;x<=3;x++) { for(y=0;y<=3;y++) if(chess.data[x][y]) { gotoxy(chess.xy.X+x*2,chess.xy.Y+y); prt("□"); } }}//隱藏棋子voidClearChess(chess_datachess){ intx,y; for(x=0;x<=3;x++) { for(y=0;y<=3;y++) if(chess.data[x][y])// { gotoxy(chess.xy.X+x*2,chess.xy.Y+y); prt(""); } }}voidMoveUp(chess_data*Chess){ chess_databakChess; //隱藏 ClearChess(*Chess); //ry+1 Chess->ry++;//1,2,3,4,5 Chess->ry%=4;//0..3 //data bakChess=DownChessData[Chess->rx][Chess->ry]; bakChess.xy=Chess->xy; bakChess.rx=Chess->rx; bakChess.ry=Chess->ry; //*Chess=bakChess; ShowChess(*Chess);}voidMoveDown(chess_data*Chess){ //隱藏 ClearChess(*Chess); Chess->xy.Y+=1; ShowChess(*Chess);}voidMoveLeft(chess_data*Chess){ //隱藏 ClearChess(*Chess); Chess->xy.X-=2; ShowChess(*Chess);}voidMoveRight(chess_data*Chess){ //隱藏 ClearChess(*Chess); Chess->xy.X+=2; ShowChess(*Chess);}//檢測左邊界是否到達(dá),到達(dá)則返回1否則返回0intCheckLeftBorder(chess_dataChess){ intx,y; for(x=0;x<=3;x++) for(y=0;y<=3;y++) { if(Chess.data[x][y]) { if(Chess.xy.X+x*2<=CHESS_X+2) { return1; } } }return0;}//檢測左邊界是否到達(dá),到達(dá)則返回1否則返回0intCheckRightBorder(chess_dataChess){ intx,y; for(x=3;x>=0;x--) for(y=3;y>=0;y--) { if(Chess.data[x][y]) { if(Chess.xy.X+x*2>=CHESS_X+CHESS_WIDTH-2)//左邊界│占2字符寬度+右邊界│占的2個字符寬度所以得減4 { return1; } } } return0;}//檢測下邊界intCheckDownBorder(chess_dataChess){ intx,y; for(y=0;y<=3;y++) for(x=0;x<=3;x++) { if(Chess.data[x][y]) { if(Chess.xy.Y+y+1>=CHESS_Y+CHESS_HIGHT) { return1; } } } return0;}//檢測下方向是否有棋子存在intCheckDownChess(chess_dataChess){ intx,y; for(y=0;y<=3;y++) for(x=0;x<=3;x++) { if(Chess.data[x][y]) { if(ChessBoard[(Chess.xy.X-CHESS_X)/2+x][Chess.xy.Y-CHESS_Y+y+1])//12*18 { return1; } } } return0;}//假設(shè)向左移一格,是否會產(chǎn)生碰撞,如果有,則返回1否則返回0intCheckLeftChess(chess_dataChess){ intx,y; for(y=0;y<=3;y++) for(x=0;x<=3;x++) { if(Chess.data[x][y]) { if(ChessBoard[(Chess.xy.X-CHESS_X)/2+x-1][Chess.xy.Y-CHESS_Y+y])//12*18 { return1; } } } return0;}//假設(shè)向右移一格,是否會產(chǎn)生碰撞,如果有,則返回1否則返回0intCheckRightChess(chess_dataChess){ intx,y; for(y=0;y<=3;y++) for(x=0;x<=3;x++) { if(Chess.data[x][y]) { if(ChessBoard[(Chess.xy.X-CHESS_X)/2+x+1][Chess.xy.Y-CHESS_Y+y])//12*18 { return1; } } } return0;}//旋轉(zhuǎn)沖突檢測intCheckSpinBorder(chess_datachess){intx,y,ty; chess_dataNextChess; //取得旋轉(zhuǎn)后的棋子數(shù)據(jù) NextChess=chess;//xy,rx,ry //取得旋轉(zhuǎn)后棋子數(shù)據(jù)data //NextChess.data=DownChessData[chess.rx][chess.ry].data; if(chess.ry==3) { ty=0; }else { ty=chess.ry+1; } memcpy(NextChess.data,DownChessData[chess.rx][ty].data,4*4*sizeof(char)); //檢測邊界沖突 for(x=0;x<=3;x++) for(y=0;y<=3;y++) { if(NextChess.data[x][y]) { if(NextChess.xy.X+x<=CHESS_X+2) { return1; } // if(NextChess.xy.X+x>=CHESS_X+CHESS_WIDTH-4)//左邊界│占2字符寬度+右邊界│占的2個字符寬度所以得減4 { return1; } // if(NextChess.xy.Y+y+1>=CHESS_Y+CHESS_HIGHT) { return1; } //檢測與棋盤數(shù)據(jù)的沖突 if(ChessBoard[(NextChess.xy.X-CHESS_X)/2+x][NextChess.xy.Y-CHESS_Y+y])//12*18 { return1; } } } return0; }//檢測ChessBoard里邊是否有一行是全1是返回這一行的下標(biāo),否則返回-1intCheckRowAllOne(){ intx,y; intnum=0; for(y=17;y>=0;y--) { num=0;//歸零初始化 for(x=0;x<=11;x++)//行是否全1 {if(ChessBoard[x][y]) { num++; } } if(num>=11) { returny; } } return-1; }//ClearRowintClearRow(introwY){ intx,y; for(x=1;x<=11;x++)//行是否全1 { ChessBoard[x][rowY]=0; gotoxy(CHESS_X+x*2,CHESS_Y+rowY); prt(""); } //下移所有的行 for(y=rowY;y>=1;y--) { for(x=1;x<11;x++) { gotoxy(CHESS_X+x*2,CHESS_Y+y-1); prt("");ChessBoard[x][y]=ChessBoard[x][y-1]; } } for(x=1;x<12;x++) { for(y=0;y<18;y++) gotoxy(CHESS_X+x*2,CHESS_Y+y); if(ChessBoard[x][y]) { prt("■"); }elseprt(""); }}//添加棋子數(shù)據(jù)到棋盤voidAdd1Chess(chess_dataChess){ intx,y; introwY; introwNum=0; for(x=0;x<4;x++) for(y=0;y<4;y++) { if(Chess.data[x][y]) { //ChessBoard ChessBoard[(Chess.xy.X-CHESS_X)/2+x][Chess.xy.Y-CHESS_Y+y]=1; } } //更新數(shù)據(jù)后檢測 for(y=0;y<4;y++) { if((rowY=CheckRowAllOne())>=0) { //消掉這一行 ClearRow(rowY); rowNum++; //記算這一局得分情況 } } // switch(rowNum) { case1: PointNum+=10; gotoxy(CHESS_X+CHESS_WIDTH+3,CHESS_Y+5); printf("當(dāng)前得分=%8d",PointNum); break; case2: PointNum+=30; gotoxy(CHESS_X+CHESS_WIDTH+3,CHESS_Y+5); printf("當(dāng)前得分=%8d",PointNum); case3: PointNum+=60; gotoxy(CHESS_X+CHESS_WIDTH+3,CHESS_Y+5); printf("當(dāng)前得分=%8d",PointNum); case4: PointNum+=100; gotoxy(CHESS_X+CHESS_WIDTH+3,CHESS_Y+5); printf("當(dāng)前得分=%8d",PointNum); break; }}//以■方塊顯示棋盤數(shù)據(jù)voidShowChessBoard()//顯示ChessBoard里的1{ intx,y; for(x=0;x<12;x++) for(y=0;y<18;y++) { if(ChessBoard[x][y]) { gotoxy(CHESS_X+x*2,CHESS_Y+y); prt("■"); } }}voidshowallchess(void){ intx,y; for(x=0;x<5;x++) { for(y=0;y<4;y++)//0..3 { ShowChess(DownChessData[x][y]); gotoxy(0,0); printf("%d,%d",x,y); getch(); getch(); ClearChess(DownChessData[x][y]); } }}voidpauseGame(){ staticintpause=0; if(pause) { gotoxy(CHESS_X+CHESS_WIDTH+3,CHESS_Y+5+2); printf("按Q鍵--暫停"); ResumeThread(th1); pause=0; }else { gotoxy(CHESS_X+CHESS_WIDTH+3,CHESS_Y+5+2); printf("按Q鍵--繼續(xù)"); SuspendThread(th1);//線程掛起后,線程代碼就暫停執(zhí)行 pause=1; }}//開始游戲voidplaygame(void){ intch=0; // srand((unsigned)time(NULL)); //初始化數(shù)據(jù) EnterCriticalSection(&cs); gotoxy(CHESS_X+CHESS_WIDTH+3,CHESS_Y+5); printf("當(dāng)前得分=%8d",PointNum); gotoxy(CHESS_X+CHESS_WIDTH+3,CHESS_Y+5+2); printf("按Q鍵--暫停"); gotoxy(CHESS_X+CHESS_WIDTH+3,CHESS_Y+5+2+2);printf("難度調(diào)節(jié)+,-號",3000-speed); gotoxy(CHESS_X+CHESS_WIDTH+3,CHESS_Y+5+2+2+2); printf("難度:%6d",3000-speed); InitChessData(); //showallchess(); //隨機(jī)初始化 rx=rand()%5; ry=0; oneChess=DownChessData[rx][ry]; oneChess.rx=rx; oneChess.ry=ry; ShowChess(oneChess); LeaveCriticalSection(&cs); // while(1) { ch=getch(); EnterCriticalSection(&cs); gotoxy(0,0); printf("%d",ch); //如果是下光標(biāo)控制↓則下移//80 //如果是左光標(biāo)控制←則左移//75 //如果是右光標(biāo)控制→則右移//77 switch(ch) { case61://+大鍵盤 speed-=100; if(speed<100) { speed=100; } gotoxy(CHESS_X+CHESS_WIDTH+3,CHESS_Y+5+2+2+2); printf("難度:%6d",3000-speed); break; case43://+數(shù)字鍵盤 speed-=100; if(speed<100) { speed=100; } gotoxy(CHESS_X+CHESS_WIDTH+3,CHESS_Y+5+2+2+2); printf("難度:%6d",3000-speed); break; case45://-號 speed+=100; if(speed>2900) { speed=2900; } gotoxy(CHESS_X+CHESS_WIDTH+3,CHESS_Y+5+2+2+2); printf("難度:%6d",3000-speed); break; case113://q //如果線程在運(yùn)行,就掛起它,如果暫停,我們恢復(fù)運(yùn)行 pauseGame(); break; case81://Q pauseGame(); break; //上光標(biāo)鍵 case72: //MoveUp if(CheckSpinBorder(oneChess)) { break; } MoveUp(&oneChess); break; //下 case80:// if(CheckDownBorder(oneChess)||CheckDownChess(oneChess)) { //更新數(shù)據(jù) Add1Chess(oneChess); ShowChessBoard(); //重新賦值OneChess進(jìn)行新的一輪棋子掉落 //隨機(jī)初始化 rx=rand()%5; ry=0; oneChess=DownChessData[rx][ry];oneChess.rx=rx; oneChess.ry=ry; ShowChess(oneChess); }else { MoveDown(&oneChess); } break; //左 case75: if(CheckLeftBorder(oneChess)||CheckLeftChess(oneChess)) {break;} MoveLeft(&oneChess); break; //右 case77: if(CheckRightBorder(oneChess)) {break; } if(CheckRightChess(oneChess)) { break;//不移動,直接下一次循環(huán) //continue; } MoveRight(&oneChess); break; }//endswitch LeaveCriticalSection(&cs); }//endwhile }#include<stdio.h>#include<stdlib.h>#include<string.h>#include<ctype.h>#include<stdarg.h>#include<time.h>#include"hello.h"#include<share.h>#include<Windows.h>#include"gameproc.h"http://#definevar333;//移動光標(biāo)位置voidgotoxy(intx,inty){ COORDxy; HANDLEhstdout; hstdout=GetStdHandle(STD_OUTPUT_HANDLE); xy.X=x; xy.Y=y; SetConsoleCursorPosition(hstdout,xy); //CloseHandle(hstdout);}voidfillchar(chara,intcharlen){ COORDxy={0}; HANDLEhstdout; longbyw; hstdout=GetStdHandle(STD_OUTPUT_HANDLE); FillConsoleOutputCharacter(hstdout,a,charlen,xy,&byw); CloseHandle(hstdout);}#defineX20#defineY6//繪制邊框voiddrawM(void){ inti; //上邊 gotoxy(X,Y); prt("┏"); for(i=1;i<=13;i++) { prt("━"); } prt("┓");//左邊 for(i=1;i<=16;i++) {gotoxy(X,Y+i); prt("┃"); } //右邊 for(i=1;i<=16;i++) { gotoxy(X+28,Y+i); prt("┃"); } //下邊 gotoxy(X,Y+17); prt("┗"); for(i=1;i<=13;i++) { prt("━"); } prt("┛"); return; }//drawmenuvoiddrawmenu(void){ gotoxy(X+3,Y+3); prt("1->菜單選項(xiàng)一");gotoxy(X+3,Y+3+2); prt("菜單選項(xiàng)二"); gotoxy(X+3,Y+3+2+2); prt("退出"); gotoxy(0,0);}intselmenu_Num=0;intselmenu(void){//0,1,2//如果按下↓selmenu_Num++;如果>2selmenu_Num=0;//如果按下↑selmenu_Num--;如果<0selmenu_Num=2; intch=0; while(1) { ch=getch(); //gotoxy(0,0); //prt("%d",ch); if(ch==13) { returnselmenu_Num; } switch(ch) { case72://上光標(biāo) selmenu_Num--; if(selmenu_Num<0) { selmenu_Num=2; } break; case80://下光標(biāo) selmenu_Num++; if(selmenu_Num>2) {

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論