캐릭터간 대전
2020. 4. 10. 18:50ㆍC#/과제
<컴파일 실행 화면>
<Class App>
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_007
{
class App
{
public App()
{
Character hong = new Character("홍길동", 100, 100, 5);
Character lim = new Character("임꺽정", 100, 100, 5);
while(true)
{
Console.Write("조작할 캐릭터의 이름을 입력하세요. ");
string player = Console.ReadLine();
Console.Write("캐릭터가 취할 행동을 입력하세요. (제작, 획득, 착용, 해제, 공격) ");
string action = Console.ReadLine();
{
if(action == "제작")
else if(action == "획득")
{
hong.GetItem(hong.item);
}
else if(action == "착용")
{
hong.EquipItem(hong.item);
}
else if(action == "해제")
{
hong.ReleaseItem(hong.item);
}
else if(action == "공격")
{
}
}
{
if(action == "제작")
else if (action == "획득")
{
lim.GetItem(lim.item);
}
else if (action == "착용")
{
lim.EquipItem(lim.item);
}
else if (action == "해제")
{
lim.ReleaseItem(lim.item);
}
else if (action == "공격")
{
}
}
}
}
}
}
|
<Class Character>
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_007
{
class Character
{
public string name;
public int hp;
public int maxHp;
public int damage;
public Item item;
public bool isItem;
public bool isEquipment;
public Character(string name, int hp, int maxHp, int basicDamage)
{
this.name = name;
this.hp = hp;
this.maxHp = maxHp;
this.damage = basicDamage;
this.isItem = false;
this.isEquipment = false;
}
public Item CreateItem(string itemName, int itemDamage)
{
item = new Item();
item.name = itemName;
item.damage = itemDamage;
return item;
}
public void GetItem(Item itemName)
{
if (isItem == true)
Console.WriteLine("인벤토리가 가득 찼습니다. ");
else
{
isItem = true;
}
}
public void EquipItem(Item itemName)
{
if (this.isEquipment == true)
{
Console.WriteLine($"이미 장비를 착용하고 있습니다.");
}
else if(this.isItem == false)
{
Console.WriteLine("착용할 아이템이 없습니다.");
}
else if(isItem == true && isEquipment == false)
{
this.isEquipment = true;
item = itemName;
this.isItem = false;
}
}
public void ReleaseItem(Item itemName)
{
if(this.isEquipment == true)
{
this.isEquipment = false;
this.isItem = true;
}
else
{
Console.WriteLine($"해제할 아이템이 없습니다.");
}
}
public void Attack(Character target)
{
target.Hit(this);
}
public void Hit(Character target)
{
if(this.hp <= 0) // 사망
{
this.Death();
}
else
{
}
}
public void Death()
{
Console.WriteLine("게임이 종료됩니다.");
}
}
}
|
<Class Item>
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_007
{
class Item
{
public string name;
public int damage;
public Item()
{
}
public Item(string itemName)
{
this.name = itemName;
}
public Item(string itemName, int damage) // Weapons의 경우
{
this.name = itemName;
this.damage = damage;
}
}
}
|
'C# > 과제' 카테고리의 다른 글
객체지향이란 (0) | 2020.04.22 |
---|---|
레시피 관리 및 요리하기 (0) | 2020.04.20 |
인벤토리 (0) | 2020.04.14 |
2020-04-03 (0) | 2020.04.03 |
2020-04-02 과제 (0) | 2020.04.02 |