/// <summary> /// Konstruktor /// </summary> public GameCellContext(GameTableContext gameTable, Hexagon hexagon) { if (hexagon == null) throw new ArgumentNullException("hexagon"); GameTable = gameTable; _Hexagon = hexagon; Player = new Player(); }
/// <summary> /// Van-e nyertes /// </summary> public bool HasWinner() { bool isWinner = false; foreach (Player p in Players) { if (p.GetPoints() >= WinnerScore) { isWinner = true; Winner = p; } } return isWinner; }
public TradeContext(GameTableContext context, Player player) { GameTableContext = context; Player = player; }
private bool CheckSecondPhase(Player player) { if (player == null) throw new ArgumentNullException("player"); var roadsCount = player.Roads.Count(); var settlementsCount = player.Settlements.Where(settlement => settlement != null) .Count(settlement => settlement.Owner == player); return roadsCount == 2 && settlementsCount == 2; }
/// <summary> /// Kereskedés más játékosokkal /// </summary> public void TradeWithPlayer(Player player, int quantity, Material material) { if (player == null) throw new ArgumentNullException("player"); if (player == this) throw new Exception("Saját magával nem kereskedhet a játékos!"); TradeItem item; if (TradeItems.TryGetValue(material, out item)) { item.Quantity -= quantity; Gold += quantity * item.Price; player.Gold -= quantity * item.Price; } }
/// <summary> /// Xml visszatöltése lementett állapotból /// </summary> /// <param name="filename">betöltendő fájlnév</param> public static void Load(String filename) { int size, score; XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNode scoreNode = doc.DocumentElement.SelectSingleNode("/Table/Winnerscore"); score = Int32.Parse(scoreNode.InnerText); XmlNode sizeNode = doc.DocumentElement.SelectSingleNode("/Table/Tablesize"); size = Int32.Parse(sizeNode.InnerText); XmlNodeList pnodes = doc.DocumentElement.SelectNodes("/Table/Players/Player"); (GameController.Instance.Players as List<Player>).Clear(); foreach (XmlNode node in pnodes) { var attr = node.Attributes; if (attr.Count != 0) { Player p = new Player(); PlayerColor c = (PlayerColor)Enum.Parse(typeof(PlayerColor), attr["color"].Value, true); p.Color = c; p.Name = attr["name"].Value; p.Gold = Int32.Parse(attr["gold"].Value); (GameController.Instance.Players as List<Player>).Add(p); } } var random = new Random(); var materials = new[] { Material.Wood, Material.Wool, Material.Clay, Material.Wheat, Material.Iron }; for (var j = 0; j < size; ++j) { for (var i = 0; i < size - Math.Abs(Math.Floor(size / 2.0) - j); ++i) { var h = new Hexagon(10, materials[random.Next(0, materials.Length)], new Hexid(j, i)); GameController.Instance.Hexagons.Add(h); } } foreach (Hexagon hex in GameController.Instance.Hexagons) { GameController.Instance.InitializeHexagonNeighbours(hex, (int)(Math.Floor(size / 2.0)), new Random()); } XmlNodeList hnodes = doc.DocumentElement.SelectNodes("/Table/Hexagons/Hexagon"); foreach (XmlNode node in hnodes) { Hexagon hex = null; Nullable<Hexid> id = null; var index = 0; if (node.Attributes.Count != 0) { id = new Hexid(Int32.Parse(node.Attributes["col"].Value), Int32.Parse(node.Attributes["row"].Value)); index = GameController.Instance.Hexagons.FindIndex(x => x.Id.Equals(id)); hex = GameController.Instance.Hexagons[index]; string mat = node.Attributes["material"].Value; int produceNumber = Int32.Parse(node.Attributes["number"].Value); Material material = (Material)Enum.Parse(typeof(Material), mat, true); hex.ProduceNumber = produceNumber; hex.Material = material; } XmlNode settlNode = node.ChildNodes[0]; if (settlNode.HasChildNodes) { for (int i = 0; i < settlNode.ChildNodes.Count; ++i) { Int32 num = Int32.Parse(settlNode.ChildNodes[i].Attributes["nodeNumber"].Value); string owner = settlNode.ChildNodes[i].Attributes["owner"].Value; Player p = GameController.Instance.Players.First(x => x.Color.ToString() == owner); hex.SetTown(new Settlement(p), num); } } XmlNode roadNode = node.ChildNodes[1]; if (roadNode.HasChildNodes) { for (int i = 0; i < roadNode.ChildNodes.Count; ++i) { Int32 side = Int32.Parse(roadNode.ChildNodes[i].Attributes["side"].Value); string owner = roadNode.ChildNodes[i].Attributes["owner"].Value; Player p = GameController.Instance.Players.First(x => x.Color.ToString() == owner); hex.SetRoad(p, side); } } GameController.Instance.Hexagons[index] = hex; } }
public void LoadGame(string fileName) { var players = new Player[2] { new Player("Gipsz Jakab", PlayerColor.Blue) { Gold = 1874, }, new Player("Mekk Elek", PlayerColor.Orange) }; var random = new Random(); players[0].Materials[Material.Clay] = 17; players[0].Materials[Material.Wheat] = 7; players[0].Materials[Material.Wool] = 37; players[1].Materials[Material.Clay] = random.Next(14, 32); players[1].Materials[Material.Iron] = random.Next(4, 9); players[1].Materials[Material.Wood] = random.Next(9, 54); TableSize = 7; GameCells = new ObservableCollection<GameCellContext>(); GameController.Instance.Init((uint)TableSize, 1, players); var materials = new[] { Material.Wood, Material.Wool, Material.Clay, Material.Wheat, Material.Iron }; for (var j = 0; j < TableSize; ++j) { for (var i = 0; i < TableSize - Math.Abs(Math.Floor(TableSize / 2.0) - j); ++i) { int value = (i + j) + 1; var h = new Hexagon(value, materials[random.Next(0, materials.Length)], new Hexid(j, i)); GameCells.Add(new GameCellContext(this, h) { Value = value }); GameController.Instance.Hexagons.Add(h); } } GameController.Instance.SetAllNeighbours(); for (int i = 0; i < players.Count(); i++) { GameController.Instance._CurrentPlayerIndex = i; foreach (var hexagon in GameController.Instance.Hexagons) { if (random.NextDouble() < 0.3) { int position = random.Next(0, 5); try { GameController.Instance.BuildSettlement(position, hexagon, true); GameController.Instance.BuildRoad(position, hexagon, true); } catch (Exception exception) { Console.WriteLine(exception); } } } } GamePhase = GamePhase.Game; }
/// <summary> /// Konstruktor. Inicializálja az objektumot. /// </summary> /// <param name="Fields">A várossal szomszédos mezõk.</param> /// <param name="Owner">Tulajdonos</param> public Settlement(Hexagon[] Fields, Player Owner) { this.Fields = Fields; this.Owner = Owner; }
public Settlement(Player Owner) { this.Owner = Owner; }
/// <summary> /// Konstruktor, meghívja az õs konstruktorát. /// </summary> /// <param name="Fields"></param> /// <param name="Owner"></param> public Town(Hexagon[] Fields, Player Owner) : base(Fields,Owner) { }
/// /// <param name="player">Tulajdonos</param> /// <param name="position">hely</param> public void SetRoad(Player player, int position) { if (player == null) throw new ArgumentNullException("player"); if (position >= 0 && position <= 5) { var road = new Road { Player = player }; Roads[position] = road; player.Roads.Add(road); var hexagon = Neighbours[position]; if (hexagon != null) Neighbours[position].Roads[(position + 3) % 6] = road; } }
public ChoosablePlayer(Player player) { if (player == null) throw new ArgumentNullException("player"); Player = player; IsChoosen = false; }