当前位置: 首页>>代码示例>>C#>>正文


C# IGameState.GetOwnDevelopmentCards方法代码示例

本文整理汇总了C#中IGameState.GetOwnDevelopmentCards方法的典型用法代码示例。如果您正苦于以下问题:C# IGameState.GetOwnDevelopmentCards方法的具体用法?C# IGameState.GetOwnDevelopmentCards怎么用?C# IGameState.GetOwnDevelopmentCards使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IGameState的用法示例。


在下文中一共展示了IGameState.GetOwnDevelopmentCards方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BeforeDiceRoll

 public void BeforeDiceRoll(IGameState state, IGameActions actions)
 {
     hasPlayedDevCard = false;
     if (!state.GetOwnDevelopmentCards().Any(dc => dc != DevelopmentCard.VictoryPoint))
         return; //No cards to play
     Console.WriteLine("Do you want to use a Development Card before roling the dice? Y/N");
     var r = Console.ReadLine() ?? "";
     if (!r.ToLower().StartsWith("y")) return;
     PlayDevelopmentCard(state, actions);
 }
开发者ID:rasmusgreve,项目名称:catan,代码行数:10,代码来源:HumanAgent.cs

示例2: PerformTurn

        public void PerformTurn(IGameState state, IGameActions actions)
        {
            Console.WriteLine("It is now your turn (#" + assignedId + ")");
            while (true)
            {
                try
                {
                    Console.Write("Resources: [");
                    foreach (Resource resource in Enum.GetValues(typeof (Resource)))
                    {
                        var count = state.GetOwnResources().Count(r => r == resource);
                        if (count == 0) continue;
                        Console.Write(resource + " x " + count + ", ");
                    }
                    Console.WriteLine("]");
                    Console.Write("Dev. cards: [");
                    foreach (DevelopmentCard devcard in Enum.GetValues(typeof(DevelopmentCard)))
                    {
                        var count = state.GetOwnDevelopmentCards().Count(r => r == devcard);
                        if (count == 0) continue;
                        Console.Write(devcard + " x " + count + ", ");
                    }
                    Console.WriteLine("]");

                    bool canBuildRoad = hasRes(state, Resource.Lumber) && hasRes(state, Resource.Brick);
                    //TODO: has any more pieces
                    bool canBuildSettlement = hasRes(state, Resource.Brick) && hasRes(state, Resource.Lumber) &&
                                              hasRes(state, Resource.Grain) && hasRes(state, Resource.Wool);
                    //TODO: has any more pieces
                    bool canBuildCity = hasRes(state, Resource.Ore, 3) && hasRes(state, Resource.Grain, 2);
                    //TODO: has any more pieces
                    bool canBuyDevCard = hasRes(state, Resource.Grain) && hasRes(state, Resource.Ore) &&
                                         hasRes(state, Resource.Wool); //TODO: any more dev cards

                    bool canTradeBank = true, canTradePlayers = true; //TODO: Implement these

                    Console.WriteLine("Choose an action:");
                                            Console.WriteLine("0) End turn");
                    if (canBuildRoad)       Console.WriteLine("1) Build road");
                    if (canBuildSettlement) Console.WriteLine("2) Build settlement");
                    if (canBuildCity)       Console.WriteLine("3) Build city");
                    if (canBuyDevCard)      Console.WriteLine("4) Buy development card");
                    if (!hasPlayedDevCard &&
                        state.GetOwnDevelopmentCards().Count(d => d != DevelopmentCard.VictoryPoint) > 0)
                                            Console.WriteLine("5) Play development card");
                    if (canTradeBank)       Console.WriteLine("6) Trade resources with the bank");
                    if (canTradePlayers)    Console.WriteLine("7) Trade resources with the other players");

                    int answer = int.Parse(Console.ReadLine() ?? "0");

                    switch (answer)
                    {
                        case 1: //road
                            var roadPos = getRoadPosition();
                            state = actions.BuildRoad(roadPos);
                            break;
                        case 2: //settlement
                            var settlementPos = getSettlementPosition();
                            state = actions.BuildSettlement(settlementPos);
                            break;
                        case 3: //city
                            var cityPos = getCityPosition();
                            state = actions.BuildCity(cityPos);
                            break;
                        case 4: //buy dev
                            state = actions.DrawDevelopmentCard();
                            break;
                        case 5: //play dev
                            state = PlayDevelopmentCard(state, actions) ?? state;
                            break;
                        case 6: //trade bank
                            Console.WriteLine("Choose which resource to give");
                            var tbGive = selectResourceTradeBank(state.Board);
                            Console.WriteLine("Choose which resource to receive");
                            var tbTake = selectResource();
                            state = actions.TradeBank(tbGive, tbTake);
                            break;
                        case 7: //trade players
                            Console.WriteLine("Which resource type do you want to give away:");
                            var tpGiveType = selectResource();
                            Console.WriteLine("How many " + tpGiveType + " do you want to give:");
                            var tpGiveAmount = int.Parse(Console.ReadLine() ?? "2");
                            Console.WriteLine("Which resource type do you want to get in return for " + tpGiveAmount + " " + tpGiveType + "? :");
                            var tpTakeType = selectResource();
                            Console.WriteLine("How many " + tpTakeType + " do you want to get:");
                            var tpTakeAmount = int.Parse(Console.ReadLine() ?? "1");

                            var give = new List<List<Resource>>(){new List<Resource>()};
                            for (int i = 0; i < tpGiveAmount; i++)
                                give[0].Add(tpGiveType);
                            var take = new List<List<Resource>>(){new List<Resource>()};
                            for (int i = 0; i < tpTakeAmount; i++)
                                take[0].Add(tpTakeType);

                            var feedback = actions.ProposeTrade(give, take);
                            Console.WriteLine("The other players responded:");
                            foreach (var f in feedback)
                            {
                                Console.Write(f.Key + ") ");
                                Console.Write(f.Value.Status + " ");
//.........这里部分代码省略.........
开发者ID:rasmusgreve,项目名称:catan,代码行数:101,代码来源:HumanAgent.cs

示例3: PlayDevelopmentCard

 private IGameState PlayDevelopmentCard(IGameState state, IGameActions actions)
 {
     Console.WriteLine("Which development card do you wish to play:");
     Console.WriteLine("0) None");
     int i = 1;
     var cards = new Dictionary<int, DevelopmentCard>();
     foreach (var c in state.GetOwnDevelopmentCards().Where(c => c != DevelopmentCard.VictoryPoint))
     {
         Console.WriteLine(i + ") " + c);
         cards.Add(i, c);
         i++;
     }
     int selection = int.Parse(Console.ReadLine() ?? "0");
     if (selection == 0) return null;
     Console.WriteLine("You played the card " + cards[selection]);
     hasPlayedDevCard = true;
     switch (cards[selection])
     {
         case DevelopmentCard.Knight:
             return actions.PlayKnight();
         case DevelopmentCard.Monopoly:
             Console.WriteLine("Choose the resource type to get monopoly on");
             return actions.PlayMonopoly(selectResource());
         case DevelopmentCard.RoadBuilding:
             Console.WriteLine("Decide where to build the two roads");
             var road1 = getRoadPosition();
             var road2 = getRoadPosition();
             return actions.PlayRoadBuilding(road1, road2);
         case DevelopmentCard.YearOfPlenty:
             Console.WriteLine("Choose which two resources you want to draw");
             return actions.PlayYearOfPlenty(selectResource(), selectResource());
     }
     return null;
 }
开发者ID:rasmusgreve,项目名称:catan,代码行数:34,代码来源:HumanAgent.cs


注:本文中的IGameState.GetOwnDevelopmentCards方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。