Skip to content

mlrlouis/Kniffel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kniffel (Yahtzee) - Java Swing Application

Java GUI Architecture

About The Project

This project is a fully functional implementation of the popular dice game Kniffel (Yahtzee), built with Java.

It demonstrates strong Object-Oriented Programming (OOP) principles by separating game logic, rule validation, and user interface. The project features a dual-interface approach: the core logic powers both a classic Console Application and a graphical Desktop GUI built with Java Swing.

Key Features

  • Graphical User Interface (GUI): Interactive window with buttons and visual dice representation using javax.swing.
  • Complete Ruleset: Implements all standard Kniffel rules (Full House, Straights, Kniffel, Bonus calculations).
  • Rule Engine: A dedicated static utility class (KniffelRules) handles complex score validation independently of the UI.
  • State Management: Holds logic for re-rolling specific dice and tracking game rounds.

Architecture

The code is organized into a modular package structure in src/kniffel/.

src/kniffel/
├── Dice.java           # Model: Manages the state of the 5 dice (values, hold status).
├── Scoreboard.java     # Model: Tracks scores for all 13 categories (Upper/Lower section).
├── KniffelRules.java   # Logic: Static Utility class to calculate points (e.g., checks for Full House).
├── KniffelGame.java    # Controller (Console): Runs the text-based version of the game.
└── KniffelVisual.java  # View/Controller (GUI): Runs the Swing-based graphical version.

Technical Breakdown

  • Encapsulation: The Dice class encapsulates the random number generation and the "hold" mechanism, protecting the internal array state.

  • Static Logic: KniffelRules contains purely functional static methods (isFullHouse, calculateSum), making the logic testable and reusable for both the Console and GUI versions.

  • Event Handling: The GUI utilizes ActionListener inner classes to handle user inputs like rolling dice or selecting categories.


How to Run

Prerequisites

  • Java Development Kit (JDK) 17 or higher installed.

Installation & Execution

  1. Clone the repository
git clone [https://github.com/mlrlouis/Kniffel.git](https://github.com/mlrlouis/Kniffel.git)
  1. Navigate to the project directory
cd Kniffel
  1. Compile the source code
javac -d bin src/kniffel/*.java
  1. Run the Game

    • To run the GUI Version (Recommended):

      java -cp bin kniffel.KniffelVisual
    • To run the Console Version:

      java -cp bin kniffel.KniffelGame

Controls (GUI)

  1. Roll Dice: Click to roll. You have 3 rolls per round.

  2. Hold Dice: Click "Würfel behalten" and enter the numbers (1-5) of the dice you want to keep (e.g., "1 4 5").

  3. Select Category: Choose a scoring category from the dropdown menu and click "Kategorie auswählen" to lock in your score.

(back to top)

About

First small project from the first semester that is finished

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages