java poker

1
Load the basic Java bridge functionality. Load the Java.util package, for Ruby-side access to ArrayList. ArrayList comes from java.util, and is visible thanks to the include_package directive. Prompt the user for a simple card-by-card input series. Report error to user and ask for re-input of the specs for this card. PokerHand includes a rating method, which returns a string indicating the content of the hand (e.g., “PAIR”). Start the input loop, tracking the number to use in the prompt. On malformed input, raise an exception of type InvalidCardException, which is defined in the com.dablack.cards Java package. Load the locally-written cards Java package. The PokerHand class comes from the com.dablack.cards package, and is visible in Ruby because that package was imported. Intercept (rescue from) the exception InvalidCardException, which the Java constructor throws if the suit and rank of a card are not recognizable. The built-in Ruby times method (on Fixnum objects) yields a number each time through its code block. get_a_card is the subroutine/method for getting user input, in the style of 5/diamonds, and returning a new Card object built from that input. The Card class is defined in the Java package com.dablack.cards. PokerHand includes a rating method, which returns a string indicating the content of the hand (e.g., “PAIR”). Start the demo by instantiating the containing class and calling go. . The constructor for the Java (and now Ruby) Card class takes two arguments. HandEvaluator will serve as the class for demo-ing the evaluation of a poker hand. ACM Learning Center -- Ruby Learning Path Copyright © 2011, Ruby Power and Light, LLC

Upload: rajul-srivastava

Post on 07-Nov-2015

213 views

Category:

Documents


0 download

DESCRIPTION

Ruby Tutorial

TRANSCRIPT

  • Load the basic Java bridge functionality.

    Load the Java.util package, forRuby-side access to ArrayList.

    ArrayList comes from java.util, andis visible thanks to the include_package directive.

    Prompt the user for a simplecard-by-card input series.

    Report error to user and ask forre-input of the specs for this card.

    PokerHand includes a rating method, which returns a string indicating thecontent of the hand (e.g., PAIR).

    Start the input loop, tracking thenumber to use in the prompt.

    On malformed input, raise an exception oftype InvalidCardException, which is definedin the com.dablack.cards Java package.

    Load the locally-written cardsJava package.

    The PokerHand class comes from thecom.dablack.cards package, and isvisible in Ruby because that packagewas imported.

    Intercept (rescue from) the exceptionInvalidCardException, which the Javaconstructor throws if the suit and rank ofa card are not recognizable.

    The built-in Ruby times method (onFixnum objects) yields a number eachtime through its code block.

    get_a_card is the subroutine/methodfor getting user input, in the style of5/diamonds, and returning a newCard object built from that input.

    The Card class is defined in theJava package com.dablack.cards.

    PokerHand includes a rating method, which returns a string indicating thecontent of the hand (e.g., PAIR).

    Start the demo by instantiatingthe containing class andcalling go. .

    The constructor for the Java (and nowRuby) Card class takes two arguments.

    HandEvaluator will serve as theclass for demo-ing the evaluationof a poker hand.

    ACM Learning Center -- Ruby Learning PathCopyright 2011, Ruby Power and Light, LLC

    Slide 1