Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package csc211project5;
  7.  
  8. /**
  9. *
  10. * @author Jason Vessella
  11. */
  12. import javax.swing.JPanel;
  13. import javax.swing.JFrame;
  14. import java.awt.Graphics;
  15. import java.awt.Color;
  16. import java.util.Scanner;
  17.  
  18. public class Project5Panel extends JPanel {
  19.  
  20.  
  21. //Constructors
  22.  
  23. private DrawableStudent st;
  24. private DrawableIgnorance ig;
  25. private DrawableTextbook bk;
  26. private DrawableBackpack bp;
  27. private Subjects newSub;
  28. boolean showBook = false;
  29.  
  30.  
  31.  
  32. private Scanner reader;
  33.  
  34. //Constructor
  35. public Project5Panel()
  36. {
  37.  
  38. reader = new Scanner(System.in);
  39.  
  40. //Array sized for max possible books
  41.  
  42.  
  43.  
  44. }// End Constructors
  45.  
  46.  
  47. @Override
  48. public void paintComponent(Graphics pen)
  49. {
  50. super.paintComponent(pen);
  51. st.draw(pen);
  52. ig.draw(pen);
  53. bp.draw(pen);
  54. if(bk != null)
  55. {
  56. if(showBook == true)
  57. {
  58. bk.draw(pen);
  59. }
  60. }//End if
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. }
  68.  
  69. public void fightIgnorance() throws InterruptedException
  70. {
  71.  
  72.  
  73. st = new DrawableStudent();
  74.  
  75.  
  76. bp = new DrawableBackpack();
  77.  
  78. repaint();
  79.  
  80. // Fill backpack
  81. for (int i=0; i<50; i++) {
  82. bp.addTextbook(new DrawableTextbook());
  83.  
  84.  
  85. }
  86. ig = new DrawableIgnorance();
  87. while (bp.getCurrentBooks() > 0)
  88. {
  89. System.out.println("HELLO");
  90. showBook = false;
  91.  
  92. if(ig.getHealth() <= 0.0)
  93. {
  94. ig.setHealth(1.0);
  95. }
  96.  
  97.  
  98. System.out.println("0 for heavy; 1 for subject") ;
  99. int n = reader.nextInt();
  100.  
  101. System.out.println(n);
  102.  
  103.  
  104.  
  105. if (n == 0) {
  106. bk = st.tossBook(bp);
  107. showBook = true;
  108. while(bk.getLocation().getX() < ig.getLocation().getX())
  109. {
  110. bk.setVelocity(4,0);
  111. bk.move();
  112. Thread.sleep(10);
  113. repaint();
  114. if(bk.getLocation().getX() >= ig.getLocation().getX())
  115. {
  116. double weight;
  117. weight = bk.getWeight();
  118. System.out.println(ig.getHealth());
  119.  
  120. ig.setHealth(ig.getHealth() - weight/10);
  121.  
  122. }
  123. }//End While
  124. showBook = false;
  125. bp.removeHeaviest();
  126.  
  127. }
  128.  
  129. if (n == 1) {
  130.  
  131. bk = st.tossBook(ig.getIgnoranceType(),bp);
  132. if(bk != null)
  133. {
  134. showBook = true;
  135. // DO STUFF HERE
  136. showBook = false;
  137. } else
  138. System.out.println("No book of that subject!");
  139.  
  140. }
  141.  
  142. System.out.println(ig.getHealth());
  143.  
  144.  
  145.  
  146. repaint();
  147.  
  148.  
  149. // if (bk == null){
  150. // bk = st.tossBook(bp);
  151. // this.addToStuff(bk);
  152. // repaint();
  153. // }
  154.  
  155.  
  156. }
  157. }
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement