I’m currently trying to implement a card game called 500.
Right here, I’m trying to index every type of bid possible into a simple index number.
I’ve already created the enums for the suits in another class.
The problem I have right now is that I keep on getting an error
“The method Bid(int, Card.Suit) is undefined for the type Bid”.
I dont understand why this is happening.
Any help would be appreciated.
public Bid(int pTricks, Suit pSuit)
{
assert pTricks >= 6;
assert pTricks <= 10;
this.trickCount = pTricks;
this.trumpSuit = pSuit;
}
public Bid(int pIndex)
{
switch (pIndex) {
case 0: Bid(6, Suit.SPADES);
case 1: Bid(6, Suit.CLUBS);
case 2: Bid(6, Suit.DIAMONDS);
case 3: Bid(6, Suit.HEARTS);
case 4: Bid(6, null);
case 5: Bid(7, Suit.SPADES);
case 6: Bid(7, Suit.CLUBS);
case 7: Bid(7, Suit.DIAMONDS);
case 8: Bid(7, Suit.HEARTS);
case 9: Bid(7, null);
case 10: Bid(8, Suit.SPADES);
case 11: Bid(8, Suit.CLUBS);
case 12: Bid(8, Suit.DIAMONDS);
case 13: Bid(8, Suit.HEARTS);
case 14: Bid(8, null);
case 15: Bid(9, Suit.SPADES);
case 16: Bid(9, Suit.CLUBS);
case 17: Bid(9, Suit.DIAMONDS);
case 18: Bid(9, Suit.HEARTS);
case 19: Bid(9, null);
case 20: Bid(10, Suit.SPADES);
case 21: Bid(10, Suit.CLUBS);
case 22: Bid(10, Suit.DIAMONDS);
case 23: Bid(10, Suit.HEARTS);
case 24: Bid(10, null);
}
}
You want to use the
thiskeyword to invoke the other constructor.e.g.
Also, make sure to have
break;at the end of each case.Edit: This doesn’t work as indicated in comments below. Move this logic into a private method that you call from the constructors, or use a static factory method to replace the second constructor.