Skip to content

Commit df1189e

Browse files
author
RUBIUS\chebanovdd
committed
Added unselect item logic.
1 parent e9f5063 commit df1189e

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

samples/Terminal.Match3/TerminalGame.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private void OnKeyPressed(object sender, ConsoleKey key)
5252
MoveCursor(GridPosition.Right);
5353
break;
5454
case ConsoleKey.Spacebar:
55-
SelectItem();
55+
ChangeItemSelection();
5656
break;
5757
}
5858
}
@@ -74,18 +74,34 @@ private void MoveCursor(GridPosition direction)
7474
_gameBoardRenderer.ActivateItem(gridPosition);
7575
}
7676

77-
private void SelectItem()
77+
private void ChangeItemSelection()
78+
{
79+
if (_hasSelectedItem)
80+
{
81+
ClearSelection();
82+
}
83+
else
84+
{
85+
SelectActiveItem();
86+
}
87+
}
88+
89+
private void DragItem(GridPosition gridPosition)
90+
{
91+
ClearSelection();
92+
SwapItemsAsync(_gameBoardRenderer.ActiveGridPosition, gridPosition).Forget();
93+
}
94+
95+
private void SelectActiveItem()
7896
{
7997
_hasSelectedItem = true;
8098
_gameBoardRenderer.SelectActiveGridSlot();
8199
}
82100

83-
private void DragItem(GridPosition gridPosition)
101+
private void ClearSelection()
84102
{
85103
_hasSelectedItem = false;
86104
_gameBoardRenderer.ClearSelection();
87-
88-
SwapItemsAsync(_gameBoardRenderer.ActiveGridPosition, gridPosition).Forget();
89105
}
90106
}
91107
}

0 commit comments

Comments
 (0)