ITD121留学生辅导、辅导JavaTP3 2018语言

- 首页 >> Java编程


ITD121 – TP3 2018 (updated Jan 20, 2018) Page 1 of 6

Class Assignment – Card Games

Specification Part C – Game Logic and Functionality

Submission Due: Friday, February 1st (all parts together)

Part C Overview

In this part of the assignment, you will implement one final GameObject in the games class called

BlackjackHand using inheritence, as well as the logic class Blackjack in the Games project. You will use these

final classes to complete the functionality of the Blackjack_Form in the GUI Project to produce a playable

game!

The BlackjackHand class will be a subclass of Hand, with details that are specific to the way in which Hands

work in Blackjack.

The Blackjack logic class is designed to completely handle the game logic and store the game data (this is

called the business layer). The GUI allows the user to view this data and to make requests to the Blackjack

class when behaviour or data about the game is needed (this is called the presentation layer).

For this reason, the GUI should NOT contain any private or public class variables. Instead, the logic class

should contain all the data necessary.

Contents

Part C Overview.................................................................................................................................................. 1

Blackjack Rules................................................................................................................................................... 2

BlackjackHand Class...........................................................................................................................................3

Blackjack Logic Class Specification and UML .....................................................................................................4

Necessary Enum.............................................................................................................................................4

UML Implementation.....................................................................................................................................4

Member Descriptions ....................................................................................................................................5

GUI Functionality................................................................................................................................................6

Video Demonstrations .......................................................................................................................................6

ITD121 – TP3 2018 (updated Jan 20, 2018) Page 2 of 6

Blackjack Rules

This section describes the rules of Blackjack. It is important that you understand these rules to implement

the logic class correctly.

The aim of the game is to win rounds against the dealer by having a more valuable hand, without earning a

score over 21 and going ‘bust’.

There are many versions of the game Blackjack, some of which add special rules. We will only be using the

rules described below:

1. Blackjack will be played with a shuffled 52-card deck

2. Cards with face values 2-10 will be scored using their face value, and cards with face cards (Jack, Queen

and King) are worth 10 points. Aces are worth 11 points, but are considered 1 point if they would cause

the score to exceed 21.

3. After the player has placed a bet, their funds are reduced by the amount. The dealer shuffles a full

deck and deals two cards to the player and two cards to themselves. One of the dealer’s cards is shown

face up, and the other is shown face down.

4. It is then the player’s turn. The player may choose to:

a. Hit: The dealer deals an additional card to the player

b. Double: If the player can afford it, they double their hand’s bet before being dealt a new card.

The player automatically stands afterwards and may not perform any more moves for this

hand.

c. Split: Splits one of the cards off into a new hand. This can only be done if the player has two

cards in their hand, each with the same point value (or two aces), and the player can afford

to split. Both hands are dealt a new card, and the player must place the same bet on the

second hand as the original. The player continues play with both hands separately. The player

may only split once.

d. Surrender:The hand is ‘surrendered’. At the end of the round, the player receives half of their

bet back. The player can only surrender at the very start of a round with their first two cards.

e. Stand: The player stops playing the hand. NOTE: Standing occurs automatically if the player

reaches 21 points or more for a hand, or if the hand is ‘doubled’ or ‘surrendered’.

5. During the dealer’s turn, the continuously deals themselves more cards until their total hand value is

at least 17. The dealer does not bother drawing cards if the player surrendered or went bust.

6. The dealer distributes funds according to the result of each of the player’s hands:

a. If the hand was surrendered, the player regains half of their bet (surrendered)

b. If the hand’s score is more than 21, the player does not get anything (bust)

c. If the hand’s score is less than the dealer’s, the player does not get anything (lose)

d. If the hand’s score is the same as the dealer’s (and did not go bust) then the player regains

their bet, but nothing more (push).

e. If the hand’s score is higher than the dealer’s score, but not greater than 21, or if the dealer

goes bust, then the player regains their own hand’s bet multiplied by two (win).

ITD121 – TP3 2018 (updated Jan 20, 2018) Page 3 of 6

BlackjackHand Class

Implement the UML diagram below in the GameObjects class library in a new class file called BlackjackHand.

BlackjackHand is a subclass of Hand with special characteristics related to the game Blackjack (such as

getting a score value, and keeping track of whether a hand has been surrendered or is standing):

class BlackjackHand extends Hand

Properties

+IsStanding : bool <+get> <+set>

+HasSurrendered : bool <+get> <+set>

+Bet : int <+get> <+set>

+Score : int <+get>

Methods

+BlackjackHand(int initialBet = 0)

Properties

IsStanding Property used to keep track of whether the Hand is standing

HasSurrendered Property used to keep track of whether the Hand was surrendered

Bet Property used to keep track of the bet placed on a Hand

Score

Property used to calculate the value or score of a Hand according

to the Blackjack rules (including values of Aces which can be 11 or

1). This property should have a Get method only (no set), and

should always calculate the correct Blackjack score.

Methods BlackjackHand(…)

Constructor used to set up the initial bet for a Hand. Note that the

Dealer does not have funds and so does not place a bet on their

hand (bet can be 0 by default).

ITD121 – TP3 2018 (updated Jan 20, 2018) Page 4 of 6

Blackjack Logic Class Specification and UML

Necessary Enum

Inside the Blackjack class, declare an enum called Result as follows:

namespace Games {

public static class Blackjack {

public enum Result { Push, Won, Lost, Bust, Surrendered }

// …

}

}

This enum represents the results for a Hand depending on the outcome of a Blackjack game. It is important

for the DealerPlay method when the dealer determines the result of a game.

UML Implementation

Implement the UML diagram below in the Blackjack class within the Games project. You must implement all

the characteristics of the UML diagram. You may add additional private variables or methods, but you may

not add additional public methods, variables, or properties.

You can test the correctness of your UML using the unit tests in 4_GamesTests in the Test Explorer.

Do not begin working on this UML diagram until all unit tests pass for part A and the BlackjackHand class.

+ class Blackjack

Fields

-_deck : CardPile

Properties

+DealerHand : BlackjackHand <+get> <-set>

+PlayerHands : List<BlackjackHand> <+get> <-set>

+PlayerFunds : int <+get> <-set>

Methods

+Reset() : void

+NewRound(initialBet: int) : void

+DealerPlay() : List<Result>

+Hit(handNum : int) : void

+Double(handNum : int) : void

+Stand(handNum : int) : void

+Surrender() : void

+Split() : void

+CanHit(handNum : int) : bool

+CanDoulble(handNum : int) : bool

+CanStand(handNum : int) : bool

+CanSurrender() : bool

+CanSplit() : bool

+CanPlayerPlay() : bool

ITD121 – TP3 2018 (updated Jan 20, 2018) Page 5 of 6

Member Descriptions

Fields _deck The shuffled CardPile from which all cards are retrieved. Should be

reset every round.

Properties

DealerHand The BlackjackHand used to represent the dealer’s hand

PlayerHands A List of BlackjackHands used to represent the player’s hands (at

most two in this version)

PlayerFunds

A property used to represent how much funds the player has.

When the player makes a bet, doubles or splits on a hand, this

should be reduced appropriately.

At the end of each round, PlayerFunds may increase appropriately

if the player has won or surrendered.

Methods

Reset

Resets the player’s funds to its initial value (1000).

Initialises the PlayerHands and DealerHand objects (should not

create any cards)

NewRound

Initiates a new round using a bet from the player (parameter).

The player’s funds are reduced by the amount they bet.

The deck of 52 cards is created and shuffled.

Cards are dealt to the player and the dealer as needed.

DealerPlay

The dealer plays out their turn according to the rules of the game.

The correct amount of funds are given back to the player according

to the rules of the game and the outcome of the dealer’s turn.

The result of each of the player’s hands forms the output of this

method. Each list item should correspond to a Hand in

PlayerHands.

Hit

Double

Stand

Surrender

Split

Acts out any steps necessary for the player to execute the chosen

action for the chosen Hand (if applicable).

For example, Hit(0) would cause the player to be dealt a new card

into their first Hand.

CanHit

CanDouble

CanStand

CanSurrender

CanSplit

Returns true if it is currently possible for the player to perform the

chosen action for the chose Hand (if applicable).

CanPlayerPlay

Returns true if it is possible for the player to do anything

Returns false if the player can do nothing (indicating that the

dealer should now play).

This method is not tested by the unit tests.

ITD121 – TP3 2018 (updated Jan 20, 2018) Page 6 of 6

GUI Functionality

The Blackjack logic class is designed to tightly control the

game logic and store the game data. The GUI is simply a way

to view this data and to make requests to the Blackjack class

when needed. For this reason, the GUI should NOT contain

any private or public class variables.

Once all the you have some of the Blackjack UML complete,

and you can successfully pass the unit tests for part A and B,

you can begin to implement and test GUI functionality to

make the game interactive.

The code design of your GUI has not been defined – it is up to

you to do this (no UML diagrams). However, it is important

that your GUI meets the following requirements:

Blackjack_Form should not contain any class

variables (private or public).

It must be possible to play a multiple rounds of of

Blackjack against the computer.

It must not be possible for the user to crash the

program.

It must not be possible for the user to break the rules of the game.

It must be easy for the user to understand what is happening at all times. You can assume that the

user already understands the rules of Blackjack.

Video Demonstrations

If you would like to see a working version of the game in action for you reference, see the Card Games

assessment folder on Blackboard.


站长地图