Skip to content

Commit f575c7e

Browse files
committed
Fixed issue where selecting a shape throws an exception
1 parent cee45d0 commit f575c7e

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

src/CodeBreaker.Blazor.Client/Components/Playground.razor.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private void SelectColor(string color)
135135
else
136136
{
137137
// If no field is selected, find the first field that is not set
138-
fieldIndex = Array.FindIndex(_currentMove, f => f.Color is null && f.Shape is null);
138+
fieldIndex = Array.FindIndex(_currentMove, f => f.Color is null);
139139

140140
// If all fields are set, do not set the color
141141
if (fieldIndex == -1)
@@ -148,8 +148,26 @@ private void SelectColor(string color)
148148

149149
private void SelectShape(string shape)
150150
{
151-
_currentMove[_selectedField].Selected = true;
152-
_currentMove[_selectedField].Shape = shape;
151+
//_currentMove[_selectedField].Selected = true;
152+
//_currentMove[_selectedField].Shape = shape;
153+
154+
int fieldIndex;
155+
156+
// If a field is selected, use the selected field
157+
if (_selectedField != -1)
158+
fieldIndex = _selectedField;
159+
else
160+
{
161+
// If no field is selected, find the first field that is not set
162+
fieldIndex = Array.FindIndex(_currentMove, f => f.Shape is null);
163+
164+
// If all fields are set, do not set the color
165+
if (fieldIndex == -1)
166+
return;
167+
}
168+
169+
_currentMove[fieldIndex].Selected = true;
170+
_currentMove[fieldIndex].Shape = shape;
153171
}
154172
#endregion
155173

0 commit comments

Comments
 (0)