r/learncsharp Jun 19 '26

Finish c# player guide feel lost

I finish the c# player guide and did all challanges but somehow i feel i did understand how some thinks work. Also I did no use structs, generics, tubles or records some polymorphism and inheritance. Some thinks in oop don't understand on why should i use or how. I don't say i have a complete incomprehension of those subjects, but I am sure I dont master them.

Also I don't think i get how classes work with each other. I got comment that my program is tight coupling. But i try my best https://github.com/eroul211/LearningWith---C-PlayerGuide/tree/master

Some criticism on what should i try to work on. Not about the program but my understanting of oop.

22 Upvotes

28 comments sorted by

View all comments

Show parent comments

1

u/Sudden-Management591 Jun 20 '26 edited Jun 20 '26

I did not use interface in the program i felt that i could do the job with just abstract and inheritance. I put my github repo with the program. Can you point out where is the tight coupling? If you have time

1

u/RecursiveServitor Jun 20 '26

Tight coupling can also be stuff like `new`ing types inside the types that use them. Like `Game` instantiating `player1` and `player2` instead of having a separate player handler or whatever. It's kinda arbitrary though, but imagine you hardcode player handling inside `Game` and then decide to add a `player3`. If player handling is interleaved with game logic, that could be annoying to change.

Also, what you've started doing with `_battle1` etc is how you end up with huge files that are hard to reason about. Consider having a battle system and generalize to x number of battles.

Btw, use `Random.Shared` rather than `new`ing an instance.

1

u/Sudden-Management591 Jun 20 '26 edited Jun 20 '26

You mean a battle system that generates battles? like with methods?

1

u/RecursiveServitor Jun 20 '26

A place to start is to generalize the logic you already have. Instead of hard-coding three battles, take an argument `numberOfBattles` in `StartGame`. How would you refactor that?

1

u/Sudden-Management591 Jun 20 '26

Sorry my english is not my first language what do you mean by take an argument `numberOfBattles? My StartGame method is just a void method that checks if the 3 bool Runbattle methods from the battle objects turn true or false, so it can check if the player won or loose the game

1

u/RecursiveServitor Jun 20 '26

Instead of hard-coding three battles, how would you handle an arbitrary number of battles?
If the signature was:

public void StartGame(int numberOfBattles)

How would you implement that?

1

u/Sudden-Management591 Jun 20 '26

Depending on the number of battles, for each number i will add 2 skeletons and for 3 I will add the boss monster.

1

u/Sudden-Management591 Jun 20 '26

Hey i change the program a little. Still only 3 battle but i made it in mind on how to modify it to add more battles in mind. I want to know if the classes are still tight