- 해외축구 축구잡담
[해축백일장] FiveBigLeagues.ts
class Team {
public name: string;
public city: string;
public point: number;
public manager: string;
public players: string[];
public tactics: 'normal' | 'experimental';
constructor(name: string, city: string) {
this.name = name;
this.city = city;
this.point = 0;
this.manager = '';
this.players = [];
this.tactics = 'normal';
}
}
abstract class League {
public fixture: Team[];
public numberOfTeams: number;
constructor(teamList: Team[]) {
this.fixture = teamList;
this.numberOfTeams = teamList.length;
}
protected rank() {
this.fixture.sort((a, b) => b.point - a.point);
}
public match(homeTeam: Team, awayTeam: Team) {
const result = Math.floor(Math.random() * 3);
if (result == 0) {
homeTeam.point += 3;
} else if (result == 1) {
awayTeam.point += 3;
} else {
homeTeam.point += 1;
awayTeam.point += 1;
}
this.rank();
}
abstract finalRound(): void;
}
class PremierLeague extends League {
finalRound() {
if (this.fixture[0].manager == 'Pep Guardiola' && this.fixture[0].tactics != 'experimental')
console.log('Treble!');
}
}
class LaLiga extends League {
finalRound() {
if ((this.fixture[0].name == 'Real Madrid' || 'Barcelona')
|| (this.fixture[0].name == 'Atletico Madrid' && this.fixture[0].tactics == 'experimental')) {
console.log(`${this.fixture[0].name} is the Champion!`);
} else throw Error('Not LaLiga!');
}
}
class SerieA extends League {
finalRound() {
const minjae = this.fixture[0].players.findIndex(player => player == 'Minjae Kim')
if (minjae != -1) this.fixture[0].players.splice(minjae, 1);
}
}
class Bundesliga extends League {
finalRound() {
if (this.fixture[0].name != 'Bayern Munich') {
console.log('Assist by Jaesung Lee!');
this.fixture[0].point -= 2;
this.rank();
}
}
}
class LigueUn extends League {
finalRound() {
if (this.fixture[0].manager == 'Christophe Galtier') {
console.log('Arrested!');
this.fixture[0].manager = 'Luis Enrique';
}
}
}