JAVA打蜜蜂小游戏源码

<body>
  <SCRIPT LANGUAGE="JAVAScript">
var timerID = null;
var patno = 1;
var cr = "\r\n";
var spcf1 = "";
var spcf2 = "";
var spcf3 = "";
var hitflag = 0;
var score = 0;
var selec = 0;
var rsmiss = "";
function array1(arn) {
this.length = arn;
for (var ar1 = 0; ar1 <= arn; ar1++) {
this[ar1] = 1; }
return this;
}
function init() {
blankx = new array1(63);
for (var makeblank = 0; makeblank < 63; makeblank++) {
blankx[makeblank] = "";
for (var addBlank = 0; addBlank < makeblank; addBlank++) {
blankx[makeblank] = blankx[makeblank] + " ";
   }
}
faker = new array1(24);
face = new array1(2);
face[1] = " (O_O) ";
face[2] = " (o_o) ";
mestotal = new array1(4);
interval1();
}
function restarter() {
inplay = 0;
blankno = 0;
totalblank = "";
lr = 1;
lowerlf = "";
downlf = "";
downno = 0;
missilex = 99;
missiley = 99;
mychrx = 1;
myblank = "";
mymove = 0;
selec = 1;
starter();
}
function starter() {
document.fmark.win.value=cr+cr+cr+cr+cr+cr+cr+cr+cr+cr
+"挨蜜蜂游戏"+cr+cr+cr
+"请单击发射开端游戏";
selec = 1;
}
function goleft() {
mymove = 0;
mychrx = mychrx - 1;
if (mychrx <= 0) { mychrx = 1; }
}
function goright() {
mymove = 0
mychrx = mychrx + 1;
if (mychrx >= 56) { mychrx = 55; }
}
function golmax() {
if (inplay == 1) { mymove = -1; }
}
function gormax() {
if (inplay == 1){ mymove = 1; }
}
function fire() {
if (inplay == 0){ if (selec == 1){ selec = 9; inplay = 1; init(); }
} else {
if (missiley == 99){ missiley = 18; missilex = mychrx + 3; }
   }
}
function gameover() {
score = 0;
for (var enerme = 1; enerme < 25; enerme++) {
if (faker[enerme] == 1){ score = score + 1; }
}
if (score == 0) {
document.fmark.win.value = cr+cr+cr+cr+cr+cr+cr+cr
+"                        Congratulations!"+cr+cr
+"                          YOU STOPPED THE ENEMY SQUAD!!";
} else {
document.fmark.win.value=cr+cr+cr+cr+cr+cr+cr+cr
+"                           GAME OVER"+cr+cr
+"                   "+score+" INVADERS GOT THROUGH";
}
inplay = 0;
}
function interval1() {
if (missiley != 99) { missiley = missiley - 1; }
if (missiley < 0){ missiley = 99; }
mychrx = mychrx + mymove;
if (mychrx <= 0){ mychrx = 1; }
if (mychrx >= 56){ mychrx = 55; }
blankno = blankno + lr;
totalblank = blankx[blankno];
if (blankno >= 20) { lr = -1; downno = downno + 1; blankno = 20; }
if (blankno <= 0) { lr = 1; downno = downno + 1; blankno = 0; }
if (downno >= 12) { gameover(); }
downlf = "";
for (var upperspc = 0; upperspc < downno; upperspc++) {
if (missiley == upperspc) {
downlf = downlf + blankx[missilex]+"|"+cr;
} else { downlf = downlf+cr; }
   }
if (inplay == 1) {
patno = patno + 1;
if (patno >= 3) { patno = 1; }
for (var addline = 1; addline < 5; addline++){
mestotal[addline] = totalblank;
rsmiss = "";
if (missiley == (downno+addline*2-2)) {
if (blankno <= missilex) {
hitflag = parseInt((missilex-blankno)/7, 10);
if (hitflag < 6) {
if ((missilex - blankno - (hitflag * 7)) >= 1) {
if ((missilex - blankno - (hitflag * 7)) <= 5) {
if (faker[(addline * 6) + hitflag - 5] == 1) {
faker[(addline * 6) + hitflag - 5] = 0;
missiley = 99;
         }
      }
   }
}else {
if (missilex > (blankno + 42)) {
rsmiss = blankx[missilex - blankno - 42]+"|";
      }
   }
} else {
mestotal[addline] = blankx[missilex]+"|";
if (missilex < (blankno-1)) {
mestotal[addline] = mestotal[addline]+blankx[blankno-1-missilex];
      }
   }
}
for (var addfaker = 1; addfaker < 7; addfaker++) {
if (faker[(addline*6)+addfaker-6] == 1) {
mestotal[addline] = mestotal[addline]+face[patno];
} else { mestotal[addline] = mestotal[addline]+"       "; }
}
mestotal[addline] = mestotal[addline]+rsmiss;
}
spcf1 = cr;
spcf2 = cr;
spcf3 = cr;
if (missiley == (downno+1)) { spcf1 = blankx[missilex]+"|"+cr; }
if (missiley == (downno+3)) { spcf2 = blankx[missilex]+"|"+cr; }
if (missiley == (downno+5)) { spcf3 = blankx[missilex]+"|"+cr; }
lowerlf = "";
for (var lowerspc = 0; lowerspc < (11-downno); lowerspc++) {
if (missiley == (downno+7+lowerspc)) {
lowerlf = lowerlf+blankx[missilex]+"|"+cr;
} else { lowerlf = lowerlf+cr; }
}
myblank = blankx[mychrx];
document.fmark.win.value = downlf+mestotal[1]+cr+spcf1
+mestotal[2]+cr+spcf2+mestotal[3]+cr+spcf3+mestotal[4]
+cr+lowerlf+myblank+""+cr+myblank+"(^_^)";
timerID = setTimeout("interval1()",250);
   }
}
< /script>
< center>
< form method=post name=fmark>
< table border=1 cellspacing=0 cellpadding=0>
< tr><td align=center>
< textarea name=win rows=20 cols=63 wrap=virtual></textarea>
< pre><input type=button name=button value="<- " onClick="golmax()"> <input type=button name=button value="发射" onClick="fire()"> <input type=button name=button value=" ->" onClick="gormax()"></pre>
< input type=button name=button value=" 新游戏 " onClick="restarter()">
< /td>
< /tr>
< /table>
< /form>
< /center>
< /body>

找更多游戏源码到:http://www.shengshiyouxi.com

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,作为AI语言模型,我不会编写代码。但是,以下是Java小蜜蜂游戏的一些示例代码,希望对您有所帮助: 主要类: ```java public class Main extends JFrame implements ActionListener, Runnable { private static final long serialVersionUID = 1L; private final static String TITLE = "Bee Game"; private final static int WIDTH = 800; private final static int HEIGHT = 600; private final static int FPS = 60; private GamePanel gamePanel; public Main() { super(TITLE); setDefaultCloseOperation(EXIT_ON_CLOSE); setResizable(false); gamePanel = new GamePanel(WIDTH, HEIGHT); getContentPane().add(gamePanel, BorderLayout.CENTER); pack(); setLocationRelativeTo(null); setVisible(true); Timer timer = new Timer(1000 / FPS, this); timer.start(); } public void actionPerformed(ActionEvent arg0) { gamePanel.update(); gamePanel.repaint(); } public void run() { while (true) { gamePanel.update(); gamePanel.repaint(); try { Thread.sleep(1000 / FPS); } catch (InterruptedException e) { e.printStackTrace(); } } } public static void main(String[] args) { new Thread(new Main()).start(); } } ``` 游戏面板: ```java public class GamePanel extends JPanel implements MouseListener { private static final long serialVersionUID = 1L; private int width; private int height; private Bee bee; private ArrayList<Flower> flowers; public GamePanel(int width, int height) { this.width = width; this.height = height; setPreferredSize(new Dimension(width, height)); setBackground(Color.WHITE); addMouseListener(this); bee = new Bee(width / 2, height / 2); flowers = new ArrayList<Flower>(); for (int i = 0; i < 10; i++) { int x = (int) (Math.random() * width); int y = (int) (Math.random() * height); flowers.add(new Flower(x, y)); } } public void paintComponent(Graphics g) { super.paintComponent(g); bee.draw(g); for (Flower flower : flowers) { flower.draw(g); } } public void update() { bee.update(); for (Flower flower : flowers) { if (bee.intersects(flower)) { bee.setFlower(flower); flowers.remove(flower); break; } } } public void mouseClicked(MouseEvent e) { bee.setTarget(e.getX(), e.getY()); } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } } ``` 蜜蜂类: ```java public class Bee { private int x; private int y; private int dx; private int dy; private int speed; private int size; private Flower flower; public Bee(int x, int y) { this.x = x; this.y = y; dx = 0; dy = 0; speed = 5; size = 20; flower = null; } public void draw(Graphics g) { g.setColor(Color.BLACK); g.fillOval(x - size / 2, y - size / 2, size, size); if (flower != null) { g.setColor(Color.BLUE); g.drawLine(x, y, flower.getX(), flower.getY()); } } public void update() { if (flower == null) { if (dx != 0 || dy != 0) { double angle = Math.atan2(dy, dx); x += speed * Math.cos(angle); y += speed * Math.sin(angle); } } else { x = flower.getX(); y = flower.getY(); } } public boolean intersects(Flower flower) { int distance = (int) Math.sqrt(Math.pow((x - flower.getX()), 2) + Math.pow((y - flower.getY()), 2)); return distance < size / 2 + flower.getSize() / 2; } public void setTarget(int tx, int ty) { dx = tx - x; dy = ty - y; } public void setFlower(Flower flower) { this.flower = flower; } } ``` 花类: ```java public class Flower { private int x; private int y; private int size; public Flower(int x, int y) { this.x = x; this.y = y; size = 30; } public void draw(Graphics g) { g.setColor(Color.RED); g.fillOval(x - size / 2, y - size / 2, size, size); } public int getX() { return x; } public int getY() { return y; } public int getSize() { return size; } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值