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 과제 제출_최종 #22

Open
wants to merge 2 commits into
base: chaeyeon
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
Binary file added .DS_Store
Binary file not shown.
Binary file added Assets/.DS_Store
Binary file not shown.
72 changes: 38 additions & 34 deletions Assets/Scripts/Character.cs
Original file line number Diff line number Diff line change
@@ -1,73 +1,81 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// �ִϸ����� Ʈ���� �̸� ���������� ���� (������ �ʿ� ����)
// 애니메이팅 트리거 이름 열거형으로 저장 (이해할 필요 없음)
public enum AnimatorParameters
{
IsAttack, IsSpecialAttack, GetHit, IsDead
}

public class Character : MonoBehaviour, Observer
{
public string _myName;
public float _myHp;
public float _myDamage;

protected int _gameRound;
protected int _whoseTurn;
protected string _whoseTurn;
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 = true;
}

/// <summary>
/// 3. Attack: ���ݽ� ����� ���� �� Player�� Enemy �������� ����� ��� �ۼ�
/// ���� �� class���� �������̵��ؼ� �ۼ�
/// 1) ������ ������ �ʾҰ� �ڽ��� _myName�� _whoseTurn�� ��ġ�Ѵٸ�,
/// 2) AttackMotion() ȣ���ؼ� �ִϸ��̼� ����
/// 3) ������ GetHit()�� �ڽ��� _myDamage �Ѱܼ� ȣ��
/// 3. Attack: 공격시 실행될 내용 중 Player와 Enemy 공통으로 실행될 기능 작성
/// 이후 각 class에서 오버라이딩해서 작성
/// 1) 게임이 끝나지 않았고 자신의 _myName와 _whoseTurn이 일치한다면,
/// 2) AttackMotion() 호출해서 애니메이션 실행
/// 3) 상대방의 GetHit()에 자신의 _myDamage 넘겨서 호출
/// </summary>
public virtual void Attack()
{

if(!_isFinished && _MyName == _whoseTurn
{
AttackMotion();
other.GetHit(_myDamage);

}
}

/// <summary>
/// 4. GetHit: �ǰݽ� ����� ���� 3���� �����ϰ� ����Ǵ� ��� �ۼ�
/// ���� �� class���� �������̵��ؼ� �ۼ�
/// 1) �Ѱ� ���� damage��ŭ _myHp ����
/// 2) ���� _myHp�� 0���� �۰ų� ���ٸ�, DeadMotion() ȣ���ؼ� �ִϸ��̼� ����
/// + Subject�� EndNotify() ȣ��
/// 3) ���� ����ִٸ�, GetHitMotion() ȣ���ؼ� �ִϸ��̼� ����
/// + Debug.Log($"{_myName} HP: {_myHp}"); �߰�
/// 4. GetHit: 피격시 실행될 내용 3번과 동일하게 공통되는 기능 작성
/// 이후 각 class에서 오버라이딩해서 작성
/// 1) 넘겨 받은 damage만큼 _myHp 감소
/// 2) 만약 _myHp가 0보다 작거나 같다면, DeadMotion() 호출해서 애니메이션 실행
/// + Subject의 EndNotify() 호출
/// 3) 아직 살아있다면, GetHitMotion() 호출해서 애니메이션 실행
/// + Debug.Log($"{_myName} HP: {_myHp}"); 추가
/// </summary>
public virtual void GetHit(float damage)
{

_myHp -= damage;
if(_myHP <= 0)
{
DeadMOtion();
GameManager.Instance().EndNotify();
}
else
{
GetHitMotion();
Debug.Log($"{_myName} HP: {_myHp}");
}
}

/// <summary>
/// �� �����δ� animation ���� code, ������ �ʿ� ���� (������ ���ǿ��� �� ��)
/// ������ �Ʒ�ó�� ���� �޼ҵ带 ���� �ʿ䵵 ������ ����� ���� �����̱� ������
/// ����� ���Ǹ� ���� 4���� �޼ҵ带 �ۼ��Ͽ���.
/// ���� Attack, GetHit �������̵���, �Ʒ��� �޼ҵ常 ȣ���ϸ� animation �����
/// 이 밑으로는 animation 관련 code, 이해할 필요 없음 (다음주 세션에서 할 것)
/// 원래는 아래처럼 여러 메소드를 만들 필요도 없지만 배우지 않은 내용이기 때문에
/// 사용의 편의를 위해 4가지 메소드를 작성하였음.
/// 위의 Attack, GetHit 오버라이딩시, 아래의 메소드만 호출하면 animation 실행됨
/// 1. AttackMotion()
/// 2. SpecialAttackMotion()
/// 3. DeadMotion()
/// 4. GetHitMotion()
/// </summary>
protected Animator _animator;

protected virtual void Init()
{
_animator = GetComponent<Animator>();
Expand All @@ -80,23 +88,19 @@ protected void SpecialAttackMotion()
{
_animator.SetTrigger(AnimatorParameters.IsSpecialAttack.ToString());
}

protected void DeadMotion()
{
StartCoroutine(DeadCoroutine());
}

protected void GetHitMotion()
{
StartCoroutine(GetHitCoroutine());
}

IEnumerator GetHitCoroutine()
{
yield return new WaitForSeconds(1f);
_animator.SetTrigger(AnimatorParameters.GetHit.ToString());
}

IEnumerator DeadCoroutine()
{
yield return new WaitForSeconds(1f);
Expand Down
42 changes: 21 additions & 21 deletions Assets/Scripts/Enemy.cs
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : Character
{
private Player _player;
private float _randomHeal;

/// <summary>
/// 1. Init: �ʱ�ȭ ���
/// 1) Subject�� Observer�� ���
/// 2) _myName, _myHp, _myDamage �ʱ�ȭ
/// 3) _myName�� ������ "Enemy"�� �� ��
/// 4) _myHp, _myDamage�� 100, 10���� ���� �ʱ�ȭ (���� ����)
/// 1. Init: 초기화 기능
/// 1) Subject에 Observer로 등록
/// 2) _myName, _myHp, _myDamage 초기화
/// 3) _myName은 무조건 "Enemy"로 할 것
/// 4) _myHp, _myDamage는 100, 10으로 각각 초기화 (권장 사항)
/// </summary>
protected override void Init()
{
base.Init();
GameManager.Instance().AddCharacter(this);
_myName = "Enemy";
_myHP = 100;
_myDamaage = 10;
}

private void Awake()
{
Init();
}

/// <summary>
/// 1) _player�� �Ҵ��� �ȵƴٸ�,
/// 2) GameObject.FindWithTag �̿��ؼ� _player �Ҵ�
/// 1) _player가 할당이 안됐다면,
/// 2) GameObject.FindWithTag 이용해서 _player 할당
/// </summary>
private void Start()
{
if(_player == null)
{
_player = GameObject.FindWithTag("Player").GetComponent<Player>();
}

}

/// <summary>
/// Attack:
/// 1) _gameRound�� ���������� ������ 3�� ����
/// 2) _gameRound�� 10�� �Ǹ� ������ Player�� ���̵��� ������ ����
/// 1) _gameRound가 지날때마다 데미지 3씩 증가
/// 2) _gameRound가 10이 되면 무조건 Player를 죽이도록 데미지 증가
/// </summary>
public override void Attack()
{

}

/// <summary>
/// GetHit:
/// 1) Player�� _randomAttack�� ������ ���
/// 2) 30%�� Ȯ���� �ǰݽ� 10 ü�� ����
/// + Debug.Log($"{_myName} Heal!"); �߰�
/// 1) Player의 _randomAttack과 동일한 기능
/// 2) 30%의 확률로 피격시 10 체력 증가
/// + Debug.Log($"{_myName} Heal!"); 추가
/// </summary>
public override void GetHit(float damage)
{

}
}

}
47 changes: 35 additions & 12 deletions Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,78 @@
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour, Subject
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour, Subject
{
// 1. Singleton Pattern: Instance() method
private static GameManager _instance;

// �ʱ�ȭ ���� �ٲ��� �� ��
private Character
// 초기화 설정 바꾸지 말 것
private int _gameRound = 0;
private string _whoseTurn = "Enemy";
private bool _isEnd = false;

// delegate: TurnHandler, FinishHandler 선언
delegate void TurnHandler(int round, string turn);
TurnHandler _turnHandler;

// delegate: TurnHandler, FinishHandler ����
delegate void FinishHandler(bool isFinish);
FinishHandler _finishHandler;

/// <summary>
/// 2. RoundNotify:
/// 1) ���� ���� Enemy�̸� ���� gameRound��
/// 1) 현재 턴이 Enemy이면 다음 gameRound로
/// + Debug.Log($"GameManager: Round {gameRound}.");
/// 2) TurnNotify() ȣ��
/// 2) TurnNotify() 호출
/// </summary>
public void RoundNotify()
{

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

/// <summary>
/// 3. TurnNotify:
/// 1) whoseTurn update
/// + Debug.Log($"GameManager: {_whoseTurn} turn.");
/// 2) _turnHandler ȣ��
/// 2) _turnHandler 호출
/// </summary>
public void TurnNotify()
{
_whoseTurn = (_whose)

}

/// <summary>
/// 4. EndNotify:
/// 4. EndNotify:
/// 1) isEnd update
/// + Debug.Log("GameManager: The End");
/// + Debug.Log($"GameManager: {_whoseTurn} is Win!");
/// 2) _finishHandler ȣ��
/// 2) _finishHandler 호출
/// </summary>
public void EndNotify()
{
_isEnd = true;
Debug.Log("GameManager: The End");
Debug.Log($"GameManager: {_whoseTurn} is Win!");
_finishHandler(_isEnd);

}

// 5. AddCharacter: _turnHandler, _finishHandler ������ �޼ҵ� �߰�
// 5. AddCharacter: _turnHandler, _finishHandler 각각에 메소드 추가
public void AddCharacter(Character character)
{

TurnHandler _turnhandler = character.TurnUpdate;
FinishHandler _finishHandler = character.FinishUpdate;
}
}
}
52 changes: 29 additions & 23 deletions Assets/Scripts/Player.cs
Original file line number Diff line number Diff line change
@@ -1,55 +1,61 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : Character
{
private Enemy _enemy;
private float _randomAttack;

/// <summary>
/// 1. Init: �ʱ�ȭ ���
/// 1) Subject�� Observer�� ���
/// 2) _myName, _myHp, _myDamage �ʱ�ȭ
/// 3) _myName�� ������ "Player"�� �� ��
/// 4) _myHp, _myDamage�� 100, 20���� ���� �ʱ�ȭ (���� ����)
/// 1. Init: 초기화 기능
/// 1) Subject에 Observer로 등록
/// 2) _myName, _myHp, _myDamage 초기화
/// 3) _myName은 무조건 "Player"로 할 것
/// 4) _myHp, _myDamage는 100, 20으로 각각 초기화 (권장 사항)
/// </summary>
protected override void Init()
{
base.Init();
}
_myName = "Player";
_myHP = 100;
_myDamaage = 20;

}
private void Awake()
{
Init();
}

/// <summary>
/// 1) _enemy�� �Ҵ��� �ȵƴٸ�,
/// 2) GameObject.FindWithTag �̿��ؼ� _enemy �Ҵ�
/// 1) _enemy가 할당이 안됐다면,
/// 2) GameObject.FindWithTag 이용해서 _enemy 할당
/// </summary>
private void Start()
{

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

/// <summary>
/// Attack:
/// 1) Player�� 30%�� Ȯ���� ���ݷ��� �� ���� ������ ���� ��
/// 2) _randomAttack = Random.Range(0,10); ���� ���� ���� ����
/// -> 0~9 ������ ���� �� �ϳ��� �������� �Ҵ����.
/// 3) _randomAttack �̿��ؼ� 30% Ȯ���� ���� ���ݷº��� 10 ���� ���� ����
/// 4) �̶��� AttackMotion() ���� SpecialAttackMotion() ȣ���� ��
/// + Debug.Log($"{_myName} Special Attack!"); �߰�
/// 5) 70% Ȯ���� �ϴ� �Ϲ� ������ Character�� ���ִ� �ּ��� ����
/// 1) Player는 30%의 확률로 공격력이 더 높은 공격을 가할 것
/// 2) _randomAttack = Random.Range(0,10); 으로 랜덤 변수 생성
/// -> 0~9 까지의 정수 중 하나를 랜덤으로 할당받음.
/// 3) _randomAttack 이용해서 30% 확률로 기존 공격력보다 10 높은 공격 실행
/// 4) 이때는 AttackMotion() 말고 SpecialAttackMotion() 호출할 것
/// + Debug.Log($"{_myName} Special Attack!"); 추가
/// 5) 70% 확률로 하는 일반 공격은 Character에 써있는 주석과 동일
/// </summary>
public override void Attack()
{
if(!_isFinished && _myName == _whoseTurn)
{
int _randomAttack = Random.Range(0,10);

}

}

}
public override void GetHit(float damage)
{

}
}
}