static void Main(string[] args) { Disc five = new Disc(5); Disc ten = new Disc(10); Disc fifteen = new Disc(15); Disc twenty = new Disc(20); Disc[] initialStack = { twenty, fifteen, ten, five }; Stick rodOne = new Stick(initialStack, "1"); Stick rodTwo = new Stick(new Disc[4], "2"); Stick rodThree = new Stick(new Disc[4], "3"); Stick fromStick = null; Stick toStick = null; Console.WriteLine(""); rodOne.reportDiscs(); rodTwo.reportDiscs(); rodThree.reportDiscs(); Console.WriteLine(""); while (rodOne.WinFlag == false && rodTwo.WinFlag == false && rodThree.WinFlag == false) { Console.WriteLine("Move from? (Enter 1, 2 or 3)"); string from = Console.ReadLine(); Console.WriteLine("Move to? (Enter 1, 2 or 3)"); string to = Console.ReadLine(); Stick [] rods = { rodOne, rodTwo, rodThree }; foreach (Stick stickin rods) { if (stick.Number == from) { fromStick = stick; } if (stick.Number == to) { toStick = stick; } } if (fromStick != null && toStick != null) { fromStick.checkAndMove(toStick); fromStick = null; toStick = null; } else { Stick.printErrorMessage(); } rodOne.reportDiscs(); rodTwo.reportDiscs(); rodThree.reportDiscs(); Console.WriteLine(""); } }
public void checkAndMove(Stick dest) { if (this.Stack[0] != null) { Disc md = this.MoveDisc(dest); if (md != null) { Console.WriteLine($"\nMoved size {md.Size} disc to stick{dest.Number}\n"); if (dest.checkForWin()) { dest.WinFlag = true; } return; } } printErrorMessage(); }