inventario

This commit is contained in:
serxoz 2022-09-13 18:57:19 +02:00
parent 08ce45da58
commit 8dc914e5e6
2 changed files with 23 additions and 1 deletions

View File

@ -1,5 +1,26 @@
use crate::objects::get_objects;
pub struct Player { pub struct Player {
pub tag: String, pub tag: String,
pub name: String, pub name: String,
pub location: String, pub location: String,
} }
pub fn execute_inventory(player: &mut Player) -> String {
let mut output: String;
let current = &player.tag;
let objetos = get_objects(current.to_string());
if objetos.is_ok() {
output = String::from("Portas los siguientes objetos:\n");
for objeto in objetos.unwrap() {
let mut nombre = objeto.nombre;
nombre.push_str("\n");
output.push_str(&nombre);
}
} else {
output = String::from("No portas ningún objeto.")
}
output
}

View File

@ -1,6 +1,6 @@
use std::io::{self, Write}; use std::io::{self, Write};
use crate::rlocation::{execute_go, execute_look}; use crate::rlocation::{execute_go, execute_look};
use crate::player::Player; use crate::player::{Player, execute_inventory};
use crate::objects::{execute_search, execute_pick}; use crate::objects::{execute_search, execute_pick};
pub struct Command { pub struct Command {
@ -58,6 +58,7 @@ pub fn update_state(player: &mut Player, command: &Command) -> String {
"o" => output = execute_go(player, "o"), "o" => output = execute_go(player, "o"),
"buscar" => output = execute_search(player), "buscar" => output = execute_search(player),
"coger" => output = execute_pick(player, command.noun.as_str()), "coger" => output = execute_pick(player, command.noun.as_str()),
"inventario" => output = execute_inventory(player),
_ => output = format!("No se como hacer eso."), _ => output = format!("No se como hacer eso."),
} }