Pcosta88 / Pcosta88.github.io

MIT License
0 stars 0 forks source link

getTimeRemaining can return 0:00 #1

Open stsawyer opened 8 years ago

stsawyer commented 8 years ago

Not all of the selected times make sense under the valid return value of 0:00 left. As an example, a fumble after the clock has run out on the last play only really matters in very specific circumstances.

Pcosta88 commented 8 years ago

Agreed. I have two ways to solve this:

  1. Make the getTimeRemaining start from 0:01
  2. Exclude 0:00 as a randomized number.

Any other ways? I think I could do #1 with your help/google searching.

stsawyer commented 8 years ago

I would honestly change the way getTimeRemaining works altogether. You don't need to roll each digit independently, just roll how many seconds there are left in the game (1 to 300 or so) and then reformat into minutes : seconds with a division and a modulus (remainder) operator.

totaltime = (random from 1 to 300) minutesLeft = totalTime / 60; //if this isn't don't integer math you'll also need a floor here secondsLeft = total time % 60;