/*
1 2 3 4
-----------------------------------------------
1 90,185 | 220,185 | 350,185 | 480,185 |
-----------------------------------------------
2 90,280 | 220,280 | 350,280 | 480,280 |
-----------------------------------------------
3 90,375 | 220,375 | 350,375 | 480,375 |
-----------------------------------------------
4 90,470 | 220,470 | 350,470 | 480,470 |
-----------------------------------------------
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class MyDialog extends JDialog{
public MyDialog(JFrame frame, String title) {
super(frame, true);
JLabel la1=new JLabel("You can't win this game because I made it impossible to win :P");
add(la1);
setSize(500,500);
setVisible(false);
}
}
public class Main extends JFrame{
private MyPanel panel=new MyPanel();
private MyDialog dialog;
public Main() {
int arr[] = new int[15];
arr[0] = 2;
arr[1]=2;
arr[2]=2;
arr[3]=2;
arr[4]=2;
arr[5]=2;
arr[6]=4;
arr[7]=4;
arr[8]=4;
arr[9]=2;
arr[10]=2;
arr[11]=8;
arr[12]=16;
arr[13]=0;
arr[14]=0;
int x1=arr[(int)(Math.random()*arr.length)];
int x2=arr[(int)(Math.random()*arr.length)];
int x3=arr[(int)(Math.random()*arr.length)];
int x4=arr[(int)(Math.random()*arr.length)];
int x5=arr[(int)(Math.random()*arr.length)];
int x6=arr[(int)(Math.random()*arr.length)];
int x7=arr[(int)(Math.random()*arr.length)];
int x8=arr[(int)(Math.random()*arr.length)];
int x9=arr[(int)(Math.random()*arr.length)];
int x10=arr[(int)(Math.random()*arr.length)];
int x11=arr[(int)(Math.random()*arr.length)];
int x12=arr[(int)(Math.random()*arr.length)];
int x13=arr[(int)(Math.random()*arr.length)];
int x14=arr[(int)(Math.random()*arr.length)];
int x15=arr[(int)(Math.random()*arr.length)];
int x16=arr[(int)(Math.random()*arr.length)];
panel.setLayout(null);
JLabel la2=new JLabel(Integer.toString(x1));
JLabel la3=new JLabel(Integer.toString(x2));
JLabel la4=new JLabel(Integer.toString(x3));
JLabel la5=new JLabel(Integer.toString(x4));
JLabel la6=new JLabel(Integer.toString(x5));
JLabel la7=new JLabel(Integer.toString(x6));
JLabel la8=new JLabel(Integer.toString(x7));
JLabel la9=new JLabel(Integer.toString(x8));
JLabel la10=new JLabel(Integer.toString(x9));
JLabel la11=new JLabel(Integer.toString(x10));
JLabel la12=new JLabel(Integer.toString(x11));
JLabel la13=new JLabel(Integer.toString(x12));
JLabel la14=new JLabel(Integer.toString(x13));
JLabel la15=new JLabel(Integer.toString(x14));
JLabel la16=new JLabel(Integer.toString(x15));
JLabel la17=new JLabel(Integer.toString(x16));
la2.setLocation(90,185);
la3.setLocation(220,185);
la4.setLocation(350,185);
la5.setLocation(480,185);
la6.setLocation(90,280);
la7.setLocation(220,280);
la8.setLocation(350,280);
la9.setLocation(480,280);
la10.setLocation(90,375);
la11.setLocation(220,375);
la12.setLocation(350,375);
la13.setLocation(480,375);
la14.setLocation(90,470);
la15.setLocation(220,470);
la16.setLocation(350,470);
la17.setLocation(480,470);
la2.setSize(50,50);
la3.setSize(50,50);
la4.setSize(50,50);
la5.setSize(50,50);
la6.setSize(50,50);
la7.setSize(50,50);
la8.setSize(50,50);
la9.setSize(50,50);
la10.setSize(50,50);
la11.setSize(50,50);
la12.setSize(50,50);
la13.setSize(50,50);
la14.setSize(50,50);
la15.setSize(50,50);
la16.setSize(50,50);
la17.setSize(50,50);
panel.add(la2);
panel.add(la3);
panel.add(la4);
panel.add(la5);
panel.add(la6);
panel.add(la7);
panel.add(la8);
panel.add(la9);
panel.add(la10);
panel.add(la11);
panel.add(la12);
panel.add(la13);
panel.add(la14);
panel.add(la15);
panel.add(la16);
panel.add(la17);
dialog= new MyDialog(this,"you win!");
setContentPane(panel);
panel.addKeyListener(new MyKeyListener());
panel.setFocusable(true);
panel.requestFocus();
setSize(609,609);
setVisible(true);
}
class MyPanel extends JPanel{
private ImageIcon icon=new ImageIcon("2048.png");
private Image img=icon.getImage();
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
}
}
class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_UP) {
dialog.setVisible(true);
}
}
}
public static void main(String[] args) {
new Main();
}
}
일본에서도 코딩하는 너의 열정♥