public void Initialize() { viewQueue.Clear(); HexaModel[][] hexaMapModel = map.GetHexaMapModel(); hexaMapView = new HexaView[hexaMapModel.Length][]; for (int i = 0; i < hexaMapModel.Length; i++) { hexaMapView[i] = new HexaView[hexaMapModel[i].Length]; for (int j = 0; j < hexaMapModel[i].Length; j++) { if (hexaMapModel[i][j] != null) { switch (hexaMapModel[i][j].GetKind()) { case HexaKind.Mountains: hexaMapView[i][j] = new MountainsView(hexaMapModel[i][j], i, j); break; case HexaKind.Cornfield: hexaMapView[i][j] = new CornfieldView(hexaMapModel[i][j], i, j); break; case HexaKind.Stone: hexaMapView[i][j] = new StoneView(hexaMapModel[i][j], i, j); break; case HexaKind.Water: hexaMapView[i][j] = getWaterView(i, j); break; case HexaKind.Forest: hexaMapView[i][j] = new ForestView(hexaMapModel[i][j], i, j); break; case HexaKind.Pasture: hexaMapView[i][j] = new PastureView(hexaMapModel[i][j], i, j); break; case HexaKind.Desert: hexaMapView[i][j] = new DesertView(hexaMapModel[i][j], i, j); break; default: hexaMapView[i][j] = new HexaView(hexaMapModel[i][j], i, j); break; } } } } }
private void CreateTownsAndRoads() { HexaModel[] neighboursModel = new HexaModel[6]; HexaView[] neighboursView = new HexaView[6]; HexaView[][] hexaMapView = mapView.GetHexaMapView(); for (int i = 0; i < hexaMapModel.Length; ++i) { for (int j = 0; j < hexaMapModel[i].Length; ++j) { if (hexaMapModel[i][j] == null) continue; hexaMapModel[i][j].SetCoord(i, j); // UP LEFT if (i >= 1 && hexaMapModel[i - 1].Length > j) { neighboursModel[(int)RoadPos.UpLeft] = hexaMapModel[i - 1][j]; neighboursView[(int)RoadPos.UpLeft] = hexaMapView[i - 1][j]; } else { neighboursModel[(int)RoadPos.UpLeft] = null; neighboursView[(int)RoadPos.UpLeft] = null; } // UP RIGHT if (i >= 1 && j > 0 && hexaMapModel[i - 1].Length > j - 1) { neighboursModel[(int)RoadPos.UpRight] = hexaMapModel[i - 1][j - 1]; neighboursView[(int)RoadPos.UpRight] = hexaMapView[i - 1][j - 1]; } else { neighboursModel[(int)RoadPos.UpRight] = null; neighboursView[(int)RoadPos.UpRight] = null; } // LEFT if (hexaMapModel[i].Length > j + 1) { neighboursModel[(int)RoadPos.MiddleLeft] = hexaMapModel[i][j + 1]; neighboursView[(int)RoadPos.MiddleLeft] = hexaMapView[i][j + 1]; } else { neighboursModel[(int)RoadPos.MiddleLeft] = null; neighboursView[(int)RoadPos.MiddleLeft] = null; } // RIGHT if (j - 1 >= 0) { neighboursModel[(int)RoadPos.MiddleRight] = hexaMapModel[i][j - 1]; neighboursView[(int)RoadPos.MiddleRight] = hexaMapView[i][j - 1]; } else { neighboursModel[(int)RoadPos.MiddleRight] = null; neighboursView[(int)RoadPos.MiddleRight] = null; } // BOTTOM LEFT if (i + 1 < hexaMapModel.Length && hexaMapModel[i + 1].Length > j + 1) { neighboursModel[(int)RoadPos.BottomLeft] = hexaMapModel[i + 1][j + 1]; neighboursView[(int)RoadPos.BottomLeft] = hexaMapView[i + 1][j + 1]; } else { neighboursModel[(int)RoadPos.BottomLeft] = null; neighboursView[(int)RoadPos.BottomLeft] = null; } // BOTTOM RIGHT if (i + 1 < hexaMapModel.Length && hexaMapModel[i + 1].Length > j) { neighboursModel[(int)RoadPos.BottomRight] = hexaMapModel[i + 1][j]; neighboursView[(int)RoadPos.BottomRight] = hexaMapView[i + 1][j]; } else { neighboursModel[(int)RoadPos.BottomRight] = null; neighboursView[(int)RoadPos.BottomRight] = null; } hexaMapModel[i][j].CreateTownsAndRoads(neighboursModel, hexaMapView[i][j], neighboursView); mapView.GetHexaMapView()[i][j].SetHexaNeighbours(neighboursView); } } }