diff --git a/Assets/Scripts/Character.cs b/Assets/Scripts/Character.cs index 20e73df..1bacdb8 100644 --- a/Assets/Scripts/Character.cs +++ b/Assets/Scripts/Character.cs @@ -15,19 +15,22 @@ public class Character : MonoBehaviour, Observer public float _myDamage; protected int _gameRound; - protected int _whoseTurn; + protected int _whoseTurn;//GameManager ->Roundnoti protected bool _isFinished; // 1. TurnUpdate: _gameRound, _whoseTurn update public void TurnUpdate(int round, string turn) { + _gameRound = round; + _whoseTurn = turn; + } // 2. FinishUpdate: _isFinished update public void FinishUpdate(bool isFinish) { - + _isFinished = isFinish; } /// @@ -39,7 +42,15 @@ public void FinishUpdate(bool isFinish) /// public virtual void Attack() { - + //���� �ȳ����� , _myName ==_whoseTurn -> AttackMotion() + //������ GetHit(float damage)�� _myDamage �� �Ѱܼ� ȣ�� -> �ʿ��Ѱ��� + + if (_isFinished == true) return; + else if (_myName == _whoseTurn) + { + AttackMotion(); + + } } /// @@ -47,13 +58,22 @@ public virtual void Attack() /// ���� �� class���� �������̵��ؼ� �ۼ� /// 1) �Ѱ� ���� damage��ŭ _myHp ���� /// 2) ���� _myHp�� 0���� �۰ų� ���ٸ�, DeadMotion() ȣ���ؼ� �ִϸ��̼� ���� - /// + Subject�� EndNotify() ȣ�� + /// ##Gamemanager ���� �� + Subject�� EndNotify() ȣ�� /// 3) ���� ����ִٸ�, GetHitMotion() ȣ���ؼ� �ִϸ��̼� ���� /// + Debug.Log($"{_myName} HP: {_myHp}"); �߰� /// public virtual void GetHit(float damage) { - + _myHp -= damage; + if (_myHp =< 0) + { + DeadMotion(); + GameManager.Instance().EndNotify(); + } + else { + GetHitMotion(); + Debug.Log($"{_myName} HP:{_myHp}"); + } } /// diff --git a/Assets/Scripts/Enemy.cs b/Assets/Scripts/Enemy.cs index 3a1636d..5b3f0ba 100644 --- a/Assets/Scripts/Enemy.cs +++ b/Assets/Scripts/Enemy.cs @@ -17,11 +17,16 @@ public class Enemy : Character protected override void Init() { base.Init(); + GameManager.Instance.AddCharacter(this); + _myName = "Enemy"; + _myHp = 100; + _myDamage = 10; } private void Awake() { Init(); + } /// @@ -30,7 +35,10 @@ private void Awake() /// private void Start() { - + if (_player == null) + { + _player = GameObject.FindWithTag("Player").GetComponent(); + } } /// @@ -40,7 +48,20 @@ private void Start() /// public override void Attack() { + if (_myName == !_isFinished && _whoseTurn) + { + if (_gameRound < 10) { + + AttackMotion(); + _player.GetHit(_myDamage); + _myDamage += 3; + } + else + { + _player.GetHit(1000); + } + } } /// @@ -51,7 +72,12 @@ public override void Attack() /// public override void GetHit(float damage) { - + _randomHeal = Random.Range(0, 100); + if (_randomHeal % 3 == 0 && !_isFinished) { + _myHp += 10; + Debug.Log($"{_myName} Heal!"); + Debug.Log($"{_myName}�� ȸ���ϰ� �� ���� HP:{_myHp}"); + } } } diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 0707dc6..ce16bfc 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -5,7 +5,23 @@ public class GameManager : MonoBehaviour, Subject { // 1. Singleton Pattern: Instance() method - private static GameManager _instance; + private static GameManager _instance; // �ڱ� �ڽ� ���� + private static GameManager Instance() + { + if (_instance == null) + { + _instance = FindObjectType(); + if(_instance == null) + { + GameObject container = new GameObject("Game Manager"); + + _instance = container.Addcomponent(); + } + } + return _instance; + + + } // �ʱ�ȭ ���� �ٲ��� �� �� private int _gameRound = 0; @@ -13,7 +29,11 @@ public class GameManager : MonoBehaviour, Subject private bool _isEnd = false; // delegate: TurnHandler, FinishHandler ���� + delegate void TurnHandler(int round, string turn); + delegate void FinishHandler(bool finish); + TurnHandler _turnHandler; + FinishHandler _finishHandler; /// /// 2. RoundNotify: /// 1) ���� ���� Enemy�̸� ���� gameRound�� @@ -22,7 +42,13 @@ public class GameManager : MonoBehaviour, Subject /// public void RoundNotify() { - + if (_whoseTurn == "Enemy") + { + int gameRound++; + Debug.Log($"GameManager: Round {gameRound}."); + } + TurnNotify(); + else return; } /// @@ -33,7 +59,9 @@ public void RoundNotify() /// public void TurnNotify() { - + _whoseTurn = (_whoseTurn == "Enemy" ? "Player" : "Enemy"); // + Debug.Log($"GameManager: {_whoseTurn} turn."); + _turnHandler(_gameRound, _whoseTurn); } /// @@ -45,12 +73,18 @@ public void TurnNotify() /// public void EndNotify() { + _isEnd = true; + Debug.Log("GameManager: The End"); + Debug.Log($"GameManager: {_whoseTurn} is Win!"); + _finishHandler() } // 5. AddCharacter: _turnHandler, _finishHandler ������ �޼ҵ� �߰� public void AddCharacter(Character character) { - + + _finishHandler += new FinishHandler(character.FinishUpdate); + _turnHandler += new TurnHandler(character.TurnUpdate); } }