我在 AS3 中完成任务时遇到了一些麻烦。我有一个名为 Rand 的变量,如果这个 rand 介于 0 - 10 之间,它将显示死亡磁盘。如果 rand 介于 90 - 100 之间,则会出现金盘。我想要实现的目标是那些磁盘永远不会连续出现两次。我尝试使用布尔值,但它没有用。除此之外,只有当“var”rand 介于我提到的数字之间时,国王和死盘才会出现。有时它出现在兰特数之外。我希望有人可以帮助我解决这个问题。
一些信息:
disks 是一个 MC 和一个按钮。这个 MC 磁盘有 8 个框架,其中 1 - 6 个是普通磁盘,7 和 8 个是国王和死亡磁盘。您可以将磁盘与骰子进行比较。当播放器按下磁盘 Movieclip 时,将选择一个随机帧。
diskRoll [类]:
package {
import flash.display.*;
import flash.events.*;
import flash.display.*;
import flash.utils.*;
import flash.media.*;
public class DiskRoll extends MovieClip
{
//Vars
var diskTilt:Timer = new Timer(1350,1);
//var rand:int = Math.random() * 100;
var rand:int = (Math.random()*(100));
var deathDisk:Boolean = false;
var kinghDisk:Boolean = false;
//Sound Vars
var diskFxChannel:SoundChannel = new SoundChannel();
var diskHitFx:Sound = new diskHitsound();
var diskRollFx:Sound = new diskRollSound();
public function DiskRoll():void
{
this.addEventListener(MouseEvent.MOUSE_DOWN, hitDisk);
diskTilt.addEventListener(TimerEvent.TIMER_COMPLETE, tiltOnComplete);
diskFxChannel = diskRollFx.play();
}
//Disk hit function
private function hitDisk(event:MouseEvent):void{
//Picks random frame after MOUSE_DOWN from Disks Mc [1-8 Frames total]
this.gotoAndStop(Math.ceil(Math.random()* 6));
//Genarate random number calc chances and luck
rand = (Math.random() * (100));
//Disk of death between Random number (block second time)
if(rand >= 90 && rand <=100){
this.gotoAndStop(7);
kinghDisk = true;
}
if(rand >= 0 && rand <=10){
this.gotoAndStop(8);
deathDisk = true;
}
//Disk of death between Random number (block second time)
if(deathDisk == true){
rand = (Math.random() * (100))+11;
}
if(deathDisk == false){
rand = (Math.random() * (100));
}
//KingsDisk Random between number (block second time)
if(kinghDisk == true){
rand = (Math.random() * (89));
}
if(kinghDisk == false){
rand = (Math.random() * (100));
}
//If statements per Disk
if(this.currentFrame == 1){
trace("DiskRoll 1")
deathDisk = false;
kinghDisk = false;
}
if(this.currentFrame == 2){
trace("DiskRoll 2")
deathDisk = false;
kinghDisk = false;
}
if(this.currentFrame == 3){
trace("DiskRoll 3")
deathDisk = false;
kinghDisk = false;
}
if(this.currentFrame == 4 /*&& stage.getChildByName("block") == null*/){
trace("DiskRoll 4")
deathDisk = false;
kinghDisk = false;
}
if(this.currentFrame == 5){
trace("DiskRoll 5")
deathDisk = false;
kinghDisk = false;
}
if(this.currentFrame == 6){
trace("DiskRoll 6")
deathDisk = false;
kinghDisk = false;
}
if(this.currentFrame == 7){
trace("DiskRoll 7")
deathDisk = false;
kinghDisk = true;
}
if(this.currentFrame == 8){
trace("DiskRoll 8")
deathDisk = true;
kinghDisk = false;
}
trace(rand);
trace(deathDisk);
trace(kinghDisk);
diskFxChannel = diskHitFx.play();
this.removeEventListener(MouseEvent.MOUSE_DOWN, hitDisk);
diskTilt.start();
}
//Deblock Disk (button) Timer
private function tiltOnComplete(event:TimerEvent):void {
this.gotoAndPlay(1);
diskTilt.stop();
this.addEventListener(MouseEvent.MOUSE_DOWN, hitDisk);
diskFxChannel = diskRollFx.play();
}
}
}