DO-8 중복 배치 수정
This commit is contained in:
parent
9d7efaaedf
commit
d0f76ff05a
@ -7,52 +7,83 @@ 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;
|
||||||
|
selectedCol = col;
|
||||||
|
SetStoneNewState(Enums.StoneState.Selected, row, col);
|
||||||
}
|
}
|
||||||
selectedRow = row;
|
|
||||||
selectedCol = col;
|
|
||||||
SetNewStoneState(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 (playerType == Enums.PlayerType.PlayerA)
|
if (_board[row, col] == Enums.PlayerType.None)
|
||||||
{
|
{
|
||||||
_stoneController.SetStoneType(Enums.StoneType.Black, row, col);
|
if (playerType == Enums.PlayerType.PlayerA)
|
||||||
_stoneController.SetStoneState(Enums.StoneState.LastPositioned, row, col);
|
{
|
||||||
_board[row, col] = Enums.PlayerType.PlayerA;
|
_stoneController.SetStoneType(Enums.StoneType.Black, row, col);
|
||||||
}
|
_stoneController.SetStoneState(Enums.StoneState.LastPositioned, row, col);
|
||||||
if (playerType == Enums.PlayerType.PlayerB)
|
_board[row, col] = Enums.PlayerType.PlayerA;
|
||||||
{
|
}
|
||||||
_stoneController.SetStoneType(Enums.StoneType.Black, row, col);
|
if (playerType == Enums.PlayerType.PlayerB)
|
||||||
_stoneController.SetStoneState(Enums.StoneState.LastPositioned, row, col);
|
{
|
||||||
_board[row, col] = Enums.PlayerType.PlayerB;
|
_stoneController.SetStoneType(Enums.StoneType.White, row, col);
|
||||||
}
|
_stoneController.SetStoneState(Enums.StoneState.LastPositioned, row, col);
|
||||||
|
_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);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user