수업 016 (04.27 2020) Maple Story
2020. 4. 28. 00:54
728x90
* Difficulties in coding design
(For ex App.cs line.48)
* Frequent mistakes about the subject
(For ex Attack and Hit, this => solved with // (need to address))
** About 'Index'
* Spend too much time....... 생각하는 시간 많음
** virtual, override, : // 상속
where to order for attack in Charater.cs? Hero.cs?
1. Problem: Require Level List - solved (list 1 copy and paste)
2. Coding
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._017
{
class App
{
// 생성자
public App()
{
// DataManager dm1 = new DataManager();
// dm.GetInstance(); // 자신의 instance 반환
// 나오는 instance가 항상 같길 원함(Data Manager는 하나면 되니까)
// "DataManager 싱글톤으로 만들어주세요" 43/4)
DataManager dm = DataManager.GetInstance();
dm.LoadDatas(); // LoadDatas 인스턴스 메서드
// 데이터 로드
BudgetData budgetData = dm.GetBudgetDataById(100);
HeroData Data = dm.GetCharacterDataById(1000);
ClassData classData = dm.GetClassDataById(100);
ItemData itemData = dm.GetItemDataById(100);
LevelUp levelUp = dm.GetLevelUpById(100000);
MonsterData monsterData = dm.GetMonsterDataById(1000);
// >> 영웅생성
Hero hero = this.CreateDefaultHero();
// 몬스터 생성
Monster monster = this.CreateMonster(1000);
// 몬스터 공격
// >>>>>>>>>>>>>>>>>>>>>>>>> Need more practice >>>>>>>>>>>>>>>>>>>>>>>>>
// 몬스터 처치/ 몬스터 Die 이면
if (monster.IsDie())
{
// 몬스터 죽음 => 경험치를 줌
// 아이템 드랍
Item item = this.DropItem(monster.dropItemId);
// 영웅이 경험치를 얻고 레벨업 => 전직
// 전직 가능한 요구 레벨
// Console.WriteLine(hero.info.classGrade); // output: -1
{
Console.WriteLine("{0}", classDatas[0].require_level);
Console.WriteLine(">> Eroor: Require Level이 10은 나오지만 검사만 출력됨 \n");
// UI상에 선택 가능한 직업 보여주기
{
Console.WriteLine("===== 선택가능한 직업 목록 ====");
foreach (var data in classDatas)
{
Console.WriteLine("{0}", data.class_name);
}
// 선택한 클래스
var selectedClassData = classDatas[0];
Console.WriteLine("\n{0}를 선택했습니다.", selectedClassData.class_name);
// 전직
hero.Upgrade(null, selectedClassData);
}
// 레벨업 testing
Console.WriteLine("\n<Level Up testing>\n");
hero.Levelup(30);
classDatas = DataManager.GetInstance().GetAvailableClassDatas(hero.info.classType);
var nextData = classDatas[hero.info.classGrade];
hero.Upgrade(beforeData, nextData); // 전직
}
// hero.GetItem(item);
}
// 경험치, 아이템 획득
// 레벨업
// 전직
}
public Hero CreateDefaultHero()
{
// 영웅 생성 :: 영웅 데이터, 영웅 인포
// 영웅 인포 객체 생성 :: 레벨, 직업 타입, 등급(직업), hp, mp
// 레벨, 직업 타입, 등급(직업), hp, mp
var characterData = DataManager.GetInstance().GetCharacterDataById(1000);
var hero = new Hero(); // 생성
hero.Init(heroInfo); // 초기화
return hero;
}
public Monster CreateMonster(int id)
{
var data = DataManager.GetInstance().GetMonsterDataById(id);
return new Monster(data);
}
public Item DropItem(int id)
{
ItemData data = DataManager.GetInstance().GetItemDataById(id);
}
}
}
|
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace Study._017
{
// 데이터 관리자
class DataManager
{
// "DataManager 싱글톤으로 만들어주세요 (1/4)"
private static DataManager instance;
Dictionary<int, BudgetData> dicBudgetDatas;
Dictionary<int, HeroData> dicCharacterDatas;
Dictionary<int, ClassData> dicClassDatas;
Dictionary<int, ItemData> dicItemDatas;
Dictionary<int, LevelUp> dicLevelUps;
Dictionary<int, MonsterData> dicMonsterDatas;
// 생성자
// "DataManager 싱글톤으로 만들어주세요 (2/4)"
private DataManager()
{
this.dicBudgetDatas = new Dictionary<int, BudgetData>();
this.dicCharacterDatas = new Dictionary<int, HeroData>();
this.dicClassDatas = new Dictionary<int, ClassData>();
this.dicItemDatas = new Dictionary<int, ItemData>();
this.dicLevelUps = new Dictionary<int, LevelUp>();
this.dicMonsterDatas = new Dictionary<int, MonsterData>();
}
// "DataManager 싱글톤으로 만들어주세요 (3/4)"
public static DataManager GetInstance()
// static : 형식에서 반환 (class) [정적] / DataManager를 App 에서 쓰고싶어!
{
// [static 때문에 정적이어야함]
// 인스턴스가 없다면 새로운 인스턴스를 반환
if (DataManager.instance == null)
{
DataManager.instance = new DataManager();
return DataManager.instance;
}
// 있다면 있는 인스턴스를 반환
else
{
return DataManager.instance;
}
}
public void LoadDatas()
{
this.dicBudgetDatas = JsonConvert.DeserializeObject<BudgetData[]>(jsonBudget).ToDictionary(x => x.id, x => x);
this.dicCharacterDatas = JsonConvert.DeserializeObject<HeroData[]>(jsonCharacter).ToDictionary(x => x.character_id, x => x);
this.dicClassDatas = JsonConvert.DeserializeObject<ClassData[]>(jsonClass).ToDictionary(x => x.class_id, x => x);
this.dicItemDatas = JsonConvert.DeserializeObject<ItemData[]>(jsonItem).ToDictionary(x => x.id, x => x);
this.dicLevelUps = JsonConvert.DeserializeObject<LevelUp[]>(jsonLevelUp).ToDictionary(x => x.exp_id, x => x);
this.dicMonsterDatas = JsonConvert.DeserializeObject<MonsterData[]>(jsonMonster).ToDictionary(x => x.id, x => x);
}
public BudgetData GetBudgetDataById(int id)
{
BudgetData data = this.dicBudgetDatas[id];
return data;
}
public HeroData GetCharacterDataById(int id)
{
HeroData data = this.dicCharacterDatas[id];
return data;
}
public ClassData GetClassDataById(int id)
{
ClassData data = this.dicClassDatas[id];
return data;
}
public ItemData GetItemDataById(int id)
{
ItemData data = this.dicItemDatas[id];
return data;
}
public LevelUp GetLevelUpById(int id)
{
LevelUp data = this.dicLevelUps[id];
return data;
}
// ***
public LevelUp GetLevelUpByIndex(int index)
{
List<LevelUp> list = new List<LevelUp>();
foreach (var pair in this.dicLevelUps)
{
}
return list[index];
}
public MonsterData GetMonsterDataById(int id)
{
MonsterData data = this.dicMonsterDatas[id];
return data;
}
// *** 새로운 list에 class type
public List<ClassData> GetAvailableClassDatas(int classType)
{
List<ClassData> list3 = new List<ClassData>();
if (classType <= 0) // 직업이 없을때
{
List<ClassData> list1 = new List<ClassData>(); // class_type = 1 인 list
List<ClassData> list2 = new List<ClassData>(); // class_type = 2 인 list
foreach (var pair in this.dicClassDatas) // list value 넣기
{
{
}
{
}
}
list3.Add(list1[0]);
list3.Add(list2[0]);
}
else // 직업이 있을떄
{
foreach (var pair in this.dicClassDatas)
{
{
}
}
}
return list3; // 반환해주는거 잊지말기
}
}
}
|
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._017
{
class Hero : Character
{
public HeroInfo info;
public Hero()
{
Console.WriteLine("영웅이 생성되었습니다.");
}
public void Init(HeroInfo info)
{
this.info = info;
}
// monster or hero 둘다 공격 가능 (모든 캐릭터가 다 때릴수 있다.)
public override void Attack(Character target)
{
Console.WriteLine("영웅이 몬스터를 공격했습니다.");
}
public override void Hit(float damage)
{
{
this.Die();
}
}
public override void Die()
{
Console.WriteLine("영웅이 죽었습니다.");
}
// >>>>>>>>>>>>>>>>>>>>>>>>> Need more practice >>>>>>>>>>>>>>>>>>>>>>>>>
public void GetExp(int exp)
{
int nextLevelUpIndex = nextLevel - 1; // 0부터 시작이니까
// 레벨업 체크
var levelUpData = DataManager.GetInstance().GetLevelUpByIndex(nextLevelUpIndex);
// 필요 경험치
Console.WriteLine("Lv. {0} 에서 Lv. {1}로 레벨업 하려면 {2}만큼의 경험치가 필요합니다. \n", info.level, nextLevel, levelUpData.require_exp);
{
this.Levelup();
}
// test for level up
}
public void Levelup(int count = 1)
{
}
// 전직
public void Upgrade(ClassData beforeData, ClassData nextData)
{
ClassData beforeClassData = null;
if (beforeData == null) // 뉴비
{
beforeClassData = DataManager.GetInstance().GetClassDataById(100);
}
else
{
beforeClassData = beforeData;
}
string beforeClassName = beforeClassData.class_name;
string nextClassName = nextData.class_name;
Console.WriteLine("\n=================================");
Console.WriteLine("{0}에서 {1}로 전직 했습니다.", beforeClassName, nextClassName);
Console.WriteLine("================================= \n");
// 직업 결정
this.info.classType = nextData.class_type;
// 직업 그레이드 초기화
this.info.classGrade = 1; // 나중에 인덱스로 접근하려면 -1
}
}
}
|
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._017
{
class Monster : Character
{
public int id;
public string name;
public int damage;
public float hp;
public float maxHp;
public int exp;
public int dropItemId;
public Monster(MonsterData data)
{
this.hp = this.maxHp;
this.dropItemId = data.drop_item_id;
Console.WriteLine("'{0}'이/(가) 생성되었습니다. \n", this.name, this.id);
}
public void Init()
{
}
public override void Attack(Character target)
{
target.Hit(this.damage);
}
public override void Hit(float damage)
{
this.hp -= damage;
Console.WriteLine("{0}/{1} \n", this.hp, this.maxHp);
if (this.hp <= 0)
{
this.Die();
}
}
public override void Die()
{
Console.WriteLine("몬스터가 죽었습니다.");
}
public bool IsDie()
{
// 몬스터 체력이 0 되었을때
this.hp = 0;
if (this.hp <= 0)
{
return true;
}
return false;
}
}
}
|
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._017
{
class Character
{
public Character()
{
}
public virtual void Attack(Character target)
{
}
public virtual void Hit(float damage)
{
}
public virtual void Die()
{
}
}
}
|
더보기
>> BudgetData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._017
{
class BudgetData
{
public int id;
public string name;
}
}
|
>> ClassData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._017
{
class ClassData
{
public int class_id;
public int class_type;
public string class_name;
public int require_level;
}
}
|
>> HeroData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._017
{
class HeroData
{
public int character_id;
public int class_id;
public int hp;
public int mp;
public int damage;
}
}
|
>> HeroInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._017
{
class HeroInfo
{
public string name;
public float hp;
public int mp;
public int level;
public int classType;
public int classGrade;
public int exp;
public float damage;
// 레벨, 직업 타입, 등급(직업), hp, mp
public HeroInfo(string name, float hp, int mp, float damage, int exp = 0, int level = 1, int classType = 0, int classGrade = -1) // 선택적 매개변수는 마지막에!
{
this.name = name;
this.hp = hp;
this.mp = mp;
this.level = level;
this.damage = damage;
this.classGrade = classGrade;
this.classType = classType;
this.exp = exp;
}
}
}
|
>>> Item.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._017
{
class Item
{
public int id;
public string name;
public Item(int id, string name)
{
this.id = id;
this.name = name;
}
}
}
|
>> ItemData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._017
{
class ItemData
{
public int id;
public string name;
public string resource_name;
public string icon_name;
public int sell_price;
public int item_type;
}
}
|
>> LevelUp.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._017
{
class LevelUp
{
public int exp_id;
public int level;
public int require_exp;
}
}
|
>> MonsterData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._017
{
class MonsterData
{
public int id;
public string name;
public int damage;
public int hp;
public int exp;
public int drop_item_id;
}
}
|
3. Result
- NewB
- Lv. 10
- Lv. 30
728x90
'C# > Study' 카테고리의 다른 글
수업 016 (04.27 2020) 메서드 재정의 (virtual / override) (0) | 2020.04.28 |
---|---|
수업 016 (04.27 2020) 상속 (:) (0) | 2020.04.28 |
수업 015 (04.24 2020) 조건연산자(?:) F9,F5,F11 swap ref (0) | 2020.04.24 |
수업 015 (04.24 2020) 복습 Inventory + percentage (0) | 2020.04.24 |
수업 014 (04.23 2020) - DateTime (0) | 2020.04.24 |