wailroth
wailroth
Explore posts from servers
CC#
Created by wailroth on 6/8/2024 in #help
Refresh a card without refreshing the whole board
Hi, For my studies we have to make a small game in MAUI; Si basically have this Matrix2D
public void RefreshMatrix(Card card)
{
var index = FlatMatrix2d.ToList().FindIndex(x => x.Value == card.Value);
_matrix = Game.GetCardBoardClone();
FlatMatrix2d.ElementAt(index).IsVisible = card.IsVisible;
OnPropertyChanged(nameof(FlatMatrix2d));
}

public IEnumerable<Card> FlatMatrix2d
{
get => _flatMatrix2d;
set
{
_flatMatrix2d = value;
OnPropertyChanged();
}
}

public IEnumerable<Card> GetFlatMatrix()
{
List<Card> flatMatrix = new();

if (_matrix == null) return flatMatrix;
for (int numRow = 0; numRow < NbRows; numRow++)
{
for (int numCol = 0; numCol < NbColumns; numCol++)
{
flatMatrix.Add(_matrix[numRow, numCol]);
}
}

return flatMatrix;
}
public void RefreshMatrix(Card card)
{
var index = FlatMatrix2d.ToList().FindIndex(x => x.Value == card.Value);
_matrix = Game.GetCardBoardClone();
FlatMatrix2d.ElementAt(index).IsVisible = card.IsVisible;
OnPropertyChanged(nameof(FlatMatrix2d));
}

public IEnumerable<Card> FlatMatrix2d
{
get => _flatMatrix2d;
set
{
_flatMatrix2d = value;
OnPropertyChanged();
}
}

public IEnumerable<Card> GetFlatMatrix()
{
List<Card> flatMatrix = new();

if (_matrix == null) return flatMatrix;
for (int numRow = 0; numRow < NbRows; numRow++)
{
for (int numCol = 0; numCol < NbColumns; numCol++)
{
flatMatrix.Add(_matrix[numRow, numCol]);
}
}

return flatMatrix;
}
then my board
public void Card_Clicked(object sender, EventArgs e)
{
_effectContainer.PlaySound();
if (!_shouldPlayNextTurn)
{
_shouldPlayNextTurn = true;
return;
}

var button = (ImageButton)sender;
var card = (Card)button.BindingContext;
_gameManager.PlayTurn(card.X, card.Y);

//Quand la game est fini si duo faire pour la persistance :

//SaveManager saveManager = new SaveManager();
//GameSave parameter = new GameSave("NameWinner", "NameLooser", "winnerScore", "looserScore", "difficulty");
//saveManager.UpdateGameHistory(parameter);
}


private void OnCardTurned(Card card)
{
Matrix.RefreshMatrix(card);
OnPropertyChanged(nameof(Matrix.FlatMatrix2d));
}


public void Card_Clicked(object sender, EventArgs e)
{
_effectContainer.PlaySound();
if (!_shouldPlayNextTurn)
{
_shouldPlayNextTurn = true;
return;
}

var button = (ImageButton)sender;
var card = (Card)button.BindingContext;
_gameManager.PlayTurn(card.X, card.Y);

//Quand la game est fini si duo faire pour la persistance :

//SaveManager saveManager = new SaveManager();
//GameSave parameter = new GameSave("NameWinner", "NameLooser", "winnerScore", "looserScore", "difficulty");
//saveManager.UpdateGameHistory(parameter);
}


private void OnCardTurned(Card card)
{
Matrix.RefreshMatrix(card);
OnPropertyChanged(nameof(Matrix.FlatMatrix2d));
}


The isssue is: I can't refresh just 1 card to make it visible
4 replies
CC#
Created by wailroth on 3/21/2024 in #help
Maui .NET 8.0 On macOS
No description
2 replies