Advertisement
EnderDragen

Unit 5 Code thing ig

Nov 19th, 2019
2,258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. - Inventory - (5.9.4)
  2. var STARTING_ITEMS_IN_INVENTORY = 20;
  3. function start(){
  4. var numItems = STARTING_ITEMS_IN_INVENTORY;
  5. while (numItems > 0) {
  6. println("We have " + numItems + " items in inventory.");
  7. var itemsBought = readInt("How many would you like to buy? ");
  8. if (itemsBought <= numItems) {
  9. numItems -= itemsBought;
  10. println("Now we have " + numItems );
  11. } else {
  12. println("There is not enough in inventory for that purchase.");
  13. }
  14. }
  15. println("All Out!" );
  16. }
  17. -----------------------------------------------------------------------------------------------------------------
  18. - Concentric Circles - (5.9.6)
  19. var x = getWidth()/2;
  20. var y = getHeight()/2;
  21. var RADIUS = 200;
  22. function start() {
  23. var circle = new Circle(RADIUS);
  24. circle.setPosition(x,y);
  25. circle.setColor(Color.red);
  26. add(circle);
  27. while(RADIUS > 0){
  28. RADIUS -= 40;
  29. circle = new Circle(RADIUS);
  30. circle.setPosition(x,y);
  31. circle.setColor(Color.black);
  32. add(circle);
  33.  
  34. RADIUS -= 60;
  35. circle = new Circle(RADIUS);
  36. circle.setPosition(x,y);
  37. circle.setColor(Color.red);
  38. add(circle);
  39.  
  40. RADIUS -= 40;
  41. circle = new Circle(RADIUS);
  42. circle.setPosition(x,y);
  43. circle.setColor(Color.black);
  44. add(circle);
  45.  
  46. RADIUS -= -60;
  47. circle = new Circle(RADIUS);
  48. circle.setPosition(x,y);
  49. circle.setColor(Color.red);
  50. add(circle);
  51. RADIUS -= -20;
  52. circle = new Circle(RADIUS);
  53. circle.setPosition(x,y);
  54. circle.setColor(Color.red);
  55. add(circle);
  56.  
  57. }
  58. }
  59. ------------------------------------------------------------------------------
  60. 5.10.4 Snake Eyes
  61.  
  62. function start(){
  63. var numRolls = 0;
  64. while (true) {
  65. numRolls++;
  66. var rollOne = Randomizer.nextInt (1,6);
  67. var rollTwo = Randomizer.nextInt (1,6);
  68. println ("Rolled: " + rollOne + "," + rollTwo);
  69.  
  70. if (rollOne == 1 && rollTwo == 1) {
  71.  
  72. break;
  73.  
  74. }
  75.  
  76. }
  77.  
  78. println ("It took you " + numRolls + " rolls to get snake eyes. ");
  79.  
  80. }
  81. - 5.10.5 - Better Password Prompt -
  82. var SECRET = "abc123";
  83.  
  84. function start(){
  85. var password = SECRET;
  86. while (true) {
  87. var potential = readLine ("What is le password ");
  88. if(potential == password) {
  89. println("You got it!");
  90. break;
  91.  
  92. }else{
  93. println("your answer is incorrect ");
  94. }
  95. }
  96. }
  97. --------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement