終於開學了,我也大三了,新的一年新的開始,我也開始我的部落格之旅,哈哈。。。。
#include
#include
#include
#pragma comment(lib,"winmm.lib")
#include
#include
#include
#define n 23
static int rat=0;//改變蛇的行動快慢
static int w=0;
using namespace std;
static int x=1;
static int ki=0; //判斷蛇是否在吃食物若為1則正在吃食物
void gotoxy(int x,int y) //游標函式
void color(int a) //顏色函式
};for(i=1;i<=n;i++)
for(i=0;i<=n+1;i++)
}cout<=190)
rat=0;
tail[0]=snake[len-1][0];
tail[1]=snake[len-1][1];
gotoxy(tail[0],tail[1]); //蛇每走一步,蛇尾都會由背景填充。
color(28);
cout<<" "
if(kbhit())
switch(ch)
gotoxy(snake[0][0],snake[0][1]);
color(30); //黃色
cout<<"★"
ki=0;
if(ki==0) //當蛇沒有吃食物時,如果它撞到自己的身體上,則死亡!
for(i=len-1;i!=0;i--)
if(snake[0][0]==snake[i][0]&&snake[0][1]==snake[i][1])
if(score==100)
if(snake[0][1]==0||snake[0][1]==n+1||snake[0][0]==0||snake[0][0]==n+7)//撞到圍牆後失敗
}return 0;}}
C語言 貪吃蛇遊戲
相信每個人都接觸過貪吃蛇遊戲,而對於學習c語言的同學來說,一開始是不是覺得c語言寫不出什麼東西來呢?那麼,貪吃蛇應該是第一步,開始了解一些模組化的知識,一些物件導向的思想,一些小專案的編寫。效果 通過 wasd 移動蛇,蛇能夠吃隨機產生的食物,並且變長。基本實現 用兩個陣列snakex,snakey...
C 簡單貪吃蛇遊戲
用c 實現的非常簡單的非圖形介面的簡單貪吃蛇遊戲 include include include include include includeusing namespace std void transport short short short void set short,short void...
C 實現貪吃蛇遊戲
一,專案簡介 距上個專案 c 實現推箱子遊戲 一周時間,再次回顧兒時經典遊戲 貪吃蛇。實現了按鍵控制蛇頭移動,按下空格鍵暫停,採用鍊錶結構實現吃到食物蛇身增長,到達一定限度,蛇頭前進速率加快 撞到牆壁或蛇身,遊戲結束。如有問題,希望大佬指導糾錯。二,區 game.h define snake h i...