Array
This commit is contained in:
parent
745a3e2df8
commit
2f5c37d84d
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"imports": {
|
||||
"readline-sync": "npm:readline-sync@^1.4.10"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"version": "4",
|
||||
"specifiers": {
|
||||
"npm:readline-sync@^1.4.10": "1.4.10"
|
||||
},
|
||||
"npm": {
|
||||
"readline-sync@1.4.10": {
|
||||
"integrity": "sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw=="
|
||||
}
|
||||
},
|
||||
"workspace": {
|
||||
"dependencies": [
|
||||
"npm:readline-sync@^1.4.10"
|
||||
]
|
||||
}
|
||||
}
|
19
index.ts
19
index.ts
|
@ -1,8 +1,20 @@
|
|||
class Personagem{
|
||||
nome: string;
|
||||
raro: boolean;
|
||||
num_constelaçao: number;
|
||||
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(){
|
||||
|
@ -29,8 +41,7 @@ function main(){
|
|||
}
|
||||
}
|
||||
}
|
||||
function create(){
|
||||
console.log("Criando. . .");
|
||||
function create(nome: string, raro: boolean, best_const: number){
|
||||
}
|
||||
|
||||
function read(){
|
||||
|
@ -45,4 +56,6 @@ function del(){
|
|||
console.log("Deletando. . .");
|
||||
}
|
||||
|
||||
|
||||
|
||||
main()
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
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() {
|
||||
if (personagens.length === 0) {
|
||||
alert("Nenhum personagem para atualizar.");
|
||||
return;
|
||||
}
|
||||
|
||||
let list = "Escolha um personagem para atualizar:\n";
|
||||
personagens.forEach((personagem, index) => {
|
||||
list += `${index + 1}. ${personagem.nome}\n`;
|
||||
});
|
||||
|
||||
const index = parseInt(prompt(list) || '0') - 1;
|
||||
|
||||
if (index < 0 || index >= personagens.length) {
|
||||
alert("Índice inválido.");
|
||||
return;
|
||||
}
|
||||
|
||||
const nome = prompt(`Novo nome para ${personagens[index].nome} (deixe vazio para não alterar): `);
|
||||
if (nome) {
|
||||
personagens[index].nome = nome;
|
||||
}
|
||||
|
||||
const raro = confirm(`O personagem ${personagens[index].nome} é raro? (OK para Sim, Cancelar para Não): `);
|
||||
personagens[index].raro = raro;
|
||||
|
||||
const best_const = parseInt(prompt(`Nova constelação para ${personagens[index].nome} (1-6): `) || '1');
|
||||
if (best_const >= 1 && best_const <= 6) {
|
||||
personagens[index].best_const = best_const;
|
||||
alert(`Personagem ${personagens[index].nome} atualizado com sucesso!`);
|
||||
} else {
|
||||
alert("Constelação inválida.");
|
||||
}
|
||||
}
|
||||
|
||||
function del() {
|
||||
if (personagens.length === 0) {
|
||||
alert("Nenhum personagem para excluir.");
|
||||
return;
|
||||
}
|
||||
|
||||
let list = "Escolha um personagem para excluir:\n";
|
||||
personagens.forEach((personagem, index) => {
|
||||
list += `${index + 1}. ${personagem.nome}\n`;
|
||||
});
|
||||
|
||||
const index = parseInt(prompt(list) || '0') - 1;
|
||||
|
||||
if (index < 0 || index >= personagens.length) {
|
||||
alert("Índice inválido.");
|
||||
return;
|
||||
}
|
||||
|
||||
const confirmacao = confirm(`Tem certeza que deseja excluir ${personagens[index].nome}?`);
|
||||
if (confirmacao) {
|
||||
personagens.splice(index, 1);
|
||||
alert("Personagem excluído com sucesso!");
|
||||
} else {
|
||||
alert("Exclusão cancelada.");
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
Loading…
Reference in New Issue