我一直在嘗試在AS3中創建的遊戲中實現一個分數。到目前爲止,我已經設法創建一個分數系統,根據遊戲中的動作增加/減少分數。我已經決定讓評分系統只是加點而不是減去它們並達到一定數量就結束遊戲會更簡單。ActionScript 3得分/數學
我遇到的問題是,一方面,遊戲執行檢查以查看棋子是否在正確的位置。如果是,則玩家獲勝。另一方面,在決定玩家失敗之前,計數器需要計數並達到一定數量(10)。此刻有一些奇怪的行爲正在發生,我可以拖動這些碎片而不會將它們放在正確的位置,並且計數器仍然超過10.我嘗試了一些更改數學的變體,以便總計不同,但功能是一樣的。我需要改變什麼,才能像第一次描述的那樣行事?
stop();
//Create the score counter
import flash.text.TextField;
var score = 0;
scorecounter.text = score;
function init(): void
{
score = 0;
scorecounter.text = "SCORE:" + score.toString();
}
function updateScore(): void
{
scorecounter.text = ++score;
}
function evaluateScore(): void //this is meant to stop the score going below 0
{
scorecounter.text = --score;
if(score < 0) {
score -= score;
}
}
/*Omitted some functions and var's for object positions and events*/
function stopDragging(e:MouseEvent):void {
e.currentTarget.stopDrag();
switch (e.currentTarget){
case apple:
if (apple.x < appleEndX - offset || apple.x > appleEndX + offset ||
apple.y < appleEndY - offset || apple.y > appleEndY + offset) {
apple.x = appleStartX;
apple.y = appleStartY;
soundOne();
updateScore();
} else {
apple.x = appleEndX;
apple.y = appleEndY;
soundTwo();
updateScore();
checkGame();
}
break;
//Lots of other cases, using the same method
//The end of the game - here, I've been trying to set it to
//check whether the player will win or lose
}
}
function checkGame(): void {
if (apple.x == appleEndX && apple.y == appleEndY && pear.x == pearEndX &&
pear.y == pearEndY && guava.x == guavaEndX && guava.y == guavaEndY &&
pineapple.x == pineappleEndX && pineapple.y == pineappleEndY &&
plum.x == plumEndX && plum.y == plumEndY &&
purple.x == purpleEndX && purple.y == purpleEndY)
{
trace("You win!");
gotoAndStop(149);
soundFive();
} else if (score == 10) {
gotoAndStop(150);
soundSix();
trace("You lose.");
}
}
user3293367調用updateScore()兩次:在'if'以及'else'。這就好像你每次都在調用它一樣。 – helloflash 2014-10-29 17:11:12