Klifu / klifu

🎮🎯 A turn-based online multiplayer pokemon game, Influenced by pokemon red and pokemon go.
MIT License
3 stars 3 forks source link

Core library design #27

Open Souvikns opened 3 years ago

Souvikns commented 3 years ago

I am mainly opening this issue for brainstorming the design of the core library. I would like to give a brief introduction to what the core library aims to solve, what we have in plan for it.

Introduction

The main idea behind creating the core library was to have a library that has the complete game logic of klifu. We intend on making the core library in such a way that anyone can build a game client on top of this, very easily. We are fetching the game data like the pokemon list from our API.

Functionalities

As of now, these are the supported functionalities

Suitable Architecture

In our core library there are static constant data, like pokemon list, move list, CPM table, and many more which will never change in the runtime, but will be used as a lookup table. Then there is code that uses this lookup table to actually perform some logic like to calculate damage in a battle.

If we follow MVC pattern then the core is mode and controller, it is being made to be consumed by the view which is our CLI. So in that regard core has to provide complete support for the game logic which includes.

Souvikns commented 3 years ago

As of now, we have a service to load pokemon data from the API. It's fine to have services but for the users, there should be suggestive functions or a master class to access the data. I think it would be best to have something like this.

Pokedex class

To get the data of all the pokemons and moves in the game. This class will only provide static data and nothing else.

Battle Class

To create custom battle instances where there is will be all the battle logic for different battle modes.

User Class

This class will have all the functions to level up pokemon check user level and all other things.

Souvikns commented 3 years ago

After putting some thought I came up with two designs for the library. First off I need to clear some things out.

Some Problems that we face

The library currently works with some custom data like the pokemon list and move list. As the library takes these two parameters, the library will work on a custom pokemon list and moves list making it very easy to change. But now this library needs to load these variables from somewhere else. So before using any other functions in the library it first needs to load the data.

First option where we export a single class.

import { Klifu } from './klifu';

const klifu = new Klifu();

console.log(klifu);

const pokedex = klifu.pokedex();

console.log(pokedex);

Second option where we import only the things we need


import {Pokedex} from './klifu/pokedex';

const pokedex = Pokedex().load();
Souvikns commented 3 years ago

Was trying something and this feels way natural

interface PokemonInterface {
    readonly id: number,
    readonly name: string
};

class Pokemon implements PokemonInterface {
    constructor(
        readonly id: number,
        readonly name: string
    ){}

    attack(move: string){
        console.log(`${this.name} used ${move}`);
    }
}

const bulbasur = new Pokemon(1, 'Bulbasuar');
bulbasur.attack('solar beam');

There is a clash in types as there is one static pokemon object that we are loading from the API, which does not have any individual values and another Pokemon object that we are generating for the game with individual values. If we divide