반응형
Bank 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bankgame
{
public enum Currency
{
g = 2, s = 1, b = 0
}
class Bank
{
static public Bank bank = new Bank();
static public int rate = 100;
Form1 form;
private Bank()
{
}
public void SetForm(Form1 form)
{
this.form = form;
}
public void Exchange(Money money, Currency currency)
{
string type = money.ToString();
int num = 0;
int have = 0;
switch (type)
{
case "Gold":
num = 2;
have = form.gold.Value;
break;
case "Silver":
num = 1;
have = form.silver.Value;
break;
case "Bronze":
num = 0;
have = form.bronze.Value;
break;
}
int d;
d = num - (int)currency;
{
MessageBox.Show("환전하려는 금액보다 가지고 있는 금액이 더 적습니다.");
return;
}
if( d < 0)
{
{
MessageBox.Show("환전하려는 금액이 나누어 떨어지지 않습니다.");
return;
}
}
switch (type)
{
case "Gold":
break;
case "Silver":
break;
case "Bronze":
break;
}
int plus = 0;
switch (currency)
{
case Currency.g:
break;
case Currency.s:
break;
case Currency.b:
break;
}
}
public void Exchange(string type, int money, string currency)
{
int num = 0;
int num2 = 0;
int have = 0;
switch (type)
{
case "Gold":
num = 2;
have = form.gold.Value;
break;
case "Silver":
num = 1;
have = form.silver.Value;
break;
case "Bronze":
num = 0;
have = form.bronze.Value;
break;
}
switch (currency)
{
case "Gold":
num2 = 2;
break;
case "Silver":
num2 = 1;
break;
case "Bronze":
num2 = 0;
break;
}
int d;
d = num - num2;
if (have < money)
{
MessageBox.Show("환전하려는 금액보다 가지고 있는 금액이 더 적습니다.");
return;
}
if (d < 0)
{
{
MessageBox.Show("환전하려는 금액이 나누어 떨어지지 않습니다.");
return;
}
}
switch (type)
{
case "Gold":
break;
case "Silver":
break;
case "Bronze":
break;
}
int plus = 0;
switch (currency)
{
case "Gold":
break;
case "Silver":
break;
case "Bronze":
break;
}
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
Money 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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bankgame
{
class Money
{
int value;
protected Form1 form;
public Money(int value, Form1 form)
{
this.value = value;
this.form = form;
}
public Money(int value)
{
this.value = value;
}
virtual public int Value
{
get { return value; }
set { this.value = value; }
}
public void SetForm(Form1 form)
{
this.form = form;
}
}
class Gold : Money
{
public Gold(int value, Form1 form) : base(value, form)
{
}
public Gold(int value) : base(value)
{
}
public override string ToString()
{
return "Gold";
}
public override int Value
{
get { return base.Value; }
set { base.Value = value; form.SetLabelG(value); }
}
}
class Silver : Money
{
public Silver(int value, Form1 form) : base(value, form)
{
}
public Silver(int value) : base(value)
{
}
public override string ToString()
{
return "Silver";
}
public override int Value
{
get { return base.Value; }
set { base.Value = value; form.SetLabelS(value); }
}
}
class Bronze : Money
{
public Bronze(int value, Form1 form) : base(value, form)
{
}
public Bronze(int value) : base(value)
{
}
public override string ToString()
{
return "Bronze";
}
public override int Value
{
get { return base.Value; }
set { base.Value = value; form.SetLabelB(value); }
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
Form1 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
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace bankgame
{
public partial class Form1 : Form
{
internal Gold gold;
internal Silver silver;
internal Bronze bronze;
public Form1()
{
InitializeComponent();
Bank.bank.SetForm(this);
gold = new Gold(100, this);
silver = new Silver(100, this);
bronze = new Bronze(100, this);
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox_from.SelectedIndex = 0;
comboBox_to.SelectedIndex = 0;
}
public void SetLabelG(int num)
{
}
public void SetLabelS(int num)
{
}
public void SetLabelB(int num)
{
}
private void Button_convert_Click(object sender, EventArgs e)
{
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
빌드된 프로그램은 첨부파일에.
반응형
'C#' 카테고리의 다른 글
[C# / 객체지향] 델리게이트 (Delegate) (0) | 2020.03.11 |
---|---|
[C# / 객체지향] 9. 추상 클래스 (Abstract Class) (0) | 2020.01.20 |
[C# / 게임] 은행 게임 만들어보기 (객체지향 정리) (0) | 2020.01.16 |
[C# / 객체지향] 8. 다형성 - 오버로드 (Method Overload) (0) | 2020.01.08 |
[C# / 객체지향] 8. 다형성 - 메서드 오버라이드 (Method Override) (0) | 2019.12.19 |