HomeProjectsContactGitHub

Jokemon

Repository

In this project I created a 2D console based game with Java. The game is inspired by Pokémon but it's really limited regarding gameplay.

Jokemon screenshot

GameState Class

The GameState class is used to store all the data related to the current game, such as the player's level, position, and their Jokemons. This class is serializable, which allows it to be saved and loaded from a file.

1public class GameState implements Serializable {
2    private int seed;
3    private int playerLevel;
4    private int playerCoins;
5    private int playerTreats;
6    private int[] playerPosition;
7    private int playerDirection;
8
9    private List<JokemonData> playerJokemons;
10    private List<JokemonData> jokemons;
11    private List<WildJokemonData> wildJokemons;
12
13    public GameState(int seed, int playerLevel, int playerCoins, int playerTreats, int[] playerPosition,
14      int playerDirection, List<JokemonData> jokemons, List<WildJokemonData> wildJokemons) {
15
16        this.seed = seed;
17        this.playerLevel = playerLevel;
18        this.playerCoins = playerCoins;
19        this.playerTreats = playerTreats;
20        this.playerPosition = playerPosition;
21        this.playerDirection = playerDirection;
22        this.jokemons = jokemons;
23        this.wildJokemons = wildJokemons;
24    }
25}

Building Abstract Class

The Building class is an abstract class that defines the common properties and methods for all buildings in the game. It uses an enum to define the different building types.

1public abstract class Building {
2    // Enum for different building types
3    public enum BuildingType {
4        MEDICAL,
5        SHOP,
6        HOUSE,
7        OUTSIDE
8    }
9
10    // Common properties
11    protected int centerX;
12    protected int centerY;
13    protected BuildingType buildingType;
14    protected boolean canEnter;
15    protected char[][] design;
16
17    // Constructor for the abstract class
18    public Building(int centerX, int centerY, BuildingType buildingType, boolean canEnter, char[][] design) {
19        this.centerX = centerX;
20        this.centerY = centerY;
21        this.buildingType = buildingType;
22        this.canEnter = canEnter;
23        this.design = design;
24    }
25
26    // Getter for the Design of the abstract class
27    public char[][] getBuildingDesign() {
28        return design;
29    }
30}

Java 21 Feature Demonstration: Pattern Matching for switch

To verify the syntax highlighting and Java 21 compatibility, here is a snippet using pattern matching for switch, introduced as a standard feature in Java 21.

1public String getBuildingDescription(Building building) {
2    return switch (building) {
3        case MedicalBuilding m -> "A medical facility located at (" + m.centerX + ", " + m.centerY + ")";
4        case ShopBuilding s -> "A shop where you can buy items";
5        case HouseBuilding h -> "A private residence";
6        default -> "An unknown building type";
7    };
8}