fla-final/index1.ts

84 lines
2.0 KiB
TypeScript

class Personagem {
nome: string;
raro: boolean;
best_const: number;
constructor(nome: string, raro: boolean, best_const: number) {
this.nome = nome;
this.raro = raro;
this.best_const = best_const;
}
}
const personagens: Personagem[] = [
new Personagem("Xiangling", false, 4),
new Personagem("Xingqiu", false, 3),
new Personagem("Dehya", true, 5)
];
function main() {
const menuPrincipal = `
1. Criar
2. Listar
3. Atualizar
4. Excluir
5. Sair
Selecione uma opção: `;
let option: number;
while (true) {
option = parseInt(prompt(menuPrincipal) || '5');
if (option === 5) break;
if (option === 1) {
create();
} else if (option === 2) {
read();
} else if (option === 3) {
update();
} else if (option === 4) {
del();
} else {
alert("Opção inválida, tente novamente.");
}
}
}
function create() {
const nome = prompt("Digite o nome do personagem: ");
const raro = confirm("O personagem é raro? (OK para Sim, Cancelar para Não): ");
const best_const = parseInt(prompt("Digite o melhor constelação (1-6): ") || '1');
if (nome && best_const >= 1 && best_const <= 6) {
const novoPersonagem = new Personagem(nome, raro, best_const);
personagens.push(novoPersonagem);
alert(`Personagem ${nome} foi criado com sucesso!`);
} else {
alert("Entrada inválida. Tente novamente.");
}
}
function read() {
if (personagens.length === 0) {
alert("Nenhum personagem na lista.");
} else {
let list = "Listando Personagens...\n";
personagens.forEach((personagem, index) => {
list += `${index + 1}. Nome: ${personagem.nome}, Raro: ${personagem.raro ? "Sim" : "Não"}, Constelação: ${personagem.best_const}\n`;
});
alert(list);
}
}
function update() {
}
function del() {
}
main();