Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1.  
  2. /*this version im working on variables var name,speed,focus*/
  3. /*if win set to boolean value true, true = wins; if win
  4. click button display picture movment jquery*/
  5. var tired;
  6. var runners;
  7. var alert;
  8.  
  9. var turtle;
  10. var rabbit;
  11. var fox;
  12. var bird;
  13.  
  14. var name;
  15.  
  16. var trackMovement=0;
  17. var movement=trackMovement+=this.speed;
  18. var winner=false;
  19.  
  20. var nameTextBox;
  21. var speedTextBox;
  22. var focusTextBox;
  23.  
  24.  
  25.  
  26. /*var userName=prompt("Input Username");
  27. var password=prompt("Input Password");*/
  28. var Animal= function(n,s,f)
  29. {
  30. this.name=n;
  31. this.speed=s;
  32. this.focus=f;
  33. this.position=0;
  34. //added win property to declare a winner
  35.  
  36. this.report=function(){
  37. /* going to put object name such as turtle see see if it give turtle with position*/
  38. console.log(this.name + " is at " + this.position);
  39. if(this.position>=distance)
  40. {// wiiner is declared here
  41. console.log(this.name+"***Wins the Race!!!***");
  42.  
  43. // if this.pos>=dist; win is true, an animal won
  44. }else{
  45. console.log(this.name+" Lost the Race!");
  46. }
  47. };
  48. this.run=function(){
  49. //low focus,lower speed
  50. tired=this.speed * .5;
  51. //higher focus, higher speed
  52. alert=this.speed* 1.5;
  53. if(this.focus>(Math.floor(Math.random() *10))){
  54. this.position+=this.speed;
  55. console.log(this.name+ " is Focused; Speed ++ by "+ alert+ " from " + this.speed+" units");
  56. }else
  57. {
  58. /*if you lack focus, you loose .5 from speed*/
  59. /*console.log should log which Runner lost focus and was slowed*/
  60. //also speed before and after reduction
  61. console.log(this.name+" You Lack Focus; Slowed -- by "+ tired+" from "+this.speed+" units");
  62. this.position+=tired;
  63. }
  64. };
  65. }
  66.  
  67. function makeAnimal(creatAnimalType)
  68. {
  69. nameTextBox=$('#nameId').val();
  70. console.log(nameTextBox);
  71.  
  72. speedTextBox=$('#speedId').val();
  73. var speedConv=parseInt(speedTextBox);
  74. console.log(speedConv);
  75.  
  76. focusTextBox=$('#focusId').val();
  77. var focusConv=parseInt(focusTextBox);
  78. console.log(focusConv);
  79. $("#nameId").val(" ");
  80. $("#speedId").val(" ");
  81. $("#focusId").val(" ");
  82.  
  83.  
  84. var useAnimalFunction= new Animal(nameTextBox,speedConv,focusConv);
  85. return useAnimalFunction;
  86.  
  87. console.log("test");
  88. };
  89.  
  90. $('#submitAnimal').on('click',function()
  91. {
  92. makeAnimal();
  93.  
  94. });
  95.  
  96.  
  97.  
  98. function displayOnButton()
  99. {
  100. turtle=new makeAnimal();
  101. rabbit=new makeAnimal();
  102. fox=new makeAnimal();
  103. bird=new makeAnimal();
  104.  
  105. };
  106.  
  107. var distance=50;
  108.  
  109.  
  110.  
  111. function runRace()
  112. {
  113. console.log("raceing");
  114. while(turtle.position < distance && rabbit.position <distance && fox.position< distance && bird.position<distance)
  115. {
  116.  
  117. turtle.run();
  118. rabbit.run();
  119. fox.run();
  120. bird.run();
  121. winner=name;
  122. console.log(winner+"winssss");
  123.  
  124. };
  125.  
  126. }
  127.  
  128. $('#buttonRace').on('click',function(){
  129.  
  130. displayOnButton();
  131. runRace();
  132. turtle.report();
  133. rabbit.report();
  134. fox.report();
  135. bird.report();
  136. $('#buttonResult').show("fast");
  137. });
  138.  
  139.  
  140.  
  141.  
  142.  
  143. $('.images img').on('click', function()
  144. {
  145. $(this).animate(
  146. {
  147. opacity:0.0,
  148. paddingLeft: '+=80'
  149. }, 500, function() {
  150. $(this).remove();
  151. });
  152. }
  153. );
  154.  
  155. $('#buttonResult').on('click',function()
  156. {
  157. $('.jumbotron h1').show("fast");
  158. $('#title:contains("My Home Work Page")').text(winner);
  159. });
  160. // replace jumbo h1 with animalDisplayWinner()
  161.  
  162. // authentification
  163. /*if(userName!=null&& password !==null)&&
  164. (userName="zato")&&(password="ichi")||
  165. (userName="pandora")&&(password="tomorrow"){
  166. alert("logged in");
  167. }else{
  168. alert("suspicous");
  169. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement