使用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

你可能感兴趣的:(java,netty,javafx)