- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经解决了这个问题,现在它可以正常运行了,我的问题是,我的构造函数出了什么问题?正如有人指出有一个问题,但我找不到它,我也想从我的牌组中提取并删除一张卡,有关于如何做这样的事情的指示吗?
我的套牌类别:
import java.util.*;
public class Deck {
private static Card[] cards;
private static int counter;
int i=52;
int x=0;
public Deck(Card[] card){
this.cards=card;
}
public int createDeck(){
cards = new Card[52];
for (int a=0; a<=3; a++)
{
for (int b=0; b<=12; b++)
{
cards[x] = new Card(a,b);
x++;
counter++;
}
}
}
public Card[] resetDeck(){
createDeck();
return cards;
}
public static void getRandomCard(){
int chosen = (int) (52*Math.random())+1;
System.out.println(cards[chosen]);
}
public static int getCounter(){
return counter;
}
public static void print(){
for(int x=0;x<52;x++){
System.out.println(Deck.cards[x]);
}
}
}
我的 DecktestDriver
public class DeckTestDriver {
public static void main(String[] args){
Deck test = new Deck(new Card[52]);
test.createDeck();
int input =test.getCounter();
System.out.println("Number of cards in Deck = "+input);
System.out.print("looking at one card in the deck-----");
test.getRandomCard();
System.out.println(".........................");
System.out.println("Printing full list of cards in deck");
System.out.println(".........................");
test.print();
System.out.println();
System.out.println(".........................");
System.out.println();
System.out.println("Creating New Deck");
System.out.println(".........................");
System.out.println();
Deck test1 = new Deck(new Card[52]);
test1.createDeck();
System.out.println();
System.out.println("Printing new full list of cards in deck");
System.out.println(".........................");
test1.print();
System.out.println(".........................");
System.out.println();
int input1 =test1.getCounter();
System.out.println("Number of cards in Deck = "+input1);
System.out.print("looking at one card in the deck-----");
test1.getRandomCard();
System.out.println(".........................");
}
}
我的卡类别:
public class Card {
private int CardFaceValue;
private int CardFaceSuit;
private int cardFlippedNum;
private int cardFlippedSuit;
final static int MIN_VALUE_NUM=1;
final static String MIN_VALUE_SUIT="Diamond";
final static int MAX_VALUE_NUM=13;
final static String MAX_VALUE_SUIT="Spade";
public Card(int cardFlippedNum,int cardFlippedSuit){
cardFlippedNumber();
cardFlippedSuitType();
}
public int cardFlippedNumber(){
int cFn = (int) (Math.random()*13)+1;
cardFlippedNum = cFn;
return CardFaceValue;
}
public int cardFlippedSuitType(){
int cFs = (int)(Math.random()*4)+1;
cardFlippedSuit = cFs;
return CardFaceSuit;
}
public int getNum(){
return cardFlippedNum;
}
public int getSuit(){
return cardFlippedSuit;
}
public String toString() {
return (getCardName() + " of " + getSuitName());
}
public String getCardName() {
switch (cardFlippedNum) { //Change return cases to numbers if you want a number shown e.g: 1 of Hearts
case 1:
return ("Ace");
case 2:
return ("TWO");
case 3:
return ("THREE");
case 4:
return ("FOURTH");
case 5:
return ("FIVE");
case 6:
return ("SIX");
case 7:
return ("SEVEN");
case 8:
return ("EIGHT");
case 9:
return ("NINE");
case 10:
return ("TEN");
case 11:
return ("Jack");
case 12:
return ("Queen");
case 13:
return ("King");
default:
return ("" + cardFlippedNum);
}
}
public String getSuitName() {
switch (cardFlippedSuit) {
case 1:
return ("Diamonds");
case 2:
return ("Clubs");
case 3:
return ("Hearts");
case 4:
return ("Spades");
default:
return ("Invalid");
}
}
}
我的输出:
Number of cards in Deck = 52
looking at one card in the deck-----Jack of Clubs
.........................
Printing full list of cards in deck
.........................
TWO of Spades
SIX of Clubs
NINE of Hearts
TWO of Diamonds
FOURTH of Clubs
FOURTH of Spades
TEN of Clubs
Jack of Spades
EIGHT of Diamonds
Queen of Diamonds
Queen of Diamonds
TEN of Spades
EIGHT of Hearts
Ace of Hearts
SIX of Diamonds
King of Clubs
THREE of Diamonds
TWO of Hearts
SIX of Spades
SIX of Hearts
THREE of Spades
EIGHT of Hearts
FIVE of Clubs
EIGHT of Diamonds
Jack of Clubs
Ace of Diamonds
NINE of Diamonds
SEVEN of Hearts
TEN of Diamonds
SEVEN of Diamonds
SEVEN of Diamonds
EIGHT of Hearts
FIVE of Hearts
THREE of Clubs
THREE of Spades
FIVE of Spades
TWO of Diamonds
TWO of Clubs
NINE of Hearts
FIVE of Hearts
SIX of Spades
TEN of Diamonds
FOURTH of Hearts
King of Hearts
Ace of Spades
THREE of Spades
NINE of Spades
King of Spades
King of Diamonds
King of Diamonds
Jack of Hearts
THREE of Clubs
.........................
Creating New Deck
.........................
Printing new full list of cards in deck
.........................
Ace of Clubs
SEVEN of Hearts
Queen of Clubs
TWO of Diamonds
King of Spades
Ace of Hearts
Ace of Spades
FOURTH of Spades
NINE of Spades
TWO of Hearts
FOURTH of Hearts
THREE of Hearts
THREE of Spades
Ace of Spades
Ace of Diamonds
Jack of Spades
TWO of Diamonds
Queen of Clubs
SIX of Hearts
TEN of Clubs
EIGHT of Diamonds
TWO of Spades
King of Hearts
TWO of Hearts
King of Hearts
NINE of Spades
FOURTH of Hearts
FIVE of Hearts
SIX of Clubs
Jack of Hearts
FOURTH of Spades
Queen of Clubs
TWO of Clubs
Ace of Clubs
NINE of Spades
TEN of Clubs
SIX of Spades
Jack of Spades
Queen of Spades
TWO of Diamonds
EIGHT of Spades
SIX of Hearts
Ace of Diamonds
FOURTH of Diamonds
Queen of Diamonds
Jack of Hearts
TWO of Clubs
FOURTH of Diamonds
SIX of Diamonds
King of Diamonds
TWO of Spades
TEN of Diamonds
.........................
Number of cards in Deck = 104
looking at one card in the deck-----SIX of Clubs
.........................
最佳答案
之后
Deck test = new Deck(new Card[52]);
你从未调用过createDeck()。顺便说一下,你的构造函数和 createDeck 有点精神 split 。您将牌组传递到构造函数中,但如果不创建新数组,则无法创建空白牌组。
编辑
关于精神 split 症......
对于 Deck 的构造函数,您有以下内容:
公共(public)牌组(卡[]卡){ this.cards=卡片; }
奇怪的是,我将牌组视为纸牌的集合,但你却将牌传递到牌组中。这可能只是风格问题。然而,我更希望:
公共(public)甲板(){ 创建甲板(); }
createDeck() 有一个奇怪的地方,顺便说一句 - 它应该返回 int
但没有返回语句。也许签名中的“void”返回会更好。我会把它设为私有(private)。如果有人想要一个新的牌组,他们应该直接使用 Deck deck = new Deck();
,不打电话createDeck();
我永远不会让 Deck 将 Cards[] 数组返回给用户。 Deck 中的数据结构和其他内部结构与任何人无关。 resetDeck()
这样做。不返回 Card[] 意味着 Deck 必须提供诸如 Card getTopCard()
之类的方法。或Card getRandomCard()
因为它不再“打开和服”。但这是一件好事 - 我们希望 Deck(一个非常好的名词)具有动词式的方法,允许人们操纵这副牌。
我看到一个非标准循环结构:for (int b=0; b<=12; b++)
这是没有错误的。然而,一般来说,循环的条件部分是不写<=的。相反,使用 <。所以我期望 for(int b=0; b<13; b++)
话虽如此,当循环不以零开头时,我会忽略这个半标准。
在 Card 中,我看到 public String getCardName()
。考虑稍微不同的实现。重点是通过定义数据结构而不是编写显式代码来消除代码行(从而消除错误)。看看字符串 switch 语句是如何消失的,取而代之的是一行运行时代码。 cardNames 的字符串数组是新的,但它是编译时代码,不太可能引入错误。
public class Card {
...
private static final String[] cardName = new String[] {'ONE','TWO','THREE', ...etc};
...
public String getCardName() {
return cardName[cardFlippedNum];
}
}
关于java - 卡组驱动java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10544398/
在 Android 的 API > 19 中是否有任何方法可以获取可移动 SD 卡的路径? 与外部 SD 卡一样,我们有 Environment.getExternalStorageDirectory
一些 Android 设备有 microSD(或其他存储卡)插槽,通常安装为 /storage/sdcard1 据我所知,自 Android 4.4 起 Google 限制了对此内存的访问,并在 An
我使用 Java Card 2.1.2 SDK 和 GPShell 作为与设备通信的方式在 Java Card 上构建一个项目。我从 GpShell 测试了 helloworld 示例,并成功发送了
我开发了一个应用程序,它有一个来电接收器,它适用于所有手机。一位用户有一部双 SIM 卡安卓手机。该应用程序适用于第一张 SIM 卡。但是当有人调用他的第二张 SIM 卡时,我们的应用程序不会被调用。
我有一个带预览的文件输入。 这是笔 Codepen 我想强制高度,我无法理解我该怎么做。我想将此组件的高度固定为 300px(示例),我还需要保持加载图像的正确纵横比,用灰色背景填充空白。现在我保持宽
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
我正在使用此代码访问 SD card : import os from os.path import join from jnius import autoclass #from android.pe
我正在为数据记录设备编写固件。它以 20 Hz 的频率从传感器读取数据并将数据写入 SD 卡。但是,向SD卡写入数据的时间并不一致(大约200-300 ms)。因此,一种解决方案是以一致的速率将数据写
我正在使用以下代码将视频放到网站上,但是在垂直方向上,手机屏幕上只能看到视频的左半部分 我不是网络开发人员。有人可以告诉我确切的内容吗,如何使其正确放置在手机屏幕上? 是在youtube iframe
我正在使用 Vuetify 1.5 和 Vuetify 网格系统来设置我的布局。现在我有一个组件 HelloWorld我将其导入到我的 Parent 中成分。我已经在我的 HelloWorld 中设置
我使用 python 制作了一个简单的二十一点游戏。我制作了游戏的其余部分,但我正在努力放入 ASCII 卡,所以这只是代码的一小部分。我尝试将 * len(phand) 放在附加行的末尾。虽然这确实
我正在使用玩家卡设置 Twitter 卡。它可以在预览工具中运行,但文档说它需要在“twitter.com 现代桌面浏览器? native iOs 和 Android Twitter 应用程序?mob
任何旧的 GSM 兼容 SIM 卡(3G USIM 的奖励)。 我想我需要一些硬件?谁能为业余爱好者推荐一些便宜的东西,以及一些更专业的东西? 我认为会有一个带有硬件的 API 的完整文档,所以也许这
我使用 python 制作了一个简单的二十一点游戏。我制作了游戏的其余部分,但我正在努力放入 ASCII 卡,所以这只是代码的一小部分。我尝试将 * len(phand) 放在附加行的末尾。虽然这确实
我记得前一段时间读到有 cpu 卡供系统添加额外的处理能力来进行大规模并行化。任何人都有这方面的经验和任何资源来研究项目的硬件和软件方面吗?这项技术是否不如传统集群?它更注重功率吗? 最佳答案 有两个
我检查外部存储是否已安装并且可用于读/写,然后从中读取。我使用的是确切的官方 Android 示例代码 ( from here )。 它说外部存储未安装。 getExternalFilesDir(nu
在 Android 2.1 及更低版本中,Android 应用程序可以请求下载到 SD 卡上吗?另外我想知道应用程序是否可以请求一些包含视频的文件夹下载到 SD 卡上?以及如何做到这一点? 提前致谢。
我们编写了一个 Windows 设备驱动程序来访问我们的自定义 PCI 卡。驱动程序使用 CreateFile 获取卡的句柄。 我们最近在一次安装中遇到了问题,卡似乎停止工作了。我们尝试更换卡(更换似
有些新设备(例如 Samsung Galaxy)带有两个 SD 卡。我想知道是否有任何方法可以确定设备是否有两张 SD 卡或一张 SD 卡。谢谢 最佳答案 我认为唯一的方法是使用 检查可用根的列表 F
我正在尝试将文件读/写到 SD 卡。我已经尝试在我的真实手机和 Eclipse 中的模拟器上执行此操作。在这两种设备上,对/mnt/sdcard/或/sdcard 的权限仅为“d--------”,我
我是一名优秀的程序员,十分优秀!