DO-8 중복 배치 수정

This commit is contained in:
Lim0_C 2025-03-14 10:04:38 +09:00
parent 9d7efaaedf
commit d0f76ff05a
2 changed files with 51 additions and 19 deletions

View File

@ -7,35 +7,53 @@ public class GameLogic : MonoBehaviour
private Enums.PlayerType[,] _board; private Enums.PlayerType[,] _board;
private StoneController _stoneController; private StoneController _stoneController;
public Enums.PlayerType currentTurn; public Enums.PlayerType currentTurn;
//선택된 좌표
public int selectedRow; public int selectedRow;
public int selectedCol; public int selectedCol;
//마지막 배치된 좌표
public int lastRow;
public int lastCol;
public GameLogic(StoneController stoneController, Enums.GameType gameType) public GameLogic(StoneController stoneController, Enums.GameType gameType)
{ {
//보드 초기화 //보드 초기화
_board = new Enums.PlayerType[15, 15]; _board = new Enums.PlayerType[15, 15];
_stoneController = stoneController; _stoneController = stoneController;
selectedRow = -1;
selectedCol = -1;
lastRow = -1;
lastCol = -1;
SetTurn(Enums.PlayerType.PlayerA); SetTurn(Enums.PlayerType.PlayerA);
} }
private void SetState()
{
}
private void SetTurn(Enums.PlayerType player) private void SetTurn(Enums.PlayerType player)
{ {
currentTurn = player; currentTurn = player;
_stoneController.OnStoneClickedDelegate = (row, col) => _stoneController.OnStoneClickedDelegate = (row, col) =>
{ {
if (selectedRow != row || selectedCol != col) if (_board[row, col] == Enums.PlayerType.None)
{ {
SetNewStoneState(Enums.StoneState.None,selectedRow, selectedCol); if ((selectedRow != row || selectedCol != col) && (selectedRow != -1 && selectedCol != -1))
{
SetStoneNewState(Enums.StoneState.None,selectedRow, selectedCol);
} }
selectedRow = row; selectedRow = row;
selectedCol = col; selectedCol = col;
SetNewStoneState(Enums.StoneState.Selected, row, col); SetStoneNewState(Enums.StoneState.Selected, row, col);
}
}; };
} }
//보드에 돌추가 함수
public void SetNewBoardValue(Enums.PlayerType playerType, int row, int col) public void SetNewBoardValue(Enums.PlayerType playerType, int row, int col)
{
if (_board[row, col] == Enums.PlayerType.None)
{ {
if (playerType == Enums.PlayerType.PlayerA) if (playerType == Enums.PlayerType.PlayerA)
{ {
@ -45,14 +63,27 @@ public class GameLogic : MonoBehaviour
} }
if (playerType == Enums.PlayerType.PlayerB) if (playerType == Enums.PlayerType.PlayerB)
{ {
_stoneController.SetStoneType(Enums.StoneType.Black, row, col); _stoneController.SetStoneType(Enums.StoneType.White, row, col);
_stoneController.SetStoneState(Enums.StoneState.LastPositioned, row, col); _stoneController.SetStoneState(Enums.StoneState.LastPositioned, row, col);
_board[row, col] = Enums.PlayerType.PlayerB; _board[row, col] = Enums.PlayerType.PlayerB;
} }
//첫수 확인
if (lastRow != -1 || lastCol != -1)
{
_stoneController.SetStoneState(Enums.StoneState.None, lastRow, lastCol);
}
//마지막 좌표 저장
lastRow = row;
lastCol = col;
//선택 좌표 초기화
selectedRow = -1;
selectedCol = -1;
}
} }
private void SetNewStoneState(Enums.StoneState state, int row, int col) //스톤의 상태변경 명령함수
private void SetStoneNewState(Enums.StoneState state, int row, int col)
{ {
_stoneController.SetStoneState(state, row, col); _stoneController.SetStoneState(state, row, col);
} }

View File

@ -24,7 +24,7 @@ public class StoneController : MonoBehaviour
}); });
} }
} }
//스톤 타입변경
public void SetStoneType(Enums.StoneType stoneType, int row, int col) public void SetStoneType(Enums.StoneType stoneType, int row, int col)
{ {
@ -32,6 +32,7 @@ public class StoneController : MonoBehaviour
stones[index].SetStone(stoneType); stones[index].SetStone(stoneType);
} }
//스톤상태변경
public void SetStoneState(Enums.StoneState state,int row, int col) public void SetStoneState(Enums.StoneState state,int row, int col)
{ {
var index = BoardValue * row + col; var index = BoardValue * row + col;