Beispiel #1
0
 /// <summary>
 /// Konstruktor
 /// </summary>
 public GameCellContext(GameTableContext gameTable, Hexagon hexagon)
 {
     if (hexagon == null)
         throw new ArgumentNullException("hexagon");
     GameTable = gameTable;
     _Hexagon = hexagon;
     Player = new Player();
 }
Beispiel #2
0
 /// <summary>
 /// Település fejlesztése
 /// </summary>
 public void UpgradeSettlement(int position, Hexagon h)
 {
     Settlement set = h.GetSettlement(position);
     CurrentPlayer.UpgradeSettlement(set);
     h.SetTown(set, position);
 }
Beispiel #3
0
 /// <summary>
 /// Út megépítése
 /// </summary>
 public void BuildRoad(int position, Hexagon h, bool isFree)
 {
     var set1 = h.Settlements[position];
     var set2 = h.Settlements[(position + 5) % 6];
     var road1 = h.Roads[(position + 1) % 6];
     var road2 = h.Roads[(position + 5) % 6];
     if ((set1 != null && set1.Owner == CurrentPlayer || set2 != null && set2.Owner == CurrentPlayer) || (road1 != null && road1.Player.Color == CurrentPlayer.Color) || (road2 != null && road2.Player.Color == CurrentPlayer.Color)) {
         CurrentPlayer.BuildRoad(isFree); //dobhat exceptiont!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
         h.SetRoad(CurrentPlayer, position);
     }
     else {
         throw new Exception("Csak saját település vagy saját út mellé lehet utat építeni!");
     }
 }
Beispiel #4
0
        /// <summary>
        /// Település építése
        /// </summary>
        public void BuildSettlement(int position, Hexagon h, bool isFree)
        {
            Settlement set1 = h.Settlements[(position + 1) % 6];
            Settlement set2 = h.Settlements[(position + 5) % 6];
            Settlement set3 = null;
            if (h.Neighbours[(position + 1) % 6] != null)
                set3 = h.Neighbours[(position + 1) % 6].GetSettlement((position + 5) % 6);

            if (set1 != null || set2 != null || set3 != null) {
                throw new Exception("Szomszédos csúcsokra nem építhető település!");
            }
            else {
                Settlement set = h.GetSettlement(position);
                set = CurrentPlayer.BuildSettlement(isFree); //dobhat exceptiont!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                h.SetTown(set, position);
            }
        }
Beispiel #5
0
        public void InitializeHexagonNeighbours(Hexagon hexagon, int half, Random random)
        {
            //0. szomszéd
            if (hexagon.Id.getRow() == 0)
            {
                hexagon.Neighbours.Add(null);
            }
            else
            {
                hexagon.Neighbours.Add(Hexagons.Find(x => (x.Id.getCol() == hexagon.Id.getCol() && x.Id.getRow() == hexagon.Id.getRow() - 1)));
            }
            //1. szomszéd
            if ((hexagon.Id.getRow() == 0 && hexagon.Id.getCol() >= half) || hexagon.Id.getCol() == size - 1)
            {
                hexagon.Neighbours.Add(null);
            }
            else if (hexagon.Id.getCol() < half)
            {
                hexagon.Neighbours.Add(Hexagons.Find(x => (x.Id.getCol() == hexagon.Id.getCol() + 1 && x.Id.getRow() == hexagon.Id.getRow())));
            }
            else
            {
                hexagon.Neighbours.Add(Hexagons.Find(x => (x.Id.getCol() == hexagon.Id.getCol() + 1 && x.Id.getRow() == hexagon.Id.getRow() - 1)));
            }
            //2. szomszéd
            if (hexagon.Id.getCol() == size - 1 || hexagon.Id.getCol() + hexagon.Id.getRow() == size - 1 + half)
            {
                hexagon.Neighbours.Add(null);
            }
            else if (hexagon.Id.getCol() < half)
            {
                hexagon.Neighbours.Add(Hexagons.Find(x => (x.Id.getCol() == hexagon.Id.getCol() + 1 && x.Id.getRow() == hexagon.Id.getRow() + 1)));
            }
            else
            {
                hexagon.Neighbours.Add(Hexagons.Find(x => (x.Id.getCol() == hexagon.Id.getCol() + 1 && x.Id.getRow() == hexagon.Id.getRow())));
            }
            //3. szomszéd
            if (hexagon.Id.getCol() + half == hexagon.Id.getRow() || hexagon.Id.getCol() + hexagon.Id.getRow() == size - 1 + half)
            {
                hexagon.Neighbours.Add(null);
            }
            else
            {
                hexagon.Neighbours.Add(Hexagons.Find(x => (x.Id.getCol() == hexagon.Id.getCol() && x.Id.getRow() == hexagon.Id.getRow() + 1)));
            }
            //4. szomszéd
            if (hexagon.Id.getCol() + half == hexagon.Id.getRow() || hexagon.Id.getCol() == 0)
            {
                hexagon.Neighbours.Add(null);
            }
            else if (hexagon.Id.getCol() <= half)
            {
                hexagon.Neighbours.Add(Hexagons.Find(x => (x.Id.getCol() == hexagon.Id.getCol() - 1 && x.Id.getRow() == hexagon.Id.getRow())));
            }
            else
            {
                hexagon.Neighbours.Add(Hexagons.Find(x => (x.Id.getCol() == hexagon.Id.getCol() - 1 && x.Id.getRow() == hexagon.Id.getRow() + 1)));
            }
            //5. szomszéd
            if ((hexagon.Id.getCol() <= half && hexagon.Id.getRow() == 0) || hexagon.Id.getCol() == 0)
            {
                hexagon.Neighbours.Add(null);
            }
            else if (hexagon.Id.getCol() <= half)
            {
                hexagon.Neighbours.Add(Hexagons.Find(x => (x.Id.getCol() == hexagon.Id.getCol() - 1 && x.Id.getRow() == hexagon.Id.getRow() - 1)));
            }
            else
            {
                hexagon.Neighbours.Add(Hexagons.Find(x => (x.Id.getCol() == hexagon.Id.getCol() - 1 && x.Id.getRow() == hexagon.Id.getRow())));
            }

            while (hexagon.Neighbours.Exists(x => (x != null && x.ProduceNumber == hexagon.ProduceNumber)))
            {
                hexagon.ProduceNumber = random.Next(2, 13);
            }
        }
Beispiel #6
0
        private GameTableContext InitializeGame(NewGameContext newGameContext)
        {
            if (newGameContext == null)
                throw new ArgumentNullException("newGameContext");

            var players = newGameContext.GetPlayers().ToList();
            var newPlayers = new List<Player>();
            var random = new Random();

            GamePhase = GamePhase.Initialization;

            while (players.Any()) {
                var index = random.Next(0, players.Count);
                newPlayers.Add(players[index]);
                players.RemoveAt(index);
            }

            TableSize = newGameContext.TableSize;
            GameController.Instance.Init((uint)TableSize, newGameContext.WinnerScore, newPlayers);

            GameCells = new ObservableCollection<GameCellContext>();

            random = new Random();

            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 = random.Next(2, 13);
                    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();

            GameController.Instance.Step();

            GamePhase = GamePhase.FirstPhase;

            return this;
        }
Beispiel #7
0
        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;
        }
Beispiel #8
0
        /// <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;
            }
        }
Beispiel #9
0
 /// <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;
 }
Beispiel #10
0
 /// <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)
 {
 }