📄 csdn技术中心 applet射击小游戏开源.htm
字号:
{<BR>
myThread.stop();<BR>
myThread =
null;<BR>
System.out.println("thread stopped
");<BR>
}<BR> }</FONT></P>
<P><FONT style="BACKGROUND-COLOR: #f1fee7"> public
void destroy()<BR>
{<BR>
System.gc();<BR> }</FONT></P>
<P><FONT style="BACKGROUND-COLOR: #f1fee7"> public
void run()<BR>
{<BR> //Do
stuff<BR>
//System.out.println("run");<BR>
myThread.setPriority(Thread.MIN_PRIORITY);</FONT></P>
<P><FONT
style="BACKGROUND-COLOR: #f1fee7">
while (myThread !=
null)<BR>
{<BR>
try<BR>
{<BR>
Thread.sleep(100);<BR>
}<BR>
catch(InterruptedException
e)<BR>
{<BR>
}<BR>
//
repaint();</FONT></P>
<P><FONT
style="BACKGROUND-COLOR: #f1fee7">
if (starty >
200)<BR>
{<BR>
System.out.println("stop" + starty + "cont is " + count);</FONT></P>
<P><FONT
style="BACKGROUND-COLOR: #f1fee7">
myThread.stop();<BR>
}</FONT></P>
<P><FONT
style="BACKGROUND-COLOR: #f1fee7">
}<BR> myThread =
null;<BR> }</FONT></P>
<P><FONT style="BACKGROUND-COLOR: #f1fee7"> public
void move()
//tells shotH to move all the shots<BR>
{<BR> starty +=
firespeed;<BR>
//
System.out.println("moving ");<BR>
}</FONT></P>
<P><FONT style="BACKGROUND-COLOR: #f1fee7"> public
void exploding(Graphics g) //tells shotH to move all the
shots<BR>
{
//starty+=firespeed;<BR>
System.out.println("exploding
");<BR>
//g.fillOval((int)startx, (int)starty, firesize, firesize); //draws
a line from the current coords to the previous coords</FONT></P>
<P><FONT
style="BACKGROUND-COLOR: #f1fee7">
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//<BR>
System.out.println(" " + (int)(Math.random() * 250) + " " +
(int)(Math.random() * 250) + " "
+<BR>
(int)(Math.random() *
250));<BR> g.setColor(new
Color((int)(Math.random() * 250), (int)(Math.random() * 250),
(int)(Math.random() *
250)));<BR> int
MaxRocketNumber = 60;<BR>
int arr[] = { -1, 0, 1, 2, -2, -3, -4, 3, 4, 5, -5, 6, -6, 7,
-7, 8, -8, 9, -9 };</FONT></P>
<P><FONT
style="BACKGROUND-COLOR: #f1fee7">
g.drawOval(startx, starty, firesize + (10 - countofexplode) * 3,
firesize + (10 - countofexplode) *
3);<BR> g.fillOval(startx,
starty, (int)((firesize + (10 - countofexplode) * 3) *
Math.random()),<BR>
(int)((firesize + (10 - countofexplode) * 3) *
Math.random()));<BR>
g.fillRoundRect(startx, starty, (10 - countofexplode) * 3, (10 -
countofexplode) *
3,<BR>
(int)((firesize + (10 - countofexplode) * 3) *
Math.random()),<BR>
(int)((firesize + (10 - countofexplode) * 3) *
Math.random()));</FONT></P>
<P><FONT style="BACKGROUND-COLOR: #f1fee7">
}<BR> public void dispsharkfirehitted(Graphics
g)<BR>
{<BR> g.drawOval(startx,
starty, firesize * 6 - countofexplode * 3, firesize * 6 -
countofexplode * 6);<BR> }<BR>
public boolean checkexplode(Graphics g)<BR>
{<BR> if
(explode)<BR>
{<BR>
exploding(g);<BR>
countofexplode--;<BR>
if (countofexplode ==
0)<BR>
{<BR>
stop();</FONT></P>
<P><FONT
style="BACKGROUND-COLOR: #f1fee7">
return
true;<BR>
}<BR>
}<BR> return
false;<BR> }<BR> public boolean
checksharkfirehitted(Graphics g)<BR>
{<BR> if
(sharkfirehitted)<BR>
{<BR>
dispsharkfirehitted(g);<BR>
countofexplode--;<BR>
if (countofexplode ==
0)<BR>
{<BR>
stop();</FONT></P>
<P><FONT
style="BACKGROUND-COLOR: #f1fee7">
return
true;<BR>
}</FONT></P>
<P><FONT
style="BACKGROUND-COLOR: #f1fee7">
}<BR> return
false;<BR> }</FONT></P>
<P><FONT style="BACKGROUND-COLOR: #f1fee7"> public
void check(int width, int height) //tells shotH to
check the shots' movement<BR>
{<BR> if (starty >
height)<BR>
{<BR>
stop();<BR> }</FONT></P>
<P><FONT style="BACKGROUND-COLOR: #f1fee7">
}<BR> public void paint(Graphics
g)<BR>
{
//this is the shots paint method... draws a line from its last
position to its current position,
basically<BR> switch
(type)<BR>
{<BR>
case
0:<BR>
rot++;
//advances color
rotation<BR>
if (rot ==
15)<BR>
{<BR>
rot =
0;<BR>
}
//keeps rotation below
15<BR>
Color col1 = new Color(255 - (rot * 15), rot * 10, 127 + rot *
8); //makes the new
color<BR>
g.setColor(col1); //sets
the current color to the rotation
color<BR>
g.fillOval((int)startx, (int)starty, firesize,
firesize); //draws a line
from the current coords to the previous
coords<BR>
break;<BR>
case
1:<BR>
//g.setColor(new
Color(255,255,156));<BR>
g.fillRect((int)startx, (int)starty, firesize / 3, firesize /
2); //draws a line from
the current coords to the previous
coords<BR>
g.setColor(new Color((int)(Math.random() * 250), (int)(Math.random()
* 60), (int)(Math.random() *
156)));<BR>
g.draw3DRect((int)startx - firesize / 4, (int)starty, firesize / 2,
firesize / 4,
false);<BR>  
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -