Guest User

Untitled

a guest
Feb 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. /* PLANNING-
  2. Draw - Alphabet
  3.  
  4. function list:
  5. draw circle
  6. drawLine
  7. drawRectangle
  8.  
  9. */
  10.  
  11. function start(){
  12. var Bg = drawRectangle(X_MAX * 2,Y_MAX,Color.green,0,0);
  13. GuessRoll();
  14. drawDice_cube();
  15. RollDice();
  16.  
  17. }
  18.  
  19. var centerX = getWidth() / 2;
  20. var centerY = getHeight() / 2;
  21. var X_MAX = getWidth();
  22. var Y_MAX = getHeight();
  23. var Reflection_Dot = 8;
  24. var Reflection_Dot_radius = 3;
  25. var roll = Randomizer.nextInt(1,6);
  26. var guess = readInt("What number do you think the dice will roll?");
  27.  
  28. function drawCircle(color, x, y, radius,){
  29. var circle = new Circle(radius);
  30. circle.setPosition(x,y);
  31. circle.setColor(color);
  32. add(circle);
  33. }
  34.  
  35. function drawLine(color, width, x1, y1, x2, y2){
  36. var line = new Line(x1, y1, x2, y2);
  37. line.setColor(color);
  38. line.setLineWidth(width);
  39. add(line);
  40.  
  41. }
  42. function drawRectangle(width, height, color, x, y){
  43. var rectangle = new Rectangle(width, height);
  44. var left = x - width/2;
  45. rectangle.setPosition( left , y);
  46. rectangle.setColor(color);
  47. add(rectangle);
  48. }
  49.  
  50. function drawDiceDot(x, y){
  51. drawCircle(Color.black, x, y, 15);
  52. drawCircle(Color.white, x, (y+ Reflection_Dot), Reflection_Dot_radius);
  53. }
  54.  
  55. function drawDice_cube(){
  56. drawRectangle(200, 200, Color.black, 200, 200);
  57. drawRectangle(190, 190, Color.white, 200, 205);
  58. drawLine(Color.black, 4, 105, 205, 50, 175);//top left
  59. drawLine(Color.black, 4, 300, 203, 250, 175);//top right
  60. drawLine(Color.black, 4, 50, 175, 250, 175)//conector line
  61. drawLine(Color.black, 4, 50, 370, 100, 396);//bottom left
  62. drawLine(Color.black, 4, 50, 175, 50, 370);
  63. var side1 = new Polygon(100, 100);
  64. side1.addPoint(100,203);
  65. side1.addPoint(52, 178);
  66. side1.addPoint(52, 370);
  67. side1.addPoint(100, 393);
  68. side1.setColor("White");
  69. add(side1);
  70. var side2 = new Polygon(100, 100);
  71. side2.addPoint(52, 176);//top left
  72. side2.addPoint(99, 200);//bottom left
  73. side2.addPoint(300, 200);//bottom right
  74. side2.addPoint(250, 176);//top right
  75. side2.setColor("White");
  76. add(side2);
  77. }
  78.  
  79.  
  80. function RollDice(){
  81. for(var i = 0; i < 1; i++){
  82. if (roll == 1){
  83. drawOne();
  84. } if (roll == 2){
  85. drawTwo();
  86. } if (roll == 3){
  87. drawThree();
  88. } if (roll == 4){
  89. drawFour();
  90. } if (roll == 5){
  91. drawFive();
  92. } if (roll == 6){
  93. drawSix();
  94. }
  95. } //for
  96. }//function
  97.  
  98. function drawOne(){
  99. drawDiceDot(200, 300);
  100. }
  101.  
  102. function drawTwo(){
  103. drawDiceDot(200, 250);
  104. drawDiceDot(200, 330);
  105. }
  106.  
  107.  
  108. function drawThree(){
  109. drawDiceDot(200, 300);
  110. drawDiceDot(240, 340);
  111. drawDiceDot(160, 260);
  112. }
  113.  
  114.  
  115. function drawFour(){
  116. drawDiceDot(240, 340);//bottom right
  117. drawDiceDot(160, 260);
  118. drawDiceDot(240, 260);
  119. drawDiceDot(160, 340); //bottom left
  120. }
  121.  
  122. function drawFive(){
  123. drawDiceDot(240, 340);//bottom right
  124. drawDiceDot(160, 260);
  125. drawDiceDot(240, 260);
  126. drawDiceDot(160, 340); //bottom left
  127. drawDiceDot(200, 300);//middle
  128. }
  129.  
  130. function drawSix(){
  131. drawDiceDot(240, 350);//bottom right
  132. drawDiceDot(160, 250);
  133. drawDiceDot(240, 250);
  134. drawDiceDot(160, 350); //bottom left
  135. drawDiceDot(240, 300);
  136. drawDiceDot(160, 300);
  137. }
  138.  
  139. function GuessRoll(){
  140. println("The dice rolled a " + roll);
  141. println("You guessed it will roll a " + guess);
  142. if (guess == roll){
  143. println("Your guess was correct");
  144. var Bg = drawRectangle(X_MAX * 2,Y_MAX,Color.green,0,0);
  145. var txt = new Text("Correct","50pt Arial");
  146. txt.setPosition(20, 70);
  147. add(txt);
  148. }else{ println("Your guess was incorrect");
  149. var Bg = drawRectangle(X_MAX * 2,Y_MAX,Color.red,0,0);
  150. var txt = new Text("Incorrect","50pt Arial");
  151. txt.setPosition(20, 70);
  152. setTimer(ChangeText, 2000);
  153. add(txt);
  154. }
  155. }
  156.  
  157. function ChangeText(){
  158. var txt = new Text("Incorrect","50pt Arial");
  159. txt.setText("Try again!");
  160. txt.setPosition(20,120);
  161. add(txt);
  162.  
  163. }
Add Comment
Please, Sign In to add comment