This is HongKong

HongKong is an implementation of the classic Mahjong patience, sometimes called Shanghai. The aim is to remove pairs of matching tiles until all have gone.

It was written as a demonstration of the Toolbox features of the Basalt module.

Using HongKong

When run, HongKong installs an icon to the iconbar. This has an attached MENU with the usual Info, Help, Choices and Quit items.

Click SELECT on the icon to open the game window. This has an attached menu for some game controls, but the game is usually played by dragging a tile to a matching tile to remove them both.

If the Help application is running then there are some useful messages and the names of the tiles are shown.

If the game window has input focus (the title bar is yellow) then some game controls can be operated by keyboard shortcuts, which are shown on the game menu. If input focus is lost it can be regained by clicking on the green area of the game window.

Tiles

There are 144 Mahjong tiles:

 3 Suits of 9 tiles, 4 of each rank:

  Circles (1-9)    - representing copper coins
  Bamboos (1-9)    - actually representing strings of coins
                     1 bamboo is shown as a bird (the sparrow)
  Characters (1-9) - chinese numerals representing a myryad (Wan) of coins

 4 sets of 4 Wind tiles:

   North wind, East wind, South wind, West wind

 3 sets of 4 Dragon tiles:

   Red dragon      - a red character
   Green dragon    - not necessarily in green
   White dragon    - a blank tile with a border

 4 Seasons - any season matches any other here:

   Spring, Summer, Autumn, Winter

 4 Flowers - any flower matches any other here:

   Plum, Orchid, Bamboo, Marigold (Chrysanthemum)

Rules

The tiles are dealt in a 4-layer pile called the Turtle.

A tile in the pile is free if it is not covered by another tile and it is able to be moved left or right without disturbing another tile.

Two free tiles that match may be removed from the pile.

Tiles match if they have the same face or they are both flowers or both seasons.

The game is completed when all the tiles are removed, if this is possible.

Lower and more central tiles become free as tiles are removed, so there is some skill in the order that tiles are removed.

Operation

Matching pairs of free tiles are removed by dragging one tile to another. A free tile will appear to be picked up and move, but if it is not free it will remain in position. Tiles that are not removed will spring back into place when released.

The game menu has these options:

 Show move, shortcut UP cursor
  - highlights a randomly chosen pair of removable tiles, if there are any

 Do move, shortcut DOWN cursor
  - removes the pair of highlighed tiles

 Backward, shortcut LEFT cursor
  - steps back through the game replacing tiles that have been removed

 Forward, shortcut RIGHT cursor
  - steps forward through the game removing tiles that were replaced

 New game, shortcut COPY/END key
  - deals a new pile of tiles

Tile sets

By default HongKong uses images of classic chinese tiles without any European markings. This makes matching tiles more tricky initially, but I think it is more satisfying.

Other tile sets can be installed in the Resources.Tiles directory and it will be made available to the user in the Choices dialogue if there is also a sprite in the Resources.Sprites file.

A tile set is a Sprites file containing sprites for the 42 tile patterns and a blank tile. These must be 36 pixels wide and 54 pixels high. The names must be the same as those in the 'Traditional' default set. The sprite in the Resources.Sprites file must be a standard icon, 34 pixels by 34 pixels, which has the same name as the tile set file.

The Choices dialogue is opened from the Iconbar menu. It has a string set showing all the installed tile sets in a menu. Another set can be chosen by selecting it, but it is only used when either Set or Save buttons are clicked. A saved choice will be used when the program is next run.

Programming

The game is written using the Toolbox features of the Basalt module, v1.51b, which is included in the application. The application also checks for the necessary Toolbox modules and some other modules that may be needed on early versions of RISC OS.

The BASIC !RunImage file in the Source directory is generously annotated, but the actual !RunImage is a Basalt file that has already been translated. This is tokenised BASIC and can be viewed in the latest versions of StrongED. Do not attempt to edit this file and run it, because it will not be correctly re-tokenised.

Licence

This software may be used under the modified BSD Licence:

Copyright (c) 2012, Steve Drain, Kappa

 http://kappa.me.uk
 mailto:steve@kappa.me.uk

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
