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?
Conversation
wip2 room transitions are ok ready mvp mmmvvvvpppp final mvp
src/dispatcher/mod.rs
Outdated
static MICS_BROKEN: AtomicU8 = AtomicU8::new(0); | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason why you chose to use AtomicU8
for MICS_BROKEN
? Asking because it's always better to go with simpler types.
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.
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 comment
The 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
src/rooms/mod.rs
Outdated
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.
It's good practice that mod.rs
file should only have lib import. So for the actual logic it's better to create other files. I guess in this case maybe another file called studio.rs
?
src/main.rs
Outdated
match current_item_data { | ||
Some(data) => { | ||
handle_current_entity(&data, &mut score, &mut current_room, &mut current_item) | ||
} | ||
None => {} | ||
} |
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.
This can be simplified to:
if let Some(data) = current_item_data {
handle_current_entity(&data, &mut score, &mut current_room, &mut current_item)
}
and same for the above code on lines 91-95.
let studio = get_studio(); | ||
let mut current_room: RoomId = RoomId::Hall; | ||
|
||
let items = get_items(); | ||
let mut current_item: ItemId = ItemId::NoItem; |
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.
this is great. Even better would be to have something like a Game
that can handle all of that. That way you can even call something like Game::init()
, and that can return you the appropriate rooms.
match handle_user_input() { | ||
Ok(user_input) => { | ||
let user_choice = index_to_action_id.get(&user_input); | ||
match user_choice { | ||
Some(choice) => call_action(choice, current_room, score, current_item), | ||
_ => {} | ||
} | ||
} | ||
_ => {} | ||
} |
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 here, update to use the if let
syntax, that's more rustic.
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.
A good practice before starting projects/programs this size is to design it first. As in, come up with all the structs and functions and how they will interact with each other. First I would draw a diagram, and possibly come up with a UML diagram (just something to represent the structs and it's function AKA the API). From that maybe you can jot down some sudocode if that helps you. But that process will help you clarify the system as a role and simplify implementation.
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.
Yeah, 100%. I just still limited with understanding of language and what is possible, so I figured out many things on the go
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.
On that note, if you have any questions on the language or logic, write them down, then we can go over them in our next call.
src/items/mod.rs
Outdated
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.
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.
src/dispatcher/mod.rs
Outdated
ExitGame, | ||
} | ||
|
||
static MICS_BROKEN: AtomicU8 = AtomicU8::new(0); |
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.
Wondering why you chose to make this static. Probably because you want this to be mutable? Maybe a better option would be lazy_static
? But now that I see, maybe it's probably better to create a struct to represent the mic, and inside have functions that mutate that struct. Something like:
struct Mic {
count: i32,
}
impl Mic {
fn break_mic() {
...
}
}
No description provided.