貪吃蛇的邂逅前續

2021-09-12 14:54:20 字數 1264 閱讀 9442

html**

//簡單的小地圖

css**

js**

//隨機小方塊**(食物)

(function()

//設定食物的樣式

food.prototype.init = function(map)

//清除上乙個小方塊和刪除陣列中的小方塊記錄

function remove()

}window.food = food;

}());

//蛇的**塊

(function() ,,];

}//設定蛇的樣式

snake.prototype.init = function(map)

}//蛇的移動,其中掌握蛇移動的規律就能理解**含義,就是蛇的身體三部分中在走的時候,第三部分將走到第二部分的地方,而蛇的第一部分,也就是頭部,將根據蛇移動方向決定

snake.prototype.move = function(food,map)

switch(this.direction)

}//同時蛇也需要清除在建立實現移動

function remove()

}window.snake = snake;

}());

//遊戲物件**塊

(function()

game.prototype.init=function()

//蛇移動加入定時器,實現連續,其中判斷蛇什麼時候撞牆,遊戲結束

game.prototype.runsnake=function(food,map)

}.bind(that),150);

}window.game=game;

}());

var gm=new game(document.queryselector(".map"));

gm.init();

蛇移動的過程:

蛇撞牆的過程:

今天就到這裡了,下次繼續貪吃蛇。

貪吃蛇遊戲

貪吃蛇遊戲 結構化程式設計 c語言程式設計 重要的的是結構化的程式設計思想 include include include include include include define field width 300 就做20個格仔的 define field height 300 define f...

貪吃蛇(改進)

該程式分成3個檔案 第乙個檔案 fang.cs using system using system.collections.generic using system.text using system.windows.forms using system.drawing namespace snak...

貪吃蛇遊戲

include include include include include 使用當前時間做種子 enum dir 列舉型別enum dir 圍牆 class fencef 定義物件 畫框框 void fence initfence 顯示框框 void fence outputf int snak...