私は本当にタイトルを呼び出すが知っていないが、私はnodejsとソケットを使用してjsで作らスネークゲームを持って知っている。スネークゲーム - 食べ物を食べるが、別の(javascript)
どのように食べ物を作りたいのですか?食べ物が生まれたとき、緑色のものを産むチャンスは21/25、赤色のものは3/25、黄色のものは1/25です。
私はまた、プレイヤーが緑のものを食べるならば、それだけでdissaper
緑= 10ポイントになり、他の食品、赤= 50点を生成します、配列内の1以上の食品がある場合はそれになりたいです
スクリーン上に1つ以上の緑色の食べ物があり、1つを食べる時を除いて、それはうまく動作します。時にはそれらの一部が消えてしまうこともあります。なぜ。おそらく本当のシンプルなものですが、私のコードです。
私は、取り入れるコードがたくさんあることを知っていますが、私は助けになるようにコメントを追加しています。アドバイスが必要です。ここで
var FoodList = [];
SpawnFood(10, 1); //Spawn a default peice of food
function SpawnFood(Value, Amount) //Add a Food to the board
{
for (var i = 0; i < Amount; i++) {
var j = i;
if (FoodList.length == 0) {
FoodList[j] = new Food(); //If there is no food in the array, spawn one
FoodList[j].init();
FoodList[j].FoodValue = Value;
j++
} else { //if there is food in the array
while (FoodList[j] !== undefined) { //choose the lowest empty place
j++
}
FoodList[j] = new Food(); //And then spawn in
FoodList[j].init();
FoodList[j].FoodValue = Value;
}
}
}
//Collision detection below :
for (var i in SnakeList) //For each instance of snake
{
var snake = SnakeList[i]; //Declare snake as the current snake
for (var j in FoodList) //For each instance of Food
{
if (snake.hasColision(FoodList[j])) //If they have collided
{
snake.addLength(); //Removes the Food and adds length to the current snake
snake.eatFood(FoodList[j]); //Rewards the player with score)
var Value = FoodList[j].FoodValue; //Asking it what score value the food has
delete FoodList[j]; //Deletes that food
var count = 0;
for (var s in FoodList) //For each instance of Food
{
count++;
} //Counts how many peices of food are in the array (.length doesnt work)
if (Value == 10) { //If the player ate a green food
if (count < 1) { //And theres more than 1 food in the array
var RandomNumber = Math.round(Math.random() * (25 - 1) + 1); //Generate a random num
if ((RandomNumber >= 1) && (RandomNumber <= 21)) //common drop, green food
{
SpawnFood(10, 1); //Soawn green food
} else if ((RandomNumber >= 22) && (RandomNumber <= 24)) //rare red
{
SpawnFood(50, 1); //spawn red
} else {
SpawnFood(200, 1); //spawn very rare yellow
}
}
} else if (Value == 50) { //If the player ate a red, spawn 3 green
SpawnFood(10, 3);
} else if (Value == 200) { //If the player ate a yellow, spawn 5 green
SpawnFood(10, 5);
}
}
}
}
問題をデバッグするために行ったことを私たちに伝えてください。 (あなたの質問で) –
私はなぜその出来事、食べ物が無作為に削除されるのか知っていないのは、唯一の場所のiveが「食べ物リストの削除」を得たときです。プレイヤーがそれを食べるときでも、 – Will
こんにちは!緑の食べ物が食べられると、あなたは有益な人を産んだりしないか? –