首页 > 代码库 > 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程序
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。