第一次專案 Greedy Snake 實用程式碼分析
阿新 • • 發佈:2022-01-18
int main(){
GameBegin();
return 0;
}
//開始遊戲
void GameBegin(){
//確定遊戲初始設定
srand(time(0));//srand()很耗效能,故只引用一次於此
HideCursor();//隱藏游標
system("chcp 65001 > nul");//中文庫
system("title Greedy Snake");//設定視窗名稱
system("mode con cols=100 lines=40");//設定視窗大小
//進入標題頁、歡迎頁與目錄頁
GameTitle();
Welcome();
Menu();
}
//進入選單並通過選項進入不同介面
void Menu(){
MenuAppearance();
while(1){
if(optionDefault) {
StressOption(option);
optionDefault = 0;
}else {
int prvoption = option;
int ch = getch();
if (ch == 'q') exit(0);
if (ch == UP || ch == 'w') option = (--option + 4) % 5 + 1;
else if (ch == DOWN || ch == 's') option = (++option + 4) % 5 + 1;
else if(ch == 13){//回車
ChooseOption(option);
}else continue;
StressOption(option);
RenewPrvOption(prvoption);
}
}
}
//全域性引數
int wallcolor = 3,snakeheadcolor = 10,snakebodycolor = 10;
int moder = 0,model = 0,moden = 1,modee = 0;
int recordbroken = 0;
int wallxlen = 60;
int wallylen = 30;
int bornx = 12;
int borny = 6;
int bornlen = 4;
int curlen;
int option = 1;
int optionDefault = 1;
int speed = 150;
int speed_change = 1;
int curscore = 0;
int maxscore = 0;
int coindoubled