Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

김보령_3.28_DogKnight 과제 제출 #15

Open
wants to merge 5 commits into
base: boryoung
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,776 changes: 1,191 additions & 585 deletions Assets/Scenes/3.28_DogKnight.unity

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Assets/Scripts/AttackButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

public class AttackButton : MonoBehaviour
{


/// <summary>
/// ���� �� �ǰ� �ִϸ��̼� ���� �� �� ������ AttackButton ��Ȱ��ȭ �ϴ� �ڵ�
/// ������ �ʿ� ���� + �ǵ帮�� �� ��
Expand Down
28 changes: 22 additions & 6 deletions Assets/Scripts/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ public class Character : MonoBehaviour, Observer
public float _myHp;
public float _myDamage;

protected int _gameRound;
protected int _whoseTurn;
protected bool _isFinished;
public int _gameRound;
public string _whoseTurn;
public bool _isFinished;

// 1. TurnUpdate: _gameRound, _whoseTurn update
public void TurnUpdate(int round, string turn)
{
//��ȭ�� round�� ������ �־��ִ� �κ�
_gameRound = round;
_whoseTurn = turn;

}

// 2. FinishUpdate: _isFinished update
public void FinishUpdate(bool isFinish)
{

_isFinished = isFinish;
}

/// <summary>
Expand All @@ -39,9 +42,11 @@ public void FinishUpdate(bool isFinish)
/// </summary>
public virtual void Attack()
{

}



/// <summary>
/// 4. GetHit: �ǰݽ� ����� ���� 3���� �����ϰ� ����Ǵ� ��� �ۼ�
/// ���� �� class���� �������̵��ؼ� �ۼ�
Expand All @@ -53,7 +58,18 @@ public virtual void Attack()
/// </summary>
public virtual void GetHit(float damage)
{

_myHp -= damage;
if (_myHp<=0)
{
DeadMotion();

GameManager.Instance().EndNotify();
}
else
{
GetHitMotion();
Debug.Log($"{_myName} HP: {_myHp}");
}
}

/// <summary>
Expand Down
53 changes: 52 additions & 1 deletion Assets/Scripts/Enemy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ public class Enemy : Character
/// </summary>
protected override void Init()
{


base.Init();

_myName = "Enemy";
_myHp = 100;
_myDamage = 10;
}

private void Awake()
{
Init();




}

/// <summary>
Expand All @@ -30,7 +40,10 @@ private void Awake()
/// </summary>
private void Start()
{

if (_player == null)
{
_player = GameObject.FindWithTag("Player").GetComponent<Player>();
}
}

/// <summary>
Expand All @@ -40,6 +53,36 @@ private void Start()
/// </summary>
public override void Attack()
{
base.Attack();

//if (_isFinished == false && _myName == _whoseTurn)
if(_myName == _whoseTurn && !_isFinished)

{

AttackMotion();
_player.GetHit(_myDamage);

//�̵�
_myDamage += 3;


}

/*
while (_gameRound__changed < 10)
{
// _myDamage += 3;
}
if (_gameRound__changed >= 10)
{
_myDamage = 100;
}*/

if(_gameRound >= 10)
{
_myDamage = 1000;
}

}

Expand All @@ -51,7 +94,15 @@ public override void Attack()
/// </summary>
public override void GetHit(float damage)
{
base.GetHit(damage);

_randomHeal = Random.Range(0, 10);
if (_randomHeal <3 && !_isFinished)
{
_myHp += 10;
Debug.Log($"{_myName} Heal!");

}
}
}

72 changes: 69 additions & 3 deletions Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,55 @@ public class GameManager : MonoBehaviour, Subject
{
// 1. Singleton Pattern: Instance() method
private static GameManager _instance;
public static GameManager Instance()
{
if (_instance == null)
{
_instance = FindObjectOfType<GameManager>();

if (_instance == null)
{
GameObject container = new GameObject("GameManager");
_instance = container.AddComponent<GameManager>();
}
}

return _instance;
}


/*
Character player;
Character enemy;

void Start()
{
if (_instance != null)
{
if (_instance != this)
{
Destroy(this.gameObject);
}
}

enemy = GameObject.FindObjectOfType<Enemy>();
player = GameObject.FindObjectOfType<Player>();
}*/


// �ʱ�ȭ ���� �ٲ��� �� ��
private int _gameRound = 0;
private string _whoseTurn = "Enemy";
private bool _isEnd = false;

// delegate: TurnHandler, FinishHandler ����
public delegate void TurnHandler(int round, string turn);
TurnHandler _turnHandler;
public delegate void FinishHandler(bool isFiish);
FinishHandler _finishHandler;




/// <summary>
/// 2. RoundNotify:
Expand All @@ -21,8 +63,16 @@ public class GameManager : MonoBehaviour, Subject
/// 2) TurnNotify() ȣ��
/// </summary>
public void RoundNotify()
{
{ if (_isEnd) return; //??????


if (_whoseTurn == "Enemy")
{
_gameRound++;
Debug.Log($"GameManager: Round {_gameRound}.");

}
TurnNotify();
}

/// <summary>
Expand All @@ -33,7 +83,18 @@ public void RoundNotify()
/// </summary>
public void TurnNotify()
{
if (_whoseTurn == "Enemy")
{
_whoseTurn = "Player";
}

else if (_whoseTurn == "Player")
{
_whoseTurn = "Enemy";
}

Debug.Log($"GameManager: {_whoseTurn} turn.");
_turnHandler(_gameRound, _whoseTurn);
}

/// <summary>
Expand All @@ -45,12 +106,17 @@ public void TurnNotify()
/// </summary>
public void EndNotify()
{

_isEnd = true;
Debug.Log("GameManager: The End");
Debug.Log($"GameManager: {_whoseTurn} is Win!");
_finishHandler(true); //////?????isEnd�ƴѰ�??
}

// 5. AddCharacter: _turnHandler, _finishHandler ������ �޼ҵ� �߰�
public void AddCharacter(Character character)
{

_turnHandler += new TurnHandler(character.TurnUpdate);
_finishHandler += new FinishHandler(character.FinishUpdate);
}
}

1 change: 1 addition & 0 deletions Assets/Scripts/ObserverSubject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ public interface Subject
{
void RoundNotify();
void TurnNotify();

}

public interface Observer
Expand Down
42 changes: 40 additions & 2 deletions Assets/Scripts/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class Player : Character
protected override void Init()
{
base.Init();
GameManager.Instance().AddCharacter(this);
_myName = "Player";
_myHp = 100;
_myDamage = 20;
}

private void Awake()
Expand All @@ -30,7 +34,10 @@ private void Awake()
/// </summary>
private void Start()
{

if (_enemy == null)
{
_enemy = GameObject.FindWithTag("Enemy").GetComponent<Enemy>();
}
}

/// <summary>
Expand All @@ -45,11 +52,42 @@ private void Start()
/// </summary>
public override void Attack()
{
//if (_isFinished == false && _myName == _whoseTurn_changed)

if (!_isFinished)
{
if (_myName == _whoseTurn)
{
_randomAttack = Random.Range(0, 10);
}
if (_randomAttack < 3)
{
_myDamage += 10;
base.SpecialAttackMotion();
Debug.Log($"{_myName} Special Attack!");
_enemy.GetHit(_myDamage);


//�߰�
_myDamage -= 10;


}


else
{
base.AttackMotion();
_enemy.GetHit(_myDamage);
}
}



}

public override void GetHit(float damage)
{

base.GetHit(damage);
}
}
8 changes: 4 additions & 4 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"dependencies": {
"com.unity.collab-proxy": "1.15.1",
"com.unity.collab-proxy": "1.15.13",
"com.unity.ide.rider": "2.0.7",
"com.unity.ide.visualstudio": "2.0.11",
"com.unity.ide.vscode": "1.2.4",
"com.unity.test-framework": "1.1.29",
"com.unity.ide.visualstudio": "2.0.14",
"com.unity.ide.vscode": "1.2.5",
"com.unity.test-framework": "1.1.31",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.4.8",
"com.unity.ugui": "1.0.0",
Expand Down
Loading