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


PHP Random::nextRange方法代码示例

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


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

示例1: populate

 public function populate(Level $level, $chunkX, $chunkZ, Random $random)
 {
     if ($random->nextRange(0, $this->waterOdd) === 0) {
         $v = new Vector3($random->nextRange($chunkX << 4, ($chunkX << 4) + 16), $random->nextRange(0, 128), $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16));
         $pond = new PondObject($random, new WaterBlock());
         if ($pond->canPlaceObject($level, $v)) {
             $pond->placeObject($level, $v);
         }
     }
 }
开发者ID:ungarscool1,项目名称:Multicraft,代码行数:10,代码来源:PondPopulator.php

示例2: growGrass

 public static function growGrass(Level $level, Vector3 $pos, Random $random, $count = 15, $radius = 10)
 {
     $arr = array(BlockAPI::get(DANDELION, 0), BlockAPI::get(CYAN_FLOWER, 0), BlockAPI::get(TALL_GRASS, 1), BlockAPI::get(TALL_GRASS, 1), BlockAPI::get(TALL_GRASS, 1), BlockAPI::get(TALL_GRASS, 1));
     $arrC = count($arr) - 1;
     for ($c = 0; $c < $count; ++$c) {
         $x = $random->nextRange($pos->x - $radius, $pos->x + $radius);
         $z = $random->nextRange($pos->z - $radius, $pos->z + $radius);
         if ($level->level->getBlockID($x, $pos->y + 1, $z) === AIR and $level->level->getBlockID($x, $pos->y, $z) === GRASS) {
             $t = $arr[$random->nextRange(0, $arrC)];
             $level->setBlockRaw(new Vector3($x, $pos->y + 1, $z), $t);
         }
     }
 }
开发者ID:ungarscool1,项目名称:Multicraft,代码行数:13,代码来源:TallGrassObject.php

示例3: populate

 public function populate(Level $level, $chunkX, $chunkZ, Random $random)
 {
     foreach ($this->oreTypes as $type) {
         $ore = new OreObject($random, $type);
         for ($i = 0; $i < $ore->type->clusterCount; ++$i) {
             $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16);
             $y = $random->nextRange($ore->type->minHeight, $ore->type->maxHeight);
             $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16);
             if ($ore->canPlaceObject($level, $x, $y, $z)) {
                 $ore->placeObject($level, new Vector3($x, $y, $z));
             }
         }
     }
 }
开发者ID:ungarscool1,项目名称:Multicraft,代码行数:14,代码来源:OrePopulator.php

示例4: growTree

 public static function growTree(Level $level, Vector3 $pos, Random $random, $type = 0)
 {
     switch ($type & 0x3) {
         case SaplingBlock::SPRUCE:
             if ($random->nextRange(0, 1) === 1) {
                 $tree = new SpruceTreeObject();
             } else {
                 $tree = new PineTreeObject();
             }
             break;
         case SaplingBlock::BIRCH:
             $tree = new SmallTreeObject();
             $tree->type = SaplingBlock::BIRCH;
             break;
         case SaplingBlock::JUNGLE:
             $tree = new SmallTreeObject();
             $tree->type = SaplingBlock::JUNGLE;
             break;
         default:
         case SaplingBlock::OAK:
             /*if($random->nextRange(0, 9) === 0){
             			$tree = new BigTreeObject();
             		}else{*/
             $tree = new SmallTreeObject();
             //}
             break;
     }
     if ($tree->canPlaceObject($level, $pos, $random)) {
         $tree->placeObject($level, $pos, $random);
     }
 }
开发者ID:ungarscool1,项目名称:Multicraft,代码行数:31,代码来源:TreeObject.php

示例5: placeObject

 public function placeObject(Level $level, Vector3 $pos, Random $random)
 {
     // The base dirt block
     $dirtpos = new Vector3($pos->x, $pos->y - 1, $pos->z);
     $level->setBlockRaw($dirtpos, new DirtBlock());
     // Adjust the tree trunk's height randomly
     //    plot [-14:11] int( x / 8 ) + 5
     //    - min=4 (all leaves are 4 tall, some trunk must show)
     //    - max=6 (top leaves are within ground-level whacking range
     //             on all small trees)
     $heightPre = $random->nextRange(-14, 11);
     $this->trunkHeight = intval($heightPre / 8) + 5;
     // Adjust the starting leaf density using the trunk height as a
     // starting position (tall trees with skimpy leaves don't look
     // too good)
     $leafPre = $random->nextRange($this->trunkHeight, 10) / 20;
     // (TODO: seed may apply)
     // Now build the tree (from the top down)
     $leaflevel = 0;
     for ($yy = $this->trunkHeight + 1; $yy >= 0; --$yy) {
         if ($leaflevel < self::$leavesHeight) {
             // The size is a slight variation on the trunkheight
             $radius = self::$leafRadii[$leaflevel] + $leafPre;
             $bRadius = 3;
             for ($xx = -$bRadius; $xx <= $bRadius; ++$xx) {
                 for ($zz = -$bRadius; $zz <= $bRadius; ++$zz) {
                     if (sqrt($xx * $xx + $zz * $zz) <= $radius) {
                         $leafpos = new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz);
                         $level->setBlockRaw($leafpos, new LeavesBlock($this->type));
                     }
                 }
             }
             $leaflevel++;
         }
         // Place the trunk last
         if ($leaflevel > 1) {
             $trunkpos = new Vector3($pos->x, $pos->y + $yy, $pos->z);
             $level->setBlockRaw($trunkpos, new WoodBlock($this->type));
         }
     }
 }
开发者ID:ungarscool1,项目名称:Multicraft,代码行数:41,代码来源:SmallTreeObject.php

示例6: __construct

 public function __construct($random = false)
 {
     if (!$random instanceof Random) {
         $random = new Random();
     }
     $this->xCoord = $random->nextFloat() * 256;
     $this->yCoord = $random->nextFloat() * 256;
     $this->zCoord = $random->nextFloat() * 256;
     for ($i = 0; $i < 512; ++$i) {
         $this->permutations[$i] = 0;
     }
     for ($i = 0; $i < 256; ++$i) {
         $this->permutations[$i] = $i;
     }
     for ($i = 0; $i < 256; ++$i) {
         $j = $random->nextRange(0, 256 - $i) + $i;
         $k = $this->permutations[$i];
         $this->permutations[$i] = $this->permutations[$j];
         $this->permutations[$j] = $k;
         $this->permutations[$i + 256] = $this->permutations[$i];
     }
 }
开发者ID:ungarscool1,项目名称:Multicraft,代码行数:22,代码来源:NoiseGeneratorPerlin.php

示例7: findRandomLeavesSize

 private function findRandomLeavesSize(Random $random)
 {
     $this->totalHeight += $random->nextRange(-1, 2);
     $this->leavesSizeY = 1 + $random->nextRange(0, 2);
     $this->leavesAbsoluteMaxRadius = 2 + $random->nextRange(0, 1);
 }
开发者ID:ungarscool1,项目名称:Multicraft,代码行数:6,代码来源:PineTreeObject.php

示例8: populate

 public function populate(Level $level, $chunkX, $chunkZ, Random $random)
 {
     if ($random->nextRange(0, MineshaftPopulator::$ODD) === 0) {
         //$mineshaft = new Mineshaft($random);
     }
 }
开发者ID:ungarscool1,项目名称:Multicraft,代码行数:6,代码来源:MineshaftPopulator.php

示例9: findRandomLeavesSize

 private function findRandomLeavesSize(Random $random)
 {
     $this->totalHeight += $random->nextRange(-1, 2);
     $this->leavesBottomY = (int) ($this->totalHeight - $random->nextRange(1, 2) - 3);
     $this->leavesMaxRadius = 1 + $random->nextRange(0, 1);
 }
开发者ID:ungarscool1,项目名称:Multicraft,代码行数:6,代码来源:SpruceTreeObject.php


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