C
C#2y ago
kiteflora

❔ [Homework] Console Game Help

Hello! I'm a newbie to coding (CS Freshman) & I have this project to submit tomorrow (4th Dec.), involving Object Oriented Programming (OOP), I have tried my hardest to watch tutorials and find a way to design the code but I can't seem to grasp the concept well enough in time. Would any of you be willing to help me out? (Only arrays can be used as a data structure, not lists e.t.c, and dictionary can only be used to Store the words) Many thanks!
68 Replies
hiyosilver
hiyosilver2y ago
Well, what have you got so far? Anyway, I'll probably be online tomorrow morning GMT, so in about 8-ish hours. If nobody else is available and you still need help. I wouldn't mind having a look. Sounds like a hoot!
kiteflora
kitefloraOP2y ago
Hey @hiyosilver I will appreciate any help I can get, I'm in GMT +2 timezone. Thanks! Encapsulating data fields and simple methods in a class... I'm still shaky on access levels, get/set etc. Nevertheless, how many classes do you think the code will need? I assumed there would be a GameBoard class and a Card class
hiyosilver
hiyosilver2y ago
Sounds about right, that should be fine to start with. Getting some user input, creating a board from that and filling it with cards would be the first steps.
kiteflora
kitefloraOP2y ago
Hey! I hope you dont with helping me out 🥲 How far have you gone with the code?
Pobiega
Pobiega2y ago
How about we reverse that question; how far have you come with the code? Especially for homework, its important you do the work. We can help you when you struggle, but the code will be mostly you.
hiyosilver
hiyosilver2y ago
@kiteflora By "having a look", I was not referring to spoonfeeding you a solution. I don't mind helping out, but'll need to put in the work 😉 As it happens, I tried a few things just to get a rough idea of how I might do it. You should have an empty console project set up to begin with. If you are unsure where to start, before jumping into code, try making a list of all the necessary steps your program needs to perform. Just to make sure you understand the problem. e.g. 1. Get size of game board 'n' from user input (maybe clamp to reasonable values?) 2. Generate 'n' / 2 random words 3. Create 'n' cards, two for each word 4. Shuffle and place on game board 5. ... I don't know if this site is any good but maybe it could be useful if you want any realtime assistance https://codeshare.io
kiteflora
kitefloraOP2y ago
Using the normal PPP (Procedural Programming Paradigm) method, i have managed to write the code until where the user inputs a "number" that corresponds to a GameBoard size of their choice (write 1 for 4x4, 2 for 6x6 or 3 for 8x8 (taking care that there is an even number of squares for all instances), then i wrote a loop that prints out the table, with the numbers in increasing order....
Pobiega
Pobiega2y ago
Thats a good start. Mind showing us what you have?
kiteflora
kitefloraOP2y ago
Because I'm unfamiliar with OOP/not quite grasped it's concept, I can't convert this code to OOP form, I'm also lost on finding a way to use a dictionary that will "assign" word pairs to the board, and how to even assign a word to a number ...? Ok https://codeshare.io/lo1q1R
Pobiega
Pobiega2y ago
do you know how classes work?
kiteflora
kitefloraOP2y ago
Just the basics, I know how a class encapsulates fields and methods that work with the fields data to make the code more convenient/manageable
Pobiega
Pobiega2y ago
Well that should be all we need here
kiteflora
kitefloraOP2y ago
But I have to spend more time practicing... What is your suggestion?
Pobiega
Pobiega2y ago
well, lets start out easy a good first step would be just making a class that represents your game board and giving it a way to render itself on screen
kiteflora
kitefloraOP2y ago
Done!
Pobiega
Pobiega2y ago
that was fast
kiteflora
kitefloraOP2y ago
? How
Pobiega
Pobiega2y ago
well, show me your class
kiteflora
kitefloraOP2y ago
No i mean i have vs open and added a new class "game board", i haven't written code xd
Pobiega
Pobiega2y ago
Ah. Well, what information should the gameboard contain?
kiteflora
kitefloraOP2y ago
hiyosilver
hiyosilver2y ago
your gameboard should presumably end up containing some sort of "Card" class, rather than integers
kiteflora
kitefloraOP2y ago
That's what I have so far ☝️
hiyosilver
hiyosilver2y ago
board selected should probably not be a field/property of gameBoard You only need the input to generate the board, it's not useful after
Pobiega
Pobiega2y ago
Also, classes are always named with PascalCase so GameBoard in this case
kiteflora
kitefloraOP2y ago
I can open another class
hiyosilver
hiyosilver2y ago
This one is fine I meant you can just keep boardSelected in your Main for now, use it to initialize a GameBoard, but dont store it in the instance because it has no use beyond initialization If you are parsing use input to get them to pick an option like that, you can just parse to int, and you should probably use TryParse rather than Parse in case the input is not a number I've made small change in your codeshare to show what I mean You should probably turn FillMatrix into a constructor. If you pass in board selected you can create an appropriately sized array in there. Although perhaps GameBoard should know nothing about different types, so instead you might want to parse the input, get the correct grid size and only pass that into the constructor.
Pobiega
Pobiega2y ago
yup I'd like to see an API like... var board = new GameBoard(8,8) for example which would make and initialize an 8 by 8 board
hiyosilver
hiyosilver2y ago
The way it is set up right now you could do this
GameBoard board = boardSelected switch {
1 => new GameBoard(4), //or GameBoard(4, 4) if you want to allow custom irregular grids later on
2 => new GameBoard(6),
3 => new GameBoard(8),
}
GameBoard board = boardSelected switch {
1 => new GameBoard(4), //or GameBoard(4, 4) if you want to allow custom irregular grids later on
2 => new GameBoard(6),
3 => new GameBoard(8),
}
Or something like that, maybe this isn't the most readable.
Pobiega
Pobiega2y ago
I think its very readable 🙂
hiyosilver
hiyosilver2y ago
Thanks 😛 I'm always nervous about suggesting things so I tend to give caveats @kiteflora You have quite a complicated formula for numbering the array slots sequentially. The formula column * width + row will give you the correct index (+ 1 if you want to start from 1). Will come in useful because you'll probably want some sort of Print/Display method on your GameBoard to write the current state to Console when needed.
kiteflora
kitefloraOP2y ago
Thanks so much guys for the help so far! I am slowly digesting the info and I'm trying to implement it 😅
hiyosilver
hiyosilver2y ago
Take your time. I would suggest trying to get the data setup correct first, don't worry too much about methods related to gameplay yet. But do what feels best to you 😉
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
kiteflora
kitefloraOP2y ago
Hey @hiyosilver and @Pobiega !!! Are you guys free tomorrow? I have been busy with exams all week so now I have an opportunity to finish up this code tomorrow. I'd appreciate if anyone can help out in guiding me, I'm down for VC as well!
hiyosilver
hiyosilver2y ago
@kiteflora Well damn, you did take your time alright. Joking aside, I'd be happy to give it another look tomorrow, although I would have to veto the VC myself.
kiteflora
kitefloraOP2y ago
Hey @hiyosilver I'll really appreciate! What about voice?
kiteflora
kitefloraOP2y ago
kiteflora
kitefloraOP2y ago
Nevertheless, ☝️ here's some more Advice i got from someone....
kiteflora
kitefloraOP2y ago
The task once again:
kiteflora
kitefloraOP2y ago
Sorry for that...i hope it's not too far off
Tvde1
Tvde12y ago
Ideally we like to help with specific lines of code or questions about C#. It's hard to help if the question is "can you take a look at this assignment"
kiteflora
kitefloraOP2y ago
Hello @Tvde1 As I'm fresh to coding & CS in general, Was hoping to atleast get some help before tomorrow's deadline I wrote some basic code to the best of my ability I'm just stuck on how to implement OOP/the different classes appropriately plus some other technicalities...
hiyosilver
hiyosilver2y ago
Can you post the current state of your code? https://codeshare.io/MNMEqO
kiteflora
kitefloraOP2y ago
That's the GameBoard class
hiyosilver
hiyosilver2y ago
I think the explict instruction to design using oo is a bit dumb.
kiteflora
kitefloraOP2y ago
Why so?
hiyosilver
hiyosilver2y ago
It's just going to be confusing, and you are already overthinking (I think) what the gameboard should contain before you have even figured out the basics That's partly why I the last thing I said last time was to focus on the initial setup first CheckCardsAgainstBoard for example, is something that I suspect you won't need in that form.
kiteflora
kitefloraOP2y ago
This?
hiyosilver
hiyosilver2y ago
I'll go through your codeshare a bit, starting from the top That was not the last thing I said 😉 But yes I think thats also a possible way but I think we can get there by just going through your code and thinking about what needs to happen since the game you are trying to make is essentially not that complex
kiteflora
kitefloraOP2y ago
Exactly... But writing code is a different story
hiyosilver
hiyosilver2y ago
Let's just see what we can do I'll keep discord open on the side, but ill write more in the codeshare I think even if there is a bit of delay
kiteflora
kitefloraOP2y ago
No problem!
kiteflora
kitefloraOP2y ago
kiteflora
kitefloraOP2y ago
hiyosilver
hiyosilver2y ago
hiyosilver
hiyosilver2y ago
hiyosilver
hiyosilver2y ago
Ok, not quite 😄
kiteflora
kitefloraOP2y ago
😄
hiyosilver
hiyosilver2y ago
hiyosilver
hiyosilver2y ago
There we go I'll make a small change again
kiteflora
kitefloraOP2y ago
The card class looks lonely lol Oh i see you made some changes my bad
hiyosilver
hiyosilver2y ago
sec pm
kiteflora
kitefloraOP2y ago
I was looking for your cursor I was thinking of setting the access level of bool in the card class to public
hiyosilver
hiyosilver2y ago
Sent you a friend request
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
kiteflora
kitefloraOP2y ago
Is this archived
Patrick
Patrick2y ago
no
Want results from more Discord servers?
Add your server