-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roman_Levin
committed
Jan 6, 2025
1 parent
025c4d9
commit ee0b49d
Showing
8 changed files
with
111 additions
and
35 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
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
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { knight } from "./heroClasses/knight"; | ||
import { archer } from "./heroClasses/archer"; | ||
import { mage } from "./heroClasses/mage"; | ||
import { Weapon } from "./weapon"; | ||
import { Player } from "./playerClass/player"; | ||
|
||
|
||
export function randomNumber(min: number, max: number): number { | ||
return Math.floor(Math.random() * (max - min + 1)) + min; | ||
} | ||
|
||
export class characterGenerator { | ||
private knightNames: string[] = ["ChaosKnight", "DragonKnight", "Fighter", "GorillaWarrior", "JohnWick"]; | ||
private archerNames: string[] = ["Legolas", "Robin", "SokolEye", "ArrowMan", "Makus"]; | ||
private mageNames: string[] = ["DarkMage", "Gandalf", "Dumbledore", "SaintMage", "Wizard"]; | ||
|
||
private knightWeapons: Weapon[] = [ | ||
new Weapon("Sword", 30), | ||
new Weapon("Axe", 35), | ||
new Weapon("Rapier", 27) | ||
]; | ||
|
||
private archerWeapons: Weapon[] = [ | ||
new Weapon("Longbow", 25), | ||
new Weapon("Crossbow", 28), | ||
new Weapon("ClassicBow", 20) | ||
]; | ||
|
||
private mageWeapons: Weapon[] = [ | ||
new Weapon("Staff", 12), | ||
new Weapon("Wand", 17), | ||
new Weapon("MagickStick", 22) | ||
]; | ||
|
||
createRandomPlayer(): Player { | ||
const playerType = randomNumber(1, 3); // 1 - Knight, 2 - Archer, 3 - Mage | ||
switch (playerType) { | ||
case 1: { | ||
const name = this.knightNames[randomNumber(0, this.knightNames.length - 1)]; | ||
const weapon = this.knightWeapons[randomNumber(0, this.knightWeapons.length - 1)]; | ||
const health = randomNumber(100, 200); | ||
const statusEffect = 2; | ||
return new knight(name, health, weapon, statusEffect); | ||
} | ||
case 2: { | ||
const name = this.archerNames[randomNumber(0, this.archerNames.length - 1)]; | ||
const weapon = this.archerWeapons[randomNumber(0, this.archerWeapons.length - 1)]; | ||
const health = randomNumber(80, 150); | ||
const statusEffect = 1; | ||
return new archer(name, health, weapon, statusEffect); | ||
} | ||
case 3: { | ||
const name = this.mageNames[randomNumber(0, this.mageNames.length - 1)]; | ||
const weapon = this.mageWeapons[randomNumber(0, this.mageWeapons.length - 1)]; | ||
const health = randomNumber(60, 120); | ||
const statusEffect = 1; | ||
return new mage(name, health, weapon, statusEffect); | ||
} | ||
default: | ||
throw new Error("Invalid player type generated."); | ||
} | ||
} | ||
|
||
initializePlayers(count: number): (Player)[] { | ||
const players: (Player)[] = []; | ||
for (let i = 0; i < count; i++) { | ||
players.push(this.createRandomPlayer()); | ||
} | ||
return players; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,15 +1,17 @@ | ||
import { knight } from '../sagaCode/heroClasses/knight'; | ||
import { archer } from '../sagaCode/heroClasses/archer'; | ||
import { Weapons } from '../sagaCode/constElements'; | ||
import { mage } from '../sagaCode/heroClasses/mage'; | ||
import { game } from '../sagaCode/game'; | ||
import { randomNumber } from '../sagaCode/randomizer'; | ||
import { characterGenerator } from '../sagaCode/randomGenerator'; | ||
|
||
const player_1 = new knight('Makus', 150,Weapons.sword,false); | ||
const player_2 = new archer('Леголас', 120,Weapons.icedBow,false); | ||
const player_3 = new mage('Колдун', 110,Weapons.wizardStuff,false); | ||
// const player_1 = new knight('Makus', 150, Weapons.sword, 2); | ||
// const player_2 = new archer('Леголас', 120, Weapons.icedBow, 1); | ||
// const player_3 = new mage('Колдун', 110, Weapons.wizardStuff, 1); | ||
|
||
const randomPlayer = new characterGenerator(); | ||
const players = randomPlayer.initializePlayers(2); | ||
players.forEach(player => { | ||
console.log( | ||
`Игрок: ${player.name}, Класс: ${player.constructor.name}, Здоровье: ${player.health}, Оружие: ${player.weapon.type} (${player.weapon.damageAmount} урона), Кол-во эффектов за игру: ${player.statusEffect}`, | ||
); | ||
}); | ||
|
||
|
||
const fight = new game([player_2, player_3]); | ||
const fight = new game(players); | ||
fight.start(); |