DO-33 Fix: GameLogic 수정
확장성을 높이기 위해 코드 수정
This commit is contained in:
parent
dcdd046ad7
commit
efaf3095c1
8
Assets/LYC.meta
Normal file
8
Assets/LYC.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2c121ebd683637b4a9f10f3360db1bd5
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
19548
Assets/LYC/GameCopyLYC.unity
Normal file
19548
Assets/LYC/GameCopyLYC.unity
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/LYC/GameCopyLYC.unity.meta
Normal file
7
Assets/LYC/GameCopyLYC.unity.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c7eedd59cc78a7648a2168fd25540b88
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -11988,7 +11988,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: a98355720bed2234fb32d55fc1b0cce6, type: 3}
|
m_Script: {fileID: 11500000, guid: a98355720bed2234fb32d55fc1b0cce6, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
widthUnit: 15.5
|
widthUnit: 15
|
||||||
--- !u!114 &1612127712 stripped
|
--- !u!114 &1612127712 stripped
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_CorrespondingSourceObject: {fileID: 2897735151576090782, guid: 42b665a12a9843240ac0860bf0eee63e, type: 3}
|
m_CorrespondingSourceObject: {fileID: 2897735151576090782, guid: 42b665a12a9843240ac0860bf0eee63e, type: 3}
|
||||||
@ -18380,10 +18380,10 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
|
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
m_UiScaleMode: 0
|
m_UiScaleMode: 1
|
||||||
m_ReferencePixelsPerUnit: 100
|
m_ReferencePixelsPerUnit: 100
|
||||||
m_ScaleFactor: 1
|
m_ScaleFactor: 1
|
||||||
m_ReferenceResolution: {x: 800, y: 600}
|
m_ReferenceResolution: {x: 1080, y: 1920}
|
||||||
m_ScreenMatchMode: 0
|
m_ScreenMatchMode: 0
|
||||||
m_MatchWidthOrHeight: 0
|
m_MatchWidthOrHeight: 0
|
||||||
m_PhysicalUnit: 3
|
m_PhysicalUnit: 3
|
||||||
|
@ -13,10 +13,4 @@ public class CameraController : MonoBehaviour
|
|||||||
_camera = GetComponent<Camera>();
|
_camera = GetComponent<Camera>();
|
||||||
_camera.orthographicSize = widthUnit / _camera.aspect / 2;
|
_camera.orthographicSize = widthUnit / _camera.aspect / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,95 +2,211 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
public abstract class BasePlayerState
|
||||||
|
{
|
||||||
|
public abstract void OnEnter(GameLogic gameLogic);
|
||||||
|
public abstract void OnExit(GameLogic gameLogic);
|
||||||
|
public abstract void HandleMove(GameLogic gameLogic, int row, int col);
|
||||||
|
public abstract void HandleNextTurn(GameLogic gameLogic);
|
||||||
|
|
||||||
|
public void ProcessMove(GameLogic gameLogic, Enums.PlayerType playerType, int row, int col)
|
||||||
|
{
|
||||||
|
gameLogic.SetNewBoardValue(playerType, row, col);
|
||||||
|
//TODO: 승패 비교 필요
|
||||||
|
|
||||||
|
HandleNextTurn(gameLogic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PlayerState : BasePlayerState
|
||||||
|
{
|
||||||
|
private Enums.PlayerType _playerType;
|
||||||
|
private bool _isFirstPlayer;
|
||||||
|
public PlayerState(bool isFirstPlayer)
|
||||||
|
{
|
||||||
|
_isFirstPlayer = isFirstPlayer;
|
||||||
|
_playerType = isFirstPlayer ? Enums.PlayerType.PlayerA : Enums.PlayerType.PlayerB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnEnter(GameLogic gameLogic)
|
||||||
|
{
|
||||||
|
gameLogic.currentTurn = _playerType;
|
||||||
|
gameLogic.stoneController.OnStoneClickedDelegate = (row, col) =>
|
||||||
|
{
|
||||||
|
HandleMove(gameLogic, row, col);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnExit(GameLogic gameLogic)
|
||||||
|
{
|
||||||
|
gameLogic.stoneController.OnStoneClickedDelegate = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void HandleMove(GameLogic gameLogic, int row, int col)
|
||||||
|
{
|
||||||
|
gameLogic.SetStoneSelectedState(row, col);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void HandleNextTurn(GameLogic gameLogic)
|
||||||
|
{
|
||||||
|
if (_isFirstPlayer)
|
||||||
|
{
|
||||||
|
gameLogic.SetState(gameLogic.secondPlayerState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gameLogic.SetState(gameLogic.firstPlayerState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AIState: BasePlayerState
|
||||||
|
{
|
||||||
|
public override void OnEnter(GameLogic gameLogic)
|
||||||
|
{
|
||||||
|
//TODO: AI이식
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnExit(GameLogic gameLogic)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void HandleMove(GameLogic gameLogic, int row, int col)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void HandleNextTurn(GameLogic gameLogic)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class MultiPlayerState: BasePlayerState
|
||||||
|
{
|
||||||
|
public override void OnEnter(GameLogic gameLogic)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnExit(GameLogic gameLogic)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void HandleMove(GameLogic gameLogic, int row, int col)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void HandleNextTurn(GameLogic gameLogic)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class GameLogic : MonoBehaviour
|
public class GameLogic : MonoBehaviour
|
||||||
{
|
{
|
||||||
private Enums.PlayerType[,] _board;
|
private Enums.PlayerType[,] _board;
|
||||||
private StoneController _stoneController;
|
public StoneController stoneController;
|
||||||
public Enums.PlayerType currentTurn;
|
public Enums.PlayerType currentTurn;
|
||||||
|
public BasePlayerState firstPlayerState;
|
||||||
|
public BasePlayerState secondPlayerState;
|
||||||
|
private BasePlayerState _currentPlayerState;
|
||||||
//선택된 좌표
|
//선택된 좌표
|
||||||
public int selectedRow;
|
public int selectedRow;
|
||||||
public int selectedCol;
|
public int selectedCol;
|
||||||
//마지막 배치된 좌표
|
//마지막 배치된 좌표
|
||||||
public int lastRow;
|
private int _lastRow;
|
||||||
public int lastCol;
|
private 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;
|
this.stoneController = stoneController;
|
||||||
selectedRow = -1;
|
selectedRow = -1;
|
||||||
selectedCol = -1;
|
selectedCol = -1;
|
||||||
lastRow = -1;
|
_lastRow = -1;
|
||||||
lastCol = -1;
|
_lastCol = -1;
|
||||||
|
|
||||||
currentTurn = Enums.PlayerType.PlayerA;
|
switch (gameType)
|
||||||
|
{
|
||||||
SetState(currentTurn);
|
case Enums.GameType.SinglePlay:
|
||||||
|
firstPlayerState = new PlayerState(true);
|
||||||
|
secondPlayerState = new PlayerState(false);
|
||||||
|
SetState(firstPlayerState);
|
||||||
|
break;
|
||||||
|
case Enums.GameType.MultiPlay:
|
||||||
|
//TODO: 멀티 구현 필요
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetState(Enums.PlayerType player)
|
public void OnConfirm()
|
||||||
{
|
{
|
||||||
currentTurn = player;
|
_currentPlayerState.ProcessMove(this, currentTurn, selectedRow, selectedCol);
|
||||||
_stoneController.OnStoneClickedDelegate = (row, col) =>
|
}
|
||||||
|
|
||||||
|
public void SetState(BasePlayerState state)
|
||||||
|
{
|
||||||
|
_currentPlayerState?.OnExit(this);
|
||||||
|
_currentPlayerState = state;
|
||||||
|
_currentPlayerState?.OnEnter(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
//스톤의 상태변경 명령함수
|
||||||
|
public void SetStoneNewState(Enums.StoneState state, int row, int col)
|
||||||
|
{
|
||||||
|
stoneController.SetStoneState(state, row, col);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetStoneSelectedState(int row, int col)
|
||||||
|
{
|
||||||
|
if (_board[row, col] != Enums.PlayerType.None) return;
|
||||||
|
//첫수 및 중복 확인
|
||||||
|
if ((selectedRow != row || selectedCol != col) && (selectedRow != -1 && selectedCol != -1))
|
||||||
{
|
{
|
||||||
if (_board[row, col] == Enums.PlayerType.None)
|
stoneController.SetStoneState(Enums.StoneState.None,selectedRow, selectedCol);
|
||||||
{
|
}
|
||||||
if ((selectedRow != row || selectedCol != col) && (selectedRow != -1 && selectedCol != -1))
|
selectedRow = row;
|
||||||
{
|
selectedCol = col;
|
||||||
SetStoneNewState(Enums.StoneState.None,selectedRow, selectedCol);
|
stoneController.SetStoneState(Enums.StoneState.Selected, row, col);
|
||||||
}
|
|
||||||
selectedRow = row;
|
|
||||||
selectedCol = 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 (_board[row, col] != Enums.PlayerType.None) return;
|
||||||
|
if (playerType == Enums.PlayerType.PlayerA)
|
||||||
{
|
{
|
||||||
if (playerType == Enums.PlayerType.PlayerA)
|
stoneController.SetStoneType(Enums.StoneType.Black, row, col);
|
||||||
{
|
stoneController.SetStoneState(Enums.StoneState.LastPositioned, row, col);
|
||||||
_stoneController.SetStoneType(Enums.StoneType.Black, row, col);
|
_board[row, col] = Enums.PlayerType.PlayerA;
|
||||||
_stoneController.SetStoneState(Enums.StoneState.LastPositioned, row, col);
|
LastNSelectedSetting(row, col);
|
||||||
_board[row, col] = Enums.PlayerType.PlayerA;
|
}
|
||||||
LastNSelectedSetting(row, col);
|
if (playerType == Enums.PlayerType.PlayerB)
|
||||||
|
{
|
||||||
SetState(Enums.PlayerType.PlayerB);
|
stoneController.SetStoneType(Enums.StoneType.White, row, col);
|
||||||
}
|
stoneController.SetStoneState(Enums.StoneState.LastPositioned, row, col);
|
||||||
if (playerType == Enums.PlayerType.PlayerB)
|
_board[row, col] = Enums.PlayerType.PlayerB;
|
||||||
{
|
LastNSelectedSetting(row, col);
|
||||||
_stoneController.SetStoneType(Enums.StoneType.White, row, col);
|
|
||||||
_stoneController.SetStoneState(Enums.StoneState.LastPositioned, row, col);
|
|
||||||
_board[row, col] = Enums.PlayerType.PlayerB;
|
|
||||||
|
|
||||||
LastNSelectedSetting(row, col);
|
|
||||||
SetState(Enums.PlayerType.PlayerA);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//마지막 좌표와 선택 좌표 세팅
|
||||||
private void LastNSelectedSetting(int row, int col)
|
private void LastNSelectedSetting(int row, int col)
|
||||||
{
|
{
|
||||||
//첫수 확인
|
//첫수 확인
|
||||||
if (lastRow != -1 || lastCol != -1)
|
if (_lastRow != -1 || _lastCol != -1)
|
||||||
{
|
{
|
||||||
_stoneController.SetStoneState(Enums.StoneState.None, lastRow, lastCol);
|
stoneController.SetStoneState(Enums.StoneState.None, _lastRow, _lastCol);
|
||||||
}
|
}
|
||||||
//마지막 좌표 저장
|
//마지막 좌표 저장
|
||||||
lastRow = row;
|
_lastRow = row;
|
||||||
lastCol = col;
|
_lastCol = col;
|
||||||
//선택 좌표 초기화
|
//선택 좌표 초기화
|
||||||
selectedRow = -1;
|
selectedRow = -1;
|
||||||
selectedCol = -1;
|
selectedCol = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//스톤의 상태변경 명령함수
|
|
||||||
private void SetStoneNewState(Enums.StoneState state, int row, int col)
|
|
||||||
{
|
|
||||||
_stoneController.SetStoneState(state, row, col);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -25,16 +25,15 @@ public class GameManager : Singleton<GameManager>
|
|||||||
{
|
{
|
||||||
GameObject userManagerObj = new GameObject("UserManager");
|
GameObject userManagerObj = new GameObject("UserManager");
|
||||||
_userManager = userManagerObj.AddComponent<UserManager>();
|
_userManager = userManagerObj.AddComponent<UserManager>();
|
||||||
|
|
||||||
//게임 씬에서 확인하기 위한 임시 코드
|
|
||||||
_gameType = Enums.GameType.SinglePlay;
|
|
||||||
}
|
}
|
||||||
|
//게임 씬에서 확인하기 위한 임시 코드
|
||||||
|
_gameType = Enums.GameType.SinglePlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
// 자동 로그인
|
// 자동 로그인
|
||||||
TryAutoSignin();
|
// TryAutoSignin();
|
||||||
|
|
||||||
//게임 씬에서 확인하기 위한 임시 코드
|
//게임 씬에서 확인하기 위한 임시 코드
|
||||||
_stoneController = GameObject.FindObjectOfType<StoneController>();
|
_stoneController = GameObject.FindObjectOfType<StoneController>();
|
||||||
@ -86,7 +85,15 @@ public class GameManager : Singleton<GameManager>
|
|||||||
|
|
||||||
public void OnClickConfirmButton()
|
public void OnClickConfirmButton()
|
||||||
{
|
{
|
||||||
_gameLogic.SetNewBoardValue(_gameLogic.currentTurn, _gameLogic.selectedRow,_gameLogic.selectedCol);
|
if (_gameLogic.selectedRow != -1 && _gameLogic.selectedCol != -1)
|
||||||
|
{
|
||||||
|
_gameLogic.OnConfirm();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log("착수 위치를 선택 해주세요");
|
||||||
|
//TODO: 착수할 위치를 선택하라는 동작
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ChangeToGameScene(Enums.GameType gameType)
|
private void ChangeToGameScene(Enums.GameType gameType)
|
||||||
|
@ -27,7 +27,6 @@ public class StoneController : MonoBehaviour
|
|||||||
//스톤 타입변경
|
//스톤 타입변경
|
||||||
public void SetStoneType(Enums.StoneType stoneType, int row, int col)
|
public void SetStoneType(Enums.StoneType stoneType, int row, int col)
|
||||||
{
|
{
|
||||||
|
|
||||||
var index = MaxCellCount * row + col;
|
var index = MaxCellCount * row + col;
|
||||||
stones[index].SetStone(stoneType);
|
stones[index].SetStone(stoneType);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user