c# - Best practice for recursive class -
problem:
i want build class custom dice
. should provide following:
side
can contain other dice
the number of sides
should dynamically expandable, must @ to the lowest degree contain 1 logically dice
need have currentside
every side
has property
, provides content of side (on d6, "4"
) so far good, went , made 2 classes dice
, side
, gave them properties think needed.
public class side { //public bool hasdice { { homecoming dice != null; } } - removed not needed public dice dice { get; set; } public string value { get; set; } } public class dice { public observablecollection<side> sides { get; set; } public string name { get; set; } public side currentside { get; set; } }
is right, never made recursive classes i'm not sure ?
also how able observe if same dice , side "endlessly" referring them self.
like:
d1.currentside = side1; side1.dice = d1;
should check when building objects ?
edit:
if d1 rolls s2 d2 shouldn't rolled. d2.dice = null
.
if d1 rolls s1 d2 should rolled.
if d2 rolls s1 d3 should rolled.
if d2 rolls s2 d4 should rolled.d3 , d4 shouldn't trigger roll.
what making called state machine. programme (the "machine") in state, can alter state consequence of performing action. depending on logic can quite acceptable machine can in same state more once. so, wouldn't bother much loops in machine's logic. if user wants loop allow him have it, long machine can reach final state , programme reaches end of execution.
c# class recursion self-reference dice
No comments:
Post a Comment