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

MVP #1

wants to merge 7 commits into from

Conversation

rtt63
Copy link
Owner

@rtt63 rtt63 commented Mar 3, 2024

No description provided.

Comment on lines 58 to 64
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)
}

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.

Copy link
Owner Author

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

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

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
Comment on lines 97 to 102
match current_item_data {
Some(data) => {
handle_current_entity(&data, &mut score, &mut current_room, &mut current_item)
}
None => {}
}

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.

Comment on lines +77 to +81
let studio = get_studio();
let mut current_room: RoomId = RoomId::Hall;

let items = get_items();
let mut current_item: ItemId = ItemId::NoItem;

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.

Comment on lines +61 to +70
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),
_ => {}
}
}
_ => {}
}

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.

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.

Copy link
Owner Author

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

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

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.

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.

ExitGame,
}

static MICS_BROKEN: AtomicU8 = AtomicU8::new(0);

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() {
   ...
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants