-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cs
135 lines (101 loc) · 2.87 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MSO_P2;
internal class Game : Form
{
Field field;
Program program;
Label stats = new();
Label code = new();
internal Game()
{
stats.Location = new Point(850, 50);
stats.Size = new(200, 100);
Controls.Add(stats);
stats.BorderStyle = BorderStyle.FixedSingle;
code.Location = new Point(850, 150);
code.Size = new(200, 600);
Controls.Add(code);
code.BorderStyle = BorderStyle.FixedSingle;
this.Size = new Size(1100, 850);
GenerateToolStrip();
InitializeField();
program = new(new(field));
}
void GenerateToolStrip()
{
ToolStrip ToolStrip = new();
ToolStripButton t1 = new();
t1.Text = "open";
t1.Click += (object o, EventArgs e) =>
{
OpenFileDialog fd = new();
fd.Filter = "Text files (*.txt)|*.txt";
if (fd.ShowDialog() == DialogResult.OK)
{
LoadProgram(fd.FileName);
}
};
ToolStrip.Items.Add(t1);
ToolStripButton t2 = new();
t2.Text = "basic";
t2.Click += (object o, EventArgs e) =>
{
LoadProgram("..\\..\\..\\Examples\\Example1.txt");
};
ToolStrip.Items.Add(t2);
ToolStripButton t3 = new();
t3.Text = "advanced";
t3.Click += (object o, EventArgs e) =>
{
LoadProgram("..\\..\\..\\Examples\\Example2.txt");
};
ToolStrip.Items.Add(t3);
ToolStripButton t4 = new();
t4.Text = "expert";
t4.Click += (object o, EventArgs e) =>
{
LoadProgram("..\\..\\..\\Examples\\Example3.txt");
};
ToolStrip.Items.Add(t4);
ToolStripButton t5 = new();
t5.Text = "Run";
t5.Click += (object o, EventArgs e) =>
{
program.Start();
field.Invalidate();
};
ToolStrip.Items.Add(t5);
ToolStripButton t6 = new();
t6.Text = "resetField";
t6.Click += (object o, EventArgs e) =>
{
ResetField();
field.Invalidate();
};
ToolStrip.Items.Add(t6);
Controls.Add(ToolStrip);
}
void LoadProgram(string filename)
{
string codetxt = File.ReadAllText(filename);
program.Parse(codetxt);
code.Text = codetxt.Replace('\t', '_');
stats.Text = program.GetStatistics();
field.Invalidate();
}
void InitializeField()
{
field = new Field(new(),new ());
ResetField();
field.Location = new Point(50, 50);
Controls.Add(field);
}
void ResetField()
{
field.Reset(new Size(60, 30), new Size(800, 700));
}
}