本文實例為大家分享了C語言實現2048游戲的具體代碼,供大家參考,具體內容如下
滑塊有顏色、有最高分(用到文件)
#include <stdio.h>#include <stdlib.h>#include <conio.h> /*使用getch()函數*/#include <time.h>#include <windows.h> /*使用Sleep()函數*/ void Menu();//菜單void Rule_of_game();//游戲規(guī)則 void Begin(int max); //開始 void Table();//打印4×4方格 int Random_number1();//產生2或4的隨機數 int Random_number2();//產生0、1、2、3的隨機數 int Get(int *p_cnt, int score);//輸入指令 void Move();//保留上一次的棋盤布局 int If_move();//判斷是否移動 int Over();//判斷是否結束 void Establish_game();//創(chuàng)建用于保存最高分的文件 void Write_max(int score);//向2048游戲-最高記錄寫入最高分 int Read_max();//讀出最高分記錄的文件void Establish_file();//創(chuàng)建存檔文件 void Write_file(int *p_cnt, int scort);//存檔 int Read_file(int *p_cnt);//讀檔 void again();//是否繼續(xù)游戲int color(int c);//更改顏色void box_color(int x);//不同數值對應不同顏色 int a[4][4] = {0};// 定義全局的二維數組 int A[4][4]; //保留上一步的棋局 char *name_max = "2048游戲-最高記錄";char *name_file = "[空白]-2048游戲";int main() { system("mode con cols=90 lines=30"); system("title 2048超級大大型游戲"); //程序標題 system("color F0");//F 表示背景顏色,0表示前景顏色 Menu(); system("pause"); //暫停,輸入任意鍵繼續(xù) system("cls"); //清屏 again(); //是否繼續(xù)游戲 return 0;}void Menu() //菜單 { printf("/t/t
主站蜘蛛池模板:
清水河县|
绵阳市|
大理市|
广州市|
太康县|
镇赉县|
布尔津县|
墨竹工卡县|
平遥县|
霸州市|
台南县|
通州市|
明水县|
博爱县|
龙南县|
三门峡市|
石门县|
枣庄市|
武邑县|
鄱阳县|
红原县|
杭州市|
独山县|
铁力市|
永善县|
壶关县|
广昌县|
盐城市|
彭泽县|
和林格尔县|
平远县|
南部县|
仁化县|
桦甸市|
安塞县|
淮阳县|
枝江市|
仙游县|
仙游县|
西青区|
泊头市|