diff --git a/data/save.json b/data/save.json index 94e67e3..5c7c3ad 100644 --- a/data/save.json +++ b/data/save.json @@ -6,17 +6,17 @@ }, "coordinates": { "x": 85, - "z": 17, + "z": 25, "map": "world" }, "inventory": [ [ - "axe", + "Steel Axe", 1 ], [ - "vape", - 1 + "Morphine", + 2 ] ] } \ No newline at end of file diff --git a/src/blocks.rs b/src/data.rs similarity index 72% rename from src/blocks.rs rename to src/data.rs index d511b5e..64389de 100644 --- a/src/blocks.rs +++ b/src/data.rs @@ -21,4 +21,12 @@ lazy_static! { map.insert('♣', vec![([0, 153, 51], true, "Oak Tree")]); map }; + pub static ref SKILLABLE: HashMap)>> = { + let mut map = HashMap::new(); + map.insert('D', vec![("mining", 15, vec!["Steel Pickaxe"])]); + map.insert('C', vec![("mining", 5, vec!["Bronze Pickaxe", "Steel Pickaxe"])]); + map.insert('i', vec![("mining", 10, vec!["Bronze Pickaxe", "Steel Pickaxe"])]); + map.insert('♣', vec![("woodcutting", 5, vec!["Bronze Axe", "Steel Axe"])]); + map + }; } diff --git a/src/function.rs b/src/function.rs index 5af9a3a..cd7a4c6 100644 --- a/src/function.rs +++ b/src/function.rs @@ -1,5 +1,7 @@ use std::io::{stdin,stdout,Write}; use crate::Command; +use crate::data; +use crate::Player; pub fn input() -> String{ let mut s=String::new(); @@ -23,3 +25,44 @@ pub fn clear_screen() .expect("Failed to clear screen"); } +pub fn skill_item +( + direction: char, + player: &Player, + map: &Vec>, +) +{ + let mut block: char = 'X'; + if direction == 'n' + { + block = map[(player.coordinates.z - 1) as usize][player.coordinates.x as usize]; + } + else if direction == 'e' + { + block = map[player.coordinates.z as usize][(player.coordinates.x + 1) as usize]; + } + else if direction == 's' + { + block = map[(player.coordinates.z + 1) as usize][player.coordinates.x as usize]; + } + else if direction == 'w' + { + block = map[player.coordinates.z as usize][(player.coordinates.x - 1) as usize]; + } + else + { + println!("Invalid Direction"); + } + /* + if blocks::SKILLABLE.contains_key(&block) + { + println!("Skilling {} to the {}.", blocks::BLOCKS.get(&block).unwrap()[0].2, direction); + + } + else + { + println!("Block: {} to the {} is not skillable.", blocks::BLOCKS.get(&block).unwrap()[0].2, direction); + return (); + } + */ +} diff --git a/src/main.rs b/src/main.rs index f6972e8..7c2c261 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,28 +13,33 @@ mod process_input; // process_input.rs #[macro_use] extern crate lazy_static; -mod blocks; +mod data; -pub enum GameAction { +pub enum GameAction +{ Continue, Exit, Error, } #[derive(Serialize, Deserialize, Debug)] -struct Coordinates { +struct Skills +{ + woodcutting: u64, + mining: u64, +} + +#[derive(Serialize, Deserialize, Debug)] +struct Coordinates +{ x: i16, z: i16, map: String, } -#[derive(Serialize, Deserialize, Debug)] -struct Skills { - woodcutting: u8, - mining: u8, -} #[derive(Serialize, Deserialize, Debug)] -struct Player { +struct Player +{ name: String, skills: Skills, coordinates: Coordinates, @@ -65,7 +70,7 @@ fn main() output_map::output_map // Call output_map fuctino from output_map.rs ( &map, - &blocks::BLOCKS, + &data::BLOCKS, &player.coordinates, ); // Output the map 'game_loop: loop @@ -77,7 +82,7 @@ fn main() user_input, &mut player, &map, - &blocks::BLOCKS, + &data::BLOCKS, ); if let Err(e) = save::save(&save_file_path, &player) diff --git a/src/process_input.rs b/src/process_input.rs index dcacc03..1e279da 100644 --- a/src/process_input.rs +++ b/src/process_input.rs @@ -70,21 +70,19 @@ pub fn process_input { println!("{:?}", player); }, - /* - "cut"|"chop"|"mine"|"pick"|"axe"|"destroy" => + "cut"|"chop"|"mine"|"pick"|"axe"|"destroy"|"skill" => { let vector: &str = command[1]; match vector { - "north"|"n"|"up" |"u" => player.coordinates.z -= 1, - "east" |"e"|"right"|"r" => player.coordinates.x += 1, - "south"|"s"|"down" |"d" => player.coordinates.z += 1, - "west" |"w"|"left" |"l" => player.coordinates.x -= 1, - _ => {println!("Invalid travel direction"); break;}, + "north"|"n"|"up" |"u" => function::skill_item('n', &player, &map), + "east" |"e"|"right"|"r" => function::skill_item('e', &player, &map), + "south"|"s"|"down" |"d" => function::skill_item('s', &player, &map), + "west" |"w"|"left" |"l" => function::skill_item('w', &player, &map), + _ => {println!("Invalid direction"); break;}, } }, - */ "travel"|"move"|"go" => { let mut magnitude: usize = 1;