基於c++的貪吃蛇簡約遊戲程式設計(還是標頭檔案的原因,大家可以手動把頭檔案放進<>裡)
#include<>iostream
#include
#include
#include<>ctime
using namespace std;
constexpr auto mapheight=25;
constexpr auto mapwidth=60;
constexpr auto snakesize=50;
struct
food;
struct
snake;
//全域性變數
int key = 『w』;//蛇的初始化移動方向
int changflag = 0;//蛇的變化標誌
//畫地圖
void drawmap();
//食物的生成
void createfood();
//按鍵操作
void keydown();
//蛇的狀態:判斷是否結束遊戲
int snakestatus();
//輔助函式:游標移動
void gotoxy(int x, int y);
int main()
}gotoxy(mapwidth / 2, mapheight / 2);
cout << 「gameover」;
system(「pause」);
return 0;
}void gotoxy(int x, int y)
void drawmap()
for (int i = 0; i <= mapwidth; i+=2)//□占用兩個字元
//畫蛇□
snake.len = 3;
snake.speed = 300;
snake.x[0] = mapwidth / 2;
snake.y[0] = mapheight / 2;
//畫蛇頭
gotoxy(snake.x[0], snake.y[0]);
cout << 「□」;
//畫身體
for (int k = 1; k < snake.len; k++)
//畫食物⊙
food.x = rand() % (mapwidth - 4) + 2;//兩邊邊框佔4個字元
food.y = rand() % (mapheight - 2) + 1;
gotoxy(food.x, food.y);
cout << 「⊙」;
}void createfood()
}if (flag&&food.x % 2 == 0)}}
gotoxy(food.x, food.y);
cout << 「⊙」;
}void keydown()
//擦除最後一節
if (!changflag)
//後面的蛇身移動
for (int i = snake.len - 1; i > 0; i–)
switch (key)
gotoxy(snake.x[0], snake.y[0]);
cout << 「□」;
changflag = 0;
gotoxy(mapheight + 2, 0);
}int snakestatus()
for (int k = 1; k < snake.len; k++)
}return 1;
}
C 貪吃蛇小遊戲
自學了幾天c 嘗試寫了乙個貪吃蛇小遊戲,比較詳細地做了注釋,實現 1 貪吃蛇基本功能 2 長按加速 3 計分板 xaml 及介面 namespace 貪吃蛇 新食物生成 public void newfoodgenerate 計時器每乙個計時週期內的時間處理程式 void timer tick ob...
C 貪吃蛇小遊戲
1.有許多值得新手學習的地方 2.不看就吃虧了噢 3.如果沒有值得學習的地方,我就倒立洗頭!include include include include include 方向鍵的ascll值 上72,左75,右77,下80 背景顏色的 0 黑色 1藍色 2 綠色 3湖藍色 4紅色 5紫色 6黃色 ...
c 貪吃蛇小遊戲
恢復內容開始 新手學習c 在上看到後自己模仿打出來的第乙個程式 開心,紀念一下 bean 食物類 block 蛇塊類 snake 蛇類 map 地圖 圖形類 食物類 class bean set 顯示食物方法 public void showbean graphics g 食物消失方法 public...