1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| package applet;
import game.Ship;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import javax.swing.JPanel;
public class GameZone extends JPanel
{
private Thread thread;
private Ship ship;
private static final long serialVersionUID = 1L;
private int width = 600; // la largeur de lu plateau (barre de même taille)
private int height = 800; // la hauteur
private String command; // les différentes commandes
public GameZone()
{
this.setPreferredSize(new Dimension(height, width));
this.setBackground(Color.BLUE);
}
public void init()
{
}
public void start()
{
}
public void paint(Graphics g)
{
}
public void run() throws InterruptedException
{
while(thread!=null)
{
Thread.sleep(100);
this.repaint();
}
}
public void destroy()
{
}
public void createShip()
{
ship = new Ship("../img.ship",this);
}
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_UP)
ship.up();
else if (e.getKeyCode() == KeyEvent.VK_DOWN)
ship.down();
else if (e.getKeyCode() == KeyEvent.VK_RIGHT)
ship.right();
else if (e.getKeyCode() == KeyEvent.VK_LEFT)
ship.left();
else if (e.getKeyCode() == KeyEvent.VK_SPACE)
ship.shoot();
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
}
public Ship getShip()
{
return ship;
}
public void event() {
// TODO Auto-generated method stub
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
public String getCommand()
{
command = "Avancer : HAUT\nReculer : BAS\nSe déplacer à gauche : GAUCHE\n" +
"Se déplacer à droite : DROITE\nTirer : Espace";
return command;
}
} |
Partager