Skip to content

Commit

Permalink
saga
Browse files Browse the repository at this point in the history
  • Loading branch information
busiginandrew committed Jan 24, 2025
1 parent 1a8697e commit a9247e9
Show file tree
Hide file tree
Showing 18 changed files with 1,202 additions and 6 deletions.
81 changes: 81 additions & 0 deletions rpgsaga/saga/src/classes/laba3Archer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Player } from '../laba3CreatingPlayer';
import { Logs } from '../laba3Logs';

export class Archer extends Player {
abilities: string[] = ['Огненные стрелы', 'Ледяные стрелы'];
private fireArrowsUsed: boolean = false;
private iceArrowsUsed: number = 0;
private fireArrowsDuration: number = 0;
private iceArrowsDuration: number = 0;

constructor(name: string, strength: number, health: number) {
super(name, strength, health);
}

// Метод для сброса состояния огненных стрел
public resetFireArrowsUsed(): void {
this.fireArrowsUsed = false;
this.fireArrowsDuration = 0;
}

// Метод для сброса состояния ледяных стрел
public resetIceArrowsUsed(): void {
this.iceArrowsUsed = 0;
this.iceArrowsDuration = 0;
}

useAbility(target: Player, logs: Logs): void {
const ability = this.getSelectedAbility();
if (!ability) return;

const baseDamage = this.getStrength();
target.takeDamage(baseDamage);

logs.logAbility(
this,
ability,
target,
`и наносит ${baseDamage} основного урона. ${target.getName()} теряет 3 единицы жизни следующие 2 хода`,
);

if (ability === 'Огненные стрелы' && !this.fireArrowsUsed) {
this.fireArrowsUsed = true;
this.fireArrowsDuration = 3;
} else if (ability === 'Ледяные стрелы' && this.iceArrowsUsed < 2) {
this.iceArrowsUsed++;
this.iceArrowsDuration = 3;
}
}

applyAbilityEffects(target: Player, logs: Logs): void {
this.applyArrowEffect(target, logs, 'Огненные стрелы', this.fireArrowsUsed, this.fireArrowsDuration);
this.applyArrowEffect(target, logs, 'Ледяные стрелы', this.iceArrowsUsed > 0, this.iceArrowsDuration);

if (this.fireArrowsDuration > 0) this.fireArrowsDuration--;
if (this.iceArrowsDuration > 0) this.iceArrowsDuration--;
}

private applyArrowEffect(target: Player, logs: Logs, arrowType: string, isUsed: boolean, duration: number): void {
if (isUsed && duration > 0) {
const damage = 3;
target.takeDamage(damage);
logs.logDamageOverTime(target, damage, arrowType);
}
}

public setStrength(strength: number): void {
if (strength >= 15 && strength <= 70) {
super.setStrength(strength);
} else {
throw new Error('Strength for Archer must be between 15 and 70');
}
}

public setHealth(health: number): void {
if (health >= 60 && health <= 180) {
super.setHealth(health);
} else {
throw new Error('Health for Archer must be between 60 and 180');
}
}
}
38 changes: 38 additions & 0 deletions rpgsaga/saga/src/classes/laba3Knight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Player } from '../laba3CreatingPlayer';
import { Logs } from '../laba3Logs';

export class Knight extends Player {
abilities: string[] = ['Короночка'];
private abilityUsed: boolean = false;

public resetAbilityUsed(): void {
this.abilityUsed = false;
}

useAbility(target: Player, logs: Logs): void {
const ability = this.getSelectedAbility();
if (!ability) return;

if (ability === 'Короночка' && !this.abilityUsed) {
const damage = Math.round(this.getStrength() * 1.5);
target.takeDamage(damage);
this.abilityUsed = true;
logs.logAbility(this, ability, target, `который получает ${damage} урона`);
this.setSelectedAbility(null); // Сбрасываем выбранную способность
}
}
public setStrength(strength: number): void {
if (strength >= 20 && strength <= 100) {
super.setStrength(strength);
} else {
throw new Error('Strength for Knight must be between 20 and 100');
}
}
public setHealth(health: number): void {
if (health >= 80 && health <= 200) {
super.setHealth(health);
} else {
throw new Error('Health for Knight must be between 80 and 200');
}
}
}
50 changes: 50 additions & 0 deletions rpgsaga/saga/src/classes/laba3Mage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Player } from '../laba3CreatingPlayer';
import { Logs } from '../laba3Logs';

export class Mage extends Player {
abilities: string[] = ['Оглушение', 'Лечение'];
private abilityUsed: boolean = false;

public resetAbilityUsed(): void {
this.abilityUsed = false;
}

useAbility(target: Player, logs: Logs): void {
const ability = this.getSelectedAbility(); // Используем выбранную способность
if (!ability) return;

if (ability === 'Оглушение' && !this.abilityUsed) {
target.setStunDuration(2); // Устанавливаем длительность оглушения на 2 хода
target.setIsStunned(true); // Применяем оглушение
this.abilityUsed = true;
logs.logAbility(this, ability, target, 'будет оглушен на 2 хода');

// Маг сразу атакует после применения оглушения
this.attack(target, logs);
} else if (ability === 'Лечение') {
const healAmount = 20;
this.setHealth(this.getHealth() + healAmount);
logs.logHeal(this, healAmount); // Логируем лечение
}
}

takeDamage(damage: number): void {
super.takeDamage(damage); // Всегда наносим урон, независимо от оглушения
}

public setStrength(strength: number): void {
if (strength >= 10 && strength <= 50) {
super.setStrength(strength);
} else {
throw new Error('Strength for Mage must be between 10 and 50');
}
}

public setHealth(health: number): void {
if (health >= 50 && health <= 150) {
super.setHealth(health);
} else {
throw new Error('Health for Mage must be between 50 and 150');
}
}
}
50 changes: 46 additions & 4 deletions rpgsaga/saga/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
import { taskA, taskB } from './laba1';
import { Car } from './laba2';
import { taskA, taskB } from './lab1and2/laba1';
import { Car } from './lab1and2/laba2';
import { Game } from './laba3Gameplay';
import { Optional } from './laba3Optionals';
import * as readline from 'readline';

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

// Функция для асинхронного запроса ввода пользователя
function askQuestion(question: string): Promise<string> {
return new Promise((resolve) => {
rl.question(question, (answer) => {
resolve(answer);
});
});
}

function output(answersX: number[], answersY: number[]): void {
for (let i = 0; i < answersX.length; i++) {
console.log(`x = ${answersX[i].toFixed(2)}, y = ${answersY[i].toFixed(2)}`);
}
}

function main(): void {
async function main() {
console.log("Бусыгин Андрей Михайлович");
let [xL, yL] = taskA(1.25, 3.25, 0.4);
output(xL, yL);
Expand All @@ -19,5 +36,30 @@ function main(): void {
const car1 = new Car('Toyota Corolla', 'Gasoline');
car1.setSpeed(120);
car1.displayInfo();

const optional = new Optional();

// Запрашиваем у пользователя выбор
const choice = await askQuestion('Выберите вариант создания игроков (1 - случайные, 2 - вручную): ');
let players;

if (choice === '2') {
const numberOfPlayersInput = await askQuestion('Введите количество игроков: ');
const numberOfPlayers = parseInt(numberOfPlayersInput, 10);
players = await optional.createPlayersManually(numberOfPlayers, askQuestion); // Передаем askQuestion
} else {
const numberOfPlayers = 6; // По умолчанию 6 игроков
players = optional.createRandomPlayers(numberOfPlayers);
}

const game = new Game(players);
game.start();

// Закрываем интерфейс чтения
rl.close();
}
main();

// Вызываем main
main().catch((error) => {
console.error('Ошибка:', error);
});
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a9247e9

Please sign in to comment.