What is the project

<aside> 🃏

UNO-Java-Game

A Java UNO card game. You can play it with a GUI (Java Swing) or in the terminal with --console. It supports 2 to 4 players, human or CPU.

</aside>

We chose UNO because we both know how to play it and the rules are clear enough to know what you need to code. It has turns, special cards with effects, and a winner condition, which is basically everything you need for a game.

The CPU is simple but ok. It tries to play action cards first. When it plays a wild, it picks the color it has the most in its hand.

Classes

Class Package What it does
Card model A card. Has a value and a color. Has a method to check if you can play it on top of the current card.
Color model Enum for the colors: RED, BLUE, GREEN, YELLOW and BLACK (black is for wild cards).
Value model Enum for the values: numbers 0 to 9, SKIP, REVERSE, DRAW_TWO, WILD and WILD_DRAW_FOUR.
Deck model The draw pile. Builds all 108 cards when you create it and shuffles them. If it runs out, it takes the discard pile and shuffles that back in.
Hand model The cards a player has in their hand right now. You can add cards, play one by position, and check if there is anything playable.
Player model A player. Has a name, a hand, and a boolean for whether it is the computer or a real person.
GameState model Stores everything about the current match: the players, the deck, the discard pile, whose turn it is, which direction the game is going, the active color, and a HashMap with how many wins each player has.
ConsoleView view All the printing and reading from the console goes here. Cards are shown with ANSI colors. There is no game logic in this class.
GameController controller Controls the flow: sets up the game, runs the turn loop, applies card effects, and calls the view and the model when needed.
FileManager utils Reads and saves scores.csv. That is basically all it does.
GUIGameController view/gui Controls the game loop in GUI mode. It runs in a background thread.
UnoGameFrame view/gui The main game window.
SetupDialog view/gui Setup screen where you pick players and the database.
CardView view/gui Draws each card using Java2D.
ColorPickerDialog view/gui Popup to pick a color after a wild.
DrawnCardDialog view/gui Asks if you want to play the card you just drew.
MusicPlayer view/gui Plays background music. You can mute it.
SoundEffect view/gui Sound effects and text-to-speech in Spanish.
BarajaDAO db Interface for saving and loading the deck.
PostgresBarajaDAO db Saves and loads the deck from PostgreSQL.
MongoBarajaDAO db Saves and loads the deck from MongoDB.
DatabaseConnection db Reads credentials from .env and connects to the database.
BarajaCatalog utils Generates the full 108-card catalog.
CartaConverter utils Converts between Card objects and DB objects.
Carta model Data class used for DB storage.
CartaNoJugableException exceptions Thrown when a card cannot be played on the current discard.
MazoVacioException exceptions Thrown when the deck runs out of cards.

How the game works

When you run it, a setup window opens. You pick how many players (2 to 4). You also choose if each one is human or CPU. You can also pick which database to use: PostgreSQL, MongoDB, or none.

Then the game starts in a window. The background is like dark green felt. Cards are drawn with Java2D. You click a card to play it.

There is background music that loops. There is a mute button. There are sound effects for each card type. It also has text-to-speech in Spanish. It says UNO and the winner.

If you get down to one card, a red UNO button appears. It has a 3-second countdown. If you miss it you draw 2 penalty cards. The CPU always calls UNO automatically.

Scores are saved in scores.csv and shown in a sidebar during the game.

Data persistence:

OOP highlights: