C
C#5w ago
wailroth

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
3 Replies
wailroth
wailroth5w ago
Without refreshing the whole board
wailroth
wailroth5w ago
GitHub
GitHub - WailRoth/student-project-memory: Student project memory game
Student project memory game. Contribute to WailRoth/student-project-memory development by creating an account on GitHub.
wailroth
wailroth5w ago
GitHub
student-project-memory/sources/Memory/Memory/Layouts/Matrix2d.cs at...
Student project memory game. Contribute to WailRoth/student-project-memory development by creating an account on GitHub.
GitHub
student-project-memory/sources/Memory/Memory/Views/Pages/BoardPage....
Student project memory game. Contribute to WailRoth/student-project-memory development by creating an account on GitHub.