I'm pretty new to scala and I really love it so far but I'm stuck with a really weird problem. I wanted to try implicit conversions by implementing D&D-style dice expressions. i.e. 2d12 "throw two twelve-sided dice" ... you know what I mean.
From what I understand scala should be able to compile this
(1 d 6).roll and probably even this
1d6 + 2 - 1d30 but I get a "value d is not a member of int" compile error in my specs test.
package meh.toast import scala.util.Random object Dice { class DiceSymbol(val amount:Int) { def d(sides:Int):Dice = new Dice(amount, sides) } implicit def int2DiceSymbol(amount:Int) = new DiceSymbol(amount) implicit def dice2Int(d:Dice) = d.roll private val rnd = new Random() protected def throwDice(sides:Int) = rnd.nextInt(sides) + 1 } class Dice(amount:Int, sides:Int) { def roll:Int = (1 to amount) map { _ => Dice.throwDice(sides)} sum } I'm really stuck. It would be awesome if you could help, it's probably something really simple.
Thanks in advance