public void Move() { int state = 0, tempState; int EndState = 15; while (state != EndState) { tempState = MovePerson(state); if (IsVaild(tempState)) { state = tempState; Console.WriteLine(state > 8 ? "人独自一人从A岸到达B岸" : "人独自一人从B岸到达A岸"); }
if (IsPeopleWithSheep(state)) { tempState = MovePersonWithSheep(state); if (IsVaild(tempState)) { state = tempState; Console.WriteLine(state > 8 ? "人带羊从A岸到达B岸" : "人带羊从B岸到达A岸"); } }
if (IsPeopleWithWolf(state)) { tempState = MovePersonWithWolf(state); if (IsVaild(tempState)) { state = tempState; Console.WriteLine(state > 8 ? "人带狼从A岸到达B岸" : "人带狼从B岸到达A岸"); } }
if (IsPeopleWithGreens(state)) { tempState = MovePersonWithGreens(state); if (IsVaild(tempState)) { state = tempState; Console.WriteLine(state > 8 ? "人带菜从A岸到达B岸" : "人带菜从B岸到达A岸"); } } } }
执行以上逻辑函数
1 2 3 4
Console.WriteLine("MoveClass 开始"); new MoveClass().Move(); Console.WriteLine("MoveClass 结束"); Console.ReadKey();