Senhor
So what do we need in OO poker? We have cards, decks, and hands. Card will be a class that contains a rank and suit variable, deck will be a container for cards, and hand will be where we evaluate and compare the poker hands. 01 | package javapoker; | 02 | |
03 | public class Card | 04 | { |
05 | private short rank, suit; | 06 | |
07 | private static String[] suits = { "hearts", "spades", "diamonds","clubs" }; | 08 | private static String[] ranks = { "Ace", "2", "3", "4", "5", "6","7", "8", "9", "10", "Jack", "Queen", "King" }; |
09 | | 10 | public static String rankAsString( int __rank ) { |
11 | return ranks[__rank]; | 12 | } |
13 | | 14 | Card(short suit, short rank) |
15 | { | 16 | this.rank=rank; |
17 | this.suit=suit; | 18 | } |
19 | | 20 | public @Override String toString() |
21 | { | 22 | return ranks[rank] + " of " + suits[suit]; |
23 | } | 24 | |
25 | public short getRank() { | 26 | return rank; |
27 | } | 28 | |
29 | public short getSuit() { | 30 | return suit; |
31 | } | 32 | } |
So we have read-only suit and rank variables, a simple constructor, a toString method, and a rankAsString method. The class will be ultra fast as it knows which strings to output just by accessing indexes of static arrays. This array functions