going to bed soon
This commit is contained in:
parent
b0318ab4da
commit
8b8d493df2
@ -6,17 +6,17 @@
|
|||||||
},
|
},
|
||||||
"coordinates": {
|
"coordinates": {
|
||||||
"x": 85,
|
"x": 85,
|
||||||
"z": 17,
|
"z": 25,
|
||||||
"map": "world"
|
"map": "world"
|
||||||
},
|
},
|
||||||
"inventory": [
|
"inventory": [
|
||||||
[
|
[
|
||||||
"axe",
|
"Steel Axe",
|
||||||
1
|
1
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"vape",
|
"Morphine",
|
||||||
1
|
2
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -21,4 +21,12 @@ lazy_static! {
|
|||||||
map.insert('♣', vec![([0, 153, 51], true, "Oak Tree")]);
|
map.insert('♣', vec![([0, 153, 51], true, "Oak Tree")]);
|
||||||
map
|
map
|
||||||
};
|
};
|
||||||
|
pub static ref SKILLABLE: HashMap<char, Vec<(&'static str, u64, Vec<&'static str>)>> = {
|
||||||
|
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
|
||||||
|
};
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
use std::io::{stdin,stdout,Write};
|
use std::io::{stdin,stdout,Write};
|
||||||
use crate::Command;
|
use crate::Command;
|
||||||
|
use crate::data;
|
||||||
|
use crate::Player;
|
||||||
|
|
||||||
pub fn input() -> String{
|
pub fn input() -> String{
|
||||||
let mut s=String::new();
|
let mut s=String::new();
|
||||||
@ -23,3 +25,44 @@ pub fn clear_screen()
|
|||||||
.expect("Failed to clear screen");
|
.expect("Failed to clear screen");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn skill_item
|
||||||
|
(
|
||||||
|
direction: char,
|
||||||
|
player: &Player,
|
||||||
|
map: &Vec<Vec<char>>,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
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 ();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
27
src/main.rs
27
src/main.rs
@ -13,28 +13,33 @@ mod process_input; // process_input.rs
|
|||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
mod blocks;
|
mod data;
|
||||||
|
|
||||||
pub enum GameAction {
|
pub enum GameAction
|
||||||
|
{
|
||||||
Continue,
|
Continue,
|
||||||
Exit,
|
Exit,
|
||||||
Error,
|
Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct Coordinates {
|
struct Skills
|
||||||
|
{
|
||||||
|
woodcutting: u64,
|
||||||
|
mining: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
struct Coordinates
|
||||||
|
{
|
||||||
x: i16,
|
x: i16,
|
||||||
z: i16,
|
z: i16,
|
||||||
map: String,
|
map: String,
|
||||||
}
|
}
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
struct Skills {
|
|
||||||
woodcutting: u8,
|
|
||||||
mining: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct Player {
|
struct Player
|
||||||
|
{
|
||||||
name: String,
|
name: String,
|
||||||
skills: Skills,
|
skills: Skills,
|
||||||
coordinates: Coordinates,
|
coordinates: Coordinates,
|
||||||
@ -65,7 +70,7 @@ fn main()
|
|||||||
output_map::output_map // Call output_map fuctino from output_map.rs
|
output_map::output_map // Call output_map fuctino from output_map.rs
|
||||||
(
|
(
|
||||||
&map,
|
&map,
|
||||||
&blocks::BLOCKS,
|
&data::BLOCKS,
|
||||||
&player.coordinates,
|
&player.coordinates,
|
||||||
); // Output the map
|
); // Output the map
|
||||||
'game_loop: loop
|
'game_loop: loop
|
||||||
@ -77,7 +82,7 @@ fn main()
|
|||||||
user_input,
|
user_input,
|
||||||
&mut player,
|
&mut player,
|
||||||
&map,
|
&map,
|
||||||
&blocks::BLOCKS,
|
&data::BLOCKS,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Err(e) = save::save(&save_file_path, &player)
|
if let Err(e) = save::save(&save_file_path, &player)
|
||||||
|
@ -70,21 +70,19 @@ pub fn process_input
|
|||||||
{
|
{
|
||||||
println!("{:?}", player);
|
println!("{:?}", player);
|
||||||
},
|
},
|
||||||
/*
|
"cut"|"chop"|"mine"|"pick"|"axe"|"destroy"|"skill" =>
|
||||||
"cut"|"chop"|"mine"|"pick"|"axe"|"destroy" =>
|
|
||||||
{
|
{
|
||||||
let vector: &str = command[1];
|
let vector: &str = command[1];
|
||||||
|
|
||||||
match vector
|
match vector
|
||||||
{
|
{
|
||||||
"north"|"n"|"up" |"u" => player.coordinates.z -= 1,
|
"north"|"n"|"up" |"u" => function::skill_item('n', &player, &map),
|
||||||
"east" |"e"|"right"|"r" => player.coordinates.x += 1,
|
"east" |"e"|"right"|"r" => function::skill_item('e', &player, &map),
|
||||||
"south"|"s"|"down" |"d" => player.coordinates.z += 1,
|
"south"|"s"|"down" |"d" => function::skill_item('s', &player, &map),
|
||||||
"west" |"w"|"left" |"l" => player.coordinates.x -= 1,
|
"west" |"w"|"left" |"l" => function::skill_item('w', &player, &map),
|
||||||
_ => {println!("Invalid travel direction"); break;},
|
_ => {println!("Invalid direction"); break;},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
*/
|
|
||||||
"travel"|"move"|"go" =>
|
"travel"|"move"|"go" =>
|
||||||
{
|
{
|
||||||
let mut magnitude: usize = 1;
|
let mut magnitude: usize = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user