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 1 commit
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
25 changes: 25 additions & 0 deletions src/playerClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Pokemon } from "./pokemonClass";
export class Player {
private _name: string;
private _pokemons: Pokemon[];
daria305 marked this conversation as resolved.
Show resolved Hide resolved
private _activePokemon: number;
private _alivePokemons: Pokemon[];
constructor(name: string, pokemons: Pokemon[]) {
if (name.length > 8) {
throw new Error("Too long name");
Expand All @@ -12,11 +14,34 @@ export class Player {
}
this._name = name;
this._pokemons = pokemons;
this._activePokemon = 0;
this._alivePokemons = pokemons;
daria305 marked this conversation as resolved.
Show resolved Hide resolved
}

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

set setActivePokemon(numOfActivePokemon: number) {
this._activePokemon = numOfActivePokemon;
}
get getActivePokemon(): number {
return this._activePokemon;
daria305 marked this conversation as resolved.
Show resolved Hide resolved
}

private isAlive() {
for (let i = 0; i < this._alivePokemons.length; i++) {
if (this._alivePokemons[i].isAlive() == false) {
this._alivePokemons.splice(i, 1);
}
}
}

get alivePokemons(): Pokemon[] {
daria305 marked this conversation as resolved.
Show resolved Hide resolved
this.isAlive();
return this._alivePokemons;
}
}
daria305 marked this conversation as resolved.
Show resolved Hide resolved