为什么某些ASCII和Unicode字符无法使用Java写入命令提示符?

问题描述 投票:0回答:1

我尝试用Java编写控制台纸牌游戏。并且我必须使用这些♥♦♠字符。但是,当我在命令提示符下启动程序时,字符看起来像什么? ? ? ? 。我尝试使用Unicode和ASCII并得到相同的结果。我用intellij的想法。我可以写这些ASCII字符217┘218┌191┐192└196─

这是我的Deck班

public class Deck {
    public Card[] cards=new Card[52];
    private final String[] SUITS={"♥H","♣K","♦D","♠S"};
    private final int[] VALUES={1,2,3,4,5,6,7,8,9,10,10,10,10};
    private final String[] RANKS={"A","2","3","4","5","6","7","8","9","10","Q","J","K"};
    public Deck(){
        int cardsIndex=0;
        for(int sIndex=0;sIndex<4;sIndex++){
            for (int rIndex=0;rIndex<13;rIndex++){
                cards[cardsIndex]= new Card();
                cards[cardsIndex].suit=SUITS[sIndex];
                cards[cardsIndex].value=VALUES[rIndex];
                cards[cardsIndex].rank=RANKS[rIndex];
                cardsIndex++;
            }
        }
    }
}

和此卡类

public class Card {
    public String rank;
    public int value;
    public String suit;
    private boolean isOpen=true;
    public boolean ownerIsDealer=true;

    @Override
    public String toString() {
        if (isOpen)
        return String.format("┌────────┐\n| %-2S  %2S |\n└────────┘",rank,suit);//217┘ 218┌ 191┐ 192└ 196─
        else return "┌────────┐\n|        |\n└────────┘";
    }

    public void setIsOpen(boolean open) {
        isOpen = open;
    }
}

我用这种方法写卡

public void writeScreen(Card c1,Card c2,Card c3, Card c4,String ...args){
    clrscr();
    System.out.println("Your Hand:");
    System.out.println(c1);
    System.out.println(c2);
    System.out.println("=============");
    System.out.println("Dealer Hand:");
    System.out.println(c3);
    System.out.println(c4);
    for(String a:args) {
        System.out.println(a);
    }
}

clrscr()调用命令提示符的clear方法。Unicode字符/ u2661 ...等。ASCII 3 4 5 6

它在Intellij Idea终端上工作。当我尝试在命令提示符alt + 3上手动编写时,我可以编写♥,但是在启动游戏时看起来像吗?

java unicode cmd ascii command-prompt
1个回答
2
投票

您真正需要粘贴的只是System.out.println("♥"),其余都无关紧要。

© www.soinside.com 2019 - 2024. All rights reserved.