-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFormMain.cs
More file actions
72 lines (71 loc) · 2.59 KB
/
FormMain.cs
File metadata and controls
72 lines (71 loc) · 2.59 KB
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
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
namespace Sailing
{
public partial class FormMain : Form
{
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormMain());
}
ContentManager m;
Land[] lands;
Shoal shoal;
Sailer boat;
public FormMain() {
InitializeComponent();
Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
LoadMap("Map.txt");
boat = new Sailer(m, 100f, 450f);
boat.AddObstacle(shoal, lands);
m.StartRender();
}
bool LoadMap(string fileName) {
if (!File.Exists(fileName)) {
MessageBox.Show("File not found or access denied\n" + fileName,
"File access error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
StreamReader f = new StreamReader(fileName);
string l = f.ReadLine();
uint count, i;
ClientSize = new Size(int.Parse(l.Split()[0]), int.Parse(l.Split()[1]));
m = new ContentManager(this, Color.FromArgb(25, 75, 90), true);
while ((l = f.ReadLine()) != null) {
switch (l) {
case "lands":
count = uint.Parse(f.ReadLine());
lands = new Land[count];
for (i = 0; i < count; i++) lands[i] = new Land(m, ReadPoints(f));
break;
case "shoal":
shoal = new Shoal(m, ReadPoints(f));
break;
default:
MessageBox.Show("Error parsing file\n" + fileName,
"Parse error", MessageBoxButtons.OK, MessageBoxIcon.Error);
f.Close();
return false;
}
}
f.Close();
return true;
}
Point[] ReadPoints(StreamReader f) {
uint count = uint.Parse(f.ReadLine());
Point[] r = new Point[count];
string l;
for (uint i = 0; i < count; i++) {
l = f.ReadLine();
string[] c = l.Split();
r[i].X = int.Parse(c[0]);
r[i].Y = int.Parse(c[1]);
}
return r;
}
}
}