-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logger completed, needs redesign with action types
- Loading branch information
Showing
5 changed files
with
163 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
export abstract class Action{ | ||
name: string | ||
|
||
constructor(name:string){ | ||
this.name = name; | ||
} | ||
} | ||
|
||
export class Attack extends Action{ | ||
constructor(){ | ||
super("default attack") | ||
} | ||
} | ||
|
||
export class AbilityAttack extends Action{ | ||
constructor(name: string){ | ||
super(name) | ||
} | ||
} | ||
|
||
export class Ability extends Action{ | ||
constructor(name: string){ | ||
super(name) | ||
} | ||
} | ||
|
||
export class State extends Action{ | ||
constructor(name: string){ | ||
super(name) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,107 @@ | ||
import { Player, ActionResult } from './player'; | ||
import { Player, ActionResult, StateChange } from './player'; | ||
|
||
export class ConsoleLogger { | ||
player1: Player; | ||
player2: Player; | ||
isEnabled: boolean; | ||
player1: Player; | ||
player2: Player; | ||
isEnabled: boolean; | ||
|
||
constructor(player1: Player, player2: Player, enable: boolean) { | ||
this.player1 = player1; | ||
this.player2 = player2; | ||
this.isEnabled = enable; | ||
} | ||
constructor(player1: Player, player2: Player, enable: boolean) { | ||
this.player1 = player1; | ||
this.player2 = player2; | ||
this.isEnabled = enable; | ||
} | ||
|
||
public startLog() { | ||
if (this.isEnabled) { | ||
console.log( | ||
'(%s) %s vs (%s) %s', | ||
this.player1.constructor.name, | ||
this.player1.name, | ||
this.player2.constructor.name, | ||
this.player2.name, | ||
); | ||
public startLog() { | ||
if (this.isEnabled) { | ||
console.log( | ||
'(%s) %s vs (%s) %s', | ||
this.player1.constructor.name, | ||
this.player1.name, | ||
this.player2.constructor.name, | ||
this.player2.name, | ||
); | ||
} | ||
} | ||
} | ||
|
||
public actionLog(attacker: Player, input: ActionResult) { | ||
if (this.isEnabled) { | ||
const defender = this.player1 === attacker ? this.player2 : this.player1; | ||
if (input.actionName === 'default attack') { | ||
console.log( | ||
'(%s) %s наносит урон %d противнику (%s) %s', | ||
attacker.constructor.name, | ||
attacker.name, | ||
input.damage, | ||
defender.constructor.name, | ||
defender.name, | ||
); | ||
} else { | ||
if (input.damage !== 0) { | ||
console.log( | ||
'(%s) %s использует (%s) и наносит урон %d противнику (%s) %s', | ||
attacker.constructor.name, | ||
attacker.name, | ||
input.actionName, | ||
input.damage, | ||
defender.constructor.name, | ||
defender.name, | ||
); | ||
} else { | ||
console.log( | ||
'(%s) %s использует (%s) на противнике (%s) %s', | ||
attacker.constructor.name, | ||
attacker.name, | ||
input.actionName, | ||
defender.constructor.name, | ||
defender.name, | ||
); | ||
public actionLog(attacker: Player, input: ActionResult) { | ||
if (this.isEnabled) { | ||
const defender = this.player1 === attacker ? this.player2 : this.player1; | ||
switch (input.action.constructor.name) { | ||
case "Attack": | ||
console.log( | ||
'(%s) %s наносит урон %d противнику (%s) %s', | ||
attacker.constructor.name, | ||
attacker.name, | ||
input.damage, | ||
defender.constructor.name, | ||
defender.name, | ||
); | ||
break; | ||
case "AbilityAttack": | ||
console.log( | ||
'(%s) %s использует (%s) и наносит урон %d противнику (%s) %s', | ||
attacker.constructor.name, | ||
attacker.name, | ||
input.action.name, | ||
input.damage, | ||
defender.constructor.name, | ||
defender.name, | ||
); | ||
break; | ||
case "Ability": | ||
console.log( | ||
'(%s) %s использует (%s) на противнике (%s) %s', | ||
attacker.constructor.name, | ||
attacker.name, | ||
input.action.name, | ||
defender.constructor.name, | ||
defender.name, | ||
); | ||
break; | ||
case "State": | ||
if (input.action.name === 'frozen') { | ||
console.log( | ||
'(%s) %s заморожен и не может двигаться', | ||
attacker.constructor.name, | ||
attacker.name | ||
); | ||
} | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public endLog(defeated: Player) { | ||
if (this.isEnabled) { | ||
console.log('(%s) %s погибает', defeated.constructor.name, defeated.name); | ||
public stateLog(player: Player, input: StateChange) { | ||
if (this.isEnabled) { | ||
if (input.action.name === "unfrozen") { | ||
console.log( | ||
'(%s) %s разморожен и готов атаковать', | ||
player.constructor.name, | ||
player.name | ||
); | ||
} | ||
} | ||
} | ||
|
||
public endLog(defeated: Player) { | ||
if (this.isEnabled) { | ||
console.log('(%s) %s погибает\n', defeated.constructor.name, defeated.name); | ||
} | ||
} | ||
} | ||
|
||
public logCurrentTournament(players: Array<Player>) { | ||
if (this.isEnabled){ | ||
console.log("\n В турнире участвуют \n") | ||
for (let i = 0; i < players.length; i++) { | ||
console.log(players[i].name, " ") | ||
public logCurrentTournament(players: Array<Player>) { | ||
if (this.isEnabled && players.length > 0) { | ||
if (players.length > 1) { | ||
console.log("\nВ турнире участвуют \n") | ||
for (let i = 0; i < players.length; i++) { | ||
console.log(players[i].name, " ") | ||
} | ||
} else { | ||
console.log("\nВ турнире побеждает \n") | ||
console.log(players[0].name, " ") | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters