首页 > 代码库 > java编写的2048程序

java编写的2048程序

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.border.*;

public class Test extends JApplet{
	private static final int UP=0,DOWN=1,LEFT=2,RIGHT=3;
	private static final int WID=150,SP=10;
	private int scores=0;
	private static JLabel scoreLabel;
	private boolean change,CheckMode=false,gameOverFlag=false,successFlag=false;
	private int[] label={2,4,8,16,32,64,128};
	private Color[] clo={
			new Color(200,200,200),new Color(228,228,160),new Color(214,163,92),
			new Color(234,124,72),new Color(240,84,77),new Color(255,68,53),new Color(200,200,64)
	};
	private Map cmap=new HashMap();
	public static RectObject[][] rset=new RectObject[4][4];
	public RectObject[][] list=new RectObject[4][4];
	private My2048Panel myp;
	private LinkedList saveList=new LinkedList();
	private JButton goBackButton;
	
	KeyListener kl=new KeyListener(){
		public void keyPressed(KeyEvent e){
			saveTheStep();
			goBackButton.setVisible(true);
			if(gameOverFlag==true){
				return;
			}
			if(!aDirAble()){
				gameOver();
			}
			int key=e.getKeyCode();
			switch(key){
			case KeyEvent.VK_UP:
				change=false;
				moveUp(true);
				if(change==true){
					getARandomRect();
					//saveTheStep();
				}
				break;
			case KeyEvent.VK_DOWN:
				change=false;
				moveDown(true);
				if(change==true){
					getARandomRect();
					//saveTheStep();
				}
				break;
			case KeyEvent.VK_LEFT:
				change=false;
				moveLeft(true);
				if(change==true){
					getARandomRect();
					//saveTheStep();
				}
				break;
			case KeyEvent.VK_RIGHT:
				change=false;
				moveRight(true);
				if(change==true){
					getARandomRect();
					//saveTheStep();
				}
				break;
			}
			//saveTheStep();
		}
		public void keyTyped(KeyEvent e){}
		public void keyReleased(KeyEvent e){}
	};
	
	class RectObject{
		private int value;
		public RectObject(){
			value=http://www.mamicode.com/0;>

java编写的2048程序