From 8dc914e5e69e064be1153d4c947110f2540c441a Mon Sep 17 00:00:00 2001 From: serxoz Date: Tue, 13 Sep 2022 18:57:19 +0200 Subject: [PATCH] inventario --- src/player.rs | 21 +++++++++++++++++++++ src/rlib.rs | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/player.rs b/src/player.rs index bf6c9a1..e26e161 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,5 +1,26 @@ +use crate::objects::get_objects; + pub struct Player { pub tag: String, pub name: 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 +} diff --git a/src/rlib.rs b/src/rlib.rs index 9dcb0bf..a949860 100644 --- a/src/rlib.rs +++ b/src/rlib.rs @@ -1,6 +1,6 @@ use std::io::{self, Write}; use crate::rlocation::{execute_go, execute_look}; -use crate::player::Player; +use crate::player::{Player, execute_inventory}; use crate::objects::{execute_search, execute_pick}; pub struct Command { @@ -58,6 +58,7 @@ pub fn update_state(player: &mut Player, command: &Command) -> String { "o" => output = execute_go(player, "o"), "buscar" => output = execute_search(player), "coger" => output = execute_pick(player, command.noun.as_str()), + "inventario" => output = execute_inventory(player), _ => output = format!("No se como hacer eso."), }