?? fallingstars.java
字號:
{
replaceStar(i);
}
}
}
public void endStar(int i)
{
if((int)(3D * Math.random() + 1.0D) == 1)
{
numberOffStars++;
if(numberOffStars > maxStars)
{
numberOffStars = maxStars;
}
replaceStar(numberOffStars);
starSize[numberOffStars] = 1;
replaceStar(i);
starSize[i] = 1;
return;
}
if((int)(5D * Math.random() + 1.0D) == 1 && starY[i] < size().height - 130)
{
numberOffStars++;
if(numberOffStars > maxStars)
{
numberOffStars = maxStars;
}
starX[numberOffStars] = starX[i] + 10;
if(starX[numberOffStars] > size().width - 5)
{
starX[numberOffStars] = (starX[numberOffStars] - (size().width - 5)) + 5;
}
starX[i] -= 10;
if(starX[i] < 5)
{
starX[i] = size().width - 5 - (starX[i] - 5);
}
starY[numberOffStars] = starY[i];
replaceStar(0);
starXAdd[i] = starXAdd[0];
starYAdd[i] = starYAdd[0];
starSize[i] = 1;
starXAdd[numberOffStars] = -starXAdd[0];
starYAdd[numberOffStars] = starYAdd[0];
starSize[numberOffStars] = 1;
if(starXAdd[i] > 0)
{
starXAdd[i] *= -1;
starXAdd[numberOffStars] *= -1;
}
if(starXAdd[i] == 0)
{
starXAdd[i] = -1;
starXAdd[numberOffStars] = 1;
return;
}
} else
{
replaceStar(i);
starSize[i] = 1;
}
}
public void choiceLevel()
{
int i = 0;
int j = 0;
Color color = offscreenG.getColor();
offscreenG.setFont(f3);
offscreenG.drawString(levelText1, (size().width - fm3.stringWidth(levelText1)) / 2, size().height / 7);
while(!choice)
{
i = ((mouseY - size().height / 14) + (fm3.getAscent() - fm3.getDescent()) / 2) / (size().height / 7);
if(i == 0)
{
i = 1;
}
if(i > 5)
{
i = 5;
}
if(i != j)
{
explosion.play();
offscreenG.setColor(Color.black);
offscreenG.fillRect(0, 0, size().width, size().height);
offscreenG.setColor(Color.red);
offscreenG.fillRect(0, (i * (size().height / 7) + size().height / 14) - (fm3.getAscent() - fm3.getDescent()) / 2, size().width, size().height / 7);
offscreenG.setColor(Color.green);
offscreenG.drawString(levelText1, (size().width - fm3.stringWidth(levelText1)) / 2, size().height / 7);
offscreenG.drawString(levelText2, (size().width - fm3.stringWidth(levelText2)) / 2, (2 * size().height) / 7);
offscreenG.drawString(levelText3, (size().width - fm3.stringWidth(levelText3)) / 2, (3 * size().height) / 7);
offscreenG.drawString(levelText4, (size().width - fm3.stringWidth(levelText4)) / 2, (4 * size().height) / 7);
offscreenG.drawString(levelText5, (size().width - fm3.stringWidth(levelText5)) / 2, (5 * size().height) / 7);
offscreenG.drawString(levelText6, (size().width - fm3.stringWidth(levelText6)) / 2, (6 * size().height) / 7);
repaint();
j = i;
}
}
level = i;
if(level > 3)
{
numberOffShips = 3 + level;
}
if(level == 5)
{
numberOffShips = 15;
}
started = true;
makeItBlack();
offscreenG.setColor(color);
}
public void scoreBoard(Color color)
{
if(drawScoreBoard)
{
Color color1 = offscreenG.getColor();
offscreenG.setColor(Color.lightGray);
offscreenG.fillRect(6, size().height - 35, size().width - 10, 2);
offscreenG.setColor(Color.green);
offscreenG.fillRect(6, (size().height - 35) + 2, size().width - 10, 3);
offscreenG.setColor(color);
offscreenG.fillRect(size().width / 3 - 2, size().height - 30, 5, 30);
offscreenG.fillRect((2 * size().width) / 3 - 2, size().height - 30, 5, 30);
offscreenG.setColor(Color.red);
offscreenG.setFont(f3);
offscreenG.drawString("SCORE = " + score, 10, size().height - 5 - fm3.getDescent() - 2);
offscreenG.drawString("Ships = " + numberOffShips, 10 + (2 * size().width) / 3, size().height - 5 - fm3.getDescent() - 2);
if(score >= hiscore[level])
{
offscreenG.setColor(Color.red);
offscreenG.drawString("HISCORE = " + score, 10 + size().width / 3, size().height - 5 - fm3.getDescent() - 2);
} else
{
offscreenG.setColor(Color.lightGray);
offscreenG.drawString("Hiscore = " + hiscore[level], 10 + size().width / 3, size().height - 5 - fm3.getDescent() - 2);
}
offscreenG.setColor(color1);
}
}
public void theEnd()
{
ended = true;
drawScoreBoard = false;
pause(1000);
makeItBlack();
resetAll();
endboard();
score = 0;
level = 0;
drawScoreBoard = true;
}
public void resetAll()
{
numberOffStars = 1;
numberOffShips = 3;
replaceStar(1);
alert.stop();
choice = false;
exploding = false;
mouseMoved = false;
sound = false;
shiphit = false;
started = false;
starting = false;
shipX = size().width / 2;
offscreenG.setColor(Color.black);
offscreenG.fillRect(0, 0, size().width, size().height);
introY = size().height + 10;
}
public void endboard()
{
int i = 1;
int j = 0;
String s = "To Java Applet Download Site.";
String s1 = "Restart";
String s2 = "YOUR HISCORE :";
String s3 = "level 1 = ";
String s4 = "level 2 = ";
String s5 = "level 3 = ";
String s6 = "level 4 = ";
String s7 = "level 5 = ";
for(clicked = false; !clicked;)
{
if(mouseY < size().height / 9 + 5)
{
i = 0;
} else
{
i = 1;
}
if(i != j)
{
offscreenG.setColor(Color.black);
offscreenG.fillRect(0, 0, size().width, size().height);
offscreenG.setColor(Color.red);
offscreenG.fillRect(0, (i * size().height) / 9 + 5, size().width, size().height / 9);
offscreenG.setColor(Color.green);
offscreenG.setFont(f3);
offscreenG.drawString(s, (size().width - fm3.stringWidth(s)) / 2, (int)((0.5D * (double)size().height) / 9D + (double)((fm3.getAscent() - fm3.getDescent()) / 2)) + 5);
offscreenG.drawString(s1, (size().width - fm3.stringWidth(s1)) / 2, (int)((1.5D * (double)size().height) / 9D + (double)((fm3.getAscent() - fm3.getDescent()) / 2)) + 5);
offscreenG.setColor(Color.white);
offscreenG.drawString(s2, (size().width - fm2.stringWidth(s2)) / 2, (3 * size().height) / 9 + (fm2.getAscent() - fm2.getDescent()) / 2 + 5);
offscreenG.setFont(f2);
setRedHiScore(1);
offscreenG.drawString(s3 + hiscore[1], (size().width - fm3.stringWidth(s)) / 2, (4 * size().height) / 9 + (fm2.getAscent() - fm2.getDescent()) / 2 + 5);
setRedHiScore(2);
offscreenG.drawString(s4 + hiscore[2], (size().width - fm3.stringWidth(s)) / 2, (5 * size().height) / 9 + (fm2.getAscent() - fm2.getDescent()) / 2 + 5);
setRedHiScore(3);
offscreenG.drawString(s5 + hiscore[3], (size().width - fm3.stringWidth(s)) / 2, (6 * size().height) / 9 + (fm2.getAscent() - fm2.getDescent()) / 2 + 5);
setRedHiScore(4);
offscreenG.drawString(s6 + hiscore[4], (size().width - fm3.stringWidth(s)) / 2, (7 * size().height) / 9 + (fm2.getAscent() - fm2.getDescent()) / 2 + 5);
setRedHiScore(5);
offscreenG.drawString(s7 + hiscore[5], (size().width - fm3.stringWidth(s)) / 2, (8 * size().height) / 9 + (fm2.getAscent() - fm2.getDescent()) / 2 + 5);
j = i;
border(Color.blue);
explosion.play();
repaint();
}
}
if(i == 0)
{
getAppletContext().showDocument(url);
ended = false;
return;
} else
{
ended = false;
alert.loop();
sound = true;
return;
}
}
public void setRedHiScore(int i)
{
if(level == i && score >= hiscore[level])
{
hiscore[level] = score;
offscreenG.setColor(Color.red);
return;
} else
{
offscreenG.setColor(Color.white);
return;
}
}
public FallingStars()
{
maxStars = 150;
numberOffStars = 1;
numberOffShips = 3;
hiscore = new int[6];
level = 1;
exploding = false;
shiphit = false;
started = false;
starting = false;
startString = "Click on me once to start";
introText1 = "Falling Stars";
introText2 = "(c)1996 RJHM van den Bergh";
introText3 = "Java Applet Download Site";
introText4 = "http://www.nedernet.nl/~rvdb";
introText5 = "rvdb@nedernet.nl";
introText6 = "--------------------------";
introText7 = "MOUSE usage : must be on applet window";
introText8 = "left button = fire laser";
introText9 = "mouse moves to left and right";
introText10 = "--------------------------";
introText11 = "KEYBOARD usage :";
introText12 = "space bar = fire laser";
introText13 = "up arrow = fire laser";
introText14 = "left arrow = move left";
introText15 = "right arrow = move right";
introText16 = "S or s = sirene off or on";
introText17 = "esc = restart game";
levelText1 = "CLICK ON YOUR LEVEL :";
levelText2 = "Level 1 ---> very easy";
levelText3 = "Level 2 ---> easy";
levelText4 = "Level 3 ---> medium";
levelText5 = "Level 4 ---> hard";
levelText6 = "Level 5 ---> very hard";
firing = false;
sound = true;
marker = "nhgube EWUZ";
mouseMoved = false;
choice = false;
marker2 = "ina qra Oretu";
clicked = false;
drawScoreBoard = true;
ended = false;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -