当前位置: 首页 > article >正文

使用java实现斗地主小游戏

Landlords

项目地址:https://github.com/chunlaiqingke/Landlords
环境要求:

  • jdk8+(新手推荐jdk8,自带javafx), jdk11及以上去除了javafx,需要单独安装,高版本jdk可见下面参考链接,jdk17的代码已升级
  • maven

基于java实现的斗地主小游戏,netty + javafx

基于: javafx-ratel-client
和ratel命令行项目进行改造,由于javafx-ratel-client这个项目
长期没有人维护,所以我这里单独发一个项目

使用方法简单介绍

  1. 运行SimpleServer,控制台会显示端口号,说明服务启动成功
  2. 运行SimpleClient,连接本地的127.0.0.1的ip,刚才控制台展示的端口
    (如果是一个人测试,可以使用idea开启允许多实例运行SimpleClient)
public class SimpleClient extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        UIService uiService = new UIService();
        IndexMethod indexMethod = new IndexController(new IndexEvent());
        uiService.addMethods(
                indexMethod,
                new LoginController(new LoginEvent()),
                new LobbyController(new LobbyEvent()),
                new RoomController(new RoomEvent()),
                new Room4PController()
        );
        uiService.getMethod(IndexController.METHOD_NAME).doShow();

        NettyClient nettyClient = new NettyClient(uiService);
        BeanUtil.addBean("nettyClient", nettyClient);

        try {
            List<String> remoteServerAddressList = fetchRemoteServerAddresses();
            Platform.runLater(() -> indexMethod.generateRemoteServerAddressOptions(remoteServerAddressList));
        } catch (IOException e) {
            SimplePrinter.printNotice("获取远程服务器列表失败" + e.getMessage());
            Platform.runLater(() -> indexMethod.setFetchRemoteServerAddressErrorTips());
        }
    }

    private List<String> fetchRemoteServerAddresses() throws IOException {
        String serverInfo = StreamUtils.convertToString(
                new URL("https://raw.githubusercontent.com/ainilili/ratel/master/serverlist.json"));
        return JSONArray.parseArray(serverInfo, String.class);
    }

    public static void main(String[] args) {
        launch(args);
    }
}
public class SimpleServer {

	public static void main(String[] args) throws InterruptedException {
		if (args != null && args.length > 1) {
			if (args[0].equalsIgnoreCase("-p") || args[0].equalsIgnoreCase("-port")) {
				ServerContains.port = Integer.parseInt(args[1]);
			}
		}
		new Thread(() -> {
			try {
				new ProtobufProxy().start(ServerContains.port);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}).start();
		new WebsocketProxy().start(ServerContains.port + 1);

	}
}

功能介绍

  • 三人联机斗地主
  • 三人人机
  • 四人联机

native打包方式

packr
参考连接

ps:如果需要mac版可执行程序(没有windows电脑,参考上面的native打包方式),需要远程服务器地址,私聊

群:742671622


http://www.kler.cn/news/10165.html

相关文章:

  • MATLAB 不同格式点云文件的读取与显示(1)
  • RCIE练习题2之BGP4+配置
  • 《Java设计模式学习》适配器模式
  • STL基础知识
  • 推荐几款程序员提升工作效率的必备工具
  • 【ChatGPT】预训练模型微调及其应用(ChatGLM-6B、duckduckgo_search、GPT在科研的应用等)
  • 23年5月高项学习笔记10 —— 采购管理
  • 双交叉注意学习用于细粒度视觉分类和目标重新识别
  • 重磅!阿里版本【ChatGPT】开放测评!
  • Thinkphp6.0服务系统
  • argparse参数总结(方便之后自己看)
  • 模板学堂|DataEase图表样式解析
  • 科技成果评价最新攻略,你确定不来看看?
  • Python实现Imagenet数据集的合并和拆分
  • 一篇文章让你搞懂TypeScript中的??和?:和?.和!.是什么意思
  • 风电的Weibull分布及光电的Beta分布组合研究(Matlab代码实现)
  • 开源后台管理系统解决方案 boot-admin 简介
  • 关于ChatGPT人工智能浅谈
  • Oracle之PL/SQL游标练习题(三)
  • 服务器部署需要注意的事项
  • 多个渠道成功销售的秘诀速递
  • 深度学习数据集—水果数据集大合集
  • C++模板初阶
  • 系统集成项目管理工程师软考第三章习题(每天更新)
  • 如何找回u盘被删除的文件
  • 00后卷王的自述,我难道真的很卷?
  • 模拟点击是啥?如何实现的呢?
  • 分享4个不可或缺的 VSCode 插件,让 Tailwind CSS开发更简单
  • Spring核心与设计思想
  • 如何使用golang库gqlgen?如何在golang中实现graphql请求?