/************************/ /* シューティングゲーム */ /************************/ import java.awt.*; import java.applet.*; public class Game1 extends Applet implements Runnable { boolean state = true, game = true; int xt = 20, yt = 50, x, y, r = 25, sp = 5; Thread th; Dimension d; public void init() { // 背景色 setBackground(new Color(238, 255, 238)); // 初期設定 d = getSize(); x = d.width / 2 - 10; y = d.height - 20; // スレッドの生成 th = new Thread(this); th.start(); } public Insets getInsets() { return new Insets(0, 0, 0, 0); } public void stop() { state = false; } public void run() { while (state) { try { th.sleep(33); } catch (InterruptedException e) {} // ターゲットの移動 yt += sp; // 再描画 repaint(); } } public void paint (Graphics g) { // ゲーム中 if (game) { // 砲台の表示 g.fill3DRect(x, y, 20, 20, true); // ターゲットの表示 g.setColor(Color.green); g.fillOval(xt, yt, 50, 50); } // ゲームオーバ else { Font f = new Font("TimesRoman", Font.BOLD, 50); g.setFont(f); g.drawString("Game Over", d.width/2-130, d.height/2); } } }