wailroth
Explore posts from serversRefresh 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
then my board
The isssue is: I can't refresh just 1 card to make it visible
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;
}
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));
}
4 replies