public static void Fight(Player attacker, HexCoordinates defenderCoordinates) { TroopInventory attackerInventory = attacker.TroopInventory; Building defender = (Building)grid.GetCell(defenderCoordinates).Structure; if (defender == null) { return; } if (defender is ProtectedBuilding) { if (attackerInventory.Fight(((ProtectedBuilding)defender).TroopInventory)) { if (attackerInventory.Fight(defender)) { ApplyDowngrade(defender.Cell.coordinates); } } } else { if (attackerInventory.Fight(defender)) { ApplyDowngrade(defender.Cell.coordinates); } } }
public static void HandleMoveTroops(int fromClient, Packet packet) { int clientIDCheck = packet.ReadInt(); if (fromClient != clientIDCheck) { Console.WriteLine($"Player with ID: \"{fromClient}\" has assumed the wrong client ID: \"{clientIDCheck}\"!"); } HexCoordinates coordinates = packet.ReadHexCoordinates(); TroopType troopType = (TroopType)packet.ReadByte(); int amount = packet.ReadInt(); Player player = Server.clients[fromClient].Player; TroopInventory buildingInventory = ((ProtectedBuilding)GameLogic.grid.GetCell(coordinates).Structure).TroopInventory; if (GameLogic.MoveTroops(player, coordinates, troopType, amount)) { ServerSend.BroadcastMoveTroops(player, coordinates, troopType, amount); Console.WriteLine("Player: " + player.Name + "of tribe " + player.Tribe.Id.ToString() + " successfully exchanged " + amount.ToString() + troopType.ToString() + " with a building at" + coordinates.ToString() + "."); } else { Console.WriteLine("Player: " + player.Name + "of tribe " + player.Tribe.Id.ToString() + " failed to exchange " + amount.ToString() + troopType.ToString() + " with building at " + coordinates.ToString() + "."); } }
private static void LoadGame() { Console.WriteLine("Loading Game..."); byte[] gamestate = File.ReadAllBytes("savegame.hex"); Packet packet = new Packet(gamestate); HexGrid hexGrid = packet.ReadHexGrid(); GameLogic.Init(hexGrid); int count = packet.ReadInt(); Console.WriteLine(count); for (int i = 0; i < count; i++) { string playerName = packet.ReadString(); int tribeId = packet.ReadByte(); HexCoordinates playerPos = packet.ReadHexCoordinates(); TroopInventory troopInventory = packet.ReadTroopInventory(); GameLogic.AddPlayer(playerName, tribeId, playerPos, troopInventory); } Console.WriteLine("Game Loaded!"); }
public Player ( string name, Tribe tribe, TroopInventory TroopInventory ) { this.Name = name; this.Tribe = tribe; this.TroopInventory = TroopInventory; }
public static void AddPlayer(string playerName, int tribeId, HexCoordinates coordinates, TroopInventory troopInventory) { Tribe tribe = GameLogic.GetTribe(tribeId); Player player = GameLogic.GetPlayer(playerName); if (player == null) { player = AddPlayer(playerName, tribe); player.Position = coordinates; player.TroopInventory = troopInventory; } else { player.Tribe = tribe; player.Position = coordinates; player.TroopInventory = troopInventory; } }
public Player(string name, Tribe tribe) { this.Name = name; this.Tribe = tribe; this.TroopInventory = new TroopInventory(); }
public Player(string name) { this.Tribe = null; this.TroopInventory = new TroopInventory(); }