-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTile.cs
198 lines (167 loc) · 7.01 KB
/
Tile.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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace gridproject
{
public struct TileCoordinates
{
public int X;
public int Y;
public TileCoordinates(int _x, int _y)
{
X = _x;
Y = _y;
}
}
public class Tile
{
public Control AssociatedButton;
public int X { get; private set; }
public int Y { get; private set; }
public TileCoordinates TileCoordinates { get; private set; }
public IOccupation Occupation { get; private set; }
public bool IsEmpty => Occupation.Type == OccupationType.Grass;
public Tile(Control ab, int x, int y)
{
AssociatedButton = ab;
X = x;
Y = y;
TileCoordinates = new TileCoordinates(x, y);
}
public void Load()
{
Occupation.Load(AssociatedButton);
AssociatedButton.BackgroundImage = Const.OccupationIDToImage[(int)Occupation.Type];
}
public void Reset()
{
Occupation.Reset(AssociatedButton);
if(!Occupation.IsUnderground)
SetOccupation(new GrassOccupation());
}
public void SetOccupation(IOccupation occupation)
{
Occupation = occupation;
Occupation.SetCoordinates(TileCoordinates);
Load();
}
public void SetOccupation(OccupationType occupation, bool isUnderground = false)
{
Reset();
switch (occupation)
{
case OccupationType.Grass:
Occupation = new GrassOccupation();
Occupation.SetCoordinates(TileCoordinates);
Load();
break;
case OccupationType.Water:
Occupation = new WaterOccupation();
Occupation.SetCoordinates(TileCoordinates);
Load();
break;
case OccupationType.Chest:
Occupation = new ChestOccupation();
Occupation.SetCoordinates(TileCoordinates);
Load();
break;
case OccupationType.Furnace:
Occupation = new FurnaceOccupation();
Occupation.SetCoordinates(TileCoordinates);
Load();
break;
case OccupationType.CraftingTable:
Occupation = new CraftingTableOccupation();
Occupation.SetCoordinates(TileCoordinates);
Load();
break;
case OccupationType.Plank:
Occupation = new PlankOccupation(TileCoordinates, new ItemStack(Item.Plank, 1));
Load();
break;
case OccupationType.CoolCraftingTable:
Occupation = new CoolCraftingTableOccupation();
Occupation.SetCoordinates(TileCoordinates);
Load();
break;
case OccupationType.CoolChest:
Occupation = new CoolChestOccupation();
Occupation.SetCoordinates(TileCoordinates);
Load();
break;
case OccupationType.DirtReactor:
Occupation = new DirtReactorOccupation();
Occupation.SetCoordinates(TileCoordinates);
Load();
break;
default:
break;
}
Occupation.IsUnderground = isUnderground;
}
public void SetOccupation(OccupationType occupation, int durability, bool isUnderground = false)
{
Reset();
switch (occupation)
{
case OccupationType.StoneSource:
Occupation = new StoneSourceOccupation(durability, TileCoordinates, Item.Cobblestone, new List<Item> { Item.WoodenPickaxe, Item.StonePickaxe, Item.IronPickaxe, Item.DiamondPickaxe, Item.GoldenPickaxe, Item.Perforator });
Load();
break;
case OccupationType.Woods:
Occupation = new WoodsOccupation(durability, TileCoordinates, Item.Wood, new List<Item> { Item.None, Item.WoodenAxe, Item.StoneAxe, Item.IronAxe, Item.DiamondAxe, Item.GoldenAxe, Item.Perforator });
Load();
break;
case OccupationType.IronOre:
Occupation = new IronOreOccupation(durability, TileCoordinates, Item.IronOre, new List<Item> { Item.StonePickaxe, Item.IronPickaxe, Item.DiamondPickaxe, Item.GoldenPickaxe, Item.Perforator });
Load();
break;
case OccupationType.CoalOre:
Occupation = new CoalOreOccupation(durability, TileCoordinates, Item.Coal, new List<Item> { Item.StonePickaxe, Item.IronPickaxe, Item.DiamondPickaxe, Item.GoldenPickaxe, Item.Perforator });
Load();
break;
case OccupationType.Dirt:
Occupation = new DirtOccupation(durability, TileCoordinates, Item.Dirt, new List<Item> { Item.WoodenShovel, Item.StoneShovel, Item.IronShovel, Item.DiamondShovel, Item.GoldenShovel, Item.Perforator });
Load();
break;
case OccupationType.GoldOre:
Occupation = new GoldOreOccupation(durability, TileCoordinates, Item.GoldOre, new List<Item> { Item.IronPickaxe, Item.DiamondPickaxe, Item.GoldenPickaxe, Item.Perforator });
Load();
break;
case OccupationType.DiamondOre:
Occupation = new GoldOreOccupation(durability, TileCoordinates, Item.Diamond, new List<Item> { Item.IronPickaxe, Item.DiamondPickaxe, Item.GoldenPickaxe });
Load();
break;
}
Occupation.IsUnderground = isUnderground;
}
public void ForceSetOccupation(IOccupation occupation, bool underground = false, bool removeAllEvents = false)
{
if (removeAllEvents)
{
try
{
AssociatedButton.Click -= (Occupation as ChestOccupation).OpenChest;
}
catch { }
try
{
AssociatedButton.Click -= (Occupation as FurnaceOccupation).OpenFurnace;
}
catch { }
//try
//{
// AssociatedButton.Click -= (Occupation as Mineable).Mine;
//}
//catch { }
}
occupation.IsUnderground = underground;
Occupation = occupation;
Occupation.SetCoordinates(TileCoordinates);
Load();
}
}
}