Created
November 13, 2014 16:36
-
-
Save erkgmz/308bd8692672e0673d55 to your computer and use it in GitHub Desktop.
Race Game
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> | |
| function Animal(name, speed, health){ | |
| this.name = name; | |
| this.speed = speed; | |
| this.health = health; | |
| this.position =0; | |
| this.isFocused = function(){ | |
| return Math.floor(Math.random() * 10) < this.health; | |
| } | |
| this.advance = function(){ | |
| if(this.isFocused()){ | |
| this.position += this.speed; | |
| } | |
| } | |
| this.status = function(){ | |
| return this.name + " is at: " + this.position | |
| } | |
| } | |
| var rabbit = new Animal("Bugs Bunny", 8, 5); | |
| var turtle = new Animal("Leonardo", 3, 10); | |
| var meters = 50; | |
| while(rabbit.position < meters && turtle.position < meters){ | |
| rabbit.advance(); | |
| turtle.advance(); | |
| alert(rabbit.status() + " - " + turtle.status()); | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment