Open Souvikns opened 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.
After putting some thought I came up with two designs for the library. First off I need to clear some things out.
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.
import { Klifu } from './klifu';
const klifu = new Klifu();
console.log(klifu);
const pokedex = klifu.pokedex();
console.log(pokedex);
import {Pokedex} from './klifu/pokedex';
const pokedex = Pokedex().load();
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
Introduction
The main idea behind creating the
core
library was to have a library that has the complete game logic ofklifu
. We intend on making thecore
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
catch battle mode
,NPC battle mode
,PVP battle mode
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.