by Luke Ashford and George Wright: Y9 Age ~14
Luke and George's card games project will have a GUI front end, but this console version is good for testing purposes. We first selected part of the project and made slight changes so that it would compile successfully in RemObjects C#. We then used the Oxidizer facility in Oxygene within Visual Studio to convert most of the C# code to Pascal syntax and then made a few manual adjustments where necessary. See both the C# source code and our Oxygene for .Net version on the following pages.
We omitted the unit testing of the card library, which requires an extension to Visual Studio. Our small changes included (1) numbering players from 1 to 3 instead of 0 to 2, (2) keeping the same player numbers after one is eliminated and (3) resetting the score of each player to zero for each hand.
Gameplay and Rules
The software makes it easy to play; each valid card is prefixed with a number so you just type the number of the card that you select. This screenshot shows an example.
The rules of this version of knock-out whist are as follows.
- Three players are dealt 7 cards each from a shuffled pack for the first hand.
- The trump suit for the hand is selected randomly.
- Each player after the first must follow suit if possible and can decide to play a trump only if he/she cannot follow suit.
- The highest card of the led suit wins the trick unless at least one trump is played, in which case the highest trump wins the trick. Aces are high.
- Player 1 plays the first card and thereafter the winner of the previous trick in the hand plays the first card. If Player 1 has been eliminated, Player 2 plays the first card of the hand.
- A player scoring no tricks in a hand is a loser of the hand. A single loser is eliminated. If there is more than one loser, one is selected at random to be eliminated.
- The number of cards in a hand decreases by 1 until (if no winner emerges before then) each player is dealt only one card.
- each trick is reported to be won by the correct player, paying special attention to trumping;
- no two players have the same card in their hand at any time;
- each player is shown with the correct cards remaining after playing each card;
- the appropriate player plays the first card in each trick;
- players are eliminated appropriately when they have scored no tricks;
- the number of cards in a hand decreases by one from seven to one if the game lasts that long.
The application is most impressive for its technical features, which include:
- careful planning with a universal card library;
- thorough comments;
- object-oriented code;
- excellent use of inheritance;
- use of interfaces;
- redefined operators for comparing cards;
- advanced use of generics;
- use of enums;
- use of LINQ with lambda expressions (in the WhistPlayer class);
- validation, with specific error messages.
Conversions from Microsoft C#
We moved AddPlayer methods from within the generic structure to derived classes in order to achieve success with the RemObjects C# solution. (In the later version 184.108.40.2067 of RemObjects C# the compiler bug has been fixed). In general, Oxidizer converted well from C# to Oxygene but it did insert unnecessary begin/end pairs which we removed to make the code more concise. More importantly, we needed to insert some crucial spaces in order to enable the Oxygene code to compile.
Structure of Solution
The CardGames and CardLibrary are library projects and compile to CardGames.dll and CardLibrary.dll, respectively. CardGames needs CardsLibrary.dll to be added as a reference and the ConsoleTesting application needs both libraries. The Visual Studio enclosing solution contains the three projects. After making changes, it is reassuring to select menu item in order to compile the latest version of all of the source code.
Follow the links below to the source code (in RemObjects C# and Oxygene for .Net) and to the project files and license.