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?`
public abstract class Player
{
private string name;
private string Disk;

public abstract void RequestMove(GameBoard GameBoard, string[] ListOfValidMoves);
}
public abstract class Player
{
private string name;
private string Disk;

public abstract void RequestMove(GameBoard GameBoard, string[] ListOfValidMoves);
}
No description
57 Replies
Merineth πŸ‡ΈπŸ‡ͺ
My basic understanding of enum is that it's used like a multiple choice question?
public abstract class Player
{
private enum Disk
{
black,
white
}
private string name;

public abstract void RequestMove(GameBoard GameBoard, string[] ListOfValidMoves);
}
public abstract class Player
{
private enum Disk
{
black,
white
}
private string name;

public abstract void RequestMove(GameBoard GameBoard, string[] ListOfValidMoves);
}
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?
public class HumanPlayer : Player
{
public HumanPlayer(string Name, string Disk)
{
this.Name = Name;
this.Disk = Disk;

}
}
public class HumanPlayer : Player
{
public HumanPlayer(string Name, string Disk)
{
this.Name = Name;
this.Disk = Disk;

}
}
Not entirely sure how this works
Dinosaure
Dinosaureβ€’2w ago
enum 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.
Merineth πŸ‡ΈπŸ‡ͺ
It's request to use enums I'm just not sure how to apply it using my classes
Dinosaure
Dinosaureβ€’2w ago
this.Disk = Disk; looks fine, is there a problem with it?
Merineth πŸ‡ΈπŸ‡ͺ
public abstract class Player
{
public enum Diskcolor
{
black,
white
}
protected string name;
protected Diskcolor disk;

public abstract void RequestMove(GameBoard GameBoard, string[] ListOfValidMoves);
}


public class HumanPlayer : Player
{
public HumanPlayer(string name, Diskcolor disk)
{
this.name = name;
this.disk = disk;

}

public override void RequestMove(GameBoard GameBoard, string[] ListOfValidMoves)
{
throw new NotImplementedException();
}
}
public abstract class Player
{
public enum Diskcolor
{
black,
white
}
protected string name;
protected Diskcolor disk;

public abstract void RequestMove(GameBoard GameBoard, string[] ListOfValidMoves);
}


public class HumanPlayer : Player
{
public HumanPlayer(string name, Diskcolor disk)
{
this.name = name;
this.disk = disk;

}

public override void RequestMove(GameBoard GameBoard, string[] ListOfValidMoves)
{
throw new NotImplementedException();
}
}
This is what i made so far
Dinosaure
Dinosaureβ€’2w ago
Hmm, you should have your disk field typed as Diskcolor if you want to use the enum.
Merineth πŸ‡ΈπŸ‡ͺ
Like so? But that messes up in the HumanPlayer..
Dinosaure
Dinosaureβ€’2w ago
Yes, but try to build it, the disk constructor argument should reflect the this.disk type.
Merineth πŸ‡ΈπŸ‡ͺ
I'm not sure i understand that As in the parameters for my HumanPlayer? okay that seems to work! Oufh this is tough :(
Dinosaure
Dinosaureβ€’2w ago
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?
Merineth πŸ‡ΈπŸ‡ͺ
Right, as in place the enum somewhere else?
Dinosaure
Dinosaureβ€’2w ago
+I kind of think ComputerPlayerwill have to set its Disk aswell?
Merineth πŸ‡ΈπŸ‡ͺ
Yes but it will always be opposite of what the human player chooses or rather the first player
Dinosaure
Dinosaureβ€’2w ago
Ooh, I see.
Merineth πŸ‡ΈπŸ‡ͺ
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?
Pobiega
Pobiegaβ€’2w ago
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 etc
Merineth πŸ‡ΈπŸ‡ͺ
Ah i see
Merineth πŸ‡ΈπŸ‡ͺ
Any advice on how i can place these button next to each other?
Pobiega
Pobiegaβ€’2w ago
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/column
Merineth πŸ‡ΈπŸ‡ͺ
oufh this is kind of painful to work with Q.Q
Merineth πŸ‡ΈπŸ‡ͺ
πŸ’€
Merineth πŸ‡ΈπŸ‡ͺ
While visual studio shows ^
No description
Merineth πŸ‡ΈπŸ‡ͺ
I guess it has something to do with the grid
Pobiega
Pobiegaβ€’2w ago
show your xaml
Merineth πŸ‡ΈπŸ‡ͺ
<Grid>
<Button Content="PvE" HorizontalAlignment="Left" VerticalAlignment="Center" Click="Button_Click" Height="50" Width="100" Margin="245,0,0,0"/>
<Button Content="PvP" HorizontalAlignment="Left" VerticalAlignment="Center" Click="Button_Click" Height="50" Width="100" Margin="355,0,0,0"/>
<TextBlock HorizontalAlignment="Center" Margin="0,170,0,0" TextWrapping="Wrap" Text="Which gamemode would you like to play?" VerticalAlignment="Top" Height="17" Width="224"/>
</Grid>
<Grid>
<Button Content="PvE" HorizontalAlignment="Left" VerticalAlignment="Center" Click="Button_Click" Height="50" Width="100" Margin="245,0,0,0"/>
<Button Content="PvP" HorizontalAlignment="Left" VerticalAlignment="Center" Click="Button_Click" Height="50" Width="100" Margin="355,0,0,0"/>
<TextBlock HorizontalAlignment="Center" Margin="0,170,0,0" TextWrapping="Wrap" Text="Which gamemode would you like to play?" VerticalAlignment="Top" Height="17" Width="224"/>
</Grid>
Pobiega
Pobiegaβ€’2w ago
you've been dragging and dropping I see remove any Margin instructions you have
Merineth πŸ‡ΈπŸ‡ͺ
Yes πŸ’€ The youtube video i watched specifically told me not to do that because of alignment issues hehe
Pobiega
Pobiegaβ€’2w ago
yes $rulesofwpf
MODiX
MODiXβ€’2w ago
Rules of WPF:

❌ Avoid the WPF Designer to eliminate a category of confusing bugs
❌ Don't rely on Margin as the primary tool for layouts
❌ Avoid writing UserControls or subclassing to extend a default control -- use Behaviors instead (Microsoft.Xaml.Behaviors.Wpf)

βœ… Write XAML by hand and autoformat with "Ctrl K,D" or XAML Styler
βœ… Rely upon XAML Hot Reload to design your app's UI at runtime
βœ… Use layout controls (Grid, DockPanel, etc) to support proper resizing
βœ… Use data binding to eliminate glue code and state synchronization issues
βœ… Use collection controls and DataTemplate to dynamically create lists of controls
βœ… Learn MVVM to create maintainable apps
βœ… Use the Dispatcher to update controls from non-UI threads
βœ… WPF's default controls can be easily modernized via $wpfuilibs
βœ… Include relevant XAML, code-behind, and ViewModel code for questions when possible
Rules of WPF:

❌ Avoid the WPF Designer to eliminate a category of confusing bugs
❌ Don't rely on Margin as the primary tool for layouts
❌ Avoid writing UserControls or subclassing to extend a default control -- use Behaviors instead (Microsoft.Xaml.Behaviors.Wpf)

βœ… Write XAML by hand and autoformat with "Ctrl K,D" or XAML Styler
βœ… Rely upon XAML Hot Reload to design your app's UI at runtime
βœ… Use layout controls (Grid, DockPanel, etc) to support proper resizing
βœ… Use data binding to eliminate glue code and state synchronization issues
βœ… Use collection controls and DataTemplate to dynamically create lists of controls
βœ… Learn MVVM to create maintainable apps
βœ… Use the Dispatcher to update controls from non-UI threads
βœ… WPF's default controls can be easily modernized via $wpfuilibs
βœ… Include relevant XAML, code-behind, and ViewModel code for questions when possible
Merineth πŸ‡ΈπŸ‡ͺ
Alright i removed them all
Pobiega
Pobiegaβ€’2w ago
https://wpf-tutorial.com/panels/grid-rows-and-columns/ check here for a brief intro to how to use a grid
Merineth πŸ‡ΈπŸ‡ͺ
Now comes that hard part trying to utilize girds :I
Pobiega
Pobiegaβ€’2w ago
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
Pobiega
Pobiegaβ€’2w ago
I'm not very good with WPF layout myself, but using a combination of grids and stackpanels got me to here:
No description
Merineth πŸ‡ΈπŸ‡ͺ
Yeahhh the tutorial was good
Merineth πŸ‡ΈπŸ‡ͺ
i almost have it Just gotta implement the text and buttons now
Pobiega
Pobiegaβ€’2w ago
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 row
Merineth πŸ‡ΈπŸ‡ͺ
Yeaa
Merineth πŸ‡ΈπŸ‡ͺ
I might need another column? I aligned it to the right not sure how i'm gonna get it perfectly centered
Dinosaure
Dinosaureβ€’2w ago
You can have a row "spanned" across multiple columns, with something like "colspan=2", or likewise.
Merineth πŸ‡ΈπŸ‡ͺ
YEAH columnspan!! That's it
Merineth πŸ‡ΈπŸ‡ͺ
LMFAO when i resize it it doesn't follow? Not sure what that is called, dynamic?
Dinosaure
Dinosaureβ€’2w ago
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.
Merineth πŸ‡ΈπŸ‡ͺ
Interesting! I'll see if i can add that This is kinda cool ngl
Dinosaure
Dinosaureβ€’2w ago
You should have a look at alignments to have a better pov on the dynamic layering.
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
Merineth πŸ‡ΈπŸ‡ͺ
I managed to do it c: Now comes the hard part......... c# :aaaa:
Dinosaure
Dinosaureβ€’2w ago
If you need help for the C#, you can ask here aswell.
Merineth πŸ‡ΈπŸ‡ͺ
I can't seem to find the appropriate tool which allows me to recieve a string from the user
No description
Merineth πŸ‡ΈπŸ‡ͺ
any ideas what it's called? aah found it, textbox
Merineth πŸ‡ΈπŸ‡ͺ
Any ideas on how i can make the button come in front of grid.column 0 and 2?
No description
Pobiega
Pobiegaβ€’2w ago
?
No description
Pobiega
Pobiegaβ€’2w ago
you can put a layout component in a grid cell and then use alignments on it
Want results from more Discord servers?
Add your server