import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class GunThread extends Thread{
JLabel gunl;
public GunThread(JLabel gunl)
{
this.gunl=gunl;
}
public void run()
{
int n=0;
while(true)
{
n=(int)(Math.random()*4)+1;
gunl.setSize(20,20);
gunl.setVisible(true);
gunl.setOpaque(true);
if(n==1)
{
int y=1000;
int x=900;
gunl.setLocation(x, y);
for(int i=0;i<10;i++)
{
y=y-75;
gunl.setLocation(x, y);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
return;
}
}
}
if(n==2)
{
int y=0;
int x=900;
gunl.setLocation(x, y);
for(int i=0;i<10;i++)
{
y=y+75;
gunl.setLocation(x, y);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
return;
}
}
}
if(n==3)
{
int y=500;
int x=0;
gunl.setLocation(x, y);
for(int i=0;i<15;i++)
{
x=x+75;
gunl.setLocation(x, y);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
return;
}
}
}
}
}
}
public class Main extends JFrame{
JFrame f1=new JFrame();
int dir=0;
ImageIcon hart=new ImageIcon("image1/hart.png");
JLabel hartl=new JLabel(hart);
ImageIcon gun=new ImageIcon("image1/총알.png");
JLabel gunl=new JLabel(gun);
ImageIcon Map=new ImageIcon("image1/맵.png");
JLabel mapl=new JLabel(Map);
ImageIcon wall=new ImageIcon("image1/벽.png");
JLabel walll=new JLabel(wall);
JLabel walll1=new JLabel(wall);
ImageIcon wall2=new ImageIcon("image1/벽2.png");
JLabel walll2=new JLabel(wall2);
JLabel walll3=new JLabel(wall2);
Main()
{
f1.setTitle("탕창피하기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f1.add(gunl);
f1.add(walll);
f1.add(walll1);
f1.add(walll2);
f1.add(walll3);
walll.setVisible(false);
walll2.setVisible(false);
walll1.setVisible(false);
walll3.setVisible(false);
walll.setOpaque(true);
walll.setSize(153,27);
walll1.setOpaque(true);
walll1.setSize(153,27);
walll2.setOpaque(true);
walll2.setSize(27,153);
walll3.setOpaque(true);
walll3.setSize(27,153);
f1.add(hartl);
f1.addKeyListener(new KeyListener() {
{
}
public void keyTyped(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_UP)
{
dir=1;
walll.setLocation(825, 430);
walll2.setVisible(false);
walll3.setVisible(false);
walll1.setVisible(false);
walll.setVisible(true);
}
else if(e.getKeyCode()==KeyEvent.VK_DOWN)
{
dir=2;
walll1.setVisible(true);
walll1.setLocation(825, 590);
walll2.setVisible(false);
walll3.setVisible(false);
walll.setVisible(false);
}
else if(e.getKeyCode()==KeyEvent.VK_LEFT)
{
dir=3;
walll2.setLocation(825, 430);
walll2.setVisible(true);
walll3.setVisible(false);
walll1.setVisible(false);
walll.setVisible(false);
}
else if(e.getKeyCode()==KeyEvent.VK_RIGHT)
{
dir=4;
walll3.setLocation(975, 430);
walll2.setVisible(false);
walll3.setVisible(true);
walll1.setVisible(false);
walll.setVisible(false);
}
}
public void keyReleased(KeyEvent e) {
}
});
f1.setFocusable(true);
f1.requestFocus();
hartl.setVisible(true);
hartl.setOpaque(true);
hartl.setSize(20, 20);
hartl.setLocation(880, 500);
mapl.setSize(1000, 1000);
mapl.setVisible(true);
mapl.setOpaque(true);
f1.add(mapl);
f1.setSize(1000,1000);
f1.setVisible(true);
GunThread th=new GunThread(gunl);
th.start();
}
public static void main(String[] args) {
new Main();
}
}



