本文整理汇总了C#中Dice.Roll方法的典型用法代码示例。如果您正苦于以下问题:C# Dice.Roll方法的具体用法?C# Dice.Roll怎么用?C# Dice.Roll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dice
的用法示例。
在下文中一共展示了Dice.Roll方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Roll
public int Roll(int timesRolled, Dice dice)
{
int total = 0;
for( int i = 0; i < timesRolled; ++i)
{
total += dice.Roll();
}
return total;
}
示例2: Hit
public void Hit(Character target)
{
Dice dice = new Dice(10);
int power = dice.Roll() * AttackPower;
double roll = dice.Roll();
if (roll <= CriticalHitChance)
{
if (roll == 1)
roll = 1.5;
power = (int)(power + AttackPower * roll);
}
if (dice.Roll() <= Speed)
target.Hurt(power);
}
示例3: Roll
/// <summary>
/// Executes the "roll" command
/// </summary>
/// <param name="prms">Expects something like "1d6".</param>
/// <returns>An array of random numbers</returns>
public static IEnumerable<int> Roll(string prms)
{
if (!prms.HasValue()) return new List<int>();
var args = prms.ToLower().Split('d').Select(x => x.To<int?>()).ToList();
if (args.Count != 2) return new List<int>();
var dice = new Dice {
Count = args[0],
Sides = args[1],
};
return dice.Roll();
}
示例4: YouCanSupplyBiggerNumbers
public void YouCanSupplyBiggerNumbers()
{
var dice = new Dice();
var roll = dice.Roll();
Assert.Greater(-1,
roll);
Assert.Less(11,
roll);
}
示例5: RollReturnsANumber
public void RollReturnsANumber()
{
var dice = new Dice();
var roll = dice.Roll();
Assert.Greater(-1,
roll);
Assert.Less(11,
roll);
}
示例6: GenerateAbilityScore
// roll 5 six sided die, take the best 3
// and return the total
public int GenerateAbilityScore()
{
Dice dice = new Dice(6);
List<int> results = new List<int>();
for (int i = 0; i < 5; i++)
{
results.Add(dice.Roll());
}
results.Sort();
results.RemoveRange(0,2);
return results.Sum();
}
示例7: DetermineDamage
public static int DetermineDamage(this AttackerRole attacker)
{
var dice = new Dice();
var abilityBonus = attacker.Power - attacker.Weapon.PowerNeeded;
var possibleDamage = attacker.Weapon.DamageBonus + abilityBonus;
possibleDamage = possibleDamage <= 0 ? 0 : possibleDamage;
var successRate = dice.Roll() / 10.0;
return (int)Math.Round(possibleDamage * successRate);
}
示例8: Parry
public static int Parry(this DefenderRole defender)
{
var dice = new Dice();
var weapon = defender.Weapon;
var abilityBonus = defender.Agility - weapon.AgilityNeeded;
var possibleParry = weapon.ParryBonus + abilityBonus;
possibleParry = possibleParry <= 0 ? 0 : possibleParry;
return dice.Roll() >= 6 ? possibleParry : 0;
}
示例9: Hits
private static bool Hits(this AttackerRole attacker, Dice dice)
{
var hits = 0;
for(int i = 0; i < attacker.Power; i++)
{
var roll = dice.Roll();
if(roll >= 7)
{
hits++;
}
}
return hits > 0;
}
示例10: Dodge
public static bool Dodge(this DefenderRole defender)
{
var dice = new Dice();
var dodges = 0;
for(int i = 0; i < defender.Agility; i++)
{
var roll = dice.Roll();
if(roll >= 7)
{
dodges++;
}
}
return dodges > 0;
}
示例11: Level
public Tile[,] tileArray = new Tile[GRIDW, GRIDH]; //X,Y; used for storing base tile information
#endregion Fields
#region Constructors
public Level(int rCount, int cCount, String type, ContentEncyclopedia content,
int rngSeed, Vector3 mapPos)
{
seed = rngSeed;
causeOfDeath = "unknown causes."; //If this never gets tripped, then wtf
mannerOfDeath = "mysterious circumstances - will they never find a cure?"; //Ditto
this.mapPos = mapPos;
levelType = type;
rng = new Random(rngSeed);
rngDie = new Dice(rngSeed);
this.content = content;
int itemCount = rng.Next(5, 11); //5 to 10 items per level
int creatureCount = rng.Next(5, 11); //5 to 10 initial creatures
int x, y;
switch(type)
{
case "dungeon":
FillWithFreshTiles(false);
MakeEmptyRooms();
MakeCorridors();
#region Place other fixtures
bool doneFixtures = false; //Set up a stop condition for the next loop
while (!doneFixtures) //A loop to place the down stairs randomly in an open space
{
int r = rng.Next(0, rooms.Count); //Random major room
while (rooms[r].isIsolated) //Make sure we don't put stuff in isolated rooms
r = rng.Next(0, rooms.Count);
x = rng.Next(rooms[r].x + 1, rooms[r].x + rooms[r].width - 1);
y = rng.Next(rooms[r].y + 1, rooms[r].y + rooms[r].height - 1); //Pick a random spot in room
if (tileArray[x, y].isPassable && tileArray[x, y].fixtureLibrary.Count <= 0)
{
tileArray[x, y].fixtureLibrary.Add(new Stairs(true));
doneFixtures = true;
}
}
doneFixtures = false; //Reset
for (int k = 0; k < 5; k++)
{
x = rng.Next(3, GRIDW - 2);
y = rng.Next(3, GRIDH - 2); //Pick a random spot
if (tileArray[x, y].isPassable && tileArray[x, y].fixtureLibrary.Count <= 0) //If it's walkable
{
Trap thisTrap = new Trap(new Effect(rngDie.Roll(5), "tripwire"));
//thisTrap.visible = true; //For now, let's see where these things go
tileArray[x, y].fixtureLibrary.Add(thisTrap); //Place a tripwire here
}
else
{
k--;
}
}
#endregion
PlacePlayer();
rng = new Random((int)DateTime.Now.Ticks); //Reseed the level so the other things will change
for (int i = 1; i <= creatureCount; i++)
{
SpawnCreature(true, "monster");
}
#region Place the items
for (int i = 1; i <= itemCount; i++)
{
bool doneItems = false; //Set up a stop condition for the next loop
while (doneItems == false) //A loop to place the creature randomly in an open space
{
int r = rng.Next(0, rooms.Count); //Random major room
while (rooms[r].isIsolated)
r = rng.Next(0, rooms.Count);
x = rng.Next(rooms[r].x + 1, rooms[r].x + rooms[r].width - 1);
y = rng.Next(rooms[r].y + 1, rooms[r].y + rooms[r].height - 1); //Pick a random spot in room
if (tileArray[x, y].isPassable == true) //If it's passable
{
List<Armor> armorList = new List<Armor>();
List<Potion> potionList = new List<Potion>();
List<Weapon> weaponList = new List<Weapon>();
List<Item> plainList = new List<Item>();
foreach (Item t in content.items) //Organze the items for random drops TODO: Is this necessary? Linq?
{
if (t is Armor)
armorList.Add((Armor)t);
else if (t is Potion)
//.........这里部分代码省略.........
示例12: MovePlayer
private void MovePlayer(Player player, Dice firstDice, Dice secondDice, Board board)
{
int spaces = firstDice.Roll() + secondDice.Roll();
int newPosition = player.Position + spaces;
if (newPosition >= board.Size)
{
newPosition -= board.Size;
player.AddMoney(200);
}
player.Move(newPosition);
}
示例13: RollWorks
public void RollWorks()
{
var dice = new Dice();
Assert.DoesNotThrow(() => dice.Roll());
}