-
Notifications
You must be signed in to change notification settings - Fork 0
/
GAME.cs
154 lines (134 loc) · 3.86 KB
/
GAME.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
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
using System.Drawing;
using System.Windows.Forms;
namespace YINSH
{
public partial class Game : Form
{
private static Game Instance = null;
public static Game GetInstance()
{
if (Instance == null)
{
Instance = new Game();
}
return Instance;
}
#region 인스턴스
readonly Map map = Map.GetInstance();
readonly Turn turn = Turn.GetInstance();
readonly Component component = Component.GetInstance();
readonly Score score = Score.GetInstance();
#endregion
#region 이벤트
public delegate void CheckChangeFile();
public event CheckChangeFile ChangeFile;
public delegate void SendRingText(string text);
public event SendRingText RingText;
public delegate void SendMarkerText(string text);
public event SendMarkerText MarkerText;
public delegate void SendResultText(string text);
public event SendResultText ResultText;
#endregion
#region 변수
public Panel Board;
readonly public string[] player = { "White", "Black" };
string result;
public bool End()
{
for (var i = 0; i < score.Player.Length; i++)
{
if (score.Player[i] == score.winscore)
{
result = player[i] + " win!";
return true;
}
}
if(component.Marker_Shortage)
{
result = "Draw";
return true;
}
return false;
}
#endregion
#region 함수
public Game()
{
InitializeComponent();
Init();
Setting();
}
private void Init()
{
TopLevel = false;
TopMost = false;
Board = panel;
score.winscore = 3;
Size size = Board.Size;
int length = (Map.Size * 2) + 1;
map.System(size, length);
}
private void Panel_Paint(object sender, PaintEventArgs e)
{
Border(e);
Image();
}
private void Panel_MouseMove(object sender, MouseEventArgs e)
{
component.Cursor_Point = e.Location;
}
private void Panel_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (!End())
{
Rule();
ComponentText();
if (End())
{
ResultText(result);
}
}
}
}
public void ComponentText()
{
ChangeFile();
RingText($"Turn {player[turn.User]}");
MarkerText($"Marker\r\n{component.Marker_Quantity.ToString()}");
}
public void Setting()
{
Size size = Board.Size;
int length = (Map.Size * 2) + 1;
turn.Setting();
component.Setting(size, length);
score.Setting(size);
}
void Border(PaintEventArgs e)
{
Rectangle r = this.ClientRectangle;
r.Width -= 1;
r.Height -= 1;
e.Graphics.DrawRectangle(Pens.Black, r);
}
void Image()
{
using (Graphics g = Board.CreateGraphics())
{
g.DrawImage(map.Board, Point.Empty);
g.DrawImage(component.Layer, Point.Empty);
g.DrawImage(score.Layer, Point.Empty);
}
}
void Rule()
{
component.System();
turn.System();
score.System();
Board.Invalidate();
}
#endregion
}
}