我正在尝试制作一个非常基本的 Black Jack 游戏,我将它分为三个简单的类,但我对 Java 非常陌生,而且我是一个糟糕的编码员,但我需要学习它才能工作。我很难理解我应该如何调用方法和类。我想出了游戏的基本结构,比如如何创建卡牌以及如何进入游戏和退出游戏。我只是无法弄清楚游戏本身。这是我到目前为止所创建的。请提供任何建议和指导,这样我才能理解这太好了,我很绝望。
BlackJack.java
import java.util.*;
public class BlackJack4 {
public static void main(String[] args) {
// write your code here
Scanner keyboard = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
String playGame = "";
System.out.print("Wanna play some BlackJack? \n");
System.out.print("Type yes or no \n");
playGame = keyboard.nextLine();
if (playGame.equals ("yes"))
{
/*
This is the area I need help in figuring out.
*/
}
else if (playGame.equals("no")) //Player decided to no play the game
{
System.out.print("Thank you for playing with us today.\n");
System.out.print("To exit the game please press enter.");
scan.nextLine();
System.exit(0);
}
else
{
System.out.print("Sorry you did something wrong. Please try again.\n");
System.out.print("To exit the game please press enter.");
scan.nextLine();
System.exit(0);
}
}
}
Deck.java
import java.util.*;
public class Deck {
ArrayList<Cards> cards = new ArrayList<Cards>();
String[] Suits = { "Clubs", "Diamonds", "Hearts", "Spades"};
String[] Ranks = {null, "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
public Deck() {
int d = Suits.length * Ranks.length;
String[] deck = new String[d];
for (int i = 0; i < Ranks.length; i++) {
for (int j = 0; j < Suits.length; j++) {
deck[Suits.length * i + j] = Ranks[i] + " of " + Suits[j];
}
}
}
public void shuffle(){//shuffle the deck when its created
Collections.shuffle(this.cards);
}
}
慕盖茨4494581
墨色风雨
holdtom
相关分类