Skip to content

Commit

Permalink
reversecount, avoid proposing the same question twice
Browse files Browse the repository at this point in the history
  • Loading branch information
bdoin committed Jun 1, 2014
1 parent d5ff5b4 commit ae68ab7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/activities/reversecount/reversecount.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ function initLevel() {
tuxIceBlockNumber = 0
items.tux.init()

fishIndex = tuxIceBlockNumber + Math.floor(Math.random() *
levels[currentLevel].maxNumber * 2) + 1
calculateNextPlaceFishToReach()
placeFishToReach()
items.backgroundImg.source = url + backgrounds[currentLevel % backgrounds.length]
}
Expand Down Expand Up @@ -195,7 +194,7 @@ function moveTuxToNextIceBlock() {
return
}

fishIndex++
calculateNextPlaceFishToReach()
placeFishToReachBool = true
return
}
Expand Down Expand Up @@ -249,9 +248,19 @@ function calculateTuxIceBlockNextPos() {
(items.chooseDiceBar.value1 + items.chooseDiceBar.value2) * 40
}

var previousFishIndex = 0
function calculateNextPlaceFishToReach() {
var newFishIndex
do {
newFishIndex = Math.floor(Math.random() *
levels[currentLevel].maxNumber * 2) + 1
} while(previousFishIndex === newFishIndex)
fishIndex = tuxIceBlockNumber + newFishIndex
fishIndex = fishIndex % iceBlocksLayout.length
previousFishIndex = newFishIndex
}

function placeFishToReach() {
fishIndex = fishIndex % iceBlocksLayout.length
items.fishToReach.source = url + fishes[fishIndex % fishes.length]
items.fishToReach.x = iceBlocksLayout[fishIndex][0] * items.background.width / 5 +
(items.background.width / 5 - items.tux.width) / 2
Expand Down

0 comments on commit ae68ab7

Please sign in to comment.