Commit 09be9f36 authored by 刘家荣's avatar 刘家荣 💬
Browse files

feat(Enum Theme)

parent 7d3b571b
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package model;

import com.alibaba.fastjson2.JSON;
import network.Client;
import view.Theme;

import java.io.IOException;
import java.nio.file.Files;
@@ -35,6 +36,8 @@ public class Account {
    
    private String name;     //名称
    
    public Theme theme;
    
    /**
     * 本机账号对象
     */
@@ -45,6 +48,9 @@ public class Account {
     * @throws IllegalArgumentException 非法名称异常,可以直接拿异常的message输出到GUI
     */
    public Account(String name) throws IllegalArgumentException {
        this(name, Theme.DEFAULT);
    }
    public Account(String name, Theme theme) throws IllegalArgumentException {
        if (name == null || name.length() == 0) {
            throw new IllegalArgumentException("名称不能为空");
        }
@@ -56,6 +62,7 @@ public class Account {
        }
        this.name = name;
        this.uuid = UUID.randomUUID().toString();
        this.theme = theme;
    }
    
    public String getName() {

src/view/Theme.java

0 → 100644
+10 −0
Original line number Diff line number Diff line
package view;

public enum Theme {
    DEFAULT("img"), STYLE_2("img"), STYLE_3("img");
    public final String imgDir;
    
    Theme(String imgDir) {
        this.imgDir = imgDir;
    }
}
+2 −0
Original line number Diff line number Diff line
import com.alibaba.fastjson2.JSON;
import model.Account;
import model.game.Game;
import model.dataType.GameType;

public class GameJSONTest {
    public static void main(String[] args) {
        System.out.println(JSON.toJSONString(new Game(GameType.LOCAL_2P)));
        System.out.println(JSON.toJSONString(Account.SELF));
    }
}