// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Yatzy { public class Program { public static void Main(string[] args) { DiceCup MyCup = new DiceCup(5); foreach(Dice d in MyCup.Dices) { Console.WriteLine(d.Value); } Console.ReadLine(); } } public class Dice { private static Random random = new Random(); private int _value; public bool Holding { get; set; } public Dice() { ThrowDice(); } public void ThrowDice() { _value = random.Next(1, 6); } public int Value { get { return _value; } } } public class DiceCup { private List _dices = new List(); public IList Dices { get { return _dices.AsReadOnly(); } } public DiceCup(int dices) { for(int i=0;i d.ThrowDice()); } public void SetHoldToAll() { _dices.ForEach((Dice d) => d.Holding = true); } public void UnSetHoldToAll() { _dices.ForEach((Dice d) => d.Holding = false); } } }