① 經典貪吃蛇的游戲簡介
橫向雙手操作更容易獲得高分,要靈活運用手指滑動與點擊控制方向。
經典的貪吃蛇游戲,能使你體驗到流暢的畫面和大口吃蘋果的快樂!你的得分將進入全球排名,想挑戰極限嗎?快快加入吧!
- 全屏游戲
- 簡單靈活的控制
- 速度級別設定
- 支持重力感應
- 中斷游戲可繼續
- 全球排名
② 貪吃蛇游戲的源代碼
?
貪吃蛇源碼:
<!doctype html>
<html>
<body style='overflow:hidden'>
<canvas id="can" width="400" height="400" style="background:Black;display: block;margin:20px auto;"></canvas>
<script>
var sn = [ 42, 41 ], dz = 43, fx = 1, n, ctx = document.getElementById("can").getContext("2d");
function draw(t, c) {
ctx.fillStyle = c;
ctx.fillRect(t % 20 * 20 + 1, ~~(t / 20) * 20 + 1, 18, 18);
}
document.onkeydown = function(e) {
fx = sn[1] - sn[0] == (n = [ -1, -20, 1, 20 ][(e || event).keyCode - 37] || fx) ? fx : n
};
!function() {
sn.unshift(n = sn[0] + fx);
if (sn.indexOf(n, 1) > 0 || n<0||n>399 || fx == 1 && n % 20 == 0 || fx == -1 && n % 20 == 19)
return alert("GAME OVER");
draw(n, "Lime");
if (n == dz) {
while (sn.indexOf(dz = ~~(Math.random() * 400)) >= 0);
draw(dz, "Yellow");
} else
draw(sn.pop(), "Black");
setTimeout(arguments.callee, 130);
}();
</script>
</body>
</html>
③ 貪吃蛇游戲開發
#include <windows.h>
#include <ctime>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#ifndef SNAKE_H
#define SNAKE_H
class Cmp
{
friend class Csnake;
int rSign; //橫坐標
int lSign; //豎坐標
public:
// friend bool isDead(const Cmp& cmp);
Cmp(int r,int l){setPoint(r,l);}
Cmp(){}
void setPoint(int r,int l){rSign=r;lSign=l;}
Cmp operator-(const Cmp &m)const
{
return Cmp(rSign-m.rSign,lSign-m.lSign);
}
Cmp operator+(const Cmp &m)const
{
return Cmp(rSign+m.rSign,lSign+m.lSign);
}
};
const int maxSize = 5; //初始蛇身長度
class Csnake
{
Cmp firstSign; //蛇頭坐標
Cmp secondSign;//蛇頸坐標
Cmp lastSign; //蛇尾坐標
Cmp nextSign; //預備蛇頭
int row; //列數
int line; //行數
int count; //蛇身長度
vector<vector<char> > snakeMap;//整個游戲界面
queue<Cmp> snakeBody; //蛇身
public:
int GetDirections()const;
char getSymbol(const Cmp& c)const
//獲取指定坐標點上的字元
{
return snakeMap[c.lSign][c.rSign];
}
Csnake(int n)
//初始化游戲界面大小
{
if(n<20)line=20+2;
else if(n>30)line=30+2;
else line=n+2;
row=line*3+2;
}
bool isDead(const Cmp& cmp)
{
return ( getSymbol(cmp)=='@' || cmp.rSign == row-1
|| cmp.rSign== 0 || cmp.lSign == line-1 ||
cmp.lSign == 0 );
}
void InitInstance(); //初始化游戲界面
bool UpdataGame(); //更新游戲界面
void ShowGame(); //顯示游戲界面
};
#endif // SNAKE_H
using namespace std;
//測試成功
void Csnake::InitInstance()
{
snakeMap.resize(line); // snakeMap[豎坐標][橫坐標]
for(int i=0;i<line;i++)
{
snakeMap[i].resize(row);
for(int j=0;j<row;j++)
{
snakeMap[i][j]=' ';
}
}
for(int m=1;m<maxSize+1;m++)
{
//初始蛇身
snakeMap[line/2][m]='@';
//將蛇身坐標壓入隊列
snakeBody.push(Cmp(m,(line/2)));
//snakeBody[橫坐標][豎坐標]
}
//鏈表頭尾
firstSign=snakeBody.back();
secondSign.setPoint(maxSize-1,line/2);
}
//測試成功
int Csnake::GetDirections()const
{
if(GetKeyState(VK_UP)<0) return 1; //1表示按下上鍵
if(GetKeyState(VK_DOWN)<0) return 2; //2表示按下下鍵
if(GetKeyState(VK_LEFT)<0) return 3; //3表示按下左鍵
if(GetKeyState(VK_RIGHT)<0)return 4; //4表示按下右鍵
return 0;
}
bool Csnake::UpdataGame()
{
//-----------------------------------------------
//初始化得分0
static int score=0;
//獲取用戶按鍵信息
int choice;
choice=GetDirections();
cout<<"Total score: "<<score<<endl;
//隨機產生食物所在坐標
int r,l;
//開始初始已經吃食,產生一個食物
static bool eatFood=true;
//如果吃了一個,才再出現第2個食物
if(eatFood)
{
do
{
//坐標范圍限制在(1,1)到(line-2,row-2)對點矩型之間
srand(time(0));
r=(rand()%(row-2))+1; //橫坐標
l=(rand()%(line-2))+1;//豎坐標
//如果隨機產生的坐標不是蛇身,則可行
//否則重新產生坐標
if(snakeMap[l][r]!='@')
{snakeMap[l][r]='*';}
}while (snakeMap[l][r]=='@');
}
switch (choice)
{
case 1://向上
//如果蛇頭和社頸的橫坐標不相同,執行下面操作
if(firstSign.rSign!=secondSign.rSign)nextSign.setPoint(firstSign.rSign,firstSign.lSign-1);
//否則,如下在原本方向上繼續移動
else nextSign=firstSign+(firstSign-secondSign);
break;
case 2://向下
if(firstSign.rSign!=secondSign.rSign)nextSign.setPoint(firstSign.rSign,firstSign.lSign+1);
else nextSign=firstSign+(firstSign-secondSign);
break;
case 3://向左
if(firstSign.lSign!=secondSign.lSign)nextSign.setPoint(firstSign.rSign-1,firstSign.lSign);
else nextSign=firstSign+(firstSign-secondSign);
break;
case 4://向右
if(firstSign.lSign!=secondSign.lSign)nextSign.setPoint(firstSign.rSign+1,firstSign.lSign);
else nextSign=firstSign+(firstSign-secondSign);
break;
default:
nextSign=firstSign+(firstSign-secondSign);
}
//----------------------------------------------------------
if(getSymbol(nextSign)!='*' && !isDead(nextSign))
//如果沒有碰到食物(且沒有死亡的情況下),刪除蛇尾,壓入新的蛇頭
{
//刪除蛇尾
lastSign=snakeBody.front();
snakeMap[lastSign.lSign][lastSign.rSign]=' ';
snakeBody.pop();
//更新蛇頭
secondSign=firstSign;
//壓入蛇頭
snakeBody.push(nextSign);
firstSign=snakeBody.back();
snakeMap[firstSign.lSign][firstSign.rSign]='@';
//沒有吃食
eatFood=false;
return true;
}
//-----吃食-----
else if(getSymbol(nextSign)=='*' && !isDead(nextSign))
{
secondSign=firstSign;
snakeMap[nextSign.lSign][nextSign.rSign]='@';
//只壓入蛇頭
snakeBody.push(nextSign);
firstSign=snakeBody.back();
eatFood=true;
//加分
score+=20;
return true;
}
//-----死亡-----
else {cout<<"Dead"<<endl;cout<<"Your last total score is "<<score<<endl; return false;}
}
void Csnake::ShowGame()
{
for(int i=0;i<line;i++)
{
for(int j=0;j<row;j++)
cout<<snakeMap[i][j];
cout<<endl;
}
Sleep(1);
system("cls");
}
int main()
{
Csnake s(20);
s.InitInstance();
//s.ShowGame();
int noDead;
do
{
s.ShowGame();
noDead=s.UpdataGame();
}while (noDead);
system("pause");
return 0;
}
④ 貪吃蛇大作戰是哪個游戲公司做的
六塊錢的嗎,麻辣燙就可以搞定我
⑤ 貪吃蛇游戲是誰發明的
吃蛇發明者是Jeremy 蛇引誘夏娃吃了蘋果之後,就被貶為毒蟲,陰險的象徵。 而蛇吃東西是整隻動物吞進去的,大概在文藝復興的時候(好象是那個時候但是不確定)就有人發明的一種游戲,是現在貪吃蛇的前身。後來慢慢的發展就變成了今天的貪吃蛇了。 蛇引誘夏娃吃了蘋果之後,就被貶為毒蟲,陰險的象徵。 而蛇吃東西是整隻動物吞進去的,大概在文藝復興的時候(好象是那個時候但是不確定)就有人發明的一種游戲,是現在貪吃蛇的前身。後來慢慢的發展就變成了今天的貪吃蛇
⑥ 貪吃蛇是誰發明的
發明者是Jeremy
貪吃蛇游戲是款非常經典的游戲,既簡單又耐玩。通過控制蛇頭方向吃蛋,使得蛇變長,從而獲得積分。
蛇引誘夏娃吃了蘋果之後,就被貶為毒蟲,陰險的象徵。而蛇吃東西是整隻動物吞進去的,大概在文藝復興的時候就有人發明的一種游戲,是現在貪吃蛇的前身。後來慢慢的發展就變成了今天的貪吃蛇。
⑦ 貪吃蛇游戲是什麼時候誕生的
貪吃蛇已經37歲了.貪吃蛇最早的原型誕生於1976年。它最早出現在一款街機上,名為Blockade,是個雙人游戲。
⑧ 貪吃蛇游戲的創始人是誰
好像無從考察,第一款真正意義上手機游戲就是貪吃蛇,它搭載在諾基亞手機上。但是在街機游戲時代也有貪吃蛇這個游戲。
⑨ 貪吃蛇游戲
下載一個,蛇蛇爭霸