Description:
Whenever I close and reopen the GameLauncher, only the last hexagon is displayed, instead of all the games that were previously added. This seems to be caused by the "index" variable in the "showGames" method, which is not correctly incremented after adding a new game.
Steps to reproduce:
Open the GameLauncher and add at least 2 games.
Close the GameLauncher.
Reopen the GameLauncher.
Expected result:
All the games previously added should be displayed as hexagons.
Actual result:
Only the last game added is displayed.
Proposed solution:
I suggest incrementing the "index" variable after adding a new game in the "showGames" method. Here's the modified code```
private void showGames(string key)
{
var hexagonPoints = new Point[] {
new Point(50, 0), new Point(100, 25), new Point(100, 75),
new Point(50, 100), new Point(0, 75), new Point(0, 25)
};
var hexagon = CreateHexagon(hexagonPoints);
int hexPerRow = Math.Min(config.Games.Count, 5);
int row = (index - 1) / hexPerRow;
int col = (index - 1) % hexPerRow;
double x = col 100 + (row % 2 == 0 ? 50 : 0);
double y = row 87;
Canvas.SetLeft(hexagon, x);
Canvas.SetTop(hexagon, y);
var button = new Button();
button.Content = key;
button.Width = 110;
button.Height = 100;
Canvas.SetLeft(button, x);
Canvas.SetTop(button, y);
button.Click += (sender, e) => Button_Click(Convert.ToString(button.Content));
button.Opacity = 0;
canvas.Children.Add(hexagon);
canvas.Children.Add(button);
index++;
}
Description: Whenever I close and reopen the GameLauncher, only the last hexagon is displayed, instead of all the games that were previously added. This seems to be caused by the "index" variable in the "showGames" method, which is not correctly incremented after adding a new game.
Steps to reproduce:
Open the GameLauncher and add at least 2 games. Close the GameLauncher. Reopen the GameLauncher. Expected result: All the games previously added should be displayed as hexagons.
Actual result: Only the last game added is displayed.
Proposed solution: I suggest incrementing the "index" variable after adding a new game in the "showGames" method. Here's the modified code``` private void showGames(string key) { var hexagonPoints = new Point[] { new Point(50, 0), new Point(100, 25), new Point(100, 75), new Point(50, 100), new Point(0, 75), new Point(0, 25) }; var hexagon = CreateHexagon(hexagonPoints); int hexPerRow = Math.Min(config.Games.Count, 5); int row = (index - 1) / hexPerRow; int col = (index - 1) % hexPerRow; double x = col 100 + (row % 2 == 0 ? 50 : 0); double y = row 87; Canvas.SetLeft(hexagon, x); Canvas.SetTop(hexagon, y); var button = new Button(); button.Content = key; button.Width = 110; button.Height = 100; Canvas.SetLeft(button, x); Canvas.SetTop(button, y); button.Click += (sender, e) => Button_Click(Convert.ToString(button.Content)); button.Opacity = 0; canvas.Children.Add(hexagon); canvas.Children.Add(button); index++; }