BalloonClass.java:
// import the packages!
import hsa.Console;
import java.awt.*;
class BalloonClass
{
// declare a console object + global variables for this class.
protected static Console c;
protected static int i_radius = 50;
protected static int i_stringlength = 50;
protected static int i_x = 200;
protected static int i_y = 250;
protected static int i_maxradius = 149;
protected static boolean b_pop = false;
protected static Color i_color;
//class constructor
public BalloonClass (Console c)
{
//refers to the c in the balloonclass, not an argument
this.c = c;
}
//draw method for a balloon.
public void draw ()
{
// make a circle!
c.setColour (i_color);
c.fillOval (i_x, i_y, i_radius, i_radius);
c.setColour (i_color);
c.drawLine (i_x + (i_radius / 2), i_radius + i_y, i_x + (i_radius / 2), i_radius + i_stringlength + i_y);
}
//erase method for a balloon.
public void erase ()
{
Color c_tmp = getcolor ();
//erase it!
i_color = Color.white;
draw ();
//set the old color back!
i_color = c_tmp;
}
//delay method.
public void delay (int idelay)
{
double garbage;
for (int i = 1 ; i <= idelay * 5000 ; i++)
{
garbage = Math.PI * Math.PI;
}
}
//shrink method [action]
public void shrink (int ifinalradius)
{
if (b_pop != true)
{
while (ifinalradius <= i_radius && b_pop != true)
{
if (i_radius > i_maxradius)
{
b_pop = true;
pop ();
}
else
{
i_radius -= 1;
draw ();
delay (20);
erase ();
}
}
if (b_pop != true)
{
draw ();
}
}
}
//grow method [action]
public void grow (int ifinalradius)
{
if (b_pop != true)
{
while (ifinalradius >= i_radius && b_pop != true)
{
if (i_radius > i_maxradius)
{
b_pop = true;
pop ();
}
else
{
i_radius += 1;
draw ();
delay (20);
erase ();
}
}
if (b_pop != true)
{
draw ();
}
}
}
//point check method
public boolean checkpoint (int x, int y)
{
boolean b_check = false;
if (Math.sqrt (Math.pow((x - i_x), 2) + Math.pow((y - i_y), 2)) <= i_radius)
{
b_check = true;
}
return (b_check);
}
//pop method [action]
public void pop ()
{
erase ();
c.setColor (i_color);
c.drawLine (i_x + (i_radius / 2), i_radius + i_y, i_x + (i_radius / 2), i_radius + i_stringlength + i_y);
c.setColour (Color.yellow);
c.fillStar (i_x, i_y, i_radius, i_radius);
delay (100);
c.setColour (Color.red);
c.fillStar (i_x, i_y, i_radius, i_radius);
delay (100);
c.setColour (Color.yellow);
c.fillStar (i_x, i_y, i_radius, i_radius);
delay (100);
c.setColour (Color.red);
c.fillStar (i_x, i_y, i_radius, i_radius);
delay (100);
c.setColour (Color.white);
c.fillStar (i_x, i_y, i_radius, i_radius);
}
//communicate methods.
public void setradius (int newradius)
{
i_radius = newradius;
}
public int getradius ()
{
return (i_radius);
}
public void setxy (int newx, int newy)
{
i_x = newx;
i_y = newy;
}
public int getx ()
{
return (i_x);
}
public int gety ()
{
return (i_y);
}
//remember color is a type ;D
public void setcolor (Color newcolor)
{
i_color = newcolor;
}
public Color getcolor ()
{
return (i_color);
}
public void setstringlength (int newstringlength)
{
i_stringlength = newstringlength;
}
public int getstringlength ()
{
return (i_stringlength);
}
public void setmaxradius (int newmaxradius)
{
i_maxradius = newmaxradius;
}
public int getmaxradius ()
{
return (i_maxradius);
}
}
--------------------------------------------------------------------------------------------------------------------------
PinClass.java:
// import the packages!
import hsa.Console;
import java.awt.*;
class PinClass
{
// declare a console object + global variables for this class.
protected static Console c;
protected static int i_headx = 100;
protected static int i_heady = 100;
protected static int i_tailx = 200;
protected static int i_taily = 200;
protected static Color i_color;
//class constructor
public PinClass (Console c)
{
this.c = c;
}
//draw method for a pin.
public void draw ()
{
// instantiate a Console object from the hsa.Console package
c.setColour (i_color);
c.fillOval (i_headx, i_heady, 5, 5);
c.drawLine (i_headx, i_heady, i_tailx, i_taily);
}
//erase method for a balloon.
public void erase ()
{
Color c_tmp = getcolor ();
//erase it!
c.setColour (Color.white);
draw ();
//set the old color back!
c.setColour (c_tmp);
}
//delay method.
public void delay (int idelay)
{
double garbage;
for (int i = 1 ; i <= idelay * 5000 ; i++)
{
garbage = Math.PI * Math.PI;
}
}
//communicate methods.
public void setheadxy (int newx, int newy)
{
i_headx = newx;
i_heady = newy;
}
public void settailxy (int newx, int newy)
{
i_tailx = newx;
i_taily = newy;
}
public int getheadx ()
{
return (i_headx);
}
public int getheady ()
{
return (i_heady);
}
public int gettailx ()
{
return (i_tailx);
}
public int gettaily ()
{
return (i_taily);
}
//remember color is a type ;D
public void setcolor (Color newcolor)
{
i_color = newcolor;
}
public Color getcolor ()
{
return (i_color);
}
}
--------------------------------------------------------------------------------------------------------------------------
UsePinBalloonClass.java:
import java.awt.*;
import hsa.Console;
class UsePinBalloon
{
public static void main (String [] args)
{
// console object
Console c;
c = new Console ();
int i = 0;
boolean bpopped = false;
//generate 2 pins + 2 balloons
PinClass p [] = new PinClass [100];
BalloonClass b = new BalloonClass (c);
b.setxy (((int) (Math.random () * 600) + 1), ((int) (Math.random () * 400) + 1));
b.draw ();
while (i < 100 && bpopped != true)
{
i += 1;
p = new PinClass (c);
p .setheadxy (((int) (Math.random () * 600) + 1), ((int) (Math.random () * 400) + 1));
p .settailxy (((int) (Math.random () * 600) + 1), ((int) (Math.random () * 400) + 1));
p .draw ();
p .delay (1000);
if (b.checkpoint (p .gettailx (), p .gettaily ()) == true)
{
bpopped = true;
b.pop ();
}
}
}
}
// import the packages!
import hsa.Console;
import java.awt.*;
class BalloonClass
{
// declare a console object + global variables for this class.
protected static Console c;
protected static int i_radius = 50;
protected static int i_stringlength = 50;
protected static int i_x = 200;
protected static int i_y = 250;
protected static int i_maxradius = 149;
protected static boolean b_pop = false;
protected static Color i_color;
//class constructor
public BalloonClass (Console c)
{
//refers to the c in the balloonclass, not an argument
this.c = c;
}
//draw method for a balloon.
public void draw ()
{
// make a circle!
c.setColour (i_color);
c.fillOval (i_x, i_y, i_radius, i_radius);
c.setColour (i_color);
c.drawLine (i_x + (i_radius / 2), i_radius + i_y, i_x + (i_radius / 2), i_radius + i_stringlength + i_y);
}
//erase method for a balloon.
public void erase ()
{
Color c_tmp = getcolor ();
//erase it!
i_color = Color.white;
draw ();
//set the old color back!
i_color = c_tmp;
}
//delay method.
public void delay (int idelay)
{
double garbage;
for (int i = 1 ; i <= idelay * 5000 ; i++)
{
garbage = Math.PI * Math.PI;
}
}
//shrink method [action]
public void shrink (int ifinalradius)
{
if (b_pop != true)
{
while (ifinalradius <= i_radius && b_pop != true)
{
if (i_radius > i_maxradius)
{
b_pop = true;
pop ();
}
else
{
i_radius -= 1;
draw ();
delay (20);
erase ();
}
}
if (b_pop != true)
{
draw ();
}
}
}
//grow method [action]
public void grow (int ifinalradius)
{
if (b_pop != true)
{
while (ifinalradius >= i_radius && b_pop != true)
{
if (i_radius > i_maxradius)
{
b_pop = true;
pop ();
}
else
{
i_radius += 1;
draw ();
delay (20);
erase ();
}
}
if (b_pop != true)
{
draw ();
}
}
}
//point check method
public boolean checkpoint (int x, int y)
{
boolean b_check = false;
if (Math.sqrt (Math.pow((x - i_x), 2) + Math.pow((y - i_y), 2)) <= i_radius)
{
b_check = true;
}
return (b_check);
}
//pop method [action]
public void pop ()
{
erase ();
c.setColor (i_color);
c.drawLine (i_x + (i_radius / 2), i_radius + i_y, i_x + (i_radius / 2), i_radius + i_stringlength + i_y);
c.setColour (Color.yellow);
c.fillStar (i_x, i_y, i_radius, i_radius);
delay (100);
c.setColour (Color.red);
c.fillStar (i_x, i_y, i_radius, i_radius);
delay (100);
c.setColour (Color.yellow);
c.fillStar (i_x, i_y, i_radius, i_radius);
delay (100);
c.setColour (Color.red);
c.fillStar (i_x, i_y, i_radius, i_radius);
delay (100);
c.setColour (Color.white);
c.fillStar (i_x, i_y, i_radius, i_radius);
}
//communicate methods.
public void setradius (int newradius)
{
i_radius = newradius;
}
public int getradius ()
{
return (i_radius);
}
public void setxy (int newx, int newy)
{
i_x = newx;
i_y = newy;
}
public int getx ()
{
return (i_x);
}
public int gety ()
{
return (i_y);
}
//remember color is a type ;D
public void setcolor (Color newcolor)
{
i_color = newcolor;
}
public Color getcolor ()
{
return (i_color);
}
public void setstringlength (int newstringlength)
{
i_stringlength = newstringlength;
}
public int getstringlength ()
{
return (i_stringlength);
}
public void setmaxradius (int newmaxradius)
{
i_maxradius = newmaxradius;
}
public int getmaxradius ()
{
return (i_maxradius);
}
}
--------------------------------------------------------------------------------------------------------------------------
PinClass.java:
// import the packages!
import hsa.Console;
import java.awt.*;
class PinClass
{
// declare a console object + global variables for this class.
protected static Console c;
protected static int i_headx = 100;
protected static int i_heady = 100;
protected static int i_tailx = 200;
protected static int i_taily = 200;
protected static Color i_color;
//class constructor
public PinClass (Console c)
{
this.c = c;
}
//draw method for a pin.
public void draw ()
{
// instantiate a Console object from the hsa.Console package
c.setColour (i_color);
c.fillOval (i_headx, i_heady, 5, 5);
c.drawLine (i_headx, i_heady, i_tailx, i_taily);
}
//erase method for a balloon.
public void erase ()
{
Color c_tmp = getcolor ();
//erase it!
c.setColour (Color.white);
draw ();
//set the old color back!
c.setColour (c_tmp);
}
//delay method.
public void delay (int idelay)
{
double garbage;
for (int i = 1 ; i <= idelay * 5000 ; i++)
{
garbage = Math.PI * Math.PI;
}
}
//communicate methods.
public void setheadxy (int newx, int newy)
{
i_headx = newx;
i_heady = newy;
}
public void settailxy (int newx, int newy)
{
i_tailx = newx;
i_taily = newy;
}
public int getheadx ()
{
return (i_headx);
}
public int getheady ()
{
return (i_heady);
}
public int gettailx ()
{
return (i_tailx);
}
public int gettaily ()
{
return (i_taily);
}
//remember color is a type ;D
public void setcolor (Color newcolor)
{
i_color = newcolor;
}
public Color getcolor ()
{
return (i_color);
}
}
--------------------------------------------------------------------------------------------------------------------------
UsePinBalloonClass.java:
import java.awt.*;
import hsa.Console;
class UsePinBalloon
{
public static void main (String [] args)
{
// console object
Console c;
c = new Console ();
int i = 0;
boolean bpopped = false;
//generate 2 pins + 2 balloons
PinClass p [] = new PinClass [100];
BalloonClass b = new BalloonClass (c);
b.setxy (((int) (Math.random () * 600) + 1), ((int) (Math.random () * 400) + 1));
b.draw ();
while (i < 100 && bpopped != true)
{
i += 1;
p = new PinClass (c);
p .setheadxy (((int) (Math.random () * 600) + 1), ((int) (Math.random () * 400) + 1));
p .settailxy (((int) (Math.random () * 600) + 1), ((int) (Math.random () * 400) + 1));
p .draw ();
p .delay (1000);
if (b.checkpoint (p .gettailx (), p .gettaily ()) == true)
{
bpopped = true;
b.pop ();
}
}
}
}