각 엑셀테이블에 해당하는 멤버변수를 선언하는 클래스의 코드는 생략했습니다.
첫번째 전직 이후의 전직을 위해
인덱스로 사용할 hero의 classGrade 값을 계속 증가시키는 작업이 필요하다고 생각되어서
매개변수가 하나인 Upgrade 메서드를 하나 더 생성하고
classGrade값을 인덱스로 사용하여 ClassData 값을 찾는 GetClassDataByIndex메서드를 추가했습니다.
1. App class
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_017
{
class App
{
public App()
{
//싱글톤으로 데이터매니저 인스턴스 생성
DataManager dataManager = DataManager.GetInstance();
dataManager.LoadData();
//영웅(캐릭터) 생성
Hero hong = this.CreateHero(1000);
//몬스터(캐릭터) 생성
Monster monster = this.CreateMonster(1000);
//영웅(캐릭터) 공격
//몬스터가 죽으면 아이템과 경험치를 얻는다
if (monster.IsDie())
{
//경험치를 얻는다
//아이템을 얻는다
Item item= this.DropItem(monster.monsterData.drop_item_id);
hong.GetItem(item);
//결과를 한번에 보기 위해서 반복문 사용
for (int i = 0; i < 5; i++)
{
//히어로가 직업이 없으면
{
//다음 전직할 클래스 데이터를 리스트로 가져온다
List<ClassData> Nextclassdatalist = DataManager.GetInstance().GetAvailableClassDatas(hong.info.classType);
//레벨이 요구레벨 이상이면 전직 선택
{
Console.WriteLine("--------------------------------------");
Console.WriteLine("\n{0}나 {1}로 전직할 수 있습니다", Nextclassdatalist[0].class_name, Nextclassdatalist[1].class_name);
//검사 선택
ClassData selectClass = Nextclassdatalist[0];
//전직
hong.Upgrade(null, selectClass);
}
}
else
{
//다음 전직할 클래스 데이터를 리스트로 가져온다
List<ClassData> Nextclassdatalist = DataManager.GetInstance().GetAvailableClassDatas(hong.info.classType);
{
ClassData NextData = Nextclassdatalist[hong.info.classGrade];
//전직
hong.Upgrade(NextData);
}
}
}
}
}
public Hero CreateHero(int id)
{
HeroData characterData = DataManager.GetInstance().GetCharacterDataById(id);
return new Hero(info);
}
public Monster CreateMonster(int id)
{
MonsterData monsterData = DataManager.GetInstance().GetMonsterDataById(id);
return new Monster(monsterData);
}
public Item DropItem(int id)
{
ItemData itemData = DataManager.GetInstance().GetItemDataById(id);
}
}
}
|
2. DataManager class
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
163
164
165
166
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Xml;
using Newtonsoft.Json;
namespace Study_017
{
class DataManager
{
static DataManager instance;
private Dictionary<int, BudgetData> dicBudgetDatas;
private Dictionary<int, HeroData> dicCharacterDatas;
private Dictionary<int, ClassData> dicClassDatas;
private Dictionary<int, ItemData> dicItemDatas;
private Dictionary<int, LevelupData> dicLevelupDatas;
private Dictionary<int, MonsterData> dicMonsterDatas;
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.dicLevelupDatas = new Dictionary<int, LevelupData>();
this.dicMonsterDatas = new Dictionary<int, MonsterData>();
}
public static DataManager GetInstance()
{
if(DataManager.instance==null)
{
DataManager.instance = new DataManager();
return DataManager.instance;
}
else
{
return DataManager.instance;
}
}
public void LoadData()
{
this.dicBudgetDatas = JsonConvert.DeserializeObject<BudgetData[]>(budgetJson).ToDictionary(x => x.id, x => x);
this.dicCharacterDatas = JsonConvert.DeserializeObject<HeroData[]>(characterJson).ToDictionary(x => x.character_id, x => x);
this.dicClassDatas = JsonConvert.DeserializeObject<ClassData[]>(classJson).ToDictionary(x => x.class_id, x => x);
this.dicItemDatas = JsonConvert.DeserializeObject<ItemData[]>(itemJson).ToDictionary(x => x.id, x => x);
this.dicLevelupDatas = JsonConvert.DeserializeObject<LevelupData[]>(levelupJson).ToDictionary(x => x.exp_id, x => x);
this.dicMonsterDatas = JsonConvert.DeserializeObject<MonsterData[]>(monsterJson).ToDictionary(x => x.id, x => x);
}
public BudgetData GetBudgetDataById(int id)
{
return this.dicBudgetDatas[id];
}
public HeroData GetCharacterDataById(int id)
{
return this.dicCharacterDatas[id];
}
public ClassData GetClassDataById(int id)
{
return this.dicClassDatas[id];
}
public ItemData GetItemDataById(int id)
{
return this.dicItemDatas[id];
}
public LevelupData GetLevelupDataByIndex(int id)
{
List<LevelupData> levelDataList = new List<LevelupData>();
foreach(var pair in this.dicLevelupDatas)
{
}
return levelDataList[id];
}
public MonsterData GetMonsterDataById(int id)
{
return this.dicMonsterDatas[id];
}
public List<ClassData> GetAvailableClassDatas(int classtype)
{
//전사계열
List<ClassData> list1 = new List<ClassData>();
//궁수계열
List<ClassData> list2 = new List<ClassData>();
//두 계열의 첫번째 값만 담기
List<ClassData> list3 = new List<ClassData>();
if (classtype <= 0)
{
foreach (KeyValuePair<int, ClassData> pair in this.dicClassDatas)
{
{
}
{
}
}
list3.Add(list1[0]);
list3.Add(list2[0]);
}
else
{
foreach(var pair in this.dicClassDatas)
{
{
}
}
}
return list3;
}
public ClassData GetClassDataByIndex(int classType,int classGrade)
{
List<ClassData> classDataList = new List<ClassData>();
foreach (var pair in this.dicClassDatas)
{
{
}
}
return classDataList[classGrade-1];
}
}
}
|
3. Hero class
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_017
{
class Hero : Character
{
public HeroInfo info;
private Item item;
public ClassData currentClassData;
public Hero(HeroInfo info)
{
this.info = info;
Console.WriteLine("{0} (Lv: {1} Hp: {2} Mp: {3})이 생성되었습니다",this.info.name,this.info.level,this.info.hp,this.info.mp);
}
public override void Attack(Character target)
{
}
public override void Hit(float damage)
{
{
this.Die();
return;
}
}
public override void Die()
{
}
public bool IsDie()
{
{
return true;
}
return false;
}
public void GetItem(Item item)
{
this.item = item;
}
public void GetExp(int exp)
{
Console.WriteLine("\n경험치 {0}를 얻었습니다.",exp);
//레벨업 표에서 다음 인덱스 가르키기
int nextLevelIndex = nextLevel - 1;
LevelupData levelupData = DataManager.GetInstance().GetLevelupDataByIndex(nextLevelIndex);
//레벨업 데이터의 다음 레벨 요구 경험치가 현재 가진 경험치보다 작으면 레벨업
{
this.Levelup();
}
//레벨 150
}
public void Levelup()
{
}
//처음 전직
public void Upgrade(ClassData beforeData, ClassData NextData)
{
ClassData beforeClassData = null;
if(beforeData==null)
{
beforeClassData = DataManager.GetInstance().GetClassDataById(100);
}
else
{
beforeClassData = beforeData;
}
Console.WriteLine("\n{0}에서 {1}로 전직하였습니다.",beforeClassData.class_name,NextData.class_name);
this.info.classType = NextData.class_type;
this.info.classGrade = 1;
this.currentClassData = NextData;
}
//다음 전직
public void Upgrade(ClassData NextData)
{
this.currentClassData = DataManager.GetInstance().GetClassDataByIndex(this.info.classType,this.info.classGrade);
Console.WriteLine("\n{0}에서 {1}로 전직하였습니다.", this.currentClassData.class_name, NextData.class_name);
this.info.classGrade ++;
}
}
}
|
4. Monster class
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_017
{
class Monster : Character
{
public MonsterData monsterData;
public Monster(MonsterData monsterData)
{
this.monsterData = monsterData;
}
public override void Attack(Character target)
{
}
public override void Hit(float damage)
{
{
Console.WriteLine("{0}가 {1}만큼 공격당했습니다 (남은 체력: {2})", this.monsterData.name, damage, this.monsterData.hp);
this.Die();
return;
}
Console.WriteLine("{0}가 {1}만큼 공격당했습니다 (남은 체력: {2})", this.monsterData.name, damage, this.monsterData.hp);
}
public override void Die()
{
}
//몬스터가 죽었는지 확인
public bool IsDie()
{
{
return true;
}
return false;
}
}
}
|
5. Character class
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 Character
{
public Character()
{
}
public virtual void Attack(Character target)
{
}
public virtual void Hit(float damage)
{
}
public virtual void Die()
{
}
}
}
|
6. CharacterInfo class
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_017
{
class HeroInfo
{
public string name;
public int level;
public int exp;
public float hp;
public int mp;
public float damage;
public int classGrade;
public int classType;
public HeroInfo(string name, int hp, int mp, float damage,
int level = 1, int exp = 0, int classType=0, int classGrade = -1)
{
this.name = name;
this.hp = hp;
this.mp = mp;
this.exp = exp;
this.level = level;
this.damage = damage;
this.classGrade = classGrade;
this.classType = classType;
}
}
}
|
7. Item class
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;
}
}
}
|
8. 결과값
'C# > 과제' 카테고리의 다른 글
2020.05.02. 과제 - 2048 게임(수정) (0) | 2020.05.02 |
---|---|
2020.04.30. 과제 - 시간 제한이 있는 상점 구현 연습하기(쿠키런 방랑박쥐 상점) (0) | 2020.04.30 |
2020.04.22. 과제 - 객체지향[OOP] 프로그래밍 특징 / 5대 원칙 (0) | 2020.04.22 |
2020.04.21. 과제 - json 파일 불러오기 (0) | 2020.04.21 |
2020.04.20. 과제 - 길바닥 아이템 획득하기(컬렉션(list)) (0) | 2020.04.21 |