예제 #1
0
파일: Hexa.cs 프로젝트: alenkacz/Expanze
        public HexaModel(int value, HexaKind kind, SourceKind sourceKind, SourceBuildingKind buildingKind,SourceAll sourceBuildingCost)
        {
            if (kind == HexaKind.Water)
            {
                this.hexaID = -1;
            } else
                this.hexaID = ++counter;

            this.sourceBuildingCost = sourceBuildingCost;

            this.kind = kind;
            this.sourceKind = sourceKind;
            this.buildingKind = buildingKind;

            this.startSource = value;
            this.towns = new TownModel[(int) TownPos.Count];
            this.roads = new RoadModel[(int)RoadPos.Count];
            this.townOwner = new Boolean[(int)TownPos.Count];
            this.roadOwner = new Boolean[(int)RoadPos.Count];

            sourceDisaster = false;
            sourceMiracle = false;
            hexaDestroy = false;
            captureIs = false;
            capturePlayer = null;
        }
예제 #2
0
파일: Road.cs 프로젝트: alenkacz/Expanze
        private int roadID; /// unique ID for road, use for picking and for searching concreate roads

        #endregion Fields

        #region Constructors

        public RoadModel()
        {
            roadID = ++counter;

            neighbour = new TownModel[2];
            pathNode = new PathNode();
            isBuild = false;
            playerOwner = null;
            goalRoad = false;
        }
예제 #3
0
파일: Town.cs 프로젝트: alenkacz/Expanze
        private TownModel[] townNeighbour; /// two or 3 neighbours

        #endregion Fields

        #region Constructors

        public TownModel()
        {
            townID = ++counter;
            isBuild = false;

            roadNeighbour = new RoadModel[3];
            townNeighbour = new TownModel[3];
            hexaNeighbour = new HexaModel[3];
            buildingKind = new BuildingKind[3];
            building = new SpecialBuilding[3];
            pathNode = new PathNode();

            for (int loop1 = 0; loop1 < buildingKind.Length; loop1++)
                buildingKind[loop1] = BuildingKind.NoBuilding;

            //building[1] = BuildingKind.SourceBuilding;

            playerOwner = null;
        }
예제 #4
0
파일: Road.cs 프로젝트: alenkacz/Expanze
 /// <summary>
 /// It build town(only model, not view) and sets its owner.
 /// </summary>
 /// <param name="player">New owner of the road.</param>
 public void BuildRoad(Player player)
 {
     playerOwner = player;
     isBuild = true;
     player.AddRoad(this);
 }
예제 #5
0
파일: Hexa.cs 프로젝트: alenkacz/Expanze
 public void CollectSources(Player player)
 {
     for (int loop1 = 0; loop1 < towns.Length; loop1++)
         if (townOwner[loop1])
             towns[loop1].CollectSources(player);
 }
예제 #6
0
        public bool StartGame()
        {
            gameCount++;
            tutorial = false;
            PrepareCampaignScenario();

            playerCount = players.Count;

            medailOwner = new Player[(int) Building.Count];
            for (int loop1 = 0; loop1 < players.Count; loop1++)
            {
                medailOwner[loop1] = null;
            }

            IComponentAI AI;
            int[][] setArray;
            for(int loop1 = 0; loop1 < players.Count; loop1++)
            {
                setArray = players[loop1].GetPersonality();
                players[loop1] = new Player(players[loop1].GetName(), players[loop1].GetColor(), players[loop1].GetComponentAI(), loop1, setArray, players[loop1].GetGen());
                AI = players[loop1].GetComponentAI();

                if (AI != null) // its computer then
                {
#if GENETIC
                    // GENETICS ALG
                    if (players[loop1].GetGen() &&
                        (gameCount - 1) % geneticFitnessRound == 0)
                    {
                        chromozone = genetic.GetChromozone();
                        setArray = chromozone;

                        // uncomment next line for finding your fitness
                        //players[loop1] = new Player(players[loop1].GetName(), players[loop1].GetColor(), null, loop1, setArray, players[loop1].GetGen());
                    }

                    if (!players[loop1].GetGen())
                    {
                        if (bosses == null)
                            setArray = genetic.GetBestOnePersonality(); // reference AI is the best AI in all population
                        else
                            setArray = bosses[(gameCount - 1) % geneticFitnessRound]; // reference AI is contant
                    }
                    // GENETICS 
#endif

                    AI.InitAIComponent(map.GetMapController(), setArray);
                }
            }

            state = EGameState.BeforeGame;
            PrepareCampaignMap();
            
            activePlayerIndex = 0;
            activePlayer = players.ElementAt(activePlayerIndex);
            targetPlayer = activePlayer;

            pausedNew = false;
            paused = false;
            winnerNew = false;

            hasAIThreadStarted = false;

            if(players[0].GetBuildingCount(Building.Town) == 0)
                state = EGameState.StateFirstTown;
            else
                state = EGameState.StateGame;

            fortState = EFortState.Normal;

            randomNumber = new System.Random();
            hasBuiltTown = false;
            turnNumber = 1;

            if (playerCount == 1)
            {
                Settings.banFortStealSources = true;
                Settings.banFortCaptureHexa = true;
            }
            if (Settings.pointsFortParade == 0)
                Settings.banFortParade = true;
            if (Settings.banChangeSources)
                Settings.banMarket = true;

            PromptWindow.Inst().Deactive();
            Message.Inst().ClearMessages();
            MarketComponent.Inst().SetIsActive(false);
            PathNode.SetIsValid(false);

            if(tutorial)
                Tutorial.Inst().TurnOn();
            StartTurn();
            return true;
        }
예제 #7
0
 public void SetTargetPlayer(Player p) { targetPlayer = p; }
예제 #8
0
        private void PrepareCampaignPlayers(XmlDocument xDoc)
        {
            players.Clear();

            XmlNodeList playersNodes = xDoc.GetElementsByTagName("players")[0].ChildNodes;

            String playerName;
            Color playerColor;
            IComponentAI playerAI;
            int playerOrder;
            int[][] playerPersonality;
            bool playerGen;

            foreach (XmlNode playerNode in playersNodes)
            {
                playerName = "";
                playerColor = Color.Black;
                playerAI = null;
                playerOrder = 0;
                playerPersonality = null;
                playerGen = false;

                foreach (XmlNode info in playerNode.ChildNodes)
                {
                    switch (info.Name)
                    {
                        case "order":
                            playerOrder = Convert.ToInt32(info.InnerText);
                            break;
                        case "name":
                            playerName = info.InnerText;
                            break;
                        case "color":
                            switch (info.InnerText)
                            {
                                case "Red": playerColor = Color.Red; break;
                                case "Blue": playerColor = Color.Blue; break;
                                case "Green": playerColor = Color.Green; break;
                                case "Orange": playerColor = Color.Orange; break;
                                case "Yellow": playerColor = Color.Yellow; break;
                                case "Black": playerColor = Color.Black; break;
                                case "Purple": playerColor = Color.Purple; break;
                            }
                            break;
                        case "AI":
                            if (info.InnerText.ToLower() == "ai gen")
                            {
                                playerGen = true;
                            }
                            if (info.InnerText.ToLower() == "human")
                            {
#if GENETIC
                                foreach (IComponentAI AI in CoreProviderAI.AI)
                                {
                                    if (AI.GetAIName() == "AI Gen")
                                        playerAI = AI.Clone();
                                }
#else
                                playerAI = null;
#endif
                            }
                            else
                            {
                                foreach (IComponentAI AI in CoreProviderAI.AI)
                                {
                                    if (AI.GetAIName() == info.InnerText)
                                        playerAI = AI.Clone();
                                }
                            }
                            break;

                        case "personality" :
                            playerPersonality = Genetic.ParsePersonality(info.InnerText);
                            break;
                    }
                }
                Player player = new Player(playerName, playerColor, playerAI, playerOrder, playerPersonality, playerGen);
                players.Add(player);
            }
        }
예제 #9
0
        public bool ChangeActivePlayer()
        {
            if (state == EGameState.StateFirstTown || state == EGameState.StateGame)
            {
                activePlayerIndex++;
                if (activePlayerIndex == players.Count)
                {
                    switch (state)
                    {
                        case EGameState.StateFirstTown :
                            activePlayerIndex--;
                            state = EGameState.StateSecondTown;
                            break;
                        case EGameState.StateGame :
                            activePlayerIndex = 0;
                            break;
                    }
                }
            } else {
                activePlayerIndex--;
                if (activePlayerIndex < 0)
                {
                    ChangeStateToStateGame();
                    activePlayerIndex = 0;
                }
            }

            activePlayer = players[activePlayerIndex];

            if (state == EGameState.StateGame && activePlayerIndex == 0)
                turnNumber++;

            if (!activePlayer.GetActive())
                return ChangeActivePlayer();

            return true;
        }
예제 #10
0
파일: Town.cs 프로젝트: alenkacz/Expanze
 public Boolean HasPlayerRoadNeighbour(Player player)
 {
     foreach (RoadModel road in roadNeighbour)
     {
         if (road != null)
         {
             if (road.GetOwner() == player)
                 return true;
         }
     }
     return false;
 }
예제 #11
0
파일: Town.cs 프로젝트: alenkacz/Expanze
        public void CollectSources(Player player)
        {
            SourceAll sourceNow = new SourceAll(0);
            SourceAll sourceNormal = new SourceAll(0);
            int amountNow;
            int amountNormal;

            for(int loop1 = 0; loop1 < 3; loop1++)
            {
                if (hexaNeighbour[loop1] != null &&
                    buildingKind[loop1] == BuildingKind.SourceBuilding)
                {
                    SourceBuildingModel tempBuilding = (SourceBuildingModel) building[loop1];
                    float multiply = (tempBuilding.GetUpgrade() == UpgradeKind.SecondUpgrade) ? 2.0f : (tempBuilding.GetUpgrade() == UpgradeKind.FirstUpgrade) ? 1.5f : 1.0f;

                    amountNormal = (int) (hexaNeighbour[loop1].GetStartSource() * multiply);
                    amountNow = (int)(hexaNeighbour[loop1].GetCurrentSource() * multiply);

                    if (player == hexaNeighbour[loop1].GetCapturedPlayer() ||
                        (player == playerOwner && !hexaNeighbour[loop1].GetCaptured()))
                    {
                        switch (hexaNeighbour[loop1].GetKind())
                        {
                            case HexaKind.Forest:
                                sourceNow    += new SourceAll(0, 0, 0, amountNow, 0);
                                sourceNormal += new SourceAll(0, 0, 0, amountNormal, 0);
                                break;

                            case HexaKind.Stone:
                                sourceNow    += new SourceAll(0, 0, amountNow, 0, 0);
                                sourceNormal += new SourceAll(0, 0, amountNormal, 0, 0);
                                break;

                            case HexaKind.Cornfield:
                                sourceNow    += new SourceAll(amountNow, 0, 0, 0, 0);
                                sourceNormal += new SourceAll(amountNormal, 0, 0, 0, 0);
                                break;

                            case HexaKind.Pasture:
                                sourceNow    += new SourceAll(0, amountNow, 0, 0, 0);
                                sourceNormal += new SourceAll(0, amountNormal, 0, 0, 0);
                                break;

                            case HexaKind.Mountains:
                                sourceNow    += new SourceAll(0, 0, 0, 0, amountNow);
                                sourceNormal += new SourceAll(0, 0, 0, 0, amountNormal);
                                break;
                        }
                    }
                }
            }
            player.AddSources(sourceNow, TransactionState.TransactionMiddle);
            player.AddCollectSources(sourceNormal, sourceNow);
        }
예제 #12
0
파일: Town.cs 프로젝트: alenkacz/Expanze
 public void BuildTown(Player player)
 {
     playerOwner = player;
     player.AddPoints(PlayerPoints.Town);
     player.AddBuilding(Building.Town);
     player.AddTown(this);
     isBuild = true;
 }
예제 #13
0
파일: Hexa.cs 프로젝트: alenkacz/Expanze
 internal void SetFree()
 {
     if (captureIs)
     {
         capturePlayer = null;
         captureIs = false;
     }
 }
예제 #14
0
        public void DoMaterialConversion(SourceKind from, SourceKind to, Player p, int fromAmount, int toAmount)
        {
            if (from == SourceKind.Null || to == SourceKind.Null)
                return;

            int rate = p.GetConversionRate(from);

            if (!this.IsMaterialAvailable(from,rate)) { return; }

            //remove material from player
            SourceAll cost = CreateSourceAllCost(from, -fromAmount);
            p.AddSources(cost,TransactionState.TransactionStart);
            

            //add new material
            SourceAll get = CreateSourceAllCost(to, toAmount);
            p.AddSources(get, TransactionState.TransactionEnd);
        }
예제 #15
0
        private int DrawAllPoints(Player[] players)
        {
            int pointKind = 0;

            if (Settings.pointsTown > 0)
                pointKind = DrawPoints(players, Strings.GOAL_TOWN_PART1, Strings.GOAL_TOWN_PART2, GameMaster.Inst().GetMedaileIcon(Building.Town), PlayerPoints.Town, Settings.pointsTown, pointKind);

            if (Settings.pointsRoad > 0)
                pointKind = DrawPoints(players, Strings.GOAL_ROAD_PART1, Strings.GOAL_ROAD_PART2, GameMaster.Inst().GetMedaileIcon(Building.Road), PlayerPoints.Road, Settings.pointsRoad, pointKind);

            if (Settings.goalRoadID > 0)
                pointKind = DrawPoints(players, Strings.GOAL_ROADID_PART1, Strings.GOAL_ROADID_PART2, GameResources.Inst().GetHudTexture(HUDTexture.IconMedalRoadID), PlayerPoints.RoadID, Settings.goalRoadID, pointKind);
            if (Settings.goalTownID > 0)
                pointKind = DrawPoints(players, Strings.GOAL_TOWNID_PART1, Strings.GOAL_TOWNID_PART2, GameResources.Inst().GetHudTexture(HUDTexture.IconMedalTownID), PlayerPoints.TownID, Settings.goalTownID, pointKind);

            if (Settings.pointsMill > 0) pointKind = DrawPoints(players, Strings.GOAL_MILL_PART1, Strings.GOAL_MILL_PART2, GameMaster.Inst().GetMedaileIcon(Building.Mill), PlayerPoints.Mill, Settings.pointsMill, pointKind);
            if (Settings.pointsMine > 0) pointKind = DrawPoints(players, Strings.GOAL_MINE_PART1, Strings.GOAL_MINE_PART2, GameMaster.Inst().GetMedaileIcon(Building.Mine), PlayerPoints.Mine, Settings.pointsMine, pointKind);
            if (Settings.pointsQuarry > 0) pointKind = DrawPoints(players, Strings.GOAL_QUARRY_PART1, Strings.GOAL_QUARRY_PART2, GameMaster.Inst().GetMedaileIcon(Building.Quarry), PlayerPoints.Quarry, Settings.pointsQuarry, pointKind);
            if (Settings.pointsSaw > 0) pointKind = DrawPoints(players, Strings.GOAL_SAW_PART1, Strings.GOAL_SAW_PART2, GameMaster.Inst().GetMedaileIcon(Building.Saw), PlayerPoints.Saw, Settings.pointsSaw, pointKind);
            if (Settings.pointsStepherd > 0) pointKind = DrawPoints(players, Strings.GOAL_STEPHERD_PART1, Strings.GOAL_STEPHERD_PART2, GameMaster.Inst().GetMedaileIcon(Building.Stepherd), PlayerPoints.Stepherd, Settings.pointsStepherd, pointKind);
            if (Settings.pointsFort > 0) pointKind = DrawPoints(players, Strings.GOAL_FORT_PART1, Strings.GOAL_FORT_PART2, GameMaster.Inst().GetMedaileIcon(Building.Fort), PlayerPoints.Fort, Settings.pointsFort, pointKind);
            if (Settings.pointsMarket > 0) pointKind = DrawPoints(players, Strings.GOAL_MARKET_PART1, Strings.GOAL_MARKET_PART2, GameMaster.Inst().GetMedaileIcon(Building.Market), PlayerPoints.Market, Settings.pointsMarket, pointKind);
            if (Settings.pointsMonastery > 0) pointKind = DrawPoints(players, Strings.GOAL_MONASTERY_PART1, Strings.GOAL_MONASTERY_PART2, GameMaster.Inst().GetMedaileIcon(Building.Monastery), PlayerPoints.Monastery, Settings.pointsMonastery, pointKind);
            if (Settings.pointsFortParade > 0) pointKind = DrawPoints(players, Strings.GOAL_FORT_PARADE_PART1, Strings.GOAL_FORT_PARADE_PART2, Settings.Game.Content.Load<Texture2D>("HUD/score_medaile"), PlayerPoints.FortParade, Settings.pointsFortParade, pointKind);
            if (Settings.pointsFortCapture > 0) pointKind = DrawPoints(players, Strings.GOAL_FORT_CAPTURE_PART1, Strings.GOAL_FORT_CAPTURE_PART2, GameResources.Inst().GetHudTexture(HUDTexture.IconFortCapture), PlayerPoints.FortCaptureHexa, Settings.pointsFortCapture, pointKind);
            if (Settings.pointsFortSteal > 0) pointKind = DrawPoints(players, Strings.GOAL_FORT_STEAL_PART1, Strings.GOAL_FORT_STEAL_PART2, GameResources.Inst().GetHudTexture(HUDTexture.IconFortSources), PlayerPoints.FortStealSources, Settings.pointsFortSteal, pointKind);
            if (Settings.pointsMarketLvl1 > 0) pointKind = DrawPoints(players, Strings.GOAL_LICENCE1_PART1, Strings.GOAL_LICENCE1_PART2, GameResources.Inst().GetHudTexture(HUDTexture.IconOre1), PlayerPoints.LicenceLvl1, Settings.pointsMarketLvl1, pointKind);
            if (Settings.pointsUpgradeLvl1 > 0) pointKind = DrawPoints(players, Strings.GOAL_UPGRADE1_PART1, Strings.GOAL_UPGRADE1_PART2, GameResources.Inst().GetHudTexture(HUDTexture.IconQuarry1), PlayerPoints.UpgradeLvl1, Settings.pointsUpgradeLvl1, pointKind);
            if (Settings.pointsMarketLvl2 > 0) pointKind = DrawPoints(players, Strings.GOAL_LICENCE2_PART1, Strings.GOAL_LICENCE2_PART2, GameResources.Inst().GetHudTexture(HUDTexture.IconOre2), PlayerPoints.LicenceLvl2, Settings.pointsMarketLvl2, pointKind);
            if (Settings.pointsUpgradeLvl2 > 0) pointKind = DrawPoints(players, Strings.GOAL_UPGRADE2_PART1, Strings.GOAL_UPGRADE2_PART2, GameResources.Inst().GetHudTexture(HUDTexture.IconQuarry2), PlayerPoints.UpgradeLvl2, Settings.pointsUpgradeLvl2, pointKind);
            if (Settings.pointsCorn > 0) pointKind = DrawPoints(players, Strings.GOAL_CORN_PART1, Strings.GOAL_CORN_PART2, GameResources.Inst().GetHudTexture(HUDTexture.SmallCorn), PlayerPoints.Corn, Settings.pointsCorn, pointKind);
            if (Settings.pointsMeat > 0) pointKind = DrawPoints(players, Strings.GOAL_MEAT_PART1, Strings.GOAL_MEAT_PART2, GameResources.Inst().GetHudTexture(HUDTexture.SmallMeat), PlayerPoints.Meat, Settings.pointsMeat, pointKind);
            if (Settings.pointsStone > 0) pointKind = DrawPoints(players, Strings.GOAL_STONE_PART1, Strings.GOAL_STONE_PART2, GameResources.Inst().GetHudTexture(HUDTexture.SmallStone), PlayerPoints.Stone, Settings.pointsStone, pointKind);
            if (Settings.pointsWood > 0) pointKind = DrawPoints(players, Strings.GOAL_WOOD_PART1, Strings.GOAL_WOOD_PART2, GameResources.Inst().GetHudTexture(HUDTexture.SmallWood), PlayerPoints.Wood, Settings.pointsWood, pointKind);
            if (Settings.pointsOre > 0) pointKind = DrawPoints(players, Strings.GOAL_ORE_PART1, Strings.GOAL_ORE_PART2, GameResources.Inst().GetHudTexture(HUDTexture.SmallOre), PlayerPoints.Ore, Settings.pointsOre, pointKind);

            return pointKind;
        }
예제 #16
0
 public void AddPlayer(Player p)
 {
     players.Add(p);
     ++playerCount;
 }
예제 #17
0
        private int DrawPoints(Player[] players, string text1, string text2, Texture2D texture2D, PlayerPoints pointKind, int goal, int pointNumber)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

            int x = 500 + pointNumber * 80;
            int y = 300;
            spriteBatch.Draw(texture2D, new Vector2(x, y - texture2D.Height), Color.White);

            SpriteFont font = GameResources.Inst().GetFont(EFont.MedievalBig);
            int count = 0;
            foreach (Player player in players)
            {
                int points = player.GetPoints()[(int)pointKind];
                switch (pointKind)
                {
                    case PlayerPoints.Corn: points = player.GetCollectSourcesNormal().GetCorn(); break;
                    case PlayerPoints.Meat: points = player.GetCollectSourcesNormal().GetMeat(); break;
                    case PlayerPoints.Stone: points = player.GetCollectSourcesNormal().GetStone(); break;
                    case PlayerPoints.Wood: points = player.GetCollectSourcesNormal().GetWood(); break;
                    case PlayerPoints.Ore: points = player.GetCollectSourcesNormal().GetOre(); break;
                    default: points = player.GetPoints()[(int)pointKind]; break;
                }

                int showPoints = (goal - points);
                if (showPoints < 0)
                    showPoints = 0;
                spriteBatch.DrawString(font, "" + showPoints, new Vector2(x + 20, y + 50 * count + 12), Settings.colorMenuText);
                count++;
            }

            return pointNumber + 1;
        }
예제 #18
0
        public void PlayerWantMedail(Player player, Building medal)
        {
            /* no medals
            int minCount = 10;
            int pointsForMedal = Settings.pointsMedal;
            if (pointsForMedal == 0)
                return;

            switch(medal)
            {
                case Building.Town :
                    minCount = 5;
                    break;
                case Building.Road :
                    minCount = 10;
                    break;
                case Building.Market :
                case Building.Fort :
                case Building.Monastery :
                    minCount = 1;
                    break;
                default :
                    minCount = 4;
                    break;
            }

            if((medailOwner[(int) medal] == null && player.GetBuildingCount(medal) >= minCount) ||
               (minCount != 1 && /// medal for special buildings
                medailOwner[(int) medal] != null && player.GetBuildingCount(medal) > medailOwner[(int) medal].GetBuildingCount(medal)))
            {
                if (medailOwner[(int)medal] != null)
                {
                    medailOwner[(int)medal].RemovePoints(PlayerPoints.Medal);
                    medailOwner[(int)medal].GetStatistic().AddStat(Statistic.Kind.Medals, -1, turnNumber);
                }
                medailOwner[(int)medal] = player;
                medailOwner[(int)medal].GetStatistic().AddStat(Statistic.Kind.Medals, 1, turnNumber);
                player.AddPoints(PlayerPoints.Medal);
                Message.Inst().Show(GetMedalTitle(medal),GetMedalDescription(medal),GetMedaileIcon(medal));
            }*/
        }
예제 #19
0
        /// <summary>
        /// Draws the loading screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
                SpriteFont font;

                String message = "Statistiky po " + GameMaster.Inst().GetTurnNumber() +". kole.";

                // Center the text in the viewport.
                font = GameResources.Inst().GetFont(EFont.MenuFont);
                Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
                Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
                Vector2 textSize = font.MeasureString(message);
                Vector2 textPosition = new Vector2((Settings.maximumResolution.X - textSize.X) / 2.0f, 300);

                Color color = Settings.colorMenuText * TransitionAlpha;

                textPosition.Y -= 180;
                int startY = (int) textPosition.Y + 70;
                int startX = 140;

                // Draw the text.
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, Settings.spriteScale);
                spriteBatch.DrawString(font, message, textPosition, color);
                font = GameResources.Inst().GetFont(EFont.MedievalBig);

                Player[] players = new Player[GameMaster.Inst().GetPlayers().Count];
                GameMaster.Inst().GetPlayers().CopyTo(players);

                Array.Sort(players, delegate(Player p1, Player p2)
                {
                    return p1.GetPointSum().CompareTo(p2.GetPointSum()); // (user1.Age - user2.Age)
                });
                Array.Reverse(players);

                int startName = startX + 80; // 150 + 80 * DrawAllPoints(players);
                DrawAllPoints(players);
                startY += 123;
                foreach(Player player in players) {
                    spriteBatch.Draw(GameResources.Inst().GetHudTexture(HUDTexture.PlayerColor), new Vector2(startX + 20, startY), player.GetColor());
                    spriteBatch.DrawString(font, player.GetName(), new Vector2(startName, startY), color);
                    //if(player.GetIsAI())
                    //    spriteBatch.DrawString(font, player.GetComponentAI().GetAIName(), new Vector2(startX + 450, startY), color);
                    //spriteBatch.DrawString(font, player.GetPointSum() + "", new Vector2(startX + 80, startY), color);
                    startY += 50;
                }

                spriteBatch.End();

                toGraphButton.Draw(gameTime);
                toMenuButton.Draw(gameTime);
        }
예제 #20
0
        internal void PrepareCampaignMap()
        {
            if (mapSource == null)  // neni kampan
                return;

            XmlDocument xDoc = new XmlDocument();
            xDoc.Load("Content/Maps/" + mapSource);

            XmlNodeList playersNodes = xDoc.GetElementsByTagName("players")[0].ChildNodes;

            for(int loop1 = 0; loop1 < playersNodes.Count; loop1++)
            {
                XmlNode playerNode = playersNodes[loop1];
                activePlayer = players[loop1];

                for (int loop2 = 0; loop2 < playerNode.ChildNodes.Count; loop2++)
                {
                    XmlNode info = playerNode.ChildNodes[loop2];
                    
                    switch (info.Name)
                    {
                        case "towns":
                            foreach (XmlNode townNode in info.ChildNodes)
                            {
                                int ID = Convert.ToInt16(townNode.Attributes[0].Value);
                                map.GetMapController().BuildTown(ID);

                                foreach (XmlNode buildingNode in townNode.ChildNodes)
                                {
                                    int pos = Convert.ToInt16(buildingNode.InnerText);
                                    switch (buildingNode.Name)
                                    {
                                        case "source-building" :
                                            map.GetTownByID(ID).BuildSourceBuilding((byte) pos);
                                            break;
                                        case "fort":
                                            map.GetTownByID(ID).BuildFort((byte)pos);
                                            break;
                                        case "market":
                                            map.GetTownByID(ID).BuildMarket((byte)pos);
                                            break;
                                        case "monastery":
                                            map.GetTownByID(ID).BuildMonastery((byte)pos);
                                            break;
                                    }
                                    
                                }
                            }

                            break;

                        case "roads":
                            foreach (XmlNode roadID in info.ChildNodes)
                            {
                                int ID = Convert.ToInt16(roadID.InnerText);
                                map.GetMapController().BuildRoad(ID);
                            }

                            break;

                        case "source":
                            //activePlayer.AddSources(new SourceAll(0), TransactionState.TransactionStart);
                            foreach (XmlNode kind in info.ChildNodes)
                            {
                                int amount = Convert.ToInt16(kind.InnerText);
                                switch (kind.Name)
                                {
                                    case "wood" :
                                        activePlayer.AddSources(new SourceAll(0, 0, 0, amount, 0), TransactionState.TransactionMiddle);
                                        break;
                                    case "ore":
                                        activePlayer.AddSources(new SourceAll(0, 0, 0, 0, amount), TransactionState.TransactionMiddle);
                                        break;
                                    case "corn":
                                        activePlayer.AddSources(new SourceAll(amount, 0, 0, 0, 0), TransactionState.TransactionMiddle);
                                        break;
                                    case "stone":
                                        activePlayer.AddSources(new SourceAll(0, 0, amount, 0, 0), TransactionState.TransactionMiddle);
                                        break;
                                    case "meat":
                                        activePlayer.AddSources(new SourceAll(0, amount, 0, 0, 0), TransactionState.TransactionMiddle);
                                        break;
                                }
                            }
                            //activePlayer.AddSources(new SourceAll(0), TransactionState.TransactionEnd);
                            break;
                    }
                }
            }
        }
예제 #21
0
파일: Road.cs 프로젝트: alenkacz/Expanze
        /// <summary>
        /// Checks if player has its road build on one of the ends
        /// of this road.
        /// </summary>
        /// <param name="player">Future road owner</param>
        /// <returns>True if there is at least one players road</returns>
        public Boolean IsActivePlayersRoadOnEndOfRoad(Player player)
        {
            foreach (TownModel town in neighbour)
            {
                if (town.HasPlayerRoadNeighbour(player) && (town.GetOwner() == player || !town.GetIsBuild()))
                    return true;
            }

            return false;
        }
예제 #22
0
        public bool NextTurn()
        {
            bool status = true;
            if (state == EGameState.StateGame)
            {
                MarketComponent.Inst().SetIsActive(false);
            }

            if (playerCount == 0)
            {
                winnerNew = true;
                return true;
            }

            if (activePlayerIndex == players.Count - 1)
                CheckWinner();
            if (winnerNew)
            {
                return true;
            }

            if (state == EGameState.StateGame)
                activePlayer.AddSumSourcesStat();

            status &= ChangeActivePlayer();
            targetPlayer = activePlayer;
            hasBuiltTown = false;

            status &= StartTurn();

            map.NextTurn();
            TownView.ResetTownView();
            HexaView.SetActiveHexaID(-1);

            return status;
        }
예제 #23
0
파일: Road.cs 프로젝트: alenkacz/Expanze
        /// <summary>
        /// Checks if players town is build on one of the road ends.
        /// </summary>
        /// <param name="player">Future road owner</param>
        /// <returns>True if there is players town</returns>
        public Boolean IsActivePlayersTownOnEndOfRoad(Player player)
        {
            foreach(TownModel town in neighbour)
            {
                if (town.GetOwner() == player)
                    return true;
            }

            return false;
        }
예제 #24
0
        private void LogWinner()
        {
            Player[] players = new Player[GameMaster.Inst().GetPlayers().Count];
            GameMaster.Inst().GetPlayers().CopyTo(players);

            Array.Sort(players, delegate(Player p1, Player p2)
            {
                return p1.GetPointSum().CompareTo(p2.GetPointSum()); // (user1.Age - user2.Age)
            });
            Array.Reverse(players);

            GameMaster gm = GameMaster.Inst();
            GameSettings gs = gm.GetGameSettings();

            //Player p = players[0]; // winner
            String playersACR = "";
            String message = gameCount + ";" + gm.GetTurnNumber();
            foreach (Player p in players)
            {
                message += ";" + p.GetComponentAI().GetAIName();
                message += ";" + p.GetOrderID();
                for (int loop1 = 0; loop1 < (int)Statistic.Kind.Count - 1 /* - SourceSum */; loop1++)
                {
                    int[] array = p.GetStatistic().GetStat()[loop1];
                    int sum = 0;
                    foreach (int i in array)
                        sum += i;
                    message += ";" + sum;
                }

                for (int loop1 = 0; loop1 < 5; loop1++)
                {
                    message += ";" + p.GetSumSpentSources()[loop1];
                }
            }

            foreach (Player p in gm.GetPlayers())
            {
                switch(p.GetComponentAI().GetAIName()[3])
                {
                    case 'T' :
                    case 't' : playersACR += 'G'; break;
                    case 'S' :
                    case 's' : playersACR += 'T'; break;
                    default : playersACR += 'Z'; break;
                }
            }

            Logger.Inst().Log(playersACR.ToUpper() + gs.GetMapSizeXML() + gs.GetMapTypeXML() + gs.GetMapWealthXML() + ".csv", message);
        }
예제 #25
0
파일: Hexa.cs 프로젝트: alenkacz/Expanze
        public void Capture(Player player)
        {
            if (!captureIs)
            {
                capturePlayer = player;
            }
            else
            {
                capturePlayer = null;
            }

            captureIs = !captureIs;
        }