用JAVA写一个2048的小游戏。

这篇具有很好参考价值的文章主要介绍了用JAVA写一个2048的小游戏。。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。


一、先看一下游戏运行什么样

如图所示:
用JAVA写一个2048的小游戏。

运行环境:

使用软件:eclipse2021-12版
JDK版本:JDK15.0.1

二、代码部分详解:

1.项目结构及下载路径:

用JAVA写一个2048的小游戏。

链接:https://pan.baidu.com/s/1NVWaklg9K2wRmBOLew6iMQ
提取码:ts08

2.所有代码部分

1. Client.java:

package com.it.client;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JOptionPane;

import com.it.constant.Constant;
import com.it.core.BlockLoader;
import com.it.core.MyFrame;


public class Client extends MyFrame{
	
	public BlockLoader loader = new BlockLoader();
	@Override
	public void loadFrame() {
		super.loadFrame();
		
		addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				loader.keyPressed(e);
			}
		});
	}
	@Override
	public void paint(Graphics g) {
		drawBasic(g);
		drawScore(g);
		if(gameStart){
			try {
				loader.draw(g);
			} catch (CloneNotSupportedException e) {
				e.printStackTrace();
			}
		}else{
			if(!gameStart&flag)
				gameReset();
		}
	}
	public static boolean gameStart =true;
	public static boolean flag=true;
	public void gameReset(){
		flag=false;
		int m = JOptionPane.showOptionDialog(null, "对不起 , 游戏结束 ! 点击确定重新开始","游戏结束",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,null,new String[]{"确定","关闭游戏"},"确定");
		if(m==JOptionPane.YES_OPTION){
			gameStart=true;
			flag=true;
			loader=new BlockLoader();
		}else{
			System.exit(0);
		}
	}
	/**
	 * 画分数
	 */
	private void drawScore(Graphics g) {
		g.setColor(Color.RED);
		g.fillRoundRect(Constant.BACK_X, Constant.BACK_Y-100, 220, 80, 10, 10);
		g.setColor(Color.WHITE);
		g.setFont(new Font("幼圆", Font.BOLD, 30));
		g.drawString("分数:"+BlockLoader.score+"",Constant.BACK_X, Constant.BACK_Y-50);
		
		g.setColor(Color.GREEN);
		g.fillRoundRect(Constant.BACK_RIGHT_IN_X+Constant.BLOCK_SPACE-250, Constant.BACK_Y-100, 250, 80, 10, 10);
		g.setColor(Color.WHITE);
		g.setFont(new Font("幼圆", Font.BOLD, 30));
		g.drawString("最高分:"+BlockLoader.bestScore+"",Constant.BACK_RIGHT_IN_X+Constant.BLOCK_SPACE-250, Constant.BACK_Y-50);
		
	}
	/**
	 * 画背景
	 * @param g
	 */
	private void drawBasic(Graphics g) {
		g.setColor(Constant.COLOR_BACK);
		g.fillRoundRect(Constant.BACK_X, Constant.BACK_Y, Constant.BACK_WIDTH, Constant.BACK_HEIGHT, 20, 20);
		g.setColor(Constant.COLOR_BLOCK_BACK);
		for(int i=1;i<=4;i++){
			for(int j=1;j<=4;j++){
				int xStart =Constant.BACK_X+Constant.BLOCK_SPACE*j+Constant.BLOCK_WIDTH*(j-1);
				int yStart = Constant.BACK_Y+Constant.BLOCK_SPACE*i+Constant.BLOCK_WIDTH*(i-1);
				g.fillRoundRect(xStart, yStart, 
						Constant.BLOCK_WIDTH, Constant.BLOCK_WIDTH, 10, 10);
			}
		}
	}
	public static void main(String[] args) {
		new Client().loadFrame();
	}
}

2.Constant.java

package com.it.constant;

import java.awt.Color;

public class Constant {
	public static final int GAME_WIDTH = 900;
	public static final int GAME_HEIGHT = 850;

	public static final int BACK_X = 150;
	public static final int BACK_Y = 150;

	public static final int BACK_WIDTH = 600;
	public static final int BACK_HEIGHT = 600;
	
	public static final int BLOCK_SPACE = 20;
	public static final int BLOCK_WIDTH = (BACK_WIDTH - 5 * BLOCK_SPACE) / 4;
	public static final int BLOCK_HEIGHT = (BACK_HEIGHT - 5 * BLOCK_SPACE) / 4;
	
	public static final int BACK_UP_IN_Y = BACK_Y+BLOCK_SPACE;
	public static final int BACK_DOWN_IN_Y = BACK_Y + BACK_HEIGHT-BLOCK_SPACE;
	public static final int BACK_LEFT_IN_X = BACK_X +BLOCK_SPACE;
	public static final int BACK_RIGHT_IN_X = BACK_X + BACK_WIDTH-BLOCK_SPACE;

	

	public static final String IMG_PRE = "com/zzk/Game_2048/img/";

	public static final Color COLOR_BACK = new Color(187, 173, 160);
	public static final Color COLOR_BLOCK_BACK = new Color(205, 192, 180);

	public static final Color COLOR_BLOCKS_ACTIVE[] = new Color[] { 
					new Color(238, 228, 218), //2
					new Color(237, 224, 200),//4
					new Color(242, 177, 121), //8
					new Color(245, 149, 99), //16
					new Color(255, 204, 0),//32
					new Color(153, 255, 153) ,//64
					new Color(204, 204, 0),//128
					new Color(255, 204, 102),//256
					new Color(255, 80, 80),//512
					new Color(102, 102, 255),//1024
					new Color(204, 0, 102),//2048
					new Color(153, 102, 0),//4096
					new Color(153, 0, 153)//8192
	};

}

3.Block.java

package com.it.core;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.Rectangle;

import com.it.constant.Constant;


public class Block implements Drawable, Moveable {

	public static final int DIRECTION_NONE = 0;
	public static final int DIRECTION_UP = 1;
	public static final int DIRECTION_DOWN = -1;
	public static final int DIRECTION_LEFT = 2;
	public static final int DIRECTION_RIGHT = -2;
	
	public int direction = DIRECTION_NONE;// 默认静止
	private String value;
	public int xOrder;// 方块坐标(非像素坐标)
	public int yOrder;// 方块坐标
	public int x;// 像素坐标
	public int y;//
	public static final int SPEED = 5;
	int level;
	boolean live;
	public int directionX = 0;
	public int directionY = 0;
	public BlockLoader loader =null;
	public Block(int xOrder, int yOrder, int level,BlockLoader loader) {
		super();
		this.xOrder = xOrder;
		this.yOrder = yOrder;
		this.level = level;
		this.value = (int) Math.pow(2, level) + "";
		if (level == 0)
			this.live = false;
		else
			this.live = true;
		this.x = Constant.BACK_Y + Constant.BLOCK_SPACE * xOrder + Constant.BLOCK_WIDTH * (xOrder - 1);
		this.y = Constant.BACK_X + Constant.BLOCK_SPACE * yOrder + Constant.BLOCK_WIDTH * (yOrder - 1);
		this.loader=loader;
	}
	public void keyPressed(int newDirection) {
		this.direction = newDirection;
		switch (direction) {
		case DIRECTION_UP:
			directionX = 0;
			directionY = -1;
			break;
		case DIRECTION_DOWN:
			directionX = 0;
			directionY = 1;
			break;
		case DIRECTION_LEFT:
			directionX = -1;
			directionY = 0;
			break;
		case DIRECTION_RIGHT:
			directionX = 1;
			directionY = 0;
			break;
		}
		updateOrder();
	}
	
	@Override
	public void draw(Graphics g) throws CloneNotSupportedException {
		updateOrder();
		updateState();
		switch (state) {
		case STATE_UNKOWN:
		case STATE_MERGE:
			break;
		case STATE_MOVING:
		case STATE_FREE:
			move();// 移动
			break;
		}
		// 画内容
		drawContent(g);
	}

	/**
	 * 画内容
	 * 
	 * @param g
	 */
	public void drawContent(Graphics g) {
		this.value = (int) Math.pow(2, level) + "";
		g.setColor(Constant.COLOR_BLOCKS_ACTIVE[level - 1]);
		Font f = new Font("微软雅黑", Font.BOLD, 60 - 5 * value.length());
		g.setFont(f);
		FontMetrics fm = new Label().getFontMetrics(f);
		int xValueStart = x + (Constant.BLOCK_WIDTH - fm.stringWidth(value)) / 2;
		int yValueStart = y+Constant.BLOCK_HEIGHT- (Constant.BLOCK_HEIGHT - fm.getHeight()) / 2-fm.getDescent();

		// 画背景
		g.fillRoundRect(x, y, Constant.BLOCK_WIDTH, Constant.BLOCK_WIDTH, 10, 10);
		g.setColor(Color.BLACK);
		// 画数字
		g.drawString(value, xValueStart, yValueStart);

//		 //测试记录
//		 f = new Font("微软雅黑", Font.BOLD, 20);
//		 g.setFont(f);
//		 String s = "(" + x + "," + y + ")" + moveCount;
//		 g.drawString(s, x, y + 20);
	}

	/**
	 * 移动
	 */
	int moveCount = 0;
	// 移动次数最大值
	public static final int MOVE_COUNT_MAX = (Constant.BLOCK_WIDTH + Constant.BLOCK_SPACE) / SPEED;

	/**
	 * 移动
	 */
	@Override
	public void move() {
		// 0到MOVE_COUNT_MAX
		switch (direction) {
		case DIRECTION_UP:
			y -= SPEED;
			break;
		case DIRECTION_DOWN:
			y += SPEED;
			break;
		case DIRECTION_LEFT:
			x -= SPEED;
			break;
		case DIRECTION_RIGHT:
			x += SPEED;
			break;
		}
		moveCount++;
		if (moveCount >= MOVE_COUNT_MAX) {
			moveCount = 0;
		}
		// 1到MOVE_COUNT_MAX
	}
	public int state=STATE_UNKOWN;
	public static final int STATE_UNKOWN = 0;// 未知态(判断态)
	public static final int STATE_MOVING = 1;// 移动态
	public static final int STATE_FREE = 2;// 自由态
	public static final int STATE_MERGE = 3;// 合并态

	/**
	 * 获得状态
	 * @return
	 */
	public int updateState() {
		if (moveCount != 0) {
			state = STATE_MOVING;
		} else if (moveCount == 0) {
			state = STATE_UNKOWN;
		}
		if (direction != DIRECTION_NONE && getNextBlock() == null) {
			state = STATE_FREE;
		}
		Block b = (Block) getNextBlock();
		//合并态判断
		if (direction != DIRECTION_NONE && b != null && b.level == level && (b.state != STATE_FREE)) {
			this.live = false;
			b.level++;
			b.state=STATE_MERGE;
			setThisBlock(null);
			BlockLoader.score += b.level * 10;
			if(BlockLoader.score>=BlockLoader.bestScore){
				BlockLoader.bestScore=BlockLoader.score;
			}
			if(b.getNextBlock()!=null&&b.getNextBlock().live&&b.getNextBlock().state==STATE_FREE){
			}else{
				b.direction=DIRECTION_NONE;
				b.directionX=0;
				b.directionY=0;
			}
			
		}
		return state;
	}
	/**
	 * 更新order
	 * 
	 * @throws CloneNotSupportedException
	 */
	public void updateOrder() {
		if (moveCount == 0) {// 判断态
			xOrder = (x - Constant.BACK_LEFT_IN_X) / (Constant.BLOCK_WIDTH + Constant.BLOCK_SPACE) + 1;
			yOrder = (y - Constant.BACK_UP_IN_Y) / (Constant.BLOCK_HEIGHT + Constant.BLOCK_SPACE) + 1;
			loader.blocks[xOrder][yOrder] = this;
			if (direction != 0 && getLastBlock() != null && getLastBlock().live && (getLastBlock() == this))
				setLastBlock(null);// 设置历史轨迹为空
		}
	}

	public void setLastBlock(Block block) {
		loader.blocks[xOrder - directionX][yOrder - directionY] = block;
	}

	public Block getLastBlock() {
		return loader.blocks[xOrder - directionX][yOrder - directionY];
	}

	public Block getNextBlock() {
		return loader.blocks[xOrder + directionX][yOrder + directionY];
	}
	public void setThisBlock(Block block){
		loader.blocks[xOrder][yOrder]=block;
	}
	/**
	 * 返回block对应的矩形
	 * 
	 * @return
	 */
	public Rectangle getRectangle() {
		return new Rectangle(x, y, Constant.BLOCK_WIDTH, Constant.BLOCK_HEIGHT);
	}

	/**
	 * 判断是否在边界
	 * 
	 * @return
	 */
	boolean xIsBounds = (x == (Constant.BACK_RIGHT_IN_X - Constant.BLOCK_WIDTH)) || (x == Constant.BACK_LEFT_IN_X);
	boolean yIsBounds = (y == (Constant.BACK_DOWN_IN_Y - Constant.BLOCK_HEIGHT)) || (y == Constant.BACK_UP_IN_Y);

	public boolean isAtBounds() {
		if ((xIsBounds || yIsBounds)) {
			return true;
		}
		return false;
	}

	/**
	 * 判断是否在角落
	 * 
	 * @return
	 */
	public boolean isAtCorner() {
		if ((xIsBounds && yIsBounds)) {
			return true;
		}
		return false;
	}

	/**
	 * 处理出界问题
	 */
	public void outOfBounds() {
		if (x > (Constant.BACK_RIGHT_IN_X - Constant.BLOCK_WIDTH)) {
			x = Constant.BACK_RIGHT_IN_X - Constant.BLOCK_WIDTH;
		}
		if (x < Constant.BACK_LEFT_IN_X) {
			x = Constant.BACK_LEFT_IN_X;
		}
		if (y == (Constant.BACK_DOWN_IN_Y - Constant.BLOCK_HEIGHT)) {
			y = Constant.BACK_DOWN_IN_Y - Constant.BLOCK_HEIGHT;
		}
		if (y == Constant.BACK_UP_IN_Y) {
			y = Constant.BACK_UP_IN_Y;
		}
	}

	@Override
	public String toString() {
		String s = "value=" + value + " (" + xOrder + "," + yOrder + "),Direction=";
		switch (direction) {
		case DIRECTION_UP:
			s += "↑";
			break;
		case DIRECTION_DOWN:
			s += "↓";
			break;
		case DIRECTION_LEFT:
			s += "←";
			break;
		case DIRECTION_RIGHT:
			s += "→";
			break;
		case DIRECTION_NONE:
			s += "0";
			break;
		default:
			s += "方向异常";
			break;
		}
		if (getNextBlock() == null)
			s += ",block=null(" + (xOrder + directionX) + "," + (yOrder + directionY) + ")";
		else
			s += ",block=(" + getNextBlock().xOrder + "," + getNextBlock().yOrder + ")";
		return s + "(state=" + state + ")";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + direction;
		result = prime * result + directionX;
		result = prime * result + directionY;
		result = prime * result + level;
		result = prime * result + (live ? 1231 : 1237);
		result = prime * result + moveCount;
		result = prime * result + ((value == null) ? 0 : value.hashCode());
		result = prime * result + x;
		result = prime * result + xOrder;
		result = prime * result + y;
		result = prime * result + yOrder;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Block other = (Block) obj;
		if (direction != other.direction)
			return false;
		if (directionX != other.directionX)
			return false;
		if (directionY != other.directionY)
			return false;
		if (level != other.level)
			return false;
		if (live != other.live)
			return false;
		if (moveCount != other.moveCount)
			return false;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.equals(other.value))
			return false;
		if (x != other.x)
			return false;
		if (xOrder != other.xOrder)
			return false;
		if (y != other.y)
			return false;
		if (yOrder != other.yOrder)
			return false;
		return true;
	}

}

4.BlockLoader.java

package com.it.core;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CopyOnWriteArrayList;

import com.it.client.Client;
import com.it.constant.Constant;

public class BlockLoader implements Drawable {

	public static Random random = new Random();
	public Block[][] blocks = new Block[6][6];
	public List<Block> blockList = new CopyOnWriteArrayList<Block>();

	public BlockLoader() {
		super();
		init();
	}

	public void init() {
		for (int i = 0; i < 6; i++) {
			for (int j = 0; j < 6; j++) {
				if (i == 5 || j == 5 || i == 0 || j == 0) {
					blocks[i][j] = new Block(i, j, 0, this);
				}
			}
		}
		 int x1 = randomBlockPoint().x;// 1-4
		 int y1 = randomBlockPoint().y;
		 blocks[x1][y1] = new Block(x1, y1, 1,this);
		 blockList.add(blocks[x1][y1]);
		 int x2 = randomBlockPoint().x;
		 int y2 = randomBlockPoint().y;
		 while (x1 == x2 && y1 == y2) {
		 x2 = randomBlockPoint().x;
		 y2 = randomBlockPoint().y;
		 }
		 blocks[x2][y2] = new Block(x2, y2, 1,this);
		 blockList.add(blocks[x2][y2]);
		 score=0;
	}

	public static Point randomBlockPoint() {
		return new Point(random.nextInt(4) + 1, random.nextInt(4) + 1);
	}

	public void newBlock() {
		int x = randomBlockPoint().x;// 1-4
		int y = randomBlockPoint().y;
		int i = 0;
		while (blocks[x][y] != null && i < 100) {
			x = randomBlockPoint().x;
			y = randomBlockPoint().y;
			i++;
		}
		if (blocks[x][y] == null) {
			newBlock = blocks[x][y] = new Block(x, y, 1, this);
			blockList.add(newBlock);
			System.out.println("newBlock:" + newBlock);
		} else {
			Client.gameStart = false;// 游戏结束
		}
	}

	public static boolean isPressed = false;
	public static Block newBlock = null;

	public void keyPressed(KeyEvent e) {
		if (!isPressed) {
			int direction = e.getKeyCode();
			switch (direction) {
			case KeyEvent.VK_UP:
			case KeyEvent.VK_W:
				direction = Block.DIRECTION_UP;
				isPressed = true;
				break;
			case KeyEvent.VK_DOWN:
			case KeyEvent.VK_S:
				direction = Block.DIRECTION_DOWN;
				isPressed = true;
				break;
			case KeyEvent.VK_LEFT:
			case KeyEvent.VK_A:
				direction = Block.DIRECTION_LEFT;
				isPressed = true;
				break;
			case KeyEvent.VK_RIGHT:
			case KeyEvent.VK_D:
				direction = Block.DIRECTION_RIGHT;
				isPressed = true;
				break;
			default:
				direction = -1;
				break;
			}
			if (isPressed) {
				for (Block block : blockList) {
					block.keyPressed(direction);
				}
			}
		}
		// newBlock();
	}

	public static int score = 0;
	public static int bestScore = 0;
	@Override
	public void draw(Graphics g) throws CloneNotSupportedException {
		boolean newFlag = true;
		for (Block block : blockList) {
			if (block.live) {
				block.draw(g);
				g.setFont(new Font("微软夜黑", Font.BOLD, 20));
				if (block.state != Block.STATE_UNKOWN) {
					newFlag = false;
				}
			} else {
				blockList.remove(block);
			}
		}
		if (newFlag && isPressed) {
			newBlock();
			isPressed = false;
		}
//		 drawTestInfo(g);//测试信息
	}

	public void drawTestInfo(Graphics g) {
		// 测试
		for (int i = 0; i < 6; i++) {
			for (int j = 0; j < 6; j++) {
				int x = Constant.BACK_Y + Constant.BLOCK_SPACE * i + Constant.BLOCK_WIDTH * (i - 1);
				int y = Constant.BACK_X + Constant.BLOCK_SPACE * j + Constant.BLOCK_WIDTH * (j - 1);
				if (blocks[i][j] == null) {
					g.drawString("null", x, y);
				} else {
					g.drawString("(" + x + "," + y + ")" + blocks[i][j].state, x, y);
				}
			}
		}
	}
}

5.Drawable.java

package com.it.core;

import java.awt.Graphics;

public interface Drawable {
	void draw(Graphics g) throws CloneNotSupportedException;
}

6.Moveable.java

package com.it.core;

public interface Moveable {
	void move();
}

7.MyFrame.java

package com.it.core;

import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import com.it.constant.Constant;

public class MyFrame extends Frame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 加载窗体
	 */
	public void loadFrame(){
		this.setTitle("2048");
		this.setSize(Constant.GAME_WIDTH, Constant.GAME_HEIGHT);
		this.setBackground(Color.WHITE);
		this.setLocationRelativeTo(null);//居中
		
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		
		this.setVisible(true);
		
		new MyThread().start();
	}
	/**
	 * 防止图片闪烁
	 * 
	 * @param g
	 */
	Image backImg = null;

	@Override
	public void update(Graphics g) {
		if (backImg == null) {
			backImg = createImage(Constant.GAME_WIDTH, Constant.GAME_HEIGHT);
		}
		Graphics backg = backImg.getGraphics();
		Color c = backg.getColor();
		backg.setColor(Color.WHITE);
		backg.fillRect(0, 0, Constant.GAME_WIDTH, Constant.GAME_HEIGHT);
		backg.setColor(c);
		paint(backg);		
		g.drawImage(backImg, 0, 0, null);
	}
	/**
	 * 这种 创建一个重新画的线程内部类
	 * 
	 * @param args
	 */
	class MyThread extends Thread{
		@Override
		public void run() {
			while(true){
				repaint();
				try {
					sleep(5);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}
}


总结

提示:代码写的有些臃肿,其中也有一些BUG,理解源码以后可以修正。
链接:https://pan.baidu.com/s/1NVWaklg9K2wRmBOLew6iMQ
提取码:ts08文章来源地址https://www.toymoban.com/news/detail-495776.html

到了这里,关于用JAVA写一个2048的小游戏。的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • vue3+uniapp在微信小程序实现一个2048小游戏

    微信小程序搜索《静远的工具箱》:偶数求和那个功能

    2024年04月12日
    浏览(47)
  • 详解Java实现2048小游戏(JavaFX,完整源码+注释说明)

    刚刚完成的一个小游戏,写文章记录一下,如果有任何错误或者可以改进的代码请提出 另一方面也是方便自己几个月或几年后忘记时,来这里翻一翻回顾思路 目录 基本界面: 类的组织: _CardPane: _CardMatrixPane: _CardColor: _GameMenuBar: _2048Demo: 基本思路: 卡片: 卡片矩阵:

    2024年02月03日
    浏览(37)
  • python小游戏 2048小游戏设计与实现

    🔥 Hi,各位同学好呀,这里是L学长! 🥇今天向大家分享一个今年(2022)最新完成的毕业设计项目作品 python小游戏毕设 2048小游戏设计与实现 (源码) 🥇 学长根据实现的难度和等级对项目进行评分(最低0分,满分5分) 难度系数:3分 工作量:3分 创新点:4分 今天我们用python实现

    2024年02月11日
    浏览(44)
  • python小游戏毕设 2048小游戏设计与实现 (源码)

    🔥 Hi,各位同学好呀,这里是L学长! 🥇今天向大家分享一个今年(2022)最新完成的毕业设计项目作品 python小游戏毕设 2048小游戏设计与实现 (源码) 🥇 学长根据实现的难度和等级对项目进行评分(最低0分,满分5分) 难度系数:3分 工作量:3分 创新点:4分 项目获取: https://

    2024年02月12日
    浏览(31)
  • 2048小游戏成品源码

    2048小游戏,可以自选背景颜色,方框颜色,音乐播放。 还可以展示当前玩家的排名,动态排名,及历史玩家的排名。 前期需求: 使用pygame加载目录音乐。MP3文件: 看下运行后的效果图: =========参数设置: =========背景设置: =========方块设置: ==========源码分享:

    2024年02月16日
    浏览(28)
  • Qt--2048小游戏

    2048 1.功能 上下左右控制数字格子的移动 WASD 4*4 格子移动操作,加操作 开始游戏的按钮,重新游戏按钮 得分计算 判断游戏是否结束 2.源程序 代码如下(示例): MainWindow.h Main.cpp MainWindow.cpp 5.结果 以上是今天要讲的内容,练习了2048小游戏。

    2024年01月25日
    浏览(33)
  • c++制作小游戏2048

    完整代码来自于爱编程的柚子《【C语言/C++游戏项目】:2048小游戏,超详细教程教会你写这个小游戏。》 这个游戏用到了#include graphics.h,思路比较简单。 首先做出游戏页面,然后画出4*4的格子,利用map二维数组,依据数字{0,2,4,8,16,32,64,128,256,512,1024,2048}找到对应颜色在固定位

    2024年02月13日
    浏览(31)
  • python快速实现2048小游戏

    《2048》是一款比较流行的数字游戏,最早于2014年3月20日发行。原版2048首先在GitHub上发布,原作者是Gabriele Cirulli,后被移植到各个平台。这款游戏是基于《1024》和《小3传奇》的玩法开发而成的新型数字游戏。 操作指南: 每次可以选择上下左右其中一个方向去滑动,每滑动

    2024年02月11日
    浏览(28)
  • Android期末项目2048小游戏

    Android期末项目2048小游戏。 2048属于益智类小游戏,它做到了娱乐性、趣味性、教育性相统一。益智类的游戏即是需要去开动大脑去思考从而获得游戏的胜利。简单的益智类游戏可以使玩家在娱乐中不断的开发大脑。这样一来就实现了在娱乐中学习。每次可以选择上下左右其中

    2024年02月06日
    浏览(42)
  • 基于C#的2048小游戏

    最近在玩过2048这个小游戏后感觉很有意思,想着正在学C#的winfrom的我能不能自己写一个2048游戏呢?于是就有了这个:   目录 1.实现思路; 2.代码实现; 1.初始化地图表示的数组; 2.绘制游戏的边框; 3.设置每个数值对应的颜色(可省略); 4.添加控件; 5.四个方向的移动;

    2024年02月08日
    浏览(29)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包