资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

关于java2048朝代代码的信息

那个大神有完整的java,eclipse,2048游戏的源代码,全部拷贝粘贴就能用的,给一个,在线等,急!!!

网上的java代码在eclipse里运行方法:

成都创新互联是一家专业提供钦南企业网站建设,专注与成都网站设计、做网站H5高端网站建设、小程序制作等业务。10年已为钦南众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。

1.打开eclipse,点击项目的空白处,选择import;

2.选择Existing Project into Workspace,点击next,找到的java代码,导入到eclipse中;

3.导入成功之后,选择项目,鼠标右键,选择run as,选择一个运行方式,然后运行即可。

求2048朝代版的源代码?

import javax.swing.*;

import java.awt.*;

@SuppressWarnings("serial")

public class Game_block extends JLabel {

private int value;

public Game_block() {

super("go!");

value = 0;

setFont(new Font("font", Font.PLAIN, 40));

setBackground(Color.black);

}

public int getValue() {

return value;

}

public void setValue(int value) {

this.value = value;

String Text = String.valueOf(value);

if (value != 0){

if(value == 2)

setText("夏");

}

if (value != 0){

if(value == 4)

setText("商");

}

if (value != 0){

if(value == 8)

setText("周");

}

if (value != 0){

if(value == 16)

setText("秦");

}

if (value != 0){

if(value == 32)

setText("汉");

}

if (value != 0){

if(value == 64)

setText("三国");

}

if (value != 0){

if(value == 128)

setText("南北朝");

}

if (value != 0){

if(value == 256)

setText("隋");

}

if (value != 0){

if(value == 1024)

setText("五代十国");

}

if (value != 0){

if(value == 2048)

setText("宋辽");

}

if (value != 0){

if(value == 4096)

setText("宋金");

}

if (value != 0){

if(value == 8192)

setText("元");

}

if (value != 0){

if(value == 16384)

setText("明");

}

if (value != 0){

if(value == 32768)

setText("清");

}

if (value != 0){

if(value == 65536)

setText("现代");

}

else

setText("2048");

setColor();

}

public void setColor() {

if (this.value == 0)

setBackground(Color.black);

else if (this.value == 2)

setBackground(new Color(238, 228, 218));

else if (this.value == 4)

setBackground(new Color(248, 232, 248));

else if (this.value == 8)

setBackground(new Color(243, 177, 116));

else if (this.value == 16)

setBackground(new Color(243, 177, 126));

else if (this.value == 32)

setBackground(new Color(248, 149, 90));

else if (this.value == 64)

setBackground(new Color(249, 94, 50));

else if (this.value == 128)

setBackground(new Color(239, 207, 108));

else if (this.value == 256)

setBackground(new Color(239, 207, 99));

else if (this.value == 512)

setBackground(new Color(239, 203, 82));

else if (this.value == 1024)

setBackground(new Color(239, 199, 57));

else if (this.value == 2048)

setBackground(new Color(239, 195, 41));

else if (this.value == 4096)

setBackground(new Color(255, 60, 57));

else if (this.value == 8192)

setBackground(new Color(258, 60, 59));

else if (this.value == 16384)

setBackground(new Color(262, 62, 59));

else if (this.value == 32768)

setBackground(new Color(262, 64, 62));

else if (this.value == 65536)

setBackground(new Color(264, 64, 66));

}

}

______________________________________________________

import java.awt.*;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import javax.swing.*;

@SuppressWarnings("serial")

public class Game_my2048 extends JFrame implements KeyListener {

Game_block[] block;

JPanel panel;

boolean numFlag;

int moveFlag;

int a ;//a 的引入是为了防止连加的情况出现

public Game_my2048() {

numFlag = true;

moveFlag = 0;

block = new Game_block[16];

setTitle("2048朝代版");

setSize(400, 400);

setLocation(500, 200);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

panel = (JPanel) getContentPane();

panel.setLayout(new GridLayout(4, 4, 5, 5));

addBlock();

for (int i = 0; i 2; i++)

appearBlock();

this.addKeyListener(this);

this.setVisible(true);

}

public void addBlock() {

for (int i = 0; i 16; i++) {

block[i] = new Game_block();

block[i].setHorizontalAlignment(JLabel.CENTER);

// 不透明

block[i].setOpaque(true);

panel.add(block[i]);

}

}

public void appearBlock() {

while(numFlag) {

int index = (int) (Math.random() * 16);

if (block[index].getValue() == 0) {

if (Math.random() 0.5)

block[index].setValue(2);

else

block[index].setValue(4);

break;

}

}

}

public void judgeAppear() {

int sum = 0;

for (int i = 0; i 16; i++) {

if (block[i].getValue() != 0)

sum++;

}

if (sum == 16)

numFlag = false;

}

public void upBlock() {

for (int i = 12; i 16; i++) {

int index = i;

for (int j = i - 4; j = i - 12; j -= 4) {

int valueI = block[index].getValue(), valueJ = block[j]

.getValue();

if (valueJ == 0) {

block[index].setValue(0);

block[j].setValue(valueI);

} else {

if (valueI == valueJ) {

block[index].setValue(0);

block[j].setValue(valueI + valueJ);

if (valueI + valueJ == 4096)

win();

numFlag = true;

moveFlag = 0;

} else if (numFlag == false)

moveFlag += 1;

}

index = j;

}

}

}

public void downBlock() {

for (int i = 0; i 4; i++) {

a = 5;

int index = i;

for (int j = i + 4; j = i + 12; j += 4) {

int valueI = block[index].getValue(), valueJ = block[j]

.getValue();

if (valueJ == 0) {

block[index].setValue(0);

block[j].setValue(valueI);

} else {

if (valueI == valueJ) {

block[index].setValue(0);

block[j].setValue(valueI + valueJ);

if (valueI + valueJ == 4096)

win();

numFlag = true;

moveFlag = 0;

} else if (numFlag == false)

moveFlag += 1;

}

index = j;

}

}

}

public void rightBlock() {

for (int i = 0; i = 12; i += 4) {

int index = i;

for (int j = i + 1; j = i + 3; j++) {

int valueI = block[index].getValue(), valueJ = block[j]

.getValue();

if (valueJ == 0) {

block[index].setValue(0);

block[j].setValue(valueI);

} else {

if (valueI == valueJ) {

block[index].setValue(0);

block[j].setValue(valueI + valueJ);

if (valueI + valueJ == 4096)

win();

numFlag = true;

moveFlag = 0;

} else if (numFlag == false)

moveFlag += 1;

}

index = j;

}

}

}

public void leftBlock() {

for (int i = 3; i = 15; i += 4) {

int index = i;

for (int j = i - 1; j = i - 3; j--) {

int valueI = block[index].getValue(), valueJ = block[j]

.getValue();

if (valueJ == 0) {

block[index].setValue(0);

block[j].setValue(valueI);

} else {

if (valueI == valueJ) {

block[index].setValue(0);

block[j].setValue(valueI + valueJ);

if (valueI + valueJ == 4096)

win();

numFlag = true;

moveFlag = 0;

} else if (numFlag == false)

moveFlag += 1;

}

index = j;

}

}

}

@Override

public void keyPressed(KeyEvent e) {

switch (e.getKeyCode()) {

case KeyEvent.VK_UP:

upBlock();

judgeAppear();

appearBlock();

over();

break;

case KeyEvent.VK_DOWN:

downBlock();

judgeAppear();

appearBlock();

over();

break;

case KeyEvent.VK_LEFT:

leftBlock();

judgeAppear();

appearBlock();

over();

break;

case KeyEvent.VK_RIGHT:

rightBlock();

judgeAppear();

appearBlock();

over();

break;

}

}

public void over() {

if (!numFlag moveFlag = 36) {

block[4].setText("G");

block[5].setText("A");

block[6].setText("M");

block[7].setText("E");

block[8].setText("O");

block[9].setText("V");

block[10].setText("E");

block[11].setText("R");

block[11].addMouseListener(new MouseAdapter() {

@Override

public void mousePressed(MouseEvent e) {

reStart();

}

});

}

}

public void win() {

block[0].setText("Y");

block[1].setText("O");

block[2].setText("U");

block[13].setText("W");

block[14].setText("I");

block[15].setText("N");

block[15].addMouseListener(new MouseAdapter() {

@Override

public void mousePressed(MouseEvent e) {

reStart();

}

});

}

public void reStart(){

numFlag=true;

moveFlag=0;

for(int i=0;i 16;i++)

block[i].setValue(0);

for (int i = 0; i 2; i++)

appearBlock();

}

@Override

public void keyTyped(KeyEvent e) {

}

@Override

public void keyReleased(KeyEvent e) {

}

public static void main(String args[]) {

JFrame.setDefaultLookAndFeelDecorated(true);

new Game_my2048();

}

}

__________________________________________________________________________

这个代码却少很多功能的

菜鸟学习java,求大神解释下面的代码各段是什么意思,尽量详细,谢谢

Zip.java

import java.io.*;

import java.util.zip.*;

public class Zip {

static final int BUFFER = 2048; // 定义缓冲区大小

public static void main (Stringargv[]) {

try {

BufferedInputStream origin= null; // 创建带有缓冲区的inputstrream

FileOutputStream dest = new

FileOutputStream("c:\\zip\\myfigs.zip"); // 创建文件输出流,并打开zip文件 CheckedOutputStream checksum = new

CheckedOutputStream(dest,new Adler32()); // 创建过滤流,并验证数据的完整性

ZipOutputStream out = new

ZipOutputStream(new

BufferedOutputStream(checksum)); // 创建压缩文件输出流,并传入参数

//out.setMethod(ZipOutputStream.DEFLATED);

byte data[] = newbyte[BUFFER]; // 创建字节数组

// get a list of files fromcurrent directory

File f = newFile("."); // 创建File变量读取根目录用于文件的读写

String files[] = f.list(); // 读取f文件夹下所有的文件名

for (int i=0; i files.length; i++) { // 根据文件名的数量进行循环

System.out.println("Adding: "+files[i]); // 打印出添加的文件名到控制台

FileInputStream fi = new

FileInputStream(files[i]); // 创建文件读取流,读取当前循环到的文件

origin = new

BufferedInputStream(fi, BUFFER); // 把文件流放入带有缓冲区的inputstream,并指定缓冲区大小

ZipEntry entry = newZipEntry(files[i]); // 创建zip压缩入口实例化,放入当前循环到的文件

out.putNextEntry(entry); // 输出流中放入压缩的文件

int count;

while((count =origin.read(data, 0,

BUFFER)) != -1) {// 当count值等于缓冲区读取的数据字节大小,且不等于-1

out.write(data, 0,count); // 输出流写入count字节大小的数据

}

origin.close();// 关闭带有缓冲区的inputstream

}

out.close(); // 关闭输出流

System.out.println("checksum:

"+checksum.getChecksum().getValue()); // 打印验证压缩文件的值到控制台

} catch(Exception e) { // 捕捉异常

e.printStackTrace(); // 打印异常信息

}

}

}

2048朝代版怎么玩

2048朝代版玩法和2048数字版一样,可以选择上下左右其中一个方向去滑动,不同的是将数字变成了中国自夏开始的各个朝代,就是两个夏拼成一个商,两个商拼成一个周...每次碰撞后便生成下一个朝代,以此类推直到中华人民共和国完成通关。

一边用数学逻辑玩游戏,一边又在温习华夏5000年历史,让不少人觉得这一改版对于中国人来说甚至超过了原版游戏,不过对于小编这种历史缺乏的人群来说,2048朝代版太难,不如2048数字版简单易懂。历史缺乏的小伙伴当然也可通过屏幕方块的颜色来判断。


当前名称:关于java2048朝代代码的信息
链接分享:http://cdkjz.cn/article/hihggp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220