-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMap.cs
161 lines (156 loc) · 5.22 KB
/
Map.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
using System;
using System.Collections.Generic;
using System.Linq;
namespace ttc_wtc
{
[Serializable]
public struct Point
{
public int x;
public int y;
public Point(int X, int Y)
{
x = X;
y = Y;
}
}
[Serializable]
class Map
{
public string name;
public int[,] transitionTo;
public char[,] drawnMap;
public bool[,] passable;
public Point[] transitionCoords;
public Entity[,] Entities;
public Chest[,] Chests;
public List<Chest> NotEmptyChests = new List<Chest>();
public Map(string[] map, int numberOfMaps)
{
map = HelpFunctions.MST(map);
int[] connections = MapSolver.ConnectionSolver(map[^2]);
int sizex = map.Length - 1;
int sizey = 0;
for (int i = 0; i < sizex - 1; i++)
{
sizey = sizey < map[i].Length ? map[i].Length : sizey;
}
transitionCoords = new Point[numberOfMaps + 1];
Chests = new Chest[sizex, sizey];
Entities = new Entity[sizex, sizey];
transitionTo = new int[sizex, sizey];
for (int i = 0; i < sizex; i++)
{
for (int j = 0; j < sizey; j++)
{
transitionTo[i, j] = -1;
}
}
drawnMap = new char[sizex, sizey];
passable = new bool[sizex, sizey];
name = map[^1];
drawnMap = MapSolver.MapSplitter(map, sizey, transitionTo, connections, passable);
foreach (var chest in Chests)
{
if (chest != null)
{
NotEmptyChests.Add(chest);
}
}
}
public Map(char[,] tiles, int numberOfMaps, bool endless)
{
int sizeX = tiles.GetLength(0);
int sizeY = tiles.GetLength(1);
passable = new bool[sizeX, sizeY];
Chests = new Chest[sizeX, sizeY];
Entities = new Entity[sizeX, sizeY];
for (int i = 0; i < sizeX; i++)
{
for (int j = 0; j < sizeY; j++)
{
if (tiles[i, j] == '#' || tiles[i, j] == ' ')
{
passable[i, j] = false;
}
else
{
passable[i, j] = true;
}
if (tiles[i, j] == '$')
{
Entities[i, j] = new Enemy("Вейн", 1000, 50, 4, CollectedMaps.AllMaps.Count(), i, j);
tiles[i, j] = '.';
}
else if (tiles[i, j] == 'C')
{
Chest chest = new Chest(CollectedMaps.AllMaps.Count(), i, j);
if (!endless)
{
if (CollectedMaps.AllMaps.Count() == 3)
{
chest.AddItem(Item.Items[(int)Item.ItemId.HeroesSword]);
chest.AddItem(Item.Items[(int)Item.ItemId.HealPotion]);
}
else
{
chest.AddItem(Item.Items[(int)Item.ItemId.UminekoStone]);
}
}
else
{
chest.AddItem(Item.GenerateItem(Program.CurrentGame.player.EndlessLevel));
chest.AddItem(Item.Items[(int)Item.ItemId.HealPotion]);
}
Chests[i, j] = chest;
passable[i, j] = false;
}
}
}
transitionCoords = new Point[numberOfMaps + 1];
drawnMap = tiles;
transitionTo = new int[sizeX, sizeY];
for (int i = 0; i < sizeX; i++)
{
for (int j = 0; j < sizeY; j++)
{
transitionTo[i, j] = -1;
}
}
if (!endless)
{
drawnMap[1, 1] = 'E';
if (CollectedMaps.AllMaps.Count == 3)
{
transitionTo[1, 1] = 0;
transitionCoords[0] = new Point(1, 1);
}
else
{
transitionTo[1, 1] = 3;
transitionCoords[3] = new Point(1, 1);
}
}
name = "Данж";
foreach (var chest in Chests)
{
if (chest != null)
{
NotEmptyChests.Add(chest);
}
if (!endless)
{
name = "Данж";
}
else if (Program.CurrentGame.player.EndlessLevel == 0)
{
name = "Данж 0";
}
else
{
name = "Данж " + Program.CurrentGame.player.EndlessLevel;
}
}
}
}
}