Senhor

6032 palavras 25 páginas
Salutations, this is CrazyJugglerDrummer with a tutorial on how to make a poker hand evaluator in java. This program will be able to generate, evaluate, and compare poker hands. A basic understanding of OO design is required (making classes, and having them interact with one another. No inheritance or interfaces here. ) Random, ArrayLists, and static variables and methods are used on occasion, but they won't be a show stopper if you don't know what they are yet. I include quick descriptions in FOR BEGINNERS: notes.

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

Relacionados

  • senhor
    7750 palavras | 31 páginas
  • Senhor
    1025 palavras | 5 páginas
  • Senhor
    402 palavras | 2 páginas
  • senhor
    156509 palavras | 627 páginas
  • senhor
    2418 palavras | 10 páginas
  • Senhor
    24011 palavras | 97 páginas
  • senhor
    358 palavras | 2 páginas
  • Senhor
    326 palavras | 2 páginas
  • Senhor
    13919 palavras | 56 páginas
  • Senhor
    923 palavras | 4 páginas