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
base: master
Are you sure you want to change the base?
MVP #1
Changes from 4 commits
a71f9d1
5c0aaf5
92de6e8
545ad11
4435b0d
755d7c6
c2f6d34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,279 @@ | ||
use crate::clear_console; | ||
use crate::ItemId; | ||
use crate::RoomId; | ||
use std::sync::atomic::{AtomicU8, Ordering}; | ||
|
||
#[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, | ||
} | ||
|
||
static MICS_BROKEN: AtomicU8 = AtomicU8::new(0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering why you chose to make this static. Probably because you want this to be mutable? Maybe a better option would be struct Mic {
count: i32,
}
impl Mic {
fn break_mic() {
...
}
} |
||
fn break_mic() { | ||
MICS_BROKEN.fetch_add(1, Ordering::SeqCst).wrapping_add(1); | ||
} | ||
fn get_broken_mics() -> u8 { | ||
MICS_BROKEN.load(Ordering::SeqCst) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any specific reason why you chose to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried to use Cell, faced errors like this might be unsafe. So I decided to end up with any working solution to get thing done, and fix it after feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good! I do that as well, first start with an ugly solution and then make it look good |
||
|
||
static THE_CURE_SINGING_ATTEMPS: AtomicU8 = AtomicU8::new(0); | ||
fn sing_the_cure() { | ||
THE_CURE_SINGING_ATTEMPS | ||
.fetch_add(1, Ordering::SeqCst) | ||
.wrapping_add(1); | ||
} | ||
fn get_the_cure_singing_attemps() -> u8 { | ||
THE_CURE_SINGING_ATTEMPS.load(Ordering::SeqCst) | ||
} | ||
|
||
static INTERCOM_OPEN_COUNTER: AtomicU8 = AtomicU8::new(0); | ||
fn open_intercome() { | ||
INTERCOM_OPEN_COUNTER | ||
.fetch_add(1, Ordering::SeqCst) | ||
.wrapping_add(1); | ||
} | ||
fn get_intercome_opened() -> u8 { | ||
INTERCOM_OPEN_COUNTER.load(Ordering::SeqCst) | ||
} | ||
|
||
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 => { | ||
sing_the_cure(); | ||
let done_attemps = get_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 = get_intercome_opened(); | ||
match intercome_opened { | ||
0 => { | ||
println!("Ha! There was a pizza delivery guy waiting! Nice one!"); | ||
*score += 2; | ||
open_intercome(); | ||
} | ||
_ => { | ||
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 => { | ||
break_mic(); | ||
let broken_mics = get_broken_mics(); | ||
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); | ||
} | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here, separate the logic from the imports. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
There was a problem hiding this comment.
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.