public static Point SearchInArea(mapObject[,] map, Point planet, mapObject typeSearch) { Point[] tmp = new Point[] { planet, new Point(planet.X, planet.Y-1), new Point(planet.X+1, planet.Y), new Point(planet.X+1, planet.Y+1), new Point(planet.X+1, planet.Y-1), new Point(planet.X-1, planet.Y), new Point(planet.X-1, planet.Y+1), new Point(planet.X-1, planet.Y-1), new Point(planet.X, planet.Y+1), }; foreach (var p in tmp) { try { if (map[p.X, p.Y] == typeSearch) return p; } catch { } } return tmp[0]; }
public void ChangeCivOnPlanet(Point locPlanet, nameCiv civ, IActForm act, mapObject[,] map, Point ship) { if (civ == nameCiv.You) { planets[locPlanet].ChangeCiv(You, act); You.AddPlanet(planets[locPlanet]); map[locPlanet.X, locPlanet.Y] = mapObject.PlanetYou; if (ship.X != -1) { You.DeleteShip(ship); map[ship.X, ship.Y] = mapObject.None; } } else { planets[locPlanet].ChangeCiv(enemy); enemy.AddPlanet(planets[locPlanet]); map[locPlanet.X, locPlanet.Y] = mapObject.PlanetEnemy; if (ship.X != -1) { enemy.DeleteShip(ship); map[ship.X, ship.Y] = mapObject.None; } } }
public static Point[] GetFreeArea(mapObject[,] map, Point place) { List<Point> freeArea = new List<Point>(); Point[] tmp = new Point[] { place, new Point(place.X, place.Y-1), new Point(place.X+1, place.Y), new Point(place.X+1, place.Y+1), new Point(place.X+1, place.Y-1), new Point(place.X-1, place.Y), new Point(place.X-1, place.Y+1), new Point(place.X-1, place.Y-1), new Point(place.X, place.Y+1), }; foreach (var p in tmp) { try { if (map[p.X, p.Y] == mapObject.None) freeArea.Add(p); } catch { } } return freeArea.ToArray(); }
public void Turn(Civilization civ, mapObject[,] map) { civ.ClearTurnShips(); civ.CollectResources(); TurnShip(civ, map); Build(civ, map); }
//public static bool CheckLocation(Point location, int[,] Map) //{ // bool before = ((location.Y == 0 || location.X == 0) || location.Y - 1 >= 0 && location.X - 1 >= 0 && Map[location.X - 1, location.Y - 1] == 0) // && (location.X == 0 || location.X - 1 >= 0 && Map[location.X - 1, location.Y] == 0) // && ((location.X == 0 || location.Y == Map.GetLength(1) || location.Y + 1 < Map.GetLength(1)) && location.X - 1 >= 0 && Map[location.X - 1, location.Y + 1] == 0); // bool middle = (location.Y == 0 || location.Y - 1 >= 0 && Map[location.X, location.Y - 1] == 0) // && (location.Y == 9 || location.Y + 1 < Map.GetLength(1) && Map[location.X, location.Y + 1] == 0); // bool after = ((location.Y == 0 || location.X == Map.GetLength(0) - 1) || location.Y - 1 >= 0 && location.X + 1 < Map.GetLength(0) && Map[location.X + 1, location.Y - 1] == 0) // && (location.X == Map.GetLength(0) - 1 || location.X + 1 < Map.GetLength(0) && Map[location.X + 1, location.Y] == 0) // && ((location.X == Map.GetLength(0) - 1 || location.Y == Map.GetLength(1) - 1) || location.Y + 1 < Map.GetLength(1) && location.X + 1 < Map.GetLength(0) && Map[location.X + 1, location.Y + 1] == 0); // return before && middle && after; //} public static bool CheckLocation(Point location, mapObject[,] MapObj) { Point[] tmp = new Point[] { location, new Point(location.X, location.Y-1), new Point(location.X+1, location.Y), new Point(location.X+1, location.Y+1), new Point(location.X+1, location.Y-1), new Point(location.X-1, location.Y), new Point(location.X-1, location.Y+1), new Point(location.X-1, location.Y-1), new Point(location.X, location.Y + 1), }; bool res = true; foreach (var p in tmp) { try { res = res && (MapObj[p.X, p.Y] == mapObject.None); } catch { } } return res; }
public void MouseClick(object sender, System.Windows.Forms.MouseEventArgs e, mapObject obj, bool grid) { var location = new Point(e.Location.X / MapStruct.BlockSize, e.Location.Y / MapStruct.BlockSize); if (location.X < 21 && location.Y < 14) { mainForm.Invalidate(AddObject(obj, location, grid)); } }
public void MouseMove(object sender, System.Windows.Forms.MouseEventArgs e, mapObject obj, bool grid) { //var location = new Point(e.Location.X / MapStruct.BlockSize, e.Location.Y / MapStruct.BlockSize); //if (location.X < 21 && location.Y < 14) //{ // mainForm.Invalidate(draw.TempObj2(obj, location, map.MapObject, grid)); //} }
public GameLogic(mapObject[,] map) { r = new Random(); You = new Civilization(); enemy = new Civilization(); planets = new Dictionary<Point, Planet>(); turnEnemy = new Enemy(); InitPlanets(map); }
public Bitmap AddObject(mapObject obj, Point location, bool grid) { if (map.MapObject[location.X, location.Y] == mapObject.None) { return draw.DrawObject(obj, location, map.MapObject, grid); } else { return draw.GetMainBT(grid); } }
public void BuildShip(mapObject[,] map) { foreach (var p in Planets) { if (p.createObj.Pic[0].TypeShip != TypeShip.None) { NewShip(map, p); p.createObj.MovePictures(0, false); // сдвиг очереди постройки } } }
public Bitmap GetMap(mapObject[,] map) { using (Graphics g = Graphics.FromImage(MainBt)) { g.Clear(Color.Black); g.DrawImage(back, new Point(0, 0)); //DrawGrid(MainBt); for (int i = 0; i < map.GetLength(0); i++) { for (int j = 0; j < map.GetLength(1); j++) { switch (map[i, j]) { case mapObject.Asteroid: g.DrawImage(AsteroidPicture, new Point(i * MapStruct.BlockSize + 5, j * MapStruct.BlockSize + MapStruct.Shift + 5)); break; case mapObject.Planet: g.DrawImage(planetPicture, new Point(i * MapStruct.BlockSize + 2, j * MapStruct.BlockSize + MapStruct.Shift + 2)); break; case mapObject.Chest: g.DrawImage(ChestPicture, new Point(i * MapStruct.BlockSize + 2, j * MapStruct.BlockSize + MapStruct.Shift + 2)); break; case mapObject.PlanetYou: g.DrawRectangle(penYou, i * MapStruct.BlockSize, j * MapStruct.BlockSize + MapStruct.Shift, MapStruct.BlockSize, MapStruct.BlockSize); g.DrawImage(planetPicture, new Point(i * MapStruct.BlockSize + 2, j * MapStruct.BlockSize + MapStruct.Shift + 2)); break; case mapObject.PlanetEnemy: g.DrawRectangle(penEnemyPlanet, i * MapStruct.BlockSize, j * MapStruct.BlockSize + MapStruct.Shift, MapStruct.BlockSize, MapStruct.BlockSize); g.DrawImage(planetPicture, new Point(i * MapStruct.BlockSize + 2, j * MapStruct.BlockSize + MapStruct.Shift + 2)); break; case mapObject.DestroyerYou: g.DrawRectangle(new Pen(Color.Purple, 1.5f), i * MapStruct.BlockSize, j * MapStruct.BlockSize + MapStruct.Shift, MapStruct.BlockSize, MapStruct.BlockSize); g.DrawImage(DestroyerPicture, new Point(i * MapStruct.BlockSize + 4, j * MapStruct.BlockSize + MapStruct.Shift + 4)); break; case mapObject.ColonistYou: g.DrawRectangle(new Pen(Color.Purple, 1.5f), i * MapStruct.BlockSize, j * MapStruct.BlockSize + MapStruct.Shift, MapStruct.BlockSize, MapStruct.BlockSize); g.DrawImage(ColonistPicture, new Point(i * MapStruct.BlockSize + 4, j * MapStruct.BlockSize + MapStruct.Shift + 4)); break; case mapObject.DestroyerEnemy: g.DrawRectangle(penEnemyShip, i * MapStruct.BlockSize, j * MapStruct.BlockSize + MapStruct.Shift, MapStruct.BlockSize, MapStruct.BlockSize); g.DrawImage(DestroyerPicture, new Point(i * MapStruct.BlockSize + 4, j * MapStruct.BlockSize + MapStruct.Shift + 4)); break; default: break; } } } return MainBt; } }
void RecordFile(string name, mapObject[,] map) { FileStream file = null; BinaryFormatter b = null; try { file = File.Create("Maps/" + name + ".swdat"); b = new BinaryFormatter(); b.Serialize(file, map); } finally { file.Close(); } }
public void Kill(Civilization enemy, mapObject[,] map, Dictionary<Point, Ship> you) { foreach (var pointShip in enemy.Ships.Keys) { Point pointKill = Ship.SearchInArea(map, pointShip, mapObject.DestroyerYou); if (pointKill != pointShip) { if (you.ContainsKey(pointKill)) { you.Remove(pointKill); map[pointKill.X, pointKill.Y] = mapObject.None; enemy.Ships[pointShip].Turn = true; } } } }
private void TurnShip(Civilization civ, mapObject[,] map) { temp.Clear(); foreach (var shipCrd in civ.Ships.Keys) { Point[] freeArea = Ship.GetFreeArea(map, shipCrd); if (freeArea.Length != 0 && !civ.Ships[shipCrd].Turn) { Point move = freeArea[r.Next(0, freeArea.Length - 1)]; map[shipCrd.X, shipCrd.Y] = mapObject.None; map[move.X, move.Y] = mapObject.DestroyerEnemy; temp.Add(move, civ.Ships[shipCrd]); temp[move].Turn = true; } } civ.Ships = new Dictionary<Point, Ship>(temp); }
private void Build(Civilization civ, mapObject[,] map) { while (civ.Titanium >= 8 && civ.Iridium >= 17 && civ.Gold >= 450) { Point planet = civ.Planets[r.Next(0, civ.Planets.Count - 1)].Location; // строим новый корабль на рандомной планете противники Point loc = Ship.SearchInArea(map, planet, mapObject.None); if (map[loc.X, loc.Y] == mapObject.None) { civ.Ships.Add(loc, new Ship()); map[loc.X, loc.Y] = mapObject.DestroyerEnemy; civ.Titanium -= 8; civ.Iridium -= 17; civ.Gold -= 450; } else break; } }
public Bitmap GetShipRegion(mapObject[,] map, Point location, bool colonist) { using (Graphics g = Graphics.FromImage(tempBt)) { g.Clear(Color.White); g.DrawImage(MainBt, new Point(0, 0)); List<Point> temp = GetAvailableArea(map, location); // Пусто foreach (var p in temp) { if (map[p.X, p.Y] == mapObject.None) g.DrawRectangle(penGreen, p.X * MapStruct.BlockSize, p.Y * MapStruct.BlockSize + MapStruct.Shift, MapStruct.BlockSize, MapStruct.BlockSize); } // Враг foreach (var p in temp) { if (map[p.X, p.Y] == mapObject.DestroyerEnemy) g.DrawRectangle(penEnemyPlanet, p.X * MapStruct.BlockSize, p.Y * MapStruct.BlockSize + MapStruct.Shift, MapStruct.BlockSize, MapStruct.BlockSize); if (map[p.X, p.Y] == mapObject.ColonistEnemy) g.DrawRectangle(penEnemyPlanet, p.X * MapStruct.BlockSize, p.Y * MapStruct.BlockSize + MapStruct.Shift, MapStruct.BlockSize, MapStruct.BlockSize); if (map[p.X, p.Y] == mapObject.PlanetEnemy) g.DrawRectangle(penEnemyPlanet, p.X * MapStruct.BlockSize, p.Y * MapStruct.BlockSize + MapStruct.Shift, MapStruct.BlockSize, MapStruct.BlockSize); } // область самого корабля g.DrawRectangle(new Pen(Color.Purple, 1.0f), location.X * MapStruct.BlockSize, location.Y * MapStruct.BlockSize + MapStruct.Shift, MapStruct.BlockSize, MapStruct.BlockSize); // Сундук foreach (var p in temp) { if (map[p.X, p.Y] == mapObject.Chest) g.DrawRectangle(penChest, p.X * MapStruct.BlockSize, p.Y * MapStruct.BlockSize + MapStruct.Shift, MapStruct.BlockSize, MapStruct.BlockSize); } if (colonist) { foreach (var p in temp) { if (map[p.X, p.Y] == mapObject.Planet) g.DrawRectangle(penPlanet, p.X * MapStruct.BlockSize, p.Y * MapStruct.BlockSize + MapStruct.Shift, MapStruct.BlockSize, MapStruct.BlockSize); } } return tempBt; } }
private void DrawRegionObj(Graphics g, Pen pen, Point[] reg, mapObject Obj, mapObject[,] map) { // Пусто foreach (var p in reg) { try { if (map[p.X, p.Y] == Obj) g.DrawRectangle(pen, p.X * MapStruct.BlockSize, p.Y * MapStruct.BlockSize + MapStruct.Shift, MapStruct.BlockSize, MapStruct.BlockSize); } catch { } } }
public Bitmap MoveShip(mapObject[,] map, Point start, Point end) { if (availableArea.Contains(end)) { map[end.X, end.Y] = map[start.X, start.Y]; map[start.X, start.Y] = mapObject.None; MovingShip = true; return GetMap(map); } else { MovingShip = false; return MainBt; } }
public void SelectEnemyCapital(Point locPlanet, nameCiv civ, IActForm act, mapObject[,] map, Point ship) { foreach (var p in planets.Keys) { if (planets[p].civ == null) { //planets[p].ChangeCiv(enemy); //enemy.AddPlanet(planets[p]); ChangeCivOnPlanet(new Point(p.X, p.Y), nameCiv.Enemy, act, map, ship); break; } } }
public void EndTurn(mapObject[,] map) { turnEnemy.Kill(enemy, map, You.Ships); turnEnemy.Turn(enemy, map); You.EndTurn(map); }
public void initiate(List <string> layerNames) { if (_prefixedObjects == null) { _prefixedObjects = new Dictionary <string, rangeHelper>(); } if (_tileObjects == null) { _tileObjects = new Dictionary <string, GameObject>(); } _tileObjects.Clear(); if (tileObjects == null) { tileObjects = new List <mapObject>(); } if (_layers == null) { _layers = new Dictionary <string, GameObject>(); } if (_layersGameObject == null) { _layersGameObject = new Dictionary <string, List <GameObject> >(); } foreach (KeyValuePair <string, GameObject> layer in _layers) { Destroy(layer.Value); } _layers.Clear(); foreach (KeyValuePair <string, List <GameObject> > layer in _layersGameObject) { foreach (GameObject objectToDestroy in layer.Value) { Destroy(objectToDestroy); } } _layersGameObject.Clear(); foreach (string prefix in prefixIdentifier) { _prefixedObjects.Add(prefix, new rangeHelper(-1, -1)); } foreach (string layerName in layerNames) { if (_layers.ContainsKey(layerName)) { continue; } GameObject layer = new GameObject("(layer)" + layerName); layer.transform.SetParent(gameObject.transform); _layersGameObject.Add(layerName, new List <GameObject>()); _layers.Add(layerName, layer); if (gamemanager.instance.debug) { Debug.Log("(mapGfx:initiate) Created hierarchy layer: " + layerName + "."); } } Object[] objects = Resources.LoadAll("Mapgeneration"); tileObjects.Add(new mapObject("allocable", null)); tileObjects.Add(new mapObject("reserved", null)); tileObjects.Add(new mapObject("path", null)); int objectID = 3; foreach (Object mapObject in objects) { mapObject newMapObject = new mapObject(); newMapObject.objectName = mapObject.name; newMapObject.objectPrefab = (GameObject)mapObject; foreach (string prefix in prefixIdentifier) { if (mapObject.name.StartsWith(prefix)) { if (_prefixedObjects[prefix].begin == -1) { _prefixedObjects[prefix].begin = objectID; _prefixedObjects[prefix].end = objectID; } else { _prefixedObjects[prefix].end++; } } } tileObjects.Add(newMapObject); _tileObjects.Add(newMapObject.objectName, newMapObject.objectPrefab); objectID++; if (gamemanager.instance.debug) { Debug.Log("(mapGfx:initiate) Loaded gameobject: " + newMapObject.objectName + "."); } } if (gamemanager.instance.debug) { foreach (KeyValuePair <string, rangeHelper> prefixedObject in _prefixedObjects) { Debug.Log("(mapGfx: initiate) Objects with prefix " + prefixedObject.Key + " start with ID " + prefixedObject.Value.begin + " and end with ID " + prefixedObject.Value.end + "."); } Debug.Log("(mapGfx:initiate) has been initiated."); } }
private void InitPlanets(mapObject[,] map) { List<string> temp = new List<string> { "Ферос", "Иден Прайм", "Мавигон", "Тучанка", "Палавен", "Сур'Кеш", "Сильва", "Солярис", "Сион", "Велес", "Элата" }; int indexName = 0; Random r = new Random(); for (int i = 0; i < map.GetLength(0); i++) { for (int j = 0; j < map.GetLength(1); j++) { if (map[i, j] == mapObject.Planet) planets.Add(new Point(i, j), new Planet(new Point(i, j), temp[indexName++], r.Next(2, 7), r.Next(2, 4), r.Next(1, 5), r.Next(50, 100))); } } }
public MapStruct() { MapObject = new mapObject[21, 14]; BlockSize = 40; Shift = 30; }
public void NewShip(mapObject[,] map, Planet p) { Point newShip = Ship.SearchInArea(map, p.Location, mapObject.None); switch (p.createObj.Pic[0].TypeShip) { case TypeShip.Colonist: map[newShip.X, newShip.Y] = mapObject.ColonistYou; break; case TypeShip.Destroyer: map[newShip.X, newShip.Y] = mapObject.DestroyerYou; break; } Ships.Add(newShip, new Ship()); }
public Bitmap DrawObject(mapObject obj, Point location, mapObject[,] Map, bool grid) { using (g = Graphics.FromImage(TempBT)) { g.Clear(Color.White); g.DrawImage(MainBT, new Point(0, 0)); switch (obj) { case mapObject.Planet: if (Check.CheckLocation(location, Map)) { g.DrawImage(planetPicture, new Point(location.X * MapStruct.BlockSize + 2, location.Y * MapStruct.BlockSize + 2)); Map[location.X, location.Y] = obj; } break; case mapObject.Chest: g.DrawImage(ChestPicture, new Point(location.X * MapStruct.BlockSize + 2, location.Y * MapStruct.BlockSize + 2)); Map[location.X, location.Y] = obj; break; case mapObject.Asteroid: g.DrawImage(AsteroidPicture, new Point(location.X * MapStruct.BlockSize + 5, location.Y * MapStruct.BlockSize + 5)); Map[location.X, location.Y] = obj; break; } MainBT.Dispose(); MainBT = new Bitmap(TempBT); if (grid) g.DrawImage(gridBT, new Point(0, 0)); } return TempBT; }
public SaveMap(mapObject[,] map) { InitializeComponent(); this.map = map; }
private List<Point> GetAvailableArea(mapObject[,] map, Point location) { Point[] reg = new Point[] { new Point(location.X, location.Y-1), new Point(location.X+1, location.Y), new Point(location.X+1, location.Y+1), new Point(location.X+1, location.Y-1), new Point(location.X-1, location.Y), new Point(location.X-1, location.Y+1), new Point(location.X-1, location.Y-1), new Point(location.X, location.Y+1), }; availableArea = new List<Point>(); foreach (var i in reg) { try { if (map[i.X, i.Y] != mapObject.Asteroid) availableArea.Add(i); } catch { } } return availableArea; }
public void EndTurn(mapObject[,] map) { BuildShip(map); // строим корабли ClearTurnShips(); // Даем корабликам ходить снова CollectResources(); // сбор ресурсов }
public void MoveShip(Point start, Point end, mapObject[,] map, IForm form, PaintGame draw, IActForm actForm) { switch (map[end.X, end.Y]) { case mapObject.None: form.Invalidate(draw.MoveShip(map, start, end)); break; case mapObject.Chest: form.Invalidate(draw.MoveShip(map, start, end)); form.Status(RandomChest()); form.ChangeResources(You.Food, You.Titanium, You.Iridium, You.Gold); break; case mapObject.DestroyerEnemy: if (map[start.X, start.Y] == mapObject.DestroyerYou) { map[end.X, end.Y] = mapObject.None; KillEnemyShip(end); form.Invalidate(draw.GetMap(map)); draw.MovingShip = false; } break; case mapObject.ColonistEnemy: if (map[start.X, start.Y] == mapObject.DestroyerYou) { map[end.X, end.Y] = mapObject.None; KillEnemyShip(end); form.Invalidate(draw.GetMap(map)); draw.MovingShip = false; } break; case mapObject.PlanetEnemy: if (map[start.X, start.Y] == mapObject.DestroyerYou) { map[end.X, end.Y] = mapObject.Planet; ClearPlanet(end); form.Invalidate(draw.GetMap(map)); draw.MovingShip = false; } draw.MovingShip = false; break; case mapObject.Planet: if (map[start.X, start.Y] == mapObject.ColonistYou) { ChangeCivOnPlanet(end, nameCiv.You, actForm, map, start); form.Invalidate(draw.GetMap(map)); } else draw.MovingShip = false; break; default: draw.MovingShip = false; break; } }