Chinese Checkers, so called Trylma, is a classic strategy board game which can be played by two, three, four or six people at once. The game takes place on the hexagram board. Objective is to get all your marbles into oposite corner. More info here.
This game is written in a client-server model. There are a few design patterns used in this project: Singleton, Mediator, Observer and Abstract Factory. All of them are described below in corresponding sections where they were used.
-
One of the primary goals was to make simple and easily usable representation of board and fields on it. Fields are expressed by two co-ordinates and current color. First coordinate is number of row and the second is order in given diagonal. All the fields are added to Array List, our board representation. All of the classes representing rules and board are in
modelpackage.The biggest issue here is generating different board for different number of players. This is where Abstract Factory design pattern do the job. There is abstract product - class
AbstractBoard, which contains methods to generate center and all corner areas. This class is extended by concrete products - boards with given number of players, which contains concrete cases generating some corners in given colors by using inheritated methods. For all board types there is concrete Factory class, for exampleFourPlayersBoardGeneratorwhich is responsible for initiating whole board, this classes are implementingBoardGeneratorinterface, so reffering by interface makes possible deciding which board to initiate in the run time. -
Server is written using sockets. There is main server socket which is waiting for clients to connect. For each connected client there is separate thread(
Playerclass), responsible for getting input and sending output to a given client socket. Here I used Mediator and Observer design patterns allow different clients to comunicate with each other and to flow messages both ways beetween server and clients.DefaultGameRoomis a mediator class which have an array of all clients threads and method which is parsing input from given thread and executing sepcified behavior and then sending proper messeges to some threads.Playeris an observer class which contains client socket and waits for some IO on it, and if given socket is sending message it is transffered to a mediator parser-class. Observer has also method to asynchronously send message to a client from a mediator. -
Client is written in JavaFX. There is simple graphical interface, very goodlooking interface was not the main purpose of the project. Client imports files from model package and whole board is generated from the same board representation as in the first paragraph.
