I wanna build a Tic Tac Toe Blazor game. To print the fields I am using html buttons and a foreach loop:
Matchfield is a list consisting the tictactoe fields.
The PrintSymbolOnButton method should print the players symbol (X(O) on the button.
The method looks like this:
is the class for the fields, it looks like this:
How can I write the
Method to print the players symbol on this button which was clicked?
Is there a similar method to the JS function GetElementById?
C#:
@if(MatchField != null)
{
@foreach(var field in MatchField)
{
<span>
<button @onclick="() => PrintSymbolOnButton(field)" >
@ElementOfMatchField.Symbol
</button>
</span>
}
}
Matchfield is a list consisting the tictactoe fields.
The PrintSymbolOnButton method should print the players symbol (X(O) on the button.
The method looks like this:
C#:
public static void PrintSymbolOnButton(ElementOfMatchField field)
{
ElementOfMatchField.Symbol = "X";
}
C#:
ElementOfMatchField()
C#:
public class ElementOfMatchField
{
public int Row { get; set; }
public int Column { get; set; }
public static string Symbol { get; set; }
public Player ClickedBy { get; set; }
public ElementOfMatchField(int row, int column)
{
this.Row = row;
this.Column = column;
}
}
How can I write the
C#:
PrintSymbolOnButton()
Is there a similar method to the JS function GetElementById?