Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package csc211project5;
- /**
- *
- * @author Jason Vessella
- */
- import javax.swing.JPanel;
- import javax.swing.JFrame;
- import java.awt.Graphics;
- import java.awt.Color;
- import java.util.Scanner;
- public class Project5Panel extends JPanel {
- //Constructors
- private DrawableStudent st;
- private DrawableIgnorance ig;
- private DrawableTextbook bk;
- private DrawableBackpack bp;
- private Subjects newSub;
- boolean showBook = false;
- private Scanner reader;
- //Constructor
- public Project5Panel()
- {
- reader = new Scanner(System.in);
- //Array sized for max possible books
- }// End Constructors
- @Override
- public void paintComponent(Graphics pen)
- {
- super.paintComponent(pen);
- st.draw(pen);
- ig.draw(pen);
- bp.draw(pen);
- if(bk != null)
- {
- if(showBook == true)
- {
- bk.draw(pen);
- }
- }//End if
- }
- public void fightIgnorance() throws InterruptedException
- {
- st = new DrawableStudent();
- bp = new DrawableBackpack();
- repaint();
- // Fill backpack
- for (int i=0; i<50; i++) {
- bp.addTextbook(new DrawableTextbook());
- }
- ig = new DrawableIgnorance();
- while (bp.getCurrentBooks() > 0)
- {
- System.out.println("HELLO");
- showBook = false;
- if(ig.getHealth() <= 0.0)
- {
- ig.setHealth(1.0);
- }
- System.out.println("0 for heavy; 1 for subject") ;
- int n = reader.nextInt();
- System.out.println(n);
- if (n == 0) {
- bk = st.tossBook(bp);
- showBook = true;
- while(bk.getLocation().getX() < ig.getLocation().getX())
- {
- bk.setVelocity(4,0);
- bk.move();
- Thread.sleep(10);
- repaint();
- if(bk.getLocation().getX() >= ig.getLocation().getX())
- {
- double weight;
- weight = bk.getWeight();
- System.out.println(ig.getHealth());
- ig.setHealth(ig.getHealth() - weight/10);
- }
- }//End While
- showBook = false;
- bp.removeHeaviest();
- }
- if (n == 1) {
- bk = st.tossBook(ig.getIgnoranceType(),bp);
- if(bk != null)
- {
- showBook = true;
- // DO STUFF HERE
- showBook = false;
- } else
- System.out.println("No book of that subject!");
- }
- System.out.println(ig.getHealth());
- repaint();
- // if (bk == null){
- // bk = st.tossBook(bp);
- // this.addToStuff(bk);
- // repaint();
- // }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement