Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*this version im working on variables var name,speed,focus*/
- /*if win set to boolean value true, true = wins; if win
- click button display picture movment jquery*/
- var tired;
- var runners;
- var alert;
- var turtle;
- var rabbit;
- var fox;
- var bird;
- var name;
- var trackMovement=0;
- var movement=trackMovement+=this.speed;
- var winner=false;
- var nameTextBox;
- var speedTextBox;
- var focusTextBox;
- /*var userName=prompt("Input Username");
- var password=prompt("Input Password");*/
- var Animal= function(n,s,f)
- {
- this.name=n;
- this.speed=s;
- this.focus=f;
- this.position=0;
- //added win property to declare a winner
- this.report=function(){
- /* going to put object name such as turtle see see if it give turtle with position*/
- console.log(this.name + " is at " + this.position);
- if(this.position>=distance)
- {// wiiner is declared here
- console.log(this.name+"***Wins the Race!!!***");
- // if this.pos>=dist; win is true, an animal won
- }else{
- console.log(this.name+" Lost the Race!");
- }
- };
- this.run=function(){
- //low focus,lower speed
- tired=this.speed * .5;
- //higher focus, higher speed
- alert=this.speed* 1.5;
- if(this.focus>(Math.floor(Math.random() *10))){
- this.position+=this.speed;
- console.log(this.name+ " is Focused; Speed ++ by "+ alert+ " from " + this.speed+" units");
- }else
- {
- /*if you lack focus, you loose .5 from speed*/
- /*console.log should log which Runner lost focus and was slowed*/
- //also speed before and after reduction
- console.log(this.name+" You Lack Focus; Slowed -- by "+ tired+" from "+this.speed+" units");
- this.position+=tired;
- }
- };
- }
- function makeAnimal(creatAnimalType)
- {
- nameTextBox=$('#nameId').val();
- console.log(nameTextBox);
- speedTextBox=$('#speedId').val();
- var speedConv=parseInt(speedTextBox);
- console.log(speedConv);
- focusTextBox=$('#focusId').val();
- var focusConv=parseInt(focusTextBox);
- console.log(focusConv);
- $("#nameId").val(" ");
- $("#speedId").val(" ");
- $("#focusId").val(" ");
- var useAnimalFunction= new Animal(nameTextBox,speedConv,focusConv);
- return useAnimalFunction;
- console.log("test");
- };
- $('#submitAnimal').on('click',function()
- {
- makeAnimal();
- });
- function displayOnButton()
- {
- turtle=new makeAnimal();
- rabbit=new makeAnimal();
- fox=new makeAnimal();
- bird=new makeAnimal();
- };
- var distance=50;
- function runRace()
- {
- console.log("raceing");
- while(turtle.position < distance && rabbit.position <distance && fox.position< distance && bird.position<distance)
- {
- turtle.run();
- rabbit.run();
- fox.run();
- bird.run();
- winner=name;
- console.log(winner+"winssss");
- };
- }
- $('#buttonRace').on('click',function(){
- displayOnButton();
- runRace();
- turtle.report();
- rabbit.report();
- fox.report();
- bird.report();
- $('#buttonResult').show("fast");
- });
- $('.images img').on('click', function()
- {
- $(this).animate(
- {
- opacity:0.0,
- paddingLeft: '+=80'
- }, 500, function() {
- $(this).remove();
- });
- }
- );
- $('#buttonResult').on('click',function()
- {
- $('.jumbotron h1').show("fast");
- $('#title:contains("My Home Work Page")').text(winner);
- });
- // replace jumbo h1 with animalDisplayWinner()
- // authentification
- /*if(userName!=null&& password !==null)&&
- (userName="zato")&&(password="ichi")||
- (userName="pandora")&&(password="tomorrow"){
- alert("logged in");
- }else{
- alert("suspicous");
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement