Skip to content

Commit baa8f35

Browse files
Merge pull request #97 from CodebreakerApp/75-ui-set-move
Enabled to select fields by clicking instead of dragging.
2 parents 60e4400 + cae3301 commit baa8f35

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
ondragover="event.preventDefault();"
2222
@ondragenter="@(() => SetDropClass(localVariable))"
2323
@ondragleave="@RemoveDropClass"
24-
@ondrop="() => UpdateField(localVariable)" />
24+
@ondrop="() => UpdateField(localVariable)"
25+
@onclick="() => SelectField(localVariable)" />
2526
}
2627
else if (_isMobile && i == 1)
2728
{
@@ -70,7 +71,8 @@
7071
{
7172
<div draggable="true"
7273
class="@($"draggable {colorField.ToLower()}")"
73-
@ondragstart="@(() => _activeColor = colorField)">
74+
@ondragstart="@(() => _activeColor = colorField)"
75+
@onclick="() => SelectColor(colorField)">
7476
@colorField[0]
7577
</div>
7678
}
@@ -91,7 +93,8 @@
9193
{
9294
<div draggable="true"
9395
class="@($"draggable shape {shapeField.ToLower()}")"
94-
@ondragstart="@(() => _activeShape = shapeField)" />
96+
@ondragstart="@(() => _activeShape = shapeField)"
97+
@onclick="() => SelectShape(shapeField)" />
9598
}
9699
else
97100
{

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,23 @@ private void SelectField(int index)
122122

123123
private void SelectColor(string color)
124124
{
125-
_currentMove[_selectedField].Selected = true;
126-
_currentMove[_selectedField].Color = color;
125+
int fieldIndex;
126+
127+
// If a field is selected, use the selected field
128+
if (_selectedField != -1)
129+
fieldIndex = _selectedField;
130+
else
131+
{
132+
// If no field is selected, find the first field that is not set
133+
fieldIndex = Array.FindIndex(_currentMove, f => f.Color is null && f.Shape is null);
134+
135+
// If all fields are set, do not set the color
136+
if (fieldIndex == -1)
137+
return;
138+
}
139+
140+
_currentMove[fieldIndex].Selected = true;
141+
_currentMove[fieldIndex].Color = color;
127142
}
128143

129144
private void SelectShape(string shape)

0 commit comments

Comments
 (0)