Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mng 82 create player class #8

Merged
merged 7 commits into from
Feb 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/playerClass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Pokemon } from "./pokemonClass";

export class Player {
private _name: string;
private _pokemons: Pokemon[];
daria305 marked this conversation as resolved.
Show resolved Hide resolved
private _indexOfActivePokemon: number;
constructor(name: string, pokemons: Pokemon[]) {
if (name.length > 8) {
throw new Error("Too long name");
}
if (pokemons.length != 3) {
throw new Error("Wrong number of pokemons");
}
this._name = name;
this._pokemons = pokemons;
this._indexOfActivePokemon = 0;
}

get name(): string {
return this._name;
}
get pokemons(): Pokemon[] {
return this._pokemons;
}

set indexOfActivePokemon(numOfActivePokemon: number) {
this._indexOfActivePokemon = numOfActivePokemon;
}
get getActivePokemon(): Pokemon {
return this._pokemons[this._indexOfActivePokemon];
}

get alivePokemons(): Pokemon[] {
daria305 marked this conversation as resolved.
Show resolved Hide resolved
const alivePokemonsTab: Pokemon[] = this.pokemons.filter((pokemon) =>
pokemon.isAlive()
);
return alivePokemonsTab;
}
}
daria305 marked this conversation as resolved.
Show resolved Hide resolved