2048小游戲c語言編程設(shè)計_第1頁
2048小游戲c語言編程設(shè)計_第2頁
2048小游戲c語言編程設(shè)計_第3頁
2048小游戲c語言編程設(shè)計_第4頁
2048小游戲c語言編程設(shè)計_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、精選#include<stdio.h>#include<conio.h> /使用getch()函數(shù) #include<time.h> #include <stdlib.h>int num44;int score, gameover, ifappear, gamew, gamef,move;char key;void explation() void menu(); system("cls"); printf("tt*ttn"); printf("tt*n"); printf("

2、tt*玩耍規(guī)章*n"); printf("tt*n"); printf("tt*ttn"); printf("玩家可以選擇上、下、左、右或W、A、S、D去移動滑塊n"); printf("玩家選擇的方向上若有相同的數(shù)字則合并n"); printf("合并所得的全部新生成數(shù)字相加即為該步的有效得分n"); printf("玩家選擇的方向行或列前方有空格則消滅位移n"); printf("每移動一步,空位隨機消滅一個2或4n"); printf(&q

3、uot;棋盤被數(shù)字填滿,無法進行有效移動,判負,玩耍結(jié)束n"); printf("棋盤上消滅2048,獲勝,玩耍結(jié)束n"); printf("按上下左右去移動滑塊n"); printf("請按任意鍵返回主菜單.n"); getch(); system("cls"); main();void gamefaile() int i, j; system("cls"); printf("tt*ttn"); printf("tt*n"); printf(&

4、quot;tt*you fail*n"); printf("tt*n"); printf("tt*ttn"); printf("ttt-nttt"); for (j = 0; j<4; j+) for (i = 0; i<4; i+) if (numji = 0) printf("| "); else printf("|%4d", numji); printf("|n"); printf("ttt-nttt"); printf(&qu

5、ot;你的成果:%d,移動了%d步n", score,move); printf("請按任意鍵返回主菜單.n"); getch(); system("cls"); main(); void gamewin() int i, j; system("cls"); printf("tt*ttn"); printf("tt*n"); printf("tt*you win*n"); printf("tt*n"); printf("tt*ttn&q

6、uot;); printf("ttt-nttt"); for (j = 0; j<4; j+) for (i = 0; i<4; i+) if (numji = 0) printf("| "); else printf("|%4d", numji); printf("|n"); printf("ttt-nttt"); printf("你的成果:%d,移動了%d步n", score,move); printf("請按任意鍵返回主菜單.n"); g

7、etch(); system("cls"); main();void prin() int i, j; system("cls"); printf("tt*ttn");/輸出界面 printf("tt*n"); printf("tt*玩耍開頭*n"); printf("tt*n"); printf("tt*ttn"); printf("tt 請按方向鍵或W、A、S、D移動滑塊n");/輸出操作提示語句 printf("tt 按

8、ESC返回至主菜單n"); printf("ttt-nttt"); for (j = 0; j<4; j+) /輸出4*4的表格 for (i = 0; i<4; i+) if (numji = 0) printf("| "); else printf("|%4d", numji); printf("|n"); printf("ttt-nttt"); printf("你的成果:%d,移動了%d步n", score,move);/輸出得分和移動步數(shù)void

9、 appear() int i, j,ran,t16,x=0,a,b; srand(int)time(0); /隨機種子初始化 for (j = 0; j < 4; j+) /將空白的區(qū)域的坐標保存到中間數(shù)組t中 for (i = 0; i < 4;i+) if (numji = 0) tx = j * 10 + i; x+; if (x = 1) /在t中隨機取一個坐標 ran = x - 1; else ran = rand() % (x - 1); a = tran / 10; /取出這個數(shù)值的十位數(shù) b = tran % 10; /取出這個數(shù)值的個位數(shù) srand(int)

10、time(0); if (rand() % 9)>2) /在此空白區(qū)域隨機賦值2或4 numab = 2; else numab = 4;void close() exit(0);void add(int *p) int i=0, b; while (i<3) if (*(p + i) != 0) for (b = i + 1; b < 4; b+) if (*(p + b) != 0) if (*(p + i) = *(p + b) score = score + (*(p + i) + (*(p + b); *(p + i) = *(p + i) + *(p + b);

11、if (*(p + i) = 2048) gamew = 1; *(p + b) = 0; i = b + i; +ifappear; break; else i = b; break; if (b = 4) i+; else i+; void Gameplay() int i, j, g, e, a, b4; appear(); appear(); while (1) if (ifappear!=0) appear(); prin(); key = getch(); switch (key) case 'w': case 'W': case 72: ifapp

12、ear = 0; for (j = 0; j < 4; j+) for (i = 0; i < 4; i+) bi = numij; numij = 0; add(b); e = 0; for (g = 0; g < 4; g+) if (bg != 0) numej = bg; if (g != e) +ifappear; e+; if (ifappear!=0) +move; break; case 's': case 'S': case 80: ifappear = 0; for (j = 0; j < 4; j+) for (i

13、= 0; i < 4; i+) bi = numij; numij = 0; add(b); e = 3; for (g = 3; g>=0; g-) if (bg != 0) numej = bg; if (g != e) +ifappear; e-; if (ifappear != 0) +move; break; case 'a': case 'A': case 75: ifappear = 0; for (j = 0; j < 4; j+) for (i = 0; i < 4; i+) bi = numji; numji = 0;

14、 add(b); e = 0; for (g = 0; g < 4; g+) if (bg != 0) numje = bg; if (g!=e) +ifappear; e+; if (ifappear != 0) +move; break; case 'd': case 'D': case 77: ifappear = 0; for (j = 0; j < 4; j+) for (i = 0; i < 4; i+) bi = numji; numji = 0; add(b); e = 3; for (g = 3; g >=0; g-)

15、if (bg != 0) numje = bg; if (g!=e) +ifappear; e-; if (ifappear != 0) +move; break; case 27: system("cls"); main(); break; for (j = 0; j < 4; j+) for (i = 0; i < 4; i+) if (j < 3) if (i < 3) if (numji = numj + 1i | numji = numji + 1 | numji = 0) gamef = 0; break; else gamef = 1;

16、 else if (numji = numj + 1i | numji = 0) gamef = 0; break; else gamef = 1; else if (i < 3) if (numji = numji + 1 | numji = 0 | numji + 1 = 0) gamef = 0; break; else gamef = 1; if (gamef = 0) break; if (gamef = 1 | gamew = 1) break; if (gamef = 1) gamefaile(); else gamewin();void menu() int n; pri

17、ntf("tt*ttn"); /輸出玩耍菜單的圖形 printf("tt* 1、開頭玩耍 *n"); printf("tt* 2、玩耍規(guī)章 *n"); printf("tt* 3、退出玩耍 *n"); printf("tt*n"); printf("請輸入1或2或3: bb"); scanf("%d", &n); switch (n) case 1: Gameplay(); /玩耍開頭函數(shù) break; case 2: explation(); /玩耍規(guī)章函數(shù) break; case 3: close(); /關(guān)閉玩耍函數(shù) break; int main()

溫馨提示

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

評論

0/150

提交評論