❔ [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
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!
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
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.
Hey!
I hope you dont with helping me out 🥲
How far have you gone with the code?
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.
@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
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....
Thats a good start. Mind showing us what you have?
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
do you know how classes work?
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
Well that should be all we need here
But I have to spend more time practicing...
What is your suggestion?
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
Done!
that was fast
? How
well, show me your class
No i mean i have vs open and added a new class "game board", i haven't written code xd
Ah.
Well, what information should the gameboard contain?
your gameboard should presumably end up containing some sort of "Card" class, rather than integers
That's what I have so far ☝️
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
Also, classes are always named with
PascalCase
so GameBoard
in this caseI can open another class
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.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 boardThe way it is set up right now you could do this
Or something like that, maybe this isn't the most readable.
I think its very readable 🙂
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.Thanks so much guys for the help so far!
I am slowly digesting the info and I'm trying to implement it 😅
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 😉
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.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!
@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.
Hey @hiyosilver I'll really appreciate!
What about voice?
Nevertheless, ☝️ here's some more Advice i got from someone....
The task once again:
Sorry for that...i hope it's not too far off
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"
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...
Can you post the current state of your code?
https://codeshare.io/MNMEqO
That's the GameBoard class
I think the explict instruction to design using oo is a bit dumb.
Why so?
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.This?
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
Exactly...
But writing code is a different story
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
No problem!
Ok, not quite 😄
😄
There we go
I'll make a small change again
The card class looks lonely lol
Oh i see you made some changes my bad
sec pm
I was looking for your cursor
I was thinking of setting the access level of bool in the card class to public
Sent you a friend request
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.Is this archived
no