Created
June 11, 2014 03:55
-
-
Save petemmitchell/e588dc11bd4a768b93c1 to your computer and use it in GitHub Desktop.
Racing Game (Using object builder)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var usa, ghana, portugal, germany, miles; | |
function Racer(name, speed, intelligence, luck) { | |
this.name = name; | |
this.speed = speed; | |
this.intelligence = intelligence; | |
this.luck = luck; | |
this.position = 0; | |
this.race = function() { | |
if (Math.random() * 10 < intelligence){ | |
this.position = (this.position + (this.speed * luck)); | |
} | |
} | |
} | |
usa = new Racer("Dempsey", 4, 8, 2); | |
ghana = new Racer("Asamoah", 3, 5, 1.75); | |
portugal = new Racer("Ronaldo", 10, 2, 1); | |
germany = new Racer("Ozil", 5, 7, 1.25); | |
miles = 100; | |
while (usa.position < miles && ghana.position < miles && portugal.position < miles && germany.position < miles) { | |
usa.race(); | |
ghana.race(); | |
portugal.race(); | |
germany.race(); | |
console.log(usa.name + ": " + usa.position + ", " + ghana.name + ": " + ghana.position + ", " + portugal.name + ": " + portugal.position + ", " + germany.name + ": " + germany.position) | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment