我正在使用Android工作室获得我最高的胜利游戏。我有三个叫做Cards,Deck,Gamelogic的java类。到目前为止一切都很顺利,但我只是在为比较卡方法启动函数时遇到一些麻烦。这就是我到目前为止......
import android.graphics.Color;
/**
* Created by azib2 on 12/1/2016.
*/
enum Suite {
Heart, diamond, spades, clubs;
public String toString()
{
switch (this) {
case Heart:
return "Heart";
case diamond:
return "diamond";
case spades:
return "spades";
case clubs:
return "clubs";
default:
return "Wrong type";
}
}
public String symbol(){
switch (this) {
case Heart:
return "\u2764";
case diamond:
return "\u2666";
case spades:
return "\u2660";
case clubs:
return "\u2663";
default:
return "Wrong type";
}
}
public int colors() {
switch (this) {
case Heart:
case diamond:
return Color.RED;
case spades:
case clubs:
return Color.BLACK;
}
return 0;
}
}
public class Cards {
private int cardnum;
private Suite suitetype;
public Cards(int cardnum, Suite suitetype){
this.cardnum = cardnum;
this.suitetype = suitetype;
}
public String CardType(int num){
switch(num){
case 1: return "A";
case 2: return "2";
case 3 : return"3";
case 4: return "4";
case 5: return "5";
case 6: return "6";
case 7: return "7";
case 8: return "8";
case 9: return "9";
case 10: return "10";
case 11: return "J";
case 12: return "Q";
case 13: return "K";
default: return " error invaild ";
}
}
public void CompareCards(){
}
public int Getcardnum (){
return cardnum;
}
public Suite getsuite(){
return suitetype;
}
}
我该如何比较卡片?
答案 0 :(得分:0)
首先,我推荐"卡片" be" Card"。但我会坚持使用"卡"这里。
这似乎是Comparable接口的一个很好的用例:
if(card.compareTo(otherCard) > 0) { ... }
然后查看一张卡是否高于另一张卡:
List<Cards> cards = new ArrayList<Cards>();
// Add all cards desired
Collections.sort(cards);
使用这种方法,您甚至可以使用以下方式对卡片列表进行排序:
public class Cards implements Comparable<Cards> {
// Ace lowest:
public int compareTo(Card other) {
// Compare by value first
int diff = Integer.compare(cardnum, other.cardnum);
if(diff != 0) return diff;
// Compare by suit
return suitetype.compareTo(other.suitetype);
}
}
如果你想要稳定的排序(通过价值和套装):
Sub UpdateXML()
Call fnUpdateXMLByTags
End Sub
Function fnUpdateXMLByTags()
Dim mainWorkBook As Workbook
Set mainWorkBook = ActiveWorkbook
Set oXMLFile = CreateObject("Microsoft.XMLDOM")
XMLFileName = "C:\Users\HP\Desktop\Python\VBA\XSDs\job.xsd"
oXMLFile.Load (XMLFileName)
Set ApplicantNodes = oXMLFile.SelectNodes("/PurchaseOrder/text()")
'Add new Attribute to the Node
Set ParentNode = oXMLFile.SelectSingleNode("/Application/USAddress/xs:attribute")
' add its attribute
Set newChildAttribute = oXMLFile.CreateAttribute("name")
newChildAttribute.Text = "Country1"
ParentNode.Attributes.SetNamedItem (newChildAttribute)
Set newChildAttribute = oXMLFile.CreateAttribute("type")
newChildAttribute.Text = "xsd:NMTOKEN"
ParentNode.Attributes.SetNamedItem (newChildAttribute)
Set newChildAttribute = oXMLFile.CreateAttribute("fixed")
newChildAttribute.Text = "US"
ParentNode.Attributes.SetNamedItem (newChildAttribute)
oXMLFile.Save (XMLFileName)
End Function