Interface IX
Home Up Interface I Interface II Interface III Interface IV Interface V Interface VI Interface VII Interface VIII Interface IX Interface X Interface XI Interface XII Code

 

Having covered many of the fundamentals of user interfaces during the previous eight lessons, it is now time to once again turn out attention to Color Belot.  In today's lesson, we will examine changes to the seven files that were used in the text-based application version.  During lessons 10, 11, and 12, the two new files that were added are covered.  It is primarily in these new files where user interface concepts are implemented.

Belot.java

This file is no longer needed.  It used to serve as the main program for the text-based application.  Now that the application has been converted to an applet, the file Interface.java (to be covered in lessons 10, 11, and 12) serves as the main program.

BelotConstants.java

Comments with the word "interface" appear to the right of all lines of code in this (and subsequent) files that represent changes from the previous solution.  Two new constants ("NUMBER_ROWS" and "NUMBER_COLUMNS") are added at the top of the file.  Each (row, column) coordinate represents a rectangular drawing surface in the user interface. 

At the bottom of the file are four additional constants. "PLAYER_1", "PLAYER_2", and "NO_ONE" are used to indicate who dealt, who called trump, who won the last trick, etc.  The final constant, "POINTS_TO_WIN" indicates the total number of points that a player must accumulate to win a game of Color Belot.  Because the previous version of the program only played one hand of Color Belot randomly, these constants were not needed.

Card.java

In this file, the "java.awt.*" library is imported so that images can be associated with each individual card.  At the bottom of the file, the "getImage" (reader) and "setImage" (writer) methods appear, and an "Image" field is added to the class.

Cards.java

Only two changes were made to this file.  First, the "shuffle" method was modified to set "currentPosition" to zero.  Since the previous version of the program only played one hand of cards, this reset was not necessary.  When more than one hand of cards is played though, this allows us to play with a complete deck of cards on each deal.

The other change is that a "getCard" method has been added to allow the interface to retrieve a particular card.

RunInfo.java

No changes were made to this file.

Player.java

Most of the changes to this file revolve around the fact that the program now allows an entire game of Color Belot to be played, instead of just one random hand.  To this end, the constructor sets "totalPoints" (the total number of points that a player has earned; 500 wins the game) to zero.  The "resetHand" is a new method that resets a player's number of cards, raw points for the game, and converted points for the game.

To make "totalPoints" useable, a reader method ("getTotalPoints"), a writer method  ("setTotalPoints"), and a method that adds to the current number of "totalPoints" ("addTotalPoints") are all added to the file.

Since the number of cards that a player holds during a game changes, a reader ("setNumberCards") and a writer ("getNumberCards") are added to the class to enforce data encapsulation.

Finally, the data field "totalPoints" is added to the class and the data fields "rawGamePoints" (the number of raw points that a player has earned during one game) and "convertedGamePoints" (the number of points that the raw points are worth) are renamed to make their names more meaningful.

Game.java

This file contains quite a few changes.  A "selectDealer" is added so that the deal will alternate back and forth between the two players.

In the "dealFiveCards" method, both players' hands are reset.  (Remember that the previous version of the program only played one hand randomly.)

The "callTrump" method has been modified by adding parameters that tell "who" has called trump and "what" they have called.

A "startPlay" method has been added.  Each player initially has won no tricks.  The number of tricks won is important for scoring bonuses at the end of one round of Color Belot.

The methods "getComputerLead" and "getComputerFollow" allow the main program to easily find out what card the computer player wants to play, depending on whether the computer player is leading or must follow what the human player has led.

The "checkLegalPlay" play ensures that the human player is selecting a legal card to play.  This is called anytime the computer player has led.  The method checks that the suit led is followed, if this is possible.

The "assignPlayerCard" method sets the appropriate slot in the "cards" array to the card that the player has just played.

The "determineWinner" method looks at the "cards" array to determine who has won the last trick.

The "finishPlay" method is called when all eight cards in the current round of Color Belot have been played.  It gives the winner of the final trick a 10 point bonus.  It also checks to see if the winner of the final trick won all of the tricks.   In this event, the winner of the final trick scores a 100 points bonus and gets credit for all of the points that the other person scored.  The other person's score is set to zero.

The "getBelotCards" method is a reader that returns the 28 card "belotCards" array.  The "getPlayer" method is a reader that returns the "Player" instance corresponding to the "whichOne" parameter.  The "getTrump" method is a reader that returns a string representation of trump.  The "getCaller" method is a reader that returns a string representation of the player who called trump.  The "getDealer" method is a reader that returns a string representation of the player who dealt.  The "getDealerNumber" method is a reader that returns an integer representing the player who dealt.  The "getFlippedCard" method is a reader that returns the card that is flipped over after both players are dealt cards.  The "getWhoseTurn" method is a reader that returns an integer indicating whose turn it is to lead a card.  The "getNumberCards" method is a reader that returns how many cards are left in each player's hand.  The "setNumberCards" method is a writer that sets the number of cards that are left in each player's hand.

Finally, three new data fields are added to the "Game" class.  The "cards" array holds each of the player's played cards on the current trick.  The "otherPlayer" variable is an integer representing the other player.  The "wins" array keeps track of how many tricks (out of eight) that each of the players has won.