Write a tank war game with knowledge points such as collections, Swing, threads, and so on in the Java language.
(1) Draw the principle of the enemy tank:
There is a Boolean type variable good in the Tank class. Used to judge the camp of tanks, when the tank object is created, the value of the good is passed in the constructor method of the tank class. When the tank is painted, judge the value of good, distinguish the color of the enemy tank;
(2) The principle of tank movement:
in the tank class in the listening keyboard key to respond to the event, the monitor heard about the next key to record, And to synthesize the eight-directional variables that the tank moves. The change in response to the value of the tank coordinate x,y after each direction is changed to achieve the movement of our tanks. The enemy tanks move automatically by random numbers to the enemy tanks to move the direction of the random, and random out the number of times each move. Two random values combine to achieve the movement of enemy tanks.
(3) The principle of the tank firing bullets:
Through the keyboard monitoring, detection of firing bullets command the main class of bullets to add a bullet class collection. The direction of the barrel and the position of the tank and the camp of the tank into the bullets, in the main class paint painting method has been circulating bullets collection, if there is a bullet in the collection, draw it. This will achieve the firing of bullets.
(4) The collision principle of tanks, bullets and walls:
in tank type bullet wall class respectively GetRect method to obtain its own range, and then in each painting tank, The bullets are matched by collision detection (in tanks, there is a way to collide with walls and tanks outside of themselves, and in the case of bullets that collide with walls and tanks). ), if it coincides with the scope of the object that should not collide, it represents two objects colliding.
(5) The principle of tank blood:
The treatment of clots in blood clots that collide with our tanks, blood clots die if the scope of the blood clot is coincident with the tank range, and the volume of the tank is restored to full.
(6) The principle of the resurrection of the tank:
Through the keyboard monitoring, detection of our tank Resurrection order, if our tank is dead, we change our tank stock status to live and put our tank blood volume back to full blood.
Programming Ideas:
The idea of the tank war programming in the main class to open a thread, not 50 milliseconds to cycle the drawing method (all things in the entire interface). The picture has the enemy tank (color distinction), bullets, walls, blood clots, explosions. So a total of several categories: Tank Tank class, missile bullets, wall wall, blood blood clots, tankclient main class. A painting method is written in each class to implement the drawing function of this class property. There is a keyboard listener event in the main class that calls this tank class. Through the keyboard monitoring to determine the corresponding movement of tank, and the enemy tank is random movement. And each refresh has to call various kinds of collision methods, to determine the circumstances of some objects should not collide to deal with. and the creation of each object, such as bullets, these are created by adding a new bullet to a set of bullets after the trigger is generated, judging the amount of the collection in the drawing, and then deleting the tank out of bounds or killing the tanks in the collection. Other classes are similar, not to elaborate.
Each step in the code is annotated with a corresponding explanation.
Tankclient.java
Import Java.awt.Color;
Import Java.awt.Font;
Import Java.awt.Graphics;
Import Java.awt.Image;
Import Java.awt.event.KeyAdapter;
Import java.awt.event.KeyEvent;
Import Java.awt.event.WindowAdapter;
Import java.awt.event.WindowEvent;
Import java.util.ArrayList;
Import java.util.List;
Import Javax.swing.JFrame; public class Tankclient extends jframe{/** * @param args/Image offscrennimage = null; Dual buffer memory Picture storage/* Game Size * * public static final int game_width = 800; Interface wide public static final int game_heigth = 600; Interface High Tank Mytank = new Tank (500,400,true,color.red,tank.direction.stop, this);//Our Tank class list<missile> missiles = new arraylist<missile> ()///The Set of bullets list<explode> Explode = new arraylist<explode> ()//explosion collection list< tank> tanks = new arraylist<tank> (); Tank set Wall wall1 = new Wall (150,200,20,300,this); Wall 1 Wall wall2 = new Wall (250,500,300,20,this); Wall 2 Wall wall3 = new Wall (650,200,20,300,this); Wall 2 Wall Wall4 = new Wall (250,300,300,20,this); Wall 2 Wall wb = new Wall (750,550,40,40,this); Wall 2 Blood B = new Blood (); Blood class public static void Main (string[] args) {//TODO auto-generated method stub tankclient tc=new tankcli
ENT ();
Tc.lauchframe (); private void Lauchframe () {//TODO auto-generated method stub for (int i = 0; i < i++) {TANKS.A
DD (New Tank (i+1), 50+40*, FALSE,COLOR.BLUE,TANK.DIRECTION.D, this)); } this.setlocation (100, 100); window Initial coordinate point this.setsize (game_width, game_heigth); Window Initial Size this.settitle ("Tankwar"); Window name/* Window monitor/this.addwindowlistener (new Windowadapter () {@Override/* point exit fork Run/public void Windowclosing (WindowEvent e) {//TODO auto-generated method stub system.exit (0);
Exit}}); This.addkeylistener (New Keymoniton ()); Set the keyboard listener this.setvisible (TRUE); The setting window appears this.setresizable (false); The settings window cannot be resized This.getcontentpane (). SetBackground (Color.green); Sets the window foreground color to green new Thread (New Paintthread ()). Start (); Start running Paintthread class run} @Override public void Paint (Graphics g) {//TODO auto-generated a stub//grap
Hics is a brush class super.paint (g);
Mytank.draw (g);
Wall1.draw (g);
Wall2.draw (g);
Wall3.draw (g);
Wall4.draw (g);
Wb.draw (g);
B.draw (g);
Mytank.eatblood (b);
Mytank.hitwall (WALL1);
Mytank.hitwall (WALL2);
Mytank.hitwall (WALL3);
Mytank.hitwall (WALL4); /* Circulation Bullets Set * * for (int i = 0; i < missiles.size (); i++) {Missile m = missiles.get (i); Get the current bullet m.hittanks (tanks); Own bullets killed enemy tank M.hitwall (WALL1);
Bullets and Wall M.hitwall (WALL2);
M.hitwall (WALL3);
M.hitwall (WALL4); M.hittank (Mytank)//enemy bullets against their tanks m.draw (g); Draw bullets} for (int i = 0; i < explode.size (); i++) {explode.get (i); draw (g);
Painting exploded} for (int i = 0; i < tanks.size (); i++) {Tank t = tanks.get (i); T.draw (g); Draw enemy Tank t.hittanks (tanks); T.hitwall (WALL1);
Tank and Wall T.hitwall (WALL2);
T.hitwall (WALL3);
T.hitwall (WALL4);
//g.setfont (New Font ("Song Body", font.bold,20)); g.DrawString ("Missiles Count:" +missiles.size (), 10, 50);//Display g.drawstring ("Explode count:" +explode.size (), 10, 80);/
Displays g.DrawString ("Tanks Count:" +tanks.size (), 10, 110);
g.DrawString ("Mytank Life:" +mytank.getlife (), 10, 130);
g.DrawString ("gyrus:", 750, 540);
g.DrawString ("the direction key moves; E: Release The Moving Blood Fast", 10, 590);
g.DrawString ("Z: Launch Dongfeng -31;a: Launch Dongfeng-41;", 10, 570);
g.DrawString ("F2: Resurrection; F3: Resurrection of Enemy (20)", 10, 550); g.DrawString ("R: position reduction;")
Q: Blood volume added, 10, 530);
@Override/*repaint-〉update->paint*/public void Update (Graphics g) {//TODO auto-generated method stub
Super.update (g);
if (offscrennimage = = null) Offscrennimage = This.createimage (Game_width, game_heigth); Graphics Goffscrenn = Offscrennimage.getgraphics (); Set a memory brush color for foreground picture colors color c = GOFFSCRenn.getcolor (); or first save the foreground color Goffscrenn.setcolor (color.green); Set the memory brush color to green goffscrenn.fillrect (0, 0, game_width, game_heigth); Picture, size for game size goffscrenn.setcolor (c); Restore Color g.drawimage (offscrennimage, 0, 0, NULL); In the interface draw a saved picture paint (Goffscrenn); Call the memory brush to paint} Private class Paintthread implements runnable{@Override public void Run () {//TODO Auto-generated method Stub while (true) {repaint (); Operation Sequence Repaint->update->paint try{Thread.Sleep (50);
Refresh the screen once every 50 milliseconds}catch (Exception e) {e.printstacktrace (); }}}///keyboard response/Private class Keymoniton extends keyadapter{/* Press the keyboard response * * @Override Publi
c void keypressed (KeyEvent e) {//TODO auto-generated Method stub super.keypressed (e);
Mytank.keypressed (e); /* Lift Keyboard Response/* @Override public void keyreleased (KeyEvent e) {//TODO auto-generated method stub su PEr.keyreleased (e);
Mytank.keyreleased (e);
}
}
}
Tank.java
Import Java.awt.Color;
Import Java.awt.Graphics;
Import Java.awt.Image;
Import Java.awt.Rectangle;
Import java.awt.event.KeyEvent;
Import java.util.List;
Import Java.util.Random;
Import Javax.swing.ImageIcon; public class Tank {* * tank itself data/int x, y;//tank coordinates private int oldx, oldy; Tank on the previous step coordinates public static final int whith = 30; Tank wide public static final int higth = 30; Tank high public static final int xspeed = 5; Transverse moving speed public static final int yspeed = 5; Vertical moving speed private color color; Tank Colors Private Boolean bl=false, Bu=false, Br=false, Bd=false; Four directional control values enum Direction {L, LU, U, RU, R, RD, D, LD, STOP}; Eight-directional mobile private Direction dir = direction.stop, synthesized by four directional values; Appearance direction private Direction Ptdir = DIRECTION.D; The initial direction of the barrel is private boolean good; Judge the camp of the tank private Boolean live = true; Determine if tanks survive private static Random R = new Random ()//set a random value variable private static int step = R.nextint (12) +3; Enemy tank Random Move step 3-14 step private int life = 100; Blood Volume private BlOodbar BB = new Bloodbar ();
Blood clots//ImageIcon icon = new ImageIcon ("res\\mytank.jpg");
ImageIcon icon2 = new ImageIcon ("res\\enemytank.jpg");
Image image = Icon.getimage ();
Image image2 = Icon2.getimage (); Private Tankclient TC;
Main class Permissions Public Tank (int x, int y, Boolean good, color color) {super ();
this.x = x;
This.y = y;
This.color = color;
This.good = good;
Tank (int x, int y, Boolean good,color color,direction dir,tankclient tc) {this (x,y,good,color);
This.dir = dir;
THIS.TC = TC;
* * Get tank Life/public int getlife () {return lives; /* Set tank Life/public void setlife (int lives) {this.
Life = life;
* * Get Tank Camp/Public Boolean Isgood () {return good;
* * Set tank camp/public void Setgood (Boolean good) {This.good = good;
* * Get Tank Live Status/public boolean islive () {return live;
/* Set Tank survival status */public void Setlive (Boolean live) {this.live = live; * * Draw Tank * * PublIC void Draw (Graphics g) {if (!live) {if (!good) {tc.tanks.remove (this);
Remove//tc.tanks.add from the collection when enemy tanks Die (new Tank (R.nextint), R.nextint (M), FALSE,COLOR.BLUE,DIRECTION.D,THIS.TC);
} return; }/* First save the previous brush color, and then restore the brush color */Color c = g.getcolor (); Gets the current brush color g.setcolor (color);
Set the brush color to red/* Draw Tank * * g.filloval (x, Y, whith, higth);
/* Two methods to draw the enemy tank, the use of previously added pictures or colors to distinguish *//if (good)//G.drawimage (image, X, y,whith,higth,null);
else//G.drawimage (Image2, x, Y, whith, higth, NULL); if (good) bb.draw (g);
Our tanks draw blood strips g.setcolor (color.black);
* * through the barrel direction to draw the barrel * * * SWITCH (PTDIR) {case L:g.drawline (X+TANK.WHITH/2, Y+TANK.HIGTH/2, X, Y+TANK.HIGTH/2);
Break
Case Lu:g.drawline (X+TANK.WHITH/2, Y+TANK.HIGTH/2, x, y);
Break
Case U:g.drawline (X+TANK.WHITH/2, Y+TANK.HIGTH/2, X+tank.whith/2, y);
Break Case Ru:g.drawline (X+TANK.WHITH/2, y+tank.higth/2, X+tank.whith, y);
Break
Case R:g.drawline (X+TANK.WHITH/2, Y+TANK.HIGTH/2, X+tank.whith, Y+TANK.HIGTH/2);
Break
Case Rd:g.drawline (X+TANK.WHITH/2, Y+TANK.HIGTH/2, X+tank.whith, y+tank.higth);
Break
Case D:g.drawline (X+TANK.WHITH/2, Y+TANK.HIGTH/2, X+TANK.WHITH/2, y+tank.higth);
Break
Case Ld:g.drawline (X+TANK.WHITH/2, Y+TANK.HIGTH/2, X, y+tank.higth);
Break } g.setcolor (c); Restore brush color Move ()//Mobile}//keyboard monitor, press key/public void keypressed (KeyEvent e) {int key = E.getkeycode ();
Keyboard to listen to the key to save/* Keyboard mobile Tank/switch (key) {/* Mobile Press key/Case keyevent.vk_up:bu=true;
Break
Case Keyevent.vk_down:bd=true;
Break
Case Keyevent.vk_right:br=true;
Break
Case Keyevent.vk_left:bl=true;
Break
} locatedirection (); /* Keyboard monitor, lift key/public void keyreleased (KeyEvent e) {int key = E.getkeycode (); To save a keyboard by holding the key you hear in an integer
/* Keyboard Mobile Tank */switch (key) {case keyevent.vk_up:bu=false;
Break
Case Keyevent.vk_down:bd=false;
Break
Case Keyevent.vk_right:br=false;
Break
Case Keyevent.vk_left:bl=false;
Break
Case KEYEVENT.VK_Z://Single Bullet if (live) fire ();
Break
Case KEYEVENT.VK_F2://Our Resurrection if (!this.live) {this.live=true;
This.setlife (100);
} break;
Case KEYEVENT.VK_F3://Enemy Resurrection Fuhuo ();
Break
Case KEYEVENT.VK_A://Invincible missile superfire ();
Break Case KEYEVENT.VK_Q://gyrus if (this.live) this.
Life = 100;
Break
Case KEYEVENT.VK_E://release of Blood clots Tc.b.fh ();
Break
/* Restore Position Key * * case keyevent.vk_r:x = 50;
y = 50;
Break } locatedirection ();
Synthesis direction}/* Synthetic moving direction/void Locatedirection () {if (BL&&!BU&&!BR&&!BD) DIR=DIRECTION.L; else if (bl&&bu&&!
BR&&!BD) dir=direction.lu;
else if (!BL&&BU&&!BR&&!BD) dir=direction.u;
else if (!BL&&BU&&BR&&!BD) dir=direction.ru;
else if (!BL&&!BU&&BR&&!BD) DIR=DIRECTION.R;
else if (!BL&&!BU&&BR&&BD) dir=direction.rd;
else if (!BL&&!BU&&!BR&&BD) dir=direction.d;
else if (BL&&!BU&&!BR&&BD) dir=direction.ld;
else if (!BL&&!BU&&!BR&&!BD) dir=direction.stop;
void Move () {///////* Record previous step position */oldx = x;
Oldy = y;
Switch (dir) {case l:x-=xspeed;
Break
Case Lu:x-=xspeed;
Y-=yspeed;
Break
Case U:y-=yspeed;
Break
Case Ru:x+=xspeed;
Y-=yspeed;
Break
Case R:x+=xspeed;
Break
Case Rd:x+=xspeed;
Y+=yspeed;
Break
Case D:y+=yspeed;
Break
Case LD: X-=xspeed;
Y+=yspeed;
Break
Case Stop:break;
} * * To determine the movement of tanks across the border (game boundary)/if (x < 5) x = 5;
if (y < n) y = 25; if (X+whith > TC. GAME_WIDTH-5) x = TC.
game_width-whith-5; if (Y+higth > TC. game_heigth-5) y = tc.
game_heigth-higth-5;
if (dir!= direction.stop)///If the tank is not stationary, change the barrel direction ptdir = dir; * * Enemy Tank automatic movement/if (!good) {direction[] dirs = Direction.values (); Set the direction variable to array if (step = 0) {step = R.nextint (12) +3; Random move step int randomnumber = R.nextint (dirs.length);
Random moving direction dir = Dirs[randomnumber];
} step--; if (r.nextint) >30) This.fire (); Randomly fired shells}}/* Enemy tank Resurrection/public void Fuhuo () {if (Tc.tanks.size () <) while (true) {int x
= R.nextint (700);
int y = r.nextint (500);
Tank t = new Tank (X,Y,FALSE,COLOR.BLUE,DIRECTION.D,TC); * * If the tank is coincident with the wall, then the new tank will be added to the collection/if (T.getrect ()) by the random position until it is not coincident. intersects (TC.WALL1.GEtrect ()) | | T.getrect (). intersects (Tc.wall2.getRect ()) | | T.getrect (). intersects (Tc.wall3.getRect ()) | |
T.getrect (). intersects (Tc.wall4.getRect ())) {continue;
} else{Tc.tanks.add (t);
Break }} * * Bullet launch/public void Fire () {int x = this.x + WHITH/2-missile.whith/2;
The control bullet direction for the tank center int y = this.y + higth/2-missile.higth/2; Tc.missiles.add (new Missile (PTDIR,COLOR,X,Y,GOOD,TC));
Create a new bullet class add to the bullet set}/* collision; Get the range of the tank/public Rectangle GetRect () {return new Rectangle (x,y,whith,higth);
/* * Receipt last position/private void stay () {x = OLDX;
y = Oldy; /* If you bang the wall, call the Stay method, return to the previous position/public boolean Hitwall (Wall W) {if (This.live&&this.getrect (). intersects (w.ge
Trect ()) {This.stay ());
return true;
return false; * * Tank Collision Event/Public Boolean hittanks (list<tank> tanks) {for (int i=0;i<tanks.size (); i++) {Tank t=
Tanks.get (i); if (this!=t) {//oneself cannot collide with oneself/* If the collision returns to the previous position */if (this.live&&t.islive () &&this.getrect (). inters
ECTS (T.getrect ())) {This.stay ();
T.stay ();
return true;
}} return false;
/*/* the launch function with firing direction */Public missile Fire (Direction dir) {if (!live) return null;
int X=THIS.X+WHITH/2-MISSILE.WHITH/2;
int Y=THIS.Y+HIGTH/2-MISSILE.HIGTH/2;
Missile m=new Missile (dir,color,x, Y,good, THIS.TC);
Tc.missiles.add (m);
return m;
}/* Super shooting Missile/private void Superfire () {direction[] dirs=direction.values (); for (int i=0;i<8;i++) {fire (dirs[i]);//Loop call Eight Directions}}/* Add blood clots class * * * Private class bloodbar{/* Draw the bloody strips/PU
Blic void Draw (Graphics g) {Color c=g.getcolor ();
G.setcolor (color.red);
G.drawrect (x, y-10, whith, 10);
int w=whith*life/100;
G.fillrect (x, Y-10, W, 10);
G.setcolor (c); }/* Eat blood Method */public Boolean eatblood (blood b) {if thiS.live&&b.islive () &&this.isgood () &&this.getrect (). intersects (B.getRect ())) {
This.setlife (100);
B.setlive (FALSE);
return true; if (This.getrect (). intersects (Tc.wb.getRect ())) this.
Life = 100;
return false;
}
}
Missile.java
Import Java.awt.Color;
Import Java.awt.Graphics;
Import Java.awt.Rectangle;
Import java.util.List; public class Missile {* * bullet itself data * * Tank.direction dir; Bullet direction Color C; Bullet color int x,y; Bullet position public static final int xspeed = 15; Transverse moving speed public static final int yspeed = 15; Vertical moving speed public static final int whith = 10; Bullets wide public static final int higth = 10; Bullet High Private Boolean live = true; Judge the survival of a bullet by private boolean good;
Judge Bullets and Camp private Tankclient tc;//main class Permissions public missile (Tank.direction dir,color C, int x, int y) {super ();
This.dir = dir;
this.x = x;
This.y = y;
THIS.C = C;
Public missile (Tank.direction dir,color C, int x, int y,boolean good,tankclient TC) {this (dir,c,x,y);
This.good = good;
THIS.TC = TC;
* * Get the Bullet Alive/Public boolean islive () {return live;
}/* Set the survival of the bullet/public void Setlive (Boolean live) {this.live = live; } public void Draw (Graphics g) {/*If the bullet dies, remove the bullet from the bullet set/if (!live) {tc.missiles.remove (this);
Delete return in the collection; }/* First save the previous brush color, and then restore the brush color */Color D = g.getcolor (); Gets the current brush color g.setcolor (c);
Set the brush color to red/* Draw bullets * * G.filloval (x, Y, whith, higth); G.setcolor (d); Restore brush color move ();
Move the public void Move () {/* To determine the movement direction of the mobile tank position */switch (dir) {case l:x-=xspeed;
Break
Case Lu:x-=xspeed;
Y-=yspeed;
Break
Case U:y-=yspeed;
Break
Case Ru:x+=xspeed;
Y-=yspeed;
Break
Case R:x+=xspeed;
Break
Case Rd:x+=xspeed;
Y+=yspeed;
Break
Case D:y+=yspeed;
Break
Case Ld:x-=xspeed;
Y+=yspeed;
Break
Case Stop:break; }/* Judge the Cross-border condition of the bullet; the bullet died out of bounds, and the bullets were deleted./if (x<0| | y<0| | x>tankclient.game_width| |
Y>tankclient.game_heigth) Live = false;
/* COLLISION; Get the range of the bullets/* public Rectangle GetRect () { return new Rectangle (x,y,whith,higth); } * * Bullets and tank Collision process/Public boolean hittank (Tank t) {/* If bullets and tanks in the same range both bullets and tanks die at the same time, and bullets can only kill each other tank/if (this.live&&t
His.getrect (). intersects (T.getrect ()) &&t.islive () &&this.good!=t.isgood ()) {if (T.isGood ()) {//Good tank
* * Our tank bullets will reduce the life value, the life value of 0 will die/T.setlife (T.getlife ()-20);
if (T.getlife () <=0) t.setlive (false); }else{//Bad tank t.setlive (false)//death} this.live=false;//Bullet death Tc.explode.add (New explode (x, y, TC)
);//new explosion join set return true;
return false; }/* Cycle tank sets are judged by bullets collision/Public Boolean hittanks (list<tank> tanks) {for (int i = 0; i < tanks.size (); i++)
{if (Hittank (Tanks.get (i)) return true;
return false; }/* The collision process between bullets and the wall/public boolean Hitwall (Wall w) {/* If the bullets are coincident with the scope of the wall bullets Death/if (This.live&&this.getrect). Inter Sects (W.getrect ())) {this.live=false;
Bullet death return true; return false;
}
}
Wall.java
Import Java.awt.Graphics;
Import Java.awt.Rectangle;
public class Wall {
/* Wall data *
/int x,y,w,h; Position and width high
private tankclient TC; Main class Permissions public
Wall (int x, int y, int w, int h, tankclient tc) {
super ();
this.x = x;
This.y = y;
THIS.W = W;
This.h = h;
THIS.TC = TC;
}
/* Get the scope of the wall * * Public
Rectangle GetRect () {return
new Rectangle (x,y,w,h);
}
* * Wall/public
void Draw (Graphics g) {
g.fillrect (x, Y, W, h);
}
}
Explode.java
Import Java.awt.Color;
Import Java.awt.Graphics;
public class Explode {
/* Tank explosion attribute *
/int x,y; Explosion Location
Private Boolean live = true; Whether the explosion exists
int step = 0; Explosion Time Control
int [] diameter = new Int[] {4, 7, 12, 18, 26, 32, 49, 56, 65, 77, 80, 50, 40, 30, 14, 6};//explosion range
Privat e tankclient tc; Main class Permissions public
Explode (int x, int y, tankclient tc) {
super ();
this.x = x;
This.y = y;
THIS.TC = TC;
}
/* Painting explosion
/public void Draw (Graphics g) {
if (!live) return; If the explosion dies, the state does not draw end
/* If the explosion time ends the explosion does not exist and is removed in the collection
/if (step = diameter.length) {
live = false; Explosion death Step
= 0; Step time to 0
tc.explode.remove (this); Delete return in the collection
;
* * Painting explosion
/Color C = G.getcolor ();
G.setcolor (color.orange);
G.filloval (x, Y, Diameter[step], diameter[step]);
G.setcolor (c);
step++
}
}
Blood.java
import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import Java . util.
Random; public class Blood {/* blood clot data */int x, Y, W, h;//blood clot position and size private tankclient TC; Main class Permissions Private Boolean live=true;//blood clot alive private static Random R = new Random ()//set a random value variable//* Get the blood clot alive/public B
Oolean islive () {return live;
/* Set the survival status of the blood clot/public void Setlive (Boolean live) {this.live = live;
}/* Blood clot position initial value random a numerical/public blood () {x=r.nextint (600) +100;
Y=r.nextint (400) +100;
w=h=15;
/* Draw blood clots/public void Draw (Graphics g) {if (!live) return;
Color C=g.getcolor ();
G.setcolor (Color.magenta);
G.fillrect (x, Y, W, h);
G.setcolor (c);
/* Release blood clot/public void FH () {if (!live) {x = R.nextint (600) +100;
y = R.nextint (400) +100;
Live = true;
}/* Get the blood clot range/public Rectangle GetRect () {return new Rectangle (x, Y, W, h); }
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.