Java卡游戏:甲板类需要帮助 [英] Java Card Game: Deck Class help needed
问题描述
这是我对堆栈溢出的第一个问题,所以原谅我,如果我有我的问题中的一个新手的错误,并随时纠正我,因为我打算使用这个网站了很多在未来几个月的时间。
This is my first question on Stack Overflow, so pardon me if I have a rookie mistake within my question and feel free to correct me as I plan to use this site a lot more over the next few months.
总之,我在高中一年级12学生和我停留在我的家庭作业的问题之一。
所以基本上我们已经给创造一个战争游戏(纸牌游戏)的一个项目,我们已经被要求每天做它的小块。到目前为止,一切都已经准备好直到今天,因此我的问题你们。
Anyhow, I'm a grade 12 Student at High School and am stuck on one of my homework questions. So basically we've been given a project of creating a War Game (card game) and we've been asked to do small chunks of it everyday. So far everything has been going good until today, hence my question to y'all.
下面是该项目是什么:
卡
- 什么它具有:
- 私人int值:卡片的价值
- 私人CHAR套装:该卡的西装
- 私人布尔得出:是否不卡已经从甲板上绘制
- 大众卡(INT VAL,char中):创建具有价值VAL,西装S和套牌吸引到假
- 公众诠释的getValue():返回一个卡 价值
- 公共字符getSuit():返回一个卡 的西装
- 公共布尔isDrawn():返回一个卡是否已经制定
- 公共字符串的toString()返回描述形式西服的价值的卡字符串
甲板
- 什么它具有:
- 私人的char [] =西装{'C','D','H','S'}:西服的再presentation
- 公众诠释numCards:卡在甲板上数(52传统 - 使这个较低的测试!)
- 专用卡[]甲板:存储卡阵列甲板
我所做的一切,高达了这一点。
I'm done everything upto this point.
- 它的作用:
- 公共甲板():创建一个扑克牌 - 值从2-14各一个西装
- 众牌的drawcard():从尚未得出尚未甲板上绘制一个随机卡
- 公共字符串的toString():设计,但是你想用于测试目的
现在我已经完成了与做琼先生但是,下面我很困惑,我应该如何去创造的drawcard方法帮助公众甲板一步。这是我到目前为止有:
Now I've finished doing the Public deck step with the help of Mr. Quynh below however I'm confused as to how I should go about creating the drawCard method. Here's what I have so far:
public Card drawnCard(){ int randNum = (int) Math.random()*13+2; }
所以我知道上面的code创建2和14,但我怎么用它来绘制物理卡之间的随机数?就像我该怎么输入,使程序知道要抽一张牌?对不起,我知道你会觉得我在问你每个步骤了,但我真的很失落,需要你的帮助!
So i know that the above code creates a random Number between 2 and 14 but how do i use that to draw the physical card? Like what do I type so that the program knows to draw a card? Sorry, I know you may feel like I'm asking you for each step now, but I truly am lost and require your help!
我是一个新手,当涉及到编程,所以我道歉,如果这个问题过于简单/ noobie你,但我真的需要你的帮助:)
I'm a newbie when it comes to programming and hence I apologize if this question is far too simple/noobie for you, but I really need your help :)
感谢您的时间!
推荐答案
作为首发,你的甲板构造应该与此类似。
As a starter, your Deck constructor should look something similar to this
for(int i = 2; i <= 14; i++){ for(int j = 0; j < suits.length; j++){ Card card = new Card(i, suits[j]); card.isDrawn(false); //ADD CARD TO YOUR DECK HERE } }
至于的drawcard功能,只需从随机1-52的数字(假设你正在使用52卡甲板),然后从甲板绘制并设置
.isDrawn(真)
这篇关于Java卡游戏:甲板类需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!