資源描述:
《貪吃蛇源程序》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、貪吃蛇源程序本程序為貪吃蛇游戲,想必大家都玩過這個游戲,程序源代碼用TC2.0編譯通過,需要圖形驅(qū)動文件的支持,在TC2.0的集成環(huán)境中有.本程序利用數(shù)據(jù)結(jié)構(gòu)中的鏈表,來將蛇身連接,同時當(dāng)蛇吃到一定數(shù)目的東西時會自動升級,及移動速度會加快,程序會時刻將一些信息顯示在屏幕上,包括所得分數(shù),要吃多少東西才能升級,并且游戲者可以自己手動選擇游戲級別,級別越高,蛇的移動速度越快.另外,此游戲可能與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