An implementation of Durak - a popular Russian card game where players aim to avoid being the last one holding cards, using strategy and clever defense to outwit their opponents.
Documentation for all important interfaces and classes can be found here.
The project consists of different components, with each having its own package.
src/main/scala/model
: Contains the data models for the game, such asStatus
,Player
, andCard
.src/main/scala/controller
: Contains theController
class which contains business logic.src/main/scala/view/gui
: Contains the GUI implementation using JavaFX.src/main/scala/view/tui
: Contains the TUI implementation.src/main/scala/util
: Contains utility classes, including theObserver
trait for the observer pattern.src/main/scala/view/tui/runner
: Contains theRunner
classes for handling user input in the TUI.
The project follows a Model-View-Controller Architecture
-
Model (
src/main/scala/model
):- This package contains the data models for the game, such as
Status
,Player
, andCard
. - These classes represent the core entities and their relationships within the game.
- Example classes:
Card
,Player
,Deck
,Turn
.
- This package contains the data models for the game, such as
-
View (
src/main/scala/view
):- This package contains the user interface implementations.
- It is divided into two sub-packages:
gui
(Graphical User Interface using JavaFX) andtui
(Text User Interface). - The view components interact with the
Controller
to display the current state of the game and to send user actions to the controller. - Example classes:
Gui
,Tui
.
-
Controller (
src/main/scala/controller
):- The
Controller
class contains the business logic and state. - It stores a
Status
instance which contains the state of the game and is updated using the controller's methods. Changes are presented to the view using the observer pattern. - Key methods include
initialize
,attack
,defend
,pickUp
,undo
,redo
,load
, andsave
.
- The
-
Initialization:
- The game starts by initializing the controller, which sets up the initial game state and creates the necessary model objects like an empty status.
- Next, the GUI and TUI are started and the game begins.
-
User Interaction:
- In the TUI, the user interacts with the game by entering commands in the console.
- In the GUI, the user interacts with the game through buttons and other UI elements.
- The view captures these interactions and sends them to the controller.
-
Business Logic:
- The controller processes user actions and updates the state accordingly.
- For example, when a user attacks, the controller updates the state to reflect the attack and checks if themove is valid.
-
Updating the View:
- The controller uses the observer pattern to notify the view of changes in the model.
- The view then updates the display to reflect the current state based on the state stored in the controller.
-
Ending the Game:
- The game ends when there is only one player left with cards, and that player is declared the loser (Durak).
- When a view is updated by the controller, it checks whether the game is over using methods provided by the controller.
This structure ensures a clear separation of concerns, with the models containin and handling data, the controller managing logic,and the view providing the user interface.
- Java 11 or higher
- sbt (Scala Build Tool)
- ScalaFX (for GUI support)
-
Clone the repository:
$ git clone
-
Change into the project directory:
$ cd durak
-
Run the application using sbt:
$ sbt "run"
A more convenient way as of installing all dependencies locally is to use the provided Docker image.
- Docker
- xMing (for GUI support)
-
Start XMing on your local machine
-
Build the Docker image:
set DOCKER_BUILDERKIT=1 docker build -t durak .
-
Run the Docker container:
docker run durak