Beispiel #1
0
		public static Tile[] Tiles2DToTiles(Tile[,] tiles2D) {
			Tile[] tiles = new Tile[19];
			int i = 0;

			for (int y = 0; y < tiles2D.GetLength(0); ++y) {
				for (int x = 0; x < tiles2D.GetLength(1); ++x) {
					if (tiles2D[y, x] != null) {
						tiles[i++] = tiles2D[y, x];
					}
				}
			}

			return tiles;
		}
Beispiel #2
0
		private static Node[] CreateNodes(Tile[,] tiles) {
			List<Node> nodes = new List<Node>();

			for (int y = 0; y < tiles.GetLength(0); ++y) {
				for (int x = 0; x < tiles.GetLength(1); ++x) {
					Tile tile = tiles[y, x];

					if (tile == null) {
						continue;
					}

					tile.nodes = new Node[6];

					for (int n = 0; n < tile.nodes.Length; ++n) {
						Node neighboursNode = null;

						#region Switch Case - Find Node in neighbouring Tile
						switch (n) {
							case 0:
								neighboursNode = GetNeighboursNode(x, y, tiles, new List<KeyValuePair<NeighbourDirection, int>>() {
									new KeyValuePair<NeighbourDirection, int>(NeighbourDirection.UP, 2),
									new KeyValuePair<NeighbourDirection, int>(NeighbourDirection.UPRIGHT, 4)
								});
								break;
							case 1:
								neighboursNode = GetNeighboursNode(x, y, tiles, new List<KeyValuePair<NeighbourDirection, int>>() {
									new KeyValuePair<NeighbourDirection, int>(NeighbourDirection.UPRIGHT, 3),
									new KeyValuePair<NeighbourDirection, int>(NeighbourDirection.RIGHT, 5)
								});
								break;
							case 2:
								neighboursNode = GetNeighboursNode(x, y, tiles, new List<KeyValuePair<NeighbourDirection, int>>() {
									new KeyValuePair<NeighbourDirection, int>(NeighbourDirection.RIGHT, 4),
									new KeyValuePair<NeighbourDirection, int>(NeighbourDirection.DOWN, 0)
								});
								break;
							case 3:
								neighboursNode = GetNeighboursNode(x, y, tiles, new List<KeyValuePair<NeighbourDirection, int>>() {
									new KeyValuePair<NeighbourDirection, int>(NeighbourDirection.DOWN, 5),
									new KeyValuePair<NeighbourDirection, int>(NeighbourDirection.DOWNLEFT, 2)
								});
								break;
							case 4:
								neighboursNode = GetNeighboursNode(x, y, tiles, new List<KeyValuePair<NeighbourDirection, int>>() {
									new KeyValuePair<NeighbourDirection, int>(NeighbourDirection.DOWNLEFT, 0),
									new KeyValuePair<NeighbourDirection, int>(NeighbourDirection.LEFT, 2)
								});
								break;
							case 5:
								neighboursNode = GetNeighboursNode(x, y, tiles, new List<KeyValuePair<NeighbourDirection, int>>() {
									new KeyValuePair<NeighbourDirection, int>(NeighbourDirection.LEFT, 1),
									new KeyValuePair<NeighbourDirection, int>(NeighbourDirection.UP, 3)
								});
								break;
						}
						#endregion

						Node node = null;
						if (neighboursNode != null) {
							node = neighboursNode;
						}
						else {
							node = new Node();
							nodes.Add(node);
						}

						tile.nodes[n] = node;

						if (node.tiles == null || !node.tiles.Contains(tile)) {
							AddTileToNode(tile, node);
						}
					}
				}
			}

			return nodes.ToArray();
		}