Development commit. Starting character systems and definitions.
This commit is contained in:
62
src/characters.rs
Normal file
62
src/characters.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
#[derive(Debug)]
|
||||
pub struct Character {
|
||||
pub name: &'static str,
|
||||
pub standing: Standing
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Standing {
|
||||
pub society: i8,
|
||||
pub court: i8,
|
||||
pub friends: Vec<&'static People>,
|
||||
pub enemies: Vec<&'static People>
|
||||
}
|
||||
|
||||
impl Standing {
|
||||
pub fn calculate (mut self: Standing) -> i8 {
|
||||
// Drain society points if mostly disliked.
|
||||
if self.friends.len() < self.enemies.len() {
|
||||
self.society = self.society.clone() - 2
|
||||
}
|
||||
|
||||
// Points
|
||||
{
|
||||
self.friends.len() as i8
|
||||
- self.enemies.len() as i8
|
||||
+ self.court
|
||||
+ self.society
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum People {
|
||||
AbigailWilliams(Option<Character>),
|
||||
AnnPutnam(Option<Character>),
|
||||
BettyParris(Option<Character>),
|
||||
DeputyGovernorDanforth(Option<Character>),
|
||||
ElizabethProctor(Option<Character>),
|
||||
EzekielCheever(Option<Character>),
|
||||
FrancisNurse(Option<Character>),
|
||||
RebeccaNurse(Option<Character>),
|
||||
GilesCorey(Option<Character>),
|
||||
GoodyOsborne(Option<Character>),
|
||||
JohnProctor(Option<Character>),
|
||||
JudgeHathorne(Option<Character>),
|
||||
MaryWarren(Option<Character>),
|
||||
MarshalHerrick(Option<Character>),
|
||||
MarthaCorey(Option<Character>),
|
||||
MercyLewis(Option<Character>),
|
||||
ReverendParris(Option<Character>),
|
||||
ReverendJohnHale(Option<Character>),
|
||||
SarahGood(Option<Character>),
|
||||
SusannaWalcott(Option<Character>),
|
||||
ThomasPutnam(Option<Character>),
|
||||
Tituba(Option<Character>)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SurvivalStatus {
|
||||
PlayerLived,
|
||||
PlayerDied
|
||||
}
|
||||
16
src/events.rs
Normal file
16
src/events.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use crate::characters::{
|
||||
Character,
|
||||
SurvivalStatus
|
||||
};
|
||||
|
||||
pub fn get_event() {}
|
||||
|
||||
pub struct Trial;
|
||||
|
||||
impl Trial {
|
||||
pub fn handle(&self, &mut player: &mut Character) -> SurvivalStatus {
|
||||
let player_status = SurvivalStatus::PlayerDied;
|
||||
|
||||
player_status
|
||||
}
|
||||
}
|
||||
173
src/main.rs
173
src/main.rs
@@ -1,3 +1,174 @@
|
||||
mod characters;
|
||||
mod events;
|
||||
mod utils;
|
||||
|
||||
use characters::{
|
||||
Character,
|
||||
People,
|
||||
Standing,
|
||||
SurvivalStatus
|
||||
};
|
||||
use events::get_event;
|
||||
use std::vec;
|
||||
use utils::{
|
||||
fmt_args,
|
||||
ArgType,
|
||||
FlagType
|
||||
};
|
||||
|
||||
//Number of game rounds.
|
||||
const ROUNDS: u8 = 15;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
let cmd_args = dbg!(fmt_args());
|
||||
let mut characters = build_characters();
|
||||
|
||||
// Set player default values based on gamemode.
|
||||
let mut player = dbg!(build_player(dbg!(get_gamemode(cmd_args))));
|
||||
let end_status = SurvivalStatus::PlayerLived;
|
||||
|
||||
for _r in 0..=ROUNDS {
|
||||
get_event().handle(player);
|
||||
|
||||
if player.standing.calculate() <= 0 {
|
||||
let mut trial = events::Trial;
|
||||
|
||||
match trial.handle(&mut player) {
|
||||
SurvivalStatus::PlayerDied => {
|
||||
end_status = SurvivalStatus::PlayerDied
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Gamemode {
|
||||
//Easy
|
||||
Abigail,
|
||||
//Normal
|
||||
MaryWarren,
|
||||
//Hard
|
||||
JohnProctor,
|
||||
//Just dead.
|
||||
GoodyOsborne
|
||||
}
|
||||
|
||||
fn build_characters() -> Vec<People> {
|
||||
vec![
|
||||
People::AbigailWilliams(Some(Character {
|
||||
name: "Abigail Williams",
|
||||
standing: Standing {
|
||||
society: 10,
|
||||
court: 10,
|
||||
friends: vec![
|
||||
&People::BettyParris(None),
|
||||
&People::DeputyGovernorDanforth(None),
|
||||
&People::ReverendParris(None),
|
||||
],
|
||||
enemies: vec![
|
||||
&People::ElizabethProctor(None),
|
||||
&People::JohnProctor(None),
|
||||
&People::ReverendJohnHale(None)
|
||||
]
|
||||
}
|
||||
})),
|
||||
People::BettyParris(Some(Character {
|
||||
name: "Betty Parris",
|
||||
standing: Standing {
|
||||
society: 10,
|
||||
court: 10,
|
||||
friends: vec![
|
||||
&People::AbigailWilliams(None),
|
||||
&People::ReverendParris(None)
|
||||
],
|
||||
enemies: vec![
|
||||
&People::JohnProctor(None),
|
||||
&People::ElizabethProctor(None)
|
||||
]
|
||||
}
|
||||
})),
|
||||
People::ElizabethProctor(Some(Character{
|
||||
name: "Elizabeth Proctor",
|
||||
standing: Standing {
|
||||
society: 10,
|
||||
court: 5,
|
||||
friends: vec![
|
||||
&People::FrancisNurse(None),
|
||||
&People::GilesCorey(None),
|
||||
&People::JohnProctor(None),
|
||||
&People::RebeccaNurse(None),
|
||||
&People::ReverendJohnHale(None)
|
||||
],
|
||||
enemies: vec![
|
||||
&People::AbigailWilliams(None),
|
||||
&People::DeputyGovernorDanforth(None),
|
||||
&People::EzekielCheever(None)
|
||||
]
|
||||
}
|
||||
}))
|
||||
]
|
||||
}
|
||||
|
||||
fn build_player(gamemode: Gamemode) -> Character {
|
||||
Character {
|
||||
name: "You",
|
||||
standing: match gamemode {
|
||||
Gamemode::Abigail => Standing {
|
||||
society: 10,
|
||||
court: 10,
|
||||
friends: vec![],
|
||||
enemies: vec![]
|
||||
},
|
||||
Gamemode::MaryWarren => Standing {
|
||||
society: 5,
|
||||
court: 5,
|
||||
friends: vec![],
|
||||
enemies: vec![]
|
||||
},
|
||||
Gamemode::JohnProctor => Standing {
|
||||
society: 2,
|
||||
court: 2,
|
||||
friends: vec![],
|
||||
enemies: vec![]
|
||||
},
|
||||
Gamemode::GoodyOsborne => Standing {
|
||||
society: -15,
|
||||
court: -5,
|
||||
friends: vec![],
|
||||
enemies: vec![]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_gamemode(cmd_args: Vec<ArgType>) -> Gamemode {
|
||||
if cmd_args.len() != 1 {
|
||||
match &cmd_args[1] {
|
||||
ArgType::Command(c) => match c.as_str() {
|
||||
"abigail" => Gamemode::Abigail,
|
||||
"john_proctor" => Gamemode::JohnProctor,
|
||||
"goody_osborne" => Gamemode::GoodyOsborne,
|
||||
_ => Gamemode::MaryWarren
|
||||
},
|
||||
ArgType::Flag(f) => match f {
|
||||
FlagType::Long(l) => match l.as_str() {
|
||||
"abigail" => Gamemode::Abigail,
|
||||
"john-proctor" => Gamemode::JohnProctor,
|
||||
"goody-osborne" => Gamemode::GoodyOsborne,
|
||||
_ => Gamemode::MaryWarren
|
||||
},
|
||||
FlagType::Short(s) => match s.as_str() {
|
||||
"a" => Gamemode::Abigail,
|
||||
"j" => Gamemode::JohnProctor,
|
||||
"o" => Gamemode::GoodyOsborne,
|
||||
_ => Gamemode::MaryWarren
|
||||
}
|
||||
},
|
||||
_ => Gamemode::MaryWarren
|
||||
}
|
||||
} else {
|
||||
Gamemode::MaryWarren
|
||||
}
|
||||
}
|
||||
77
src/utils.rs
Normal file
77
src/utils.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
use std::env::args;
|
||||
use std::io;
|
||||
|
||||
|
||||
const DASH:char = 45 as u8 as char;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ArgType {
|
||||
#[allow(dead_code)]
|
||||
Binary(String),
|
||||
Command(String),
|
||||
Flag(FlagType)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum FlagType {
|
||||
//Currently only handles single flags. eg. "-S", "-y"
|
||||
Short(String),
|
||||
Long(String)
|
||||
}
|
||||
|
||||
pub fn fmt_args() -> Vec<ArgType> {
|
||||
let mut args_vec:Vec<ArgType> = Vec::new();
|
||||
|
||||
for x in args() {
|
||||
match try_flag(x.clone()) {
|
||||
None => args_vec.push(ArgType::Command(x)),
|
||||
Some(f) => args_vec.push(ArgType::Flag(f))
|
||||
}
|
||||
}
|
||||
|
||||
args_vec[0] = {
|
||||
ArgType::Binary({
|
||||
match args_vec[0].clone() {
|
||||
ArgType::Command(c) => c,
|
||||
err => panic!("Expected ArgType::Command at args_vec[0], found {:?}", err)
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
args_vec
|
||||
}
|
||||
|
||||
fn try_flag(arg: String) -> Option<FlagType> {
|
||||
if arg.chars().nth(1).unwrap() == DASH {
|
||||
//eg. --my-flag
|
||||
Some(FlagType::Long(break_flag_long(arg)))
|
||||
} else if arg.chars().nth(0).unwrap() == DASH {
|
||||
//eg. -Syu
|
||||
Some(FlagType::Short(break_flag_short(arg)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn break_flag_short(mut arg: String) -> String {
|
||||
arg.remove(0);
|
||||
arg
|
||||
}
|
||||
|
||||
fn break_flag_long(mut arg: String) -> String {
|
||||
for _ in 1..=2 {
|
||||
arg.remove(0);
|
||||
};
|
||||
|
||||
arg
|
||||
}
|
||||
|
||||
pub fn input() -> String {
|
||||
let mut input_buffer = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line( &mut input_buffer)
|
||||
.expect("Failed to read line");
|
||||
|
||||
input_buffer
|
||||
}
|
||||
Reference in New Issue
Block a user