Skip to main content
Olivetian
Participant
November 12, 2014
Question

Dice and Board Game

  • November 12, 2014
  • 2 replies
  • 1429 views

Using Actionscript 3, How does a player move base on dice result?

I'm developing a game that is based on the popular snake and ladder game as my undergraduate project. It has 36 tiles. Thus far, I'm able to roll the dice but needs the player to move with dice result. I appreciate help. Here is code:

package{

   

    import flash.display.*;

    import flash.events.*;

    import flash.text.*;

   

    public class peaconty extends MovieClip{

       

        //variables

        public var rollBtn;

        public var dieMov;

        public var boardMov;

        public var textResult;

       

        public function peaconty() :void{

            rollBtn.addEventListener(MouseEvent.CLICK, rollRandomNumber);

            dieMov.gotoAndStop(Math.ceil(Math.random() * 6));

            boardMov.gotoAndStop(Math.ceil(Math.random() * 6));

        }

       

        function rollRandomNumber(Event:MouseEvent) :void{

            //trace(randNumb);

            var randNumb:uint = Math.ceil(Math.random() * 6);

            textResult.text = "You rolled "+randNumb;

           

            dieMov.gotoAndStop(randNumb);

            boardMov.gotoAndStop((currentFrame) +(randNumb));

    }

}

}

This topic has been closed for replies.

2 replies

Olivetian
OlivetianAuthor
Participant
November 12, 2014

My thought is that I'm using randNumb to move the player. So something must be wrong somewhere. Everything works except the strike through line which is the last statement. The purpose of the statement is to move the player on tiles base on dice result.

package{

   

    import flash.display.*;

    import flash.events.*;

    import flash.text.*;

   

    public class peaconty extends MovieClip{

       

        //variables

        public var rollBtn;

        public var dieMov;

        public var boardMov;

        public var textResult;

       

        public function peaconty() :void{

            rollBtn.addEventListener(MouseEvent.CLICK, rollRandomNumber);

            dieMov.gotoAndStop(Math.ceil(Math.random() * 6));

            boardMov.gotoAndStop(Math.ceil(Math.random() * 6));

        }

       

        function rollRandomNumber(Event:MouseEvent) :void{

            //trace(randNumb);

            var randNumb:uint = Math.ceil(Math.random() * 6);

            textResult.text = "You rolled "+randNumb;

           

            dieMov.gotoAndStop(randNumb);

            boardMov.gotoAndStop((currentFrame) +(randNumb));

    }

}

}

Nothing much in the files though, except look up; as you can see here:

The purpose of the game is instructional game, so it will later ''ve stuffs like quiz; but I want to take one step at a time. Thank you.

kglad
Community Expert
Community Expert
November 12, 2014

what i would do:

use a variable to keep track of the players tile:

var currentTileNum:int=1;  // at start

var finalTileNum:int=1;

var playerTimer:Timer=new Timer(300,0);

playerTimer.addEventListener(TimerEvent.TIMER,playerMoveF);

     function rollRandomNumber(Event:MouseEvent) :void{

            //trace(randNumb);

            var randNumb:uint = Math.ceil(Math.random() * 6);

            textResult.text = "You rolled "+randNumb;

            finalTileNum+=randNumb;

            finalTileNum=Math.min(finalTileNum,36);

            dieMov.gotoAndStop(randNumb);

            playerTimer.start();

    }

function playerMoveF(e:TimerEvent):void{

if(currentTileNum<finalTileNum){

currentTileNum++;

player.x=this['tile_'+currentTileNum].x;  // name your tiles, tile_1, tile_2,...,tile_36.  // name your player marker player

player.y=this['tile_'+currentTileNum].y;

} else {

playerTimer.stop();

if(finalTileNum==36){

// game over.  do whatever.

} else {

// take another turn.  ie, re-roll the die.

}

}

}

kglad
Community Expert
Community Expert
November 12, 2014

advance (or allow the user to advance) 'the player' symbol randNumb tiles.

how you should do that depends on how you setup your 'board'.

Olivetian
OlivetianAuthor
Participant
November 12, 2014

Thank you Kglad, the truth is "I'm not versatile @ actionscript or even coding". But then here are the files (.fla & .as) to the game. I hope it helps for you to see how my board and the entire game is set up.

Link here: PEACONty.zip - Google Drive

Kindly help to check

kglad
Community Expert
Community Expert
November 12, 2014

i don't download and correct files unless i'm hired.  for free help, post to the adobe forums.

as a rule, if you state your issue clearly, and especially if you pinpoint the problem, you almost certainly will be helped free of charge.  if you have a complex problem and especially if you require files to be downloaded, you almost certainly should consider hiring someone to help.