1 Replies - 1930 Views - Last Post: 17 November 2010 - 05:28 PM

#1 skater_00  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 12
  • View blog
  • Posts: 256
  • Joined: 30-April 08

Roll the dice!

Posted 20 February 2009 - 11:04 AM

Description: /Provides a class with the functionality of a dice.
/*********************/
/* ActionScript File */
/*********************/

package net.dreamincode.as3
{
	public class Dice
	{
		/* --- Constructor --- */
		public function Dice():void
		{
			this.eyes = 0;
		}
		
		/* --- Properties --- */
		public var eyes:uint;
		
		/* --- Methods --- */
		public function roll():uint
		{
			// Roll the dice!
			this.eyes = Math.round(Math.random() * 5 + 1);
			return this.eyes;
		}
	}
}

/**************/
/* Flash File */
/**************/

import net.dreamincode.as3.Dice;     // Import Dice class

var dice:Dice = new Dice();     // Create a new object (instance) of the Dice class
trace("Eyes: " + dice.roll());     // Output: unsigned integer between 1 and 6


Is This A Good Question/Topic? 0
  • +

Replies To: Roll the dice!

#2 skater_00  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 12
  • View blog
  • Posts: 256
  • Joined: 30-April 08

Re: Roll the dice!

Posted 20 February 2009 - 11:04 AM

Description: /Provides a class with the functionality of a dice.
/*********************/
/* ActionScript File */
/*********************/

package net.dreamincode.as3
{
	public class Dice
	{
		/* --- Constructor --- */
		public function Dice():void
		{
			_eyes = 0;
		}
		
		/* --- Properties --- */
		private var _eyes:uint;
		
		/* --- Methods --- */
		public function roll():uint
		{
			// Roll the dice!
			_eyes = Math.round(Math.random() * 5 + 1);
			return _eyes;
		}
	}
}

/**************/
/* Flash File */
/**************/

import net.dreamincode.as3.Dice;     // Import Dice class

var dice:Dice = new Dice();     // Create a new object (instance) of the Dice class
trace("Eyes: " + dice.roll());     // Output: unsigned integer between 1 and 6

Was This Post Helpful? 0
  • +
  • -

#3 ethanyako  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 17-November 10

Re: Roll the dice!

Posted 17 November 2010 - 05:28 PM

hi, may i know where i can get the file "net.dreamincode.as3" ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1