import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class Gallows extends JPanel
{
private int bodyParts;
private boolean isGameOver;
private boolean winOrLose;
public Gallows()
{
setSize(200,200);
setBackground(Color.white);
bodyParts = 0;
isGameOver = false;
}
public void paint(Graphics g)
{
super.paint(g);
// draws gallow itself
g.drawLine(25, 100, 25, 350);
g.drawLine(0, 350, 50, 350);
g.drawLine(25, 100, 125, 100);
g.drawLine(125, 100, 125, 150);
if(bodyParts > 0)
{
g.drawOval(112, 150, 25, 25);
}
if(bodyParts > 1)
{
g.drawLine(125, 175, 125, 250);
}
if(bodyParts > 2)
{
g.drawLine(125, 200, 75, 175);
}
if(bodyParts > 3)
{
g.drawLine(125, 200, 175, 175);
}
if(bodyParts > 4)
{
g.drawLine(125, 250, 75, 300);
}
if(bodyParts > 5)
{
g.drawLine(125, 250, 175, 300);
}
if(isGameOver)
{
g.setFont(new Font("Times", 0, 25));
g.setColor(Color.BLACK);
if(winOrLose)
{
g.drawString("YOU WIN!!!", 75, 95);
}
else
{
g.drawString("YOU LOSE!", 78, 95);
}
}
}
public void addBodyPart()
{
bodyParts++;
repaint();
}
public void reset()
{
bodyParts = 0;
isGameOver = false;
repaint();
}
public void gameOver(boolean winner)
{
isGameOver = true;
winOrLose = winner;
repaint();
}
}