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


C# List.Random方法代码示例

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


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

示例1: On

        public static Grid On(Grid grid)
        {
            foreach (var row in grid.EachRow())
            {
                var run = new List<Cell>();

                foreach(var cell in row)
                {
                    run.Add(cell);
                    var closeOut = cell.East == null || (cell.North != null && rand.Next(2) == 0);

                    if (closeOut)
                    {
                        var member = run.Random();
                        if (member.North != null)
                        {
                            member.Link(member.North);
                        }
                        run.Clear();
                    }
                    else
                    {
                        cell.Link(cell.East);
                    }
                }
            }

            return grid;
        }
开发者ID:justinkurtz,项目名称:Mazes,代码行数:29,代码来源:Sidewinder.cs

示例2: RandomNeutralColor

 public Color RandomNeutralColor()
 {
     var lightGreen = new ColorHSV(132f, 0.8f, 1.0f).ToColor();
     var lime = new ColorHSV(0.95f, 0.866f, 1.0f).ToColor();
     var neutrals = new List<Color>()
     {
         lightGreen, lime
     };
     var neutralColor = neutrals.Random();
     return neutralColor;
 }
开发者ID:qualiabyte,项目名称:mukei-dolphin,代码行数:11,代码来源:CubeForm.cs

示例3: GenerateClicks

        private static void GenerateClicks(List<int> articles, List<string> users)
        {
            Parallel.ForEach(articles, new ParallelOptions { MaxDegreeOfParallelism = 30 }, articleId =>
            {
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                var random = new Random();
                var viewCount = random.Next(50, 1000);
                var acrticlesView = new List<StatiscticArticleView>();
                Console.WriteLine("Proccessing Clicks for ArticleId: {0}, Clicks count: {1}", articleId, viewCount);
                for (int i = 0; i < viewCount; i++)
                {
                    acrticlesView.Add(new StatiscticArticleView
                    {
                        ArticleId = articleId,
                        Time = DateTime.UtcNow.AddDays(0 - random.Next(5, 100)).AddHours(0 - random.Next(0, 24)).AddMinutes(0 - random.Next(0, 60)),
                        UserId = random.Next(0, 100) > 15 ? users.Random() : null
                    });
                }

                try
                {
                    using (var context = new ApplicationDbContext())
                    {
                        var commentEnity = (DbSet<StatiscticArticleView>)context.StatiscticArticleViews;
                        commentEnity.AddRange(acrticlesView);
                        context.SaveChanges();
                    }
                }
                catch (Exception exception)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("ERROR Proccessing Clicks for ArticleId: {0}", articleId);
                    Console.WriteLine(exception.Message);
                    if (exception.InnerException != null)
                    {
                        Console.WriteLine(exception.InnerException.Message);
                    }
                    Console.ResetColor();
                }
                stopWatch.Stop();
                TimeSpan ts = stopWatch.Elapsed;

                var elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                    ts.Hours, ts.Minutes, ts.Seconds,
                    ts.Milliseconds / 10);
                Console.WriteLine("Done with article id {0} time spend {1}", articleId, elapsedTime);
            });
        }
开发者ID:PavelMats,项目名称:ScalabelSimpleBlog,代码行数:49,代码来源:Program.cs

示例4: GenerateArticles

        private static void GenerateArticles(List<string> users)
        {
            var random = new Random();

            Parallel.For(0, 3000, new ParallelOptions {MaxDegreeOfParallelism = 30}, index =>
            {
                using (var context = new ApplicationDbContext())
                {
                    var articles = new List<Article>();
                    var tags = context.Tags.ToList();
                    for (var i = 0; i < 10; i++)
                    {
                        var article = new Article();
                        article.Tags.Add(tags.Random());
                        article.Tags.Add(tags.Random());
                        article.Header = SeedExtensions.Headers.Random();
                        article.TeaserText = SeedExtensions.TeaserTexts.Random();
                        article.Body = SeedExtensions.Body;
                        article.CreatedDate = DateTime.UtcNow.AddDays(0 - random.Next(5, 100));
                        article.IsPublished = random.Next(0, 100) > 15;
                        article.AuthorId = users.Random();
                        article.Stamp = Guid.NewGuid();
                        articles.Add(article);
                    }
                    ((DbSet<Article>) context.Articles).AddRange(articles);
                    try
                    {
                        Console.WriteLine("Saving categories index {0}, count {1}", index, articles.Count());
                        context.SaveChanges();
                    }
                    catch (Exception exception)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("ERROR Proccessing Clicks for ArticleId: {0}", index);
                        Console.WriteLine(exception.Message);
                        if (exception.InnerException != null)
                        {
                            Console.WriteLine(exception.InnerException.Message);
                        }
                        Console.ResetColor();
                    }
                }
            });
        }
开发者ID:PavelMats,项目名称:ScalabelSimpleBlog,代码行数:44,代码来源:Program.cs

示例5: On

        public static Grid On(Grid grid)
        {
            foreach (Cell cell in grid)
            {
                var neighbors = new List<Cell>();

                if (cell.North != null)
                    neighbors.Add(cell.North);

                if (cell.East != null)
                    neighbors.Add(cell.East);

                if (neighbors.Any())
                {
                    cell.Link(neighbors.Random());
                }
            }

            return grid;
        }
开发者ID:justinkurtz,项目名称:Mazes,代码行数:20,代码来源:BinaryTree.cs

示例6: GettingRepeatedlyRandomItemFromListReturnsItemsWithUniformDistribution

 public void GettingRepeatedlyRandomItemFromListReturnsItemsWithUniformDistribution()
 {
     IList<int> list = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
     int count = 10000;
     IDictionary<int, int> extracted = new Dictionary<int, int>();
     foreach (int i in list)
     {
         extracted.Add(i, 0);
     }
     for (int i = 0; i < count; i++)
     {
         int rnd = list.Random();
         extracted[rnd] =extracted[rnd] + 1;
     }
     int perfectDistributionCount = count / list.Count;
     foreach (int i in extracted.Keys)
     {
         Assert.True(extracted[i] > 0.8 * perfectDistributionCount);
         Assert.True(extracted[i] < 1.2 * perfectDistributionCount);
     }
 }
开发者ID:CodicePlastico,项目名称:Plastiline.Net,代码行数:21,代码来源:IListExtensionTest.cs

示例7: FindEmptiestNieghbour

    /// <summary>
    /// The neighbour with the most empty space. Otherwise picks at random
    /// </summary>
    /// <returns>The emptiest nieghbour.</returns>
    private Neighbours FindEmptiestNieghbour()
    {
        var neighbourPop = new List<KeyValuePair<Neighbours, int>>(4);

        var directions = Enum.GetValues(typeof(Neighbours)).Cast<Neighbours>().ToList();
        foreach(var dir in directions)
        {
            var n = this[dir];
            if(n != null)
            {
                var space = n.maxPopulation - n.population.Count;
                neighbourPop.Add(new KeyValuePair<Neighbours, int>(dir, space));
            }
        }

        neighbourPop.Sort( (a, b) => a.Value.CompareTo(b.Value) );

        bool allTheSame = true;
        int value = neighbourPop[0].Value;
        if(neighbourPop.Count > 1)
        {
            for (int i = 1; i < neighbourPop.Count; i++)
            {
                var t = neighbourPop[i].Value;
                if(t != value)
                {
                    allTheSame = false;
                    break;
                }
            }
        }

        if(allTheSame)
            return neighbourPop.Random().Key;
        else
            return neighbourPop[neighbourPop.Count-1].Key; //Last has most space
    }
开发者ID:jbgh2,项目名称:OfGodsAndMen,代码行数:41,代码来源:LandscapeBlock.cs

示例8: Conversion

    /// <summary>
    /// See if some of the population will convert to a different religion
    /// Work down pop from oldest to youngest. Pick a random pop, try and convert.
    /// Atheists don't convert others.
    /// </summary>
    public void Conversion()
    {
        var t = new List<Population>(population);

        t.Sort( (a, b) => a.age.CompareTo(b.age) );
        t.Reverse();

        foreach(var attacker in t)
        {
            //Atheists don't convert
            if(attacker.owner == parent.game.nullGod)
                continue;

            var defender = t.Random();

            if(attacker.owner == defender.owner)
                continue;

            //Attacker roll d6 + age difference.
            //Wins if greater than defenders age or 6
            var attackerBaseRoll = UnityEngine.Random.Range(1, 7);
            var attackerRoll = attackerBaseRoll + (attacker.age - defender.age);

            if(attackerBaseRoll == 6 || attackerRoll > defender.age)
            {
                defender.owner = attacker.owner;
            }

        }
    }
开发者ID:jbgh2,项目名称:OfGodsAndMen,代码行数:35,代码来源:LandscapeBlock.cs

示例9: GettingRandomItemFromEmptyListReturnsNull

 public void GettingRandomItemFromEmptyListReturnsNull()
 {
     IList<string> list = new List<string>();
     Assert.Null(list.Random());
 }
开发者ID:CodicePlastico,项目名称:Plastiline.Net,代码行数:5,代码来源:IListExtensionTest.cs

示例10: ShowDownloadDialog

        void ShowDownloadDialog()
        {
            statusLabel.GetText = () => "Fetching list of mirrors...";
            progressBar.Indeterminate = true;

            var retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON");
            retryButton.IsVisible = () => false;

            var cancelButton = panel.Get<ButtonWidget>("CANCEL_BUTTON");

            var mirrorsFile = Platform.ResolvePath("^", "Content", Game.modData.Manifest.Mod.Id, "mirrors.txt");
            var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            var dest = Platform.ResolvePath("^", "Content", Game.modData.Manifest.Mod.Id);

            Action<DownloadProgressChangedEventArgs> onDownloadProgress = i =>
            {
                var dataReceived = 0.0f;
                var dataTotal = 0.0f;
                var mag = 0;
                var dataSuffix = "";

                if (i.TotalBytesToReceive < 0)
                {
                    dataTotal = float.NaN;
                    dataReceived = i.BytesReceived;
                    dataSuffix = SizeSuffixes[0];
                }
                else
                {
                    mag = (int)Math.Log(i.TotalBytesToReceive, 1024);
                    dataTotal = i.TotalBytesToReceive / (float)(1L << (mag * 10));
                    dataReceived = i.BytesReceived / (float)(1L << (mag * 10));
                    dataSuffix = SizeSuffixes[mag];
                }

                progressBar.Indeterminate = false;
                progressBar.Percentage = i.ProgressPercentage;

                statusLabel.GetText = () => "Downloading from {4} {1:0.00}/{2:0.00} {3} ({0}%)".F(i.ProgressPercentage,
                    dataReceived, dataTotal, dataSuffix,
                    mirror != null ? new Uri(mirror).Host : "unknown host");
            };

            Action<string> onExtractProgress = s => Game.RunAfterTick(() => statusLabel.GetText = () => s);

            Action<string> onError = s => Game.RunAfterTick(() =>
            {
                statusLabel.GetText = () => "Error: " + s;
                retryButton.IsVisible = () => true;
            });

            Action<AsyncCompletedEventArgs, bool> onDownloadComplete = (i, cancelled) =>
            {
                if (i.Error != null)
                {
                    onError(Download.FormatErrorMessage(i.Error));
                    return;
                }
                else if (cancelled)
                {
                    onError("Download cancelled");
                    return;
                }

                // Automatically extract
                statusLabel.GetText = () => "Extracting...";
                progressBar.Indeterminate = true;
                if (InstallUtils.ExtractZip(file, dest, onExtractProgress, onError))
                {
                    Game.RunAfterTick(() =>
                    {
                        Ui.CloseWindow();
                        afterInstall();
                    });
                }
            };

            Action<AsyncCompletedEventArgs, bool> onFetchMirrorsComplete = (i, cancelled) =>
            {
                progressBar.Indeterminate = true;

                if (i.Error != null)
                {
                    onError(Download.FormatErrorMessage(i.Error));
                    return;
                }
                else if (cancelled)
                {
                    onError("Download cancelled");
                    return;
                }

                var mirrorList = new List<string>();
                using (var r = new StreamReader(mirrorsFile))
                {
                    string line;
                    while ((line = r.ReadLine()) != null)
                        if (!string.IsNullOrEmpty(line))
                            mirrorList.Add(line);
                }
//.........这里部分代码省略.........
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:101,代码来源:DownloadPackagesLogic.cs

示例11: TriggerTrap

 public void TriggerTrap(bool click)
 {
     bool actor_here = (actor() != null);
     if(actor_here && actor().type == ActorType.CYCLOPEAN_TITAN){
         if(name == "floor"){
             B.Add(actor().TheName(true) + " smashes " + Tile.Prototype(type).a_name + ". ",this);
         }
         else{
             B.Add(actor().TheName(true) + " smashes " + the_name + ". ",this);
         }
         TransformTo(TileType.FLOOR);
         return;
     }
     if(click){
         if(actor() == player || (actor() == null && player.CanSee(this))){
             B.Add("*CLICK* ",this);
             B.PrintAll();
         }
         else{
             if(actor() != null && player.CanSee(this) && player.CanSee(actor())){
                 B.Add("You hear a *CLICK* from under " + actor().the_name + ". ");
                 B.PrintAll();
             }
             else{
                 if(DistanceFrom(player) <= 12){
                     B.Add("You hear a *CLICK* nearby. ");
                     B.PrintAll();
                 }
                 else{
                     B.Add("You hear a *CLICK* in the distance. ");
                     B.PrintAll();
                 }
             }
         }
     }
     if(actor() == player){
         Help.TutorialTip(TutorialTopic.Traps);
     }
     switch(type){
     case TileType.GRENADE_TRAP:
     {
         if(actor_here && player.CanSee(actor())){
             B.Add("Grenades fall from the ceiling above " + actor().the_name + "! ",this);
         }
         else{
             B.Add("Grenades fall from the ceiling! ",this);
         }
         List<Tile> valid = new List<Tile>();
         foreach(Tile t in TilesWithinDistance(1)){
             if(t.passable && !t.Is(FeatureType.GRENADE)){
                 valid.Add(t);
             }
         }
         int count = R.OneIn(10)? 3 : 2;
         for(;count>0 & valid.Count > 0;--count){
             Tile t = valid.Random();
             if(t.actor() != null){
                 if(t.actor() == player){
                     B.Add("One lands under you! ");
                 }
                 else{
                     if(player.CanSee(this)){
                         B.Add("One lands under " + t.actor().the_name + ". ",t.actor());
                     }
                 }
             }
             else{
                 if(t.inv != null){
                     B.Add("One lands under " + t.inv.TheName() + ". ",t);
                 }
             }
             t.features.Add(FeatureType.GRENADE);
             valid.Remove(t);
             Q.Add(new Event(t,100,EventType.GRENADE));
         }
         Toggle(actor());
         break;
     }
     case TileType.SLIDING_WALL_TRAP:
     {
         List<int> dirs = new List<int>();
         for(int i=2;i<=8;i+=2){
             Tile t = this;
             bool good = true;
             while(t.type != TileType.WALL){
                 t = t.TileInDirection(i);
                 if(t.opaque && t.type != TileType.WALL){
                     good = false;
                     break;
                 }
                 if(DistanceFrom(t) > 6){
                     good = false;
                     break;
                 }
             }
             if(good && t.row > 0 && t.row < ROWS-1 && t.col > 0 && t.col < COLS-1){
                 t = t.TileInDirection(i);
             }
             else{
                 good = false;
//.........这里部分代码省略.........
开发者ID:ptrefall,项目名称:ForaysIntoNorrendrin,代码行数:101,代码来源:Tile.cs

示例12: Use


//.........这里部分代码省略.........
				attacker.RightHand.Data.HasTag("/weapon/bow/") ||
				attacker.RightHand.Data.HasTag("/weapon/crossbow/") ||
				attacker.RightHand.Data.HasTag("/weapon/shuriken/") ||
				attacker.RightHand.Data.HasTag("/weapon/atlatl/") ||
				attacker.RightHand.Data.HasTag("/weapon/gun/dualgun/")))
				{
					damage = attacker.GetRndBareHandDamage();
				}
				else
				{
					damage = attacker.GetRndTotalDamage();
				}
				damage *= skill.RankData.Var1 / 100f;

				// Handle skills and reductions
				var allCrit = false;
				var critSkill = target.Skills.Get(SkillId.CriticalHit);
				if (allCrit)
				{
					// Add crit bonus
					var bonus = critSkill.RankData.Var1 / 100f;
					damage = damage + (damage * bonus);

					// Set target option
					tAction.Set(TargetOptions.Critical);
				}
				else if (i == 1)
				{

					CriticalHit.Handle(attacker, attacker.GetTotalCritChance(0), ref damage, tAction);
					if (tAction.Has(TargetOptions.Critical))
						allCrit = true;
				}
				var maxDamage = damage; //Damage without Defense and Protection
				SkillHelper.HandleDefenseProtection(target, ref damage);
				Defense.Handle(aAction, tAction, ref damage);
				ManaShield.Handle(target, ref damage, tAction, maxDamage);

				// Clean Hit if not defended nor critical
				if (!tAction.Is(CombatActionType.Defended) && !tAction.Has(TargetOptions.Critical))
					tAction.Set(TargetOptions.CleanHit);

				// Take damage if any is left
				if (damage > 0)
					target.TakeDamage(tAction.Damage = damage, attacker);

				// Finish if dead, knock down if not defended
				if (target.IsDead)
					tAction.Set(TargetOptions.KnockDownFinish);
				else if (!tAction.Is(CombatActionType.Defended))
					tAction.Set(TargetOptions.KnockDown);

				// Anger Management
				if (!target.IsDead)
					survived.Add(target);

				if (target.UseBattleStanceFromAOE)
					target.IsInBattleStance = true;

				// Stun & knock back
				aAction.Stun = CombatMastery.GetAttackerStun(attacker.AverageKnockCount, attacker.AverageAttackSpeed, true);

				if (!tAction.Is(CombatActionType.Defended))
				{
					tAction.Stun = CombatMastery.GetTargetStun(attacker.AverageKnockCount, attacker.AverageAttackSpeed, true);
					target.Stability = Creature.MinStability;
					attacker.Shove(target, KnockbackDistance);
				}

				// Add action
				cap.Add(tAction);
			}

			// Only select a random aggro if there is no aggro yet,
			// WM only aggroes one target at a time.
			if (survived.Count != 0 && attacker.Region.CountAggro(attacker) < 1)
			{
				var rnd = RandomProvider.Get();
				var aggroTarget = survived.Random();
				aggroTarget.Aggro(attacker);
			}

			// Reduce life in old combat system
			if (!AuraData.FeaturesDb.IsEnabled("CombatSystemRenewal"))
			{
				var amount = (attacker.LifeMax < 10 ? 2 : attacker.LifeMax / 10);
				attacker.ModifyLife(-amount);

				attacker.InvincibilityTime = DateTime.Now.AddMilliseconds(2300);
			}

			// Spin it~
			Send.UseMotion(attacker, 8, 4);

			cap.Handle();

			Send.SkillUse(attacker, skill.Info.Id, targetAreaId, unkInt1, unkInt2);

			skill.Stacks = 0;
		}
开发者ID:xKamuna,项目名称:aura,代码行数:101,代码来源:Windmill.cs

示例13: AddPillars

 public void AddPillars(int percent_chance_per_room)
 {
     //currently does 50% 'pillar', 25% 'statue', and 25% 'other', where relevant.
     ForEachRectangularRoom((start_r,start_c,end_r,end_c) => {
         if(PercentChance(percent_chance_per_room)){
             int height = end_r - start_r + 1;
             int width = end_c - start_c + 1;
             if(height > 3 || width > 3){
                 List<PillarArrangement> layouts = new List<PillarArrangement>();
                 if(height % 2 == 1 && width % 2 == 1){
                     layouts.Add(PillarArrangement.Single);
                 }
                 if((height % 2 == 1 || width % 2 == 1) && height != 4 && width != 4){
                     layouts.Add(PillarArrangement.Row);
                 }
                 if(height >= 5 && width >= 5){
                     layouts.Add(PillarArrangement.Corners);
                 }
                 if(height > 2 && width > 2 && height != 4 && width != 4){
                     layouts.Add(PillarArrangement.Full);
                 }
                 if((width % 2 == 1 && width >= 5) || (height % 2 == 1 && height >= 5)){
                     layouts.Add(PillarArrangement.StatueEdges);
                 }
                 if(layouts.Count == 0 || CoinFlip()){ //otherwise they're too common
                     layouts.Add(PillarArrangement.StatueCorners);
                 }
                 if(layouts.Count > 0){
                     CellType pillar = CellType.Pillar;
                     /*switch(Roll(4)){ //this part should be done later. Until then, they should remain pillars.
                     case 1:
                     case 2:
                         pillar = CellType.Pillar;
                         break;
                     case 3:
                         pillar = CellType.Statue;
                         break;
                     case 4:
                         pillar = CellType.OtherRoomFeature;
                         break;
                     }*/
                     switch(layouts.Random()){
                     case PillarArrangement.Single:
                         map[(start_r + end_r)/2,(start_c + end_c)/2] = pillar;
                         break;
                     case PillarArrangement.Row:
                     {
                         bool vertical;
                         if(width % 2 == 1 && height % 2 == 0){
                             vertical = true;
                         }
                         else{
                             if(height % 2 == 1 && width % 2 == 0){
                                 vertical = false;
                             }
                             else{
                                 vertical = CoinFlip();
                             }
                         }
                         if(vertical){
                             if(height % 2 == 1){
                                 for(int i=start_r+1;i<=end_r-1;i+=2){
                                     map[i,(start_c + end_c)/2] = pillar;
                                 }
                             }
                             else{
                                 int offset = 0;
                                 if(height % 4 == 0){
                                     offset = Roll(2) - 1;
                                 }
                                 for(int i=start_r+1+offset;i<(start_r + end_r)/2;i+=2){
                                     map[i,(start_c + end_c)/2] = pillar;
                                 }
                                 for(int i=end_r-1-offset;i>(start_r + end_r)/2+1;i-=2){
                                     map[i,(start_c + end_c)/2] = pillar;
                                 }
                             }
                         }
                         else{
                             if(width % 2 == 1){
                                 for(int i=start_c+1;i<=end_c-1;i+=2){
                                     map[(start_r + end_r)/2,i] = pillar;
                                 }
                             }
                             else{
                                 int offset = 0;
                                 if(width % 4 == 0){
                                     offset = Roll(2) - 1;
                                 }
                                 for(int i=start_c+1+offset;i<(start_c + end_c)/2;i+=2){
                                     map[(start_r + end_r)/2,i] = pillar;
                                 }
                                 for(int i=end_c-1-offset;i>(start_c + end_c)/2+1;i-=2){
                                     map[(start_r + end_r)/2,i] = pillar;
                                 }
                             }
                         }
                         break;
                     }
                     case PillarArrangement.Corners:
//.........这里部分代码省略.........
开发者ID:ptrefall,项目名称:ForaysIntoNorrendrin,代码行数:101,代码来源:Schism.cs

示例14: GenerateScrollName

 public static string GenerateScrollName()
 {
     //List<string> vowel = new List<string>{"a","e","i","o","u"};
     //List<string> consonant = new List<string>{"k","s","t","n","h","m","y","r","w","g","d","p","b"}; //Japanese-inspired - used AEIOU, 4 syllables max, and 3-9 total
     //List<string> consonant = new List<string>{"h","k","l","n","m","p","w"}; //Hawaiian-inspired
     //List<string> vowel = new List<string>{"y","i","e","u","ae"}; //some kinda Gaelic-inspired
     //List<string> consonant = new List<string>{"r","t","s","rr","m","n","w","b","c","d","f","g","l","ss","v"}; //some kinda Gaelic-inspired
     List<string> vowel = new List<string>{"a","e","i","o","u","ea","ei","io","a","e","i","o","u","a","e","i","o","u","a","e","i","o","oo","ee","a","e","o"}; //the result of a bunch of tweaking
     List<string> consonant = new List<string>{"k","s","t","n","h","m","y","r","w","g","d","p","b","f","l","v","z","ch","br","cr","dr","fr","gr","kr","pr","tr","th","sc","sh","sk","sl","sm","sn","sp","st","k","s","t","n","m","r","g","d","p","b","l","k","s","t","n","m","r","d","p","b","l",};
     int syllables = 0;
     List<int> syllable_count = null;
     do{
         syllables = R.Roll(4) + 2;
         syllable_count = new List<int>();
         while(syllables > 0){
             if(syllable_count.Count == 2){
                 syllable_count.Add(syllables);
                 syllables = 0;
                 break;
             }
             int R2 = Math.Min(syllables,3);
             int M = 0;
             if(syllable_count.Count == 0){ //sorry, magic numbers here
                 M = 6;
             }
             if(syllable_count.Count == 1){
                 M = 5;
             }
             int D = 0;
             if(syllable_count.Count == 0){
                 D = Math.Max(0,syllables - M);
             }
             int s = R.Roll(R2 - D) + D;
             syllable_count.Add(s);
             syllables -= s;
         }
     }
     while(!syllable_count.Any(x => x!=1)); // if every word has only 1 syllable, try again
     string result = "";
     while(syllable_count.Count > 0){
         string word = "";
         if(R.OneIn(5)){
             word = word + vowel.Random();
         }
         for(int count = syllable_count.RemoveRandom();count > 0;--count){
             word = word + consonant.Random() + vowel.Random();
             /*if(R.OneIn(20)){ //used for the Japanese-inspired one
                 word = word + "n";
             }*/
         }
         if(result == ""){
             result = result + word;
         }
         else{
             result = result + " " + word;
         }
     }
     return result;
 }
开发者ID:ptrefall,项目名称:ForaysIntoNorrendrin,代码行数:59,代码来源:Item.cs

示例15: Use


//.........这里部分代码省略.........
             if(user == player){
                 B.Add("You would feel at home in the shadows. ");
             }
             else{
                 B.Add("A shadow moves across " + user.the_name + ". ",user);
             }
         }
         else{
             B.Add(user.You("fade") + " away in the darkness. ",user);
         }
         user.RefreshDuration(AttrType.SHADOW_CLOAK,(R.Roll(2,20)+30)*100,user.YouAre() + " no longer cloaked. ",user);
         break;
     case ConsumableType.MYSTIC_MIND:
     {
         B.Add(user.Your() + " mind expands. ",user);
         int duration = R.Roll(2,20)+60;
         user.attrs[AttrType.ASLEEP] = 0;
         //user.RefreshDuration(AttrType.MAGICAL_DROWSINESS,0);
         user.RefreshDuration(AttrType.CONFUSED,0);
         user.RefreshDuration(AttrType.STUNNED,0);
         user.RefreshDuration(AttrType.ENRAGED,0);
         user.RefreshDuration(AttrType.MENTAL_IMMUNITY,duration*100);
         user.RefreshDuration(AttrType.DETECTING_MONSTERS,duration*100);
         user.RefreshDuration(AttrType.MYSTIC_MIND,duration*100,user.Your() + " consciousness returns to normal. ",user);
         if(user == player){
             Help.TutorialTip(TutorialTopic.MysticMind);
         }
         break;
     }
     case ConsumableType.BLINKING:
     {
         List<Tile> tiles = user.TilesWithinDistance(8).Where(x => x.passable && x.actor() == null && user.ApproximateEuclideanDistanceFromX10(x) >= 45);
         if(tiles.Count > 0 && !user.HasAttr(AttrType.IMMOBILE)){
             Tile t = tiles.Random();
             B.Add(user.You("step") + " through a rip in reality. ",M.tile[user.p],t);
             user.AnimateStorm(2,3,4,'*',Color.DarkMagenta);
             user.Move(t.row,t.col);
             M.Draw();
             user.AnimateStorm(2,3,4,'*',Color.DarkMagenta);
         }
         else{
             B.Add("Nothing happens. ",user);
             IDed = false;
         }
         break;
     }
     case ConsumableType.PASSAGE:
     {
         if(user.HasAttr(AttrType.IMMOBILE)){
             B.Add("Nothing happens. ",user);
             IDed = false;
             break;
         }
         List<int> valid_dirs = new List<int>();
         foreach(int dir in U.FourDirections){
             Tile t = user.TileInDirection(dir);
             if(t != null && t.Is(TileType.WALL,TileType.CRACKED_WALL,TileType.WAX_WALL,TileType.DOOR_C,TileType.HIDDEN_DOOR,TileType.STONE_SLAB)){
                 while(!t.passable){
                     if(t.row == 0 || t.row == Global.ROWS-1 || t.col == 0 || t.col == Global.COLS-1){
                         break;
                     }
                     t = t.TileInDirection(dir);
                 }
                 if(t.passable){
                     valid_dirs.Add(dir);
                 }
开发者ID:ptrefall,项目名称:ForaysIntoNorrendrin,代码行数:67,代码来源:Item.cs


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