資源描述:
《貪吃蛇源程序》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、貪吃蛇源程序本程序?yàn)樨澇陨哂螒?想必大家都玩過(guò)這個(gè)游戲,程序源代碼用TC2.0編譯通過(guò),需要圖形驅(qū)動(dòng)文件的支持,在TC2.0的集成環(huán)境中有.本程序利用數(shù)據(jù)結(jié)構(gòu)中的鏈表,來(lái)將蛇身連接,同時(shí)當(dāng)蛇吃到一定數(shù)目的東西時(shí)會(huì)自動(dòng)升級(jí),及移動(dòng)速度會(huì)加快,程序會(huì)時(shí)刻將一些信息顯示在屏幕上,包括所得分?jǐn)?shù),要吃多少東西才能升級(jí),并且游戲者可以自己手動(dòng)選擇游戲級(jí)別,級(jí)別越高,蛇的移動(dòng)速度越快.另外,此游戲可能與CPU的速度有關(guān)系.源代碼如下:*************************************************************
2、*********************/*******************************COMMENTS**********************************//*snake_game.c??????????????*//*itisagameforentermainment.??????????*//*inthebegin,thereisonlyasnakehead,anditwillhavetoeatfood?*//*tobecomestronger,anditeatapieceoffoodeachtime
3、,itwill??????*//*lengthenit'sbody,withthenumberoffoodthesnakeeatsgoingup,it*//*willbecomelongmoreandmore,andthescorewillgoesupalso.??*//*thereisalwaysusefulinformationduringthegameprocess.???*//*ifthepathbywhichthesnakegoestoeatfoodistheshortest,the??*//*scorewilladdupadou
4、ble.???????????*//*??????????????????*//*enjoyyourself,andanyproblem,contact?????????????*//*************************************************************************//*allheadfilethatwillbeused*/#include#include#include#include#include#include/*usefulMACRO
5、*/#defineFOOD_SIZE??8#define?SCALE???8#define?UP_KEY???0x4800#define?DOWN_KEY??0x5000#define?LEFT_KEY??0x4b00#define?RIGHT_KEY??0x4d00#define?MOVE_UP???1#define?MOVE_LEFT??2#define?MOVE_DOWN??3#define?MOVE_RIGHT??4#define?INVALID_DIRECTION?0#define?QUIT_KEYC??0x1051#define
6、?QUIT_KEY??0x1071#define?SELECT_KEYC?0x1f53#define?SELECT_KEY?????0x1f73#define?PAUSE_KEYC?????0x1950#define?PAUSE_KEY??????0x1970#defineDEFAULT_LEVEL?1#define?HELP_COLOR??WHITE#define?WELCOME_COLOR?WHITE#define?DEFAULT_COLOR?GREEN/*definethemacroasfollowstoimprovethegamei
7、nfuture*/#defineFOOD_COLOR??YELLOW#define?SNAKE_HEAD_COLOR?RED#defineDEFAULT_SNAKE_COLOR?YELLOW#define?EXIT_COLOR???WHITE#defineSCORE_COLOR???YELLOW/*sturctureforsnakebodymainly,andfoodalso*/typedefstructfood_infor?*FOOD_INFOR_PTR;typedefstructfood_infor{??intposx;???/*pos
8、itionforeachpieceofsnakebody*/??intposy;??intnext_move;?????/*nextmovedirection*/??intpre