Creating a class Player based on instructions
Hi i got a few questions.
What exactly does an enum do and how would it apply to my program?`
57 Replies
My basic understanding of enum is that it's used like a multiple choice question?
Like if i made it something like this instead?
If i made a constructor not withing a subclass of
Player
, would i pass a number to it?
0 = black and 1 for white?
Not entirely sure how this worksenum
stands for "Enumeration". It's a type that contains information about possible values.
You often find examples as enum WeekDay { Monday, Tuesday, ... }
, that you can then use as reference in situation like WeekDay currentDay = WeekDay.Saturday;
.
In the case of player colors, maybe you would have enum PlayerColor { Blue, Red, Green, Yellow }
.? If an enum isn't requested, you may also use already existing Color
types from System.Drawing.Color
.It's request to use enums
I'm just not sure how to apply it using my classes
this.Disk = Disk;
looks fine, is there a problem with it?
This is what i made so far
Hmm, you should have your
disk
field typed as Diskcolor
if you want to use the enum.Like so?
But that messes up in the HumanPlayer..
Yes, but try to build it, the
disk
constructor argument should reflect the this.disk
type.I'm not sure i understand that
As in the parameters for my HumanPlayer?
okay that seems to work!
Oufh this is tough :(
As the enum is inside the
Player
class, you may have trouble accessing it when building a new HumanPlayer
.
Maybe you should extract it elsewhere, to make it more globally available?Right, as in place the enum somewhere else?
+I kind of think
ComputerPlayer
will have to set its Disk
aswell?Yes but it will always be opposite of what the human player chooses
or rather the first player
Ooh, I see.
So my suspicion is that i pass the opposite enum to the computer class
Got a quck question tho
when we pass an enum, is what we are passing an integer or a string?
under the hood its a numeric type,
int
by default but it can be changed
but thats not something you should care about
just use the enum type everywhere
an enum
is a custom type, just like a class, struct, record etcAh i see
Any advice on how i can place these button next to each other?
well, you have a
Grid
there, which is a layout control
you can use that to position controls, by creating row and column definitions, then assigning your buttons to a given row/columnoufh this is kind of painful to work with Q.Q
π
While visual studio shows ^
I guess it has something to do with the grid
show your xaml
you've been dragging and dropping I see
remove any
Margin
instructions you haveYes π The youtube video i watched specifically told me not to do that because of alignment issues hehe
yes
$rulesofwpf
Alright i removed them all
https://wpf-tutorial.com/panels/grid-rows-and-columns/
check here for a brief intro to how to use a grid
Now comes that hard part trying to utilize girds :I
in your case, you need to make 4 rows
the top empty space, the text, the buttons and the bottom empty space
then we need either 1 or 2 columns, depends on how much fine control you need
I'm not very good with WPF layout myself, but using a combination of grids and stackpanels got me to here:
Yeahhh the tutorial was good
i almost have it
Just gotta implement the text and buttons now
there ya go
it might cause some issues with resizing, when you do it like that
for example, you can get a very long way with just setting
VerticalAlignment="Center"
on your outer grid
that removes the need for setting the heights on any row
and you just have your empty space be an empty rowYeaa
I might need another column?
I aligned it to the right
not sure how i'm gonna get it perfectly centered
You can have a row "spanned" across multiple columns, with something like "colspan=2", or likewise.
YEAH columnspan!!
That's it
LMFAO when i resize it
it doesn't follow? Not sure what that is called, dynamic?
Because your grid has a fixed width. If your (outermost) container doesn't have a width of
*
, it may not resize with the window size.Interesting!
I'll see if i can add that
This is kinda cool ngl
Stack Overflow
How to use DockStyle.Fill for standard controls in WPF?
I'm used from windows forms, that I create a panel, place controls inside it and give them DockStyle.Fill to max out their size to the surrounding panel.
In WPF I want to have the same. I have a
I managed to do it c:
Now comes the hard part......... c#
:aaaa:
If you need help for the C#, you can ask here aswell.
I can't seem to find the appropriate tool which allows me to recieve a string from the user
any ideas what it's called?
aah found it, textbox
Any ideas on how i can make the button come in front of grid.column 0 and 2?
?
you can put a layout component in a grid cell
and then use alignments on it