Skip to content

Commit

Permalink
Merge pull request #191 from 2024FALL-SWPP/ref/chaehwan/design-pattern
Browse files Browse the repository at this point in the history
Ref/chaehwan/design pattern
  • Loading branch information
Prown0 authored Dec 11, 2024
2 parents 4434153 + 05fb164 commit 98ba833
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 36 deletions.
5 changes: 4 additions & 1 deletion 302/Assets/Scripts/AbstractBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,19 @@ public class MyManager : AbstractBehaviour // TODO: 클래스 이름 수정하
// `Awake` 메시지 용 메서드
protected override bool Awake_()
{
bool res = false;
if (Instance == null) {
Log($"`Instance` has not been set => set `Instance` as `{Name}`");
Instance = this;
DontDestroyOnLoad(gameObject);
res = base.Awake_();
} else {
Log($"`Instance` has already been set => destroy `{gameObject.name}`");
Destroy(gameObject);
}
return base.Awake_();
return res;
}
// 필드를 초기화하는 메서드
Expand Down
114 changes: 86 additions & 28 deletions 302/Assets/Scripts/SlideManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,40 +46,29 @@ public bool UpdateStage()
bool res = true;

if (stage == 0) {
// generate random slide index list
_slideList = _random.Combination(numSlide, numStage);
Log($"Generate `_slideList` success: [{string.Join(", ", _slideList)}]");

// find and put away the slides
Log("Call `FindSlides` begin");
if (FindSlides()) {
Log("Call `FindSlides` success");

foreach (GameObject obj in _objects) {
obj.transform.Translate(Vector3.down * 100.0f);
}

Log("Set slide success: off");
Log("Call `PutAwaySlides` begin");
if (PutAwaySlides()) {
Log("Call `PutAwaySlides` success");
} else {
Log("Call `FindSlides` failed", mode: 1);
Log("Call `PutAwaySlides` failed", mode: 1);
res = false;
}
} else if (stage > 0 && stage <= numStage) {
// find and update slides
Log("Call `FindSlides` begin");
if (FindSlides()) {
Log("Call `FindSlides` success");

int index = _slideList[stage - 1];

foreach (SlideController controller in _controllers) {
controller.Index = index;
controller.ResetSlide();
if (stage == 1) {
Log("Call `GenerateList` begin");
if (GenerateList()) {
Log("Call `GenerateList` success");
} else {
Log("Call `GenerateList` failed", mode: 1);
res = false;
}
}

Log($"Set slide success: {index}");
Log("Call `UpdateSlides` begin");
if (UpdateSlides(stage)) {
Log("Call `UpdateSlides` success");
} else {
Log("Call `FindSlides` failed", mode: 1);
Log("Call `UpdateSlides` failed", mode: 1);
res = false;
}
} else {
Expand All @@ -97,16 +86,19 @@ public bool UpdateStage()
// `Awake` 메시지 용 메서드
protected override bool Awake_()
{
bool res = false;

if (Instance == null) {
Log($"`Instance` has not been set => set `Instance` as `{Name}`");
Instance = this;
DontDestroyOnLoad(gameObject);
res = base.Awake_();
} else {
Log($"`Instance` has already been set => destroy `{gameObject.name}`");
Destroy(gameObject);
}

return base.Awake_();
return res;
}

// 필드를 초기화하는 메서드
Expand All @@ -118,6 +110,12 @@ protected override bool InitFields()
_random = new SCH_Random();
Log("Initialize `_random` success");

// _objects
_objects = new List<GameObject>();

// _controllers
_controllers = new List<SlideController>();

// _slideList
_slideList = new int[numStage];
Log("Initialize `_slideList` success");
Expand All @@ -129,11 +127,71 @@ protected override bool InitFields()
* new methods *
***************/

// 슬라이드를 치우는 메서드
private bool PutAwaySlides()
{
bool res = true;

Log("Call `FindSlides` begin");
if (FindSlides()) {
Log("Call `FindSlides` success");

foreach (GameObject obj in _objects) {
obj.transform.Translate(Vector3.down * 100.0f);
}

Log("Set slide success: off");
} else {
Log("Call `FindSlides` failed", mode: 1);
res = false;
}

return res;
}

// 슬라이드 색인 리스트를 생성하는 메서드
private bool GenerateList()
{
bool res = true;

_slideList = _random.Combination(numSlide, numStage);
Log($"Generate `_slideList` success: [{string.Join(", ", _slideList)}]");

return res;
}

// 슬라이드를 갱신하는 메서드
private bool UpdateSlides(int stage)
{
int index = _slideList[stage - 1];
bool res = true;

Log("Call `FindSlides` begin");
if (FindSlides()) {
Log("Call `FindSlides` success");

foreach (SlideController controller in _controllers) {
controller.Index = index;
controller.ResetSlide();
}

Log($"Set slide success: {index}");
} else {
Log("Call `FindSlides` failed", mode: 1);
res = false;
}

return res;
}

// 슬라이드를 찾는 메서드
private bool FindSlides()
{
bool res = true;

_objects.Clear();
_controllers.Clear();

for (int idx = 0; idx < names.Length; idx++) {
GameObject obj = GameObject.Find(names[idx]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override void OnInteract()
Log("Call `GameManager.SetStageClear` end");

// Code used before `GameManager` updates begin
GameObject controllerObject = GameObject.Find("Anomaly18Manager");
GameObject controllerObject = GameObject.Find("AnomalyManager (18)(Clone)");
AbstractAnomalyObject controller = controllerObject.GetComponent<AbstractAnomalyObject>();

Log($"Call `{controller.Name}.ResetAnomaly` begin");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override void OnInteract()
Log("Call `GameManager.SetStageClear` end");

// Code used before `GameManager` updates begin
GameObject controllerObject = GameObject.Find("Anomaly19Manager");
GameObject controllerObject = GameObject.Find("AnomalyManager (19)(Clone)");
AbstractAnomalyObject controller = controllerObject.GetComponent<AbstractAnomalyObject>();

Log($"Call `{controller.Name}.ResetAnomaly` begin");
Expand Down
2 changes: 1 addition & 1 deletion 302/Assets/Scripts/SpecificAnomalyManager/Anomaly1_Girl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override void OnInteract()
Log("Call `GameManager.SetStageClear` end");

// Code used before `GameManager` updates begin
GameObject controllerObject = GameObject.Find("Anomaly1Manager");
GameObject controllerObject = GameObject.Find("AnomalyManager (1)(Clone)");
AbstractAnomalyObject controller = controllerObject.GetComponent<AbstractAnomalyObject>();

Log($"Call `{controller.Name}.ResetAnomaly` begin");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override void OnInteract()
Log("Call `GameManager.SetStageClear` end");

// Code used before `GameManager` updates begin
GameObject controllerObject = GameObject.Find("Anomaly20Manager");
GameObject controllerObject = GameObject.Find("AnomalyManager (20)(Clone)");
AbstractAnomalyObject controller = controllerObject.GetComponent<AbstractAnomalyObject>();

Log($"Call `{controller.Name}.ResetAnomaly` begin");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void Update()
Log("Call `GameManager.SetStageClear` end");

// Code used before `GameManager` updates begin
GameObject controllerObject = GameObject.Find("Anomaly23Manager");
GameObject controllerObject = GameObject.Find("AnomalyManager (23)(Clone)");
AbstractAnomalyObject controller = controllerObject.GetComponent<AbstractAnomalyObject>();

Log($"Call `{controller.Name}.ResetAnomaly` begin");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override void OnInteract()
Log("Call `GameManager.SetStageClear` end");

// Code used before `GameManager` updates begin
GameObject controllerObject = GameObject.Find("Anomaly2Manager");
GameObject controllerObject = GameObject.Find("AnomalyManager (2)(Clone)");
AbstractAnomalyObject controller = controllerObject.GetComponent<AbstractAnomalyObject>();

Log($"Call `{controller.Name}.ResetAnomaly` begin");
Expand Down
2 changes: 1 addition & 1 deletion 302/Assets/Scripts/SpecificAnomalyManager/Anomaly6_Cake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void OnInteract()
Log("Call `GameManager.SetStageClear` end");

// Code used before `GameManager` updates begin
GameObject controllerObject = GameObject.Find("Anomaly6Manager");
GameObject controllerObject = GameObject.Find("AnomalyManager (6)(Clone)");
AbstractAnomalyObject controller = controllerObject.GetComponent<AbstractAnomalyObject>();

Log($"Call `{controller.Name}.ResetAnomaly` begin");
Expand Down
109 changes: 109 additions & 0 deletions 302/Assets/Scripts/TimeManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using UnityEngine;

public class TimeManager : AbstractBehaviour, IStageObserver
{
/**********
* fields *
**********/

// 오브젝트 이름
public string nameClock;
public string nameLaptop;

/**************
* properties *
**************/

// 클래스 이름
public override string Name { get; } = "TimeManager";

// 클래스 인스턴스
public static TimeManager Instance { get; private set; }

/**********************************
* implementation: IStageObserver *
**********************************/

// 단계 변경 시 불리는 메서드
public bool UpdateStage()
{
int stage = GameManager.Instance.GetCurrentStage();
ClockController clock = FindClock();
LaptopScreenController laptop = FindLaptop();
bool res = true;

if (clock != null) {
Log("Find `ClockController` success");
clock.SetTime(stage);
} else {
Log("Find `ClockController` failed", mode: 1);
res = false;
}

if (laptop != null) {
Log("Find `LaptopScreenController` success");
laptop.ChangeScreen(stage);
} else {
Log("Find `LaptopScreenController` failed", mode: 1);
res = false;
}

return res;
}

/*************************************
* implementation: AbstractBehaviour *
*************************************/

// `Awake` 메시지 용 메서드
protected override bool Awake_()
{
bool res = false;

if (Instance == null) {
Log($"`Instance` has not been set => set `Instance` as `{Name}`");
Instance = this;
DontDestroyOnLoad(gameObject);
res = base.Awake_();
} else {
Log($"`Instance` has already been set => destroy `{gameObject.name}`");
Destroy(gameObject);
}

return res;
}

/***************
* new methods *
***************/

// 시계를 찾는 메서드
private ClockController FindClock()
{
GameObject obj = GameObject.Find(nameClock);
ClockController clock;

if (obj != null) {
clock = obj.GetComponent<ClockController>();
} else {
clock = null;
}

return clock;
}

// 노트북을 찾는 메서드
private LaptopScreenController FindLaptop()
{
GameObject obj = GameObject.Find(nameLaptop);
LaptopScreenController laptop;

if (obj != null) {
laptop = obj.GetComponent<LaptopScreenController>();
} else {
laptop = null;
}

return laptop;
}
}
11 changes: 11 additions & 0 deletions 302/Assets/Scripts/TimeManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 98ba833

Please sign in to comment.