Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVP #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
279 changes: 279 additions & 0 deletions src/dispatcher/mod.rs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, separate the logic from the imports.

@@ -0,0 +1,279 @@
use crate::clear_console;
use crate::ItemId;
use crate::RoomId;

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum ActionId {
GoToControlRoom,
GoToHall,
GoToToneRoom,
GoToVocalBooth,

SpillBeerOnTheConsole,

PickConsole,
PushRandomButton,
MakeAllFadersUp,
StaringAtTheDeskWithTheDumbFace,

PickImac,
TurnOffImac,
BreakScreenOfImac,
CloseOpenedProToolsSession,
TouchImacDisplayWithFinger,

PickChair,
KickChairFromSoundGuy,
PutLegsOnTheChair,

PickBottle,
MakeHoleInBottleAndGetHigh,
ThrowBottleToTheAssistant,
DrinkFromBottle,

PickDrums,
HitCymbalsRandomly,
ScreamAtTheSnare,

PickGuitarAmp,
TurnVolumeToEleven,
AllButtonsUp,
PressStandBy,

PickMic,
SwearAtTheCleaner,
CaughtForThreeMinutesStraight,
ThrowMicAtTheWall,

SingToTheCureAndCry,
PressRandomNumbersOnAnIntercom,
StaringAtTheDoorForLoongTime,

DropItem,

ExitGame,
}

struct GlobalState {
mics_broken: u8,
the_cure_singing_attemps: u8,
intercom_open_counter: u8,
}

impl GlobalState {
pub fn break_mic(&self) {
let upd_value = &self.mics_broken + 1;
self.mics_broken = upd_value;
}

pub fn sing_the_cure(&self) {
let upd_value = &self.the_cure_singing_attemps + 1;
self.the_cure_singing_attemps = upd_value;
}

pub fn open_intercom(&self) {
let upd_value = &self.intercom_open_counter + 1;
self.intercom_open_counter = upd_value;
}
}

const STATE: GlobalState = GlobalState {
mics_broken: 0,
the_cure_singing_attemps: 0,
intercom_open_counter: 0,
};

pub fn call_action(
action_id: &ActionId,
current_room: &mut RoomId,
score: &mut i8,
current_item: &mut ItemId,
) {
clear_console();

match action_id {
ActionId::GoToControlRoom => {
*current_room = RoomId::ControlRoom;
println!("You're in the control room");
}
ActionId::GoToToneRoom => {
*current_room = RoomId::ToneRoom;
println!("You're in the tone room");
}
ActionId::GoToHall => {
*current_room = RoomId::Hall;
println!("You're in the hall");
}
ActionId::GoToVocalBooth => {
*current_room = RoomId::VoiceBooth;
println!("You're in the voice booth. It's so scary! No way!!! You're going back");
*current_room = RoomId::ToneRoom;
println!("You're in the tone room");
}
ActionId::SpillBeerOnTheConsole => {
println!("Well... don't do that again");
*score -= 2;
}
ActionId::PickConsole => {
*current_item = ItemId::Console;
}
ActionId::PushRandomButton => {
println!("Wow! That's mixing!");
*score += 1;
}
ActionId::MakeAllFadersUp => {
println!("You're the greatest punk rocker of the universe!");
*score += 2;
}
ActionId::PickMic => {
*current_item = ItemId::Mic;
}
ActionId::PickDrums => {
*current_item = ItemId::Drums;
}
ActionId::PickBottle => {
*current_item = ItemId::BottleOfWatter;
}
ActionId::PickGuitarAmp => {
*current_item = ItemId::GuitarAmp;
}
ActionId::PickChair => {
*current_item = ItemId::ArmChair;
}
ActionId::StaringAtTheDeskWithTheDumbFace => {
println!("Well.. it least you're not hurting anyone");
*score += 1;
}
ActionId::PickImac => {
*current_item = ItemId::Imac;
}
ActionId::TurnOffImac => {
println!("This Little Maneuver's Gonna Cost Us 51 Years");
*score -= 2;
}
ActionId::BreakScreenOfImac => {
println!("And how you wanted to complete the session? Game over, go away");
*score = -127;
std::process::exit(0);
}
ActionId::CloseOpenedProToolsSession => {
println!("This Little Maneuver's Gonna Cost Us 51 Years");
*score -= 1;
}
ActionId::TouchImacDisplayWithFinger => {
println!("And why sound guy is screaming?");
}
ActionId::PressStandBy => {
println!("Ooops, you powered it off. Need help!!");
*score -= 1;
}
ActionId::TurnVolumeToEleven => {
println!("Yeah! It is Marshall!");
*score += 2;
}
ActionId::AllButtonsUp => {
println!("You broke it!");
*score -= 1;
}
ActionId::SwearAtTheCleaner => {
println!("WOW! An album full of hits is done!");
*score = 127;
}
ActionId::CaughtForThreeMinutesStraight => {
println!("Great lyrics!!");
*score += 1;
}
ActionId::HitCymbalsRandomly => {
println!("No one can talk, no one can hear a thing. You're happy???");
*score -= 2;
}
ActionId::ScreamAtTheSnare => {
println!("Wow.. sound like.. some... Pink Floyd?...");
*score += 1;
}
ActionId::SingToTheCureAndCry => {
STATE.sing_the_cure();
let done_attemps = STATE.the_cure_singing_attemps;
match done_attemps {
1 => {
println!("Your band members already want to get rid of you");
}
2 => {
println!("Seriosly, stop it");
}
3 => {
println!("No more The Cure please");
}
_ => {
println!("They kicked you out from the studio. What did you expect?");
*score = -127;
std::process::exit(0);
}
}
*score -= 2;
}
ActionId::PressRandomNumbersOnAnIntercom => {
let intercome_opened = STATE.intercom_open_counter;
match intercome_opened {
0 => {
println!("Ha! There was a pizza delivery guy waiting! Nice one!");
*score += 2;
STATE.open_intercom();
}
_ => {
println!("Nobody there");
}
}
}
ActionId::StaringAtTheDoorForLoongTime => {
println!("At least you're not hurting anyone");
*score += 1;
}
ActionId::DrinkFromBottle => {
println!("Hydrating!");
*score += 1;
}
ActionId::MakeHoleInBottleAndGetHigh => {
println!("TRUEEE PUNK ROCKER");
*score += 2;
}
ActionId::ThrowBottleToTheAssistant => {
println!("Sound guy doesn't like him anyway");
*score += 1;
}
ActionId::ThrowMicAtTheWall => {
STATE.break_mic();
let broken_mics = STATE.mics_broken;
match broken_mics {
1 => {
println!("You broke it");
}
2 => {
println!("They ain't free!!!'");
}
3 => {
println!("There is only one now");
}
_ => {
println!("You broke the entire studio.");
}
}
*score -= 2;
}
ActionId::KickChairFromSoundGuy => {
println!("Make him moooove!");
*score += 1;
}
ActionId::PutLegsOnTheChair => {
println!("...");
}
ActionId::DropItem => {
*current_item = ItemId::NoItem;
println!("Item dropped");
}
ActionId::ExitGame => {
println!("Bye!");
std::process::exit(0);
}
}
}
118 changes: 118 additions & 0 deletions src/items/mod.rs
@@ -0,0 +1,118 @@
use std::collections::HashMap;

use crate::create_actions;
use crate::ActionId;
use crate::EntityData;

#[derive(Debug, PartialEq, Eq, Hash)]
pub enum ItemId {
Console,
Imac,
ArmChair,
BottleOfWatter,
Drums,
GuitarAmp,
Mic,
NoItem,
}

struct StudioGear {
mix_console: EntityData,
imac: EntityData,
arm_chair: EntityData,
bottle_of_water: EntityData,
drums: EntityData,
guitar_amp: EntityData,
mic: EntityData,
}

fn get_gear() -> StudioGear {
let mix_console: EntityData = EntityData {
title: "Mixing console".to_owned(),
allowed_actions: create_actions(vec![
ActionId::SpillBeerOnTheConsole,
ActionId::PushRandomButton,
ActionId::MakeAllFadersUp,
ActionId::StaringAtTheDeskWithTheDumbFace,
ActionId::DropItem,
]),
};
let imac: EntityData = EntityData {
title: "iMac".to_owned(),
allowed_actions: create_actions(vec![
ActionId::TurnOffImac,
ActionId::BreakScreenOfImac,
ActionId::CloseOpenedProToolsSession,
ActionId::TouchImacDisplayWithFinger,
ActionId::DropItem,
]),
};
let arm_chair: EntityData = EntityData {
title: "Arm chair".to_owned(),
allowed_actions: create_actions(vec![
ActionId::PutLegsOnTheChair,
ActionId::KickChairFromSoundGuy,
ActionId::DropItem,
]),
};
let bottle_of_water = EntityData {
title: "Bottle of watter".to_owned(),
allowed_actions: create_actions(vec![
ActionId::DrinkFromBottle,
ActionId::ThrowBottleToTheAssistant,
ActionId::MakeHoleInBottleAndGetHigh,
ActionId::DropItem,
]),
};
let guitar_amp = EntityData {
title: "Guitar amp".to_owned(),
allowed_actions: create_actions(vec![
ActionId::TurnVolumeToEleven,
ActionId::AllButtonsUp,
ActionId::PressStandBy,
ActionId::DropItem,
]),
};
let drums = EntityData {
title: "Drums".to_owned(),
allowed_actions: create_actions(vec![
ActionId::HitCymbalsRandomly,
ActionId::ScreamAtTheSnare,
ActionId::DropItem,
]),
};
let mic = EntityData {
title: "Mic".to_owned(),
allowed_actions: create_actions(vec![
ActionId::ThrowMicAtTheWall,
ActionId::CaughtForThreeMinutesStraight,
ActionId::SwearAtTheCleaner,
ActionId::DropItem,
]),
};
let studio_gear = StudioGear {
mix_console,
imac,
arm_chair,
bottle_of_water,
guitar_amp,
drums,
mic,
};

studio_gear
}

pub fn get_items() -> HashMap<ItemId, EntityData> {
let studio_gear = get_gear();
let mut gear_map: HashMap<ItemId, EntityData> = HashMap::new();
gear_map.insert(ItemId::Console, studio_gear.mix_console);
gear_map.insert(ItemId::Imac, studio_gear.imac);
gear_map.insert(ItemId::Drums, studio_gear.drums);
gear_map.insert(ItemId::GuitarAmp, studio_gear.guitar_amp);
gear_map.insert(ItemId::ArmChair, studio_gear.arm_chair);
gear_map.insert(ItemId::BottleOfWatter, studio_gear.bottle_of_water);
gear_map.insert(ItemId::Mic, studio_gear.mic);

gear_map
}