private bool ProhibitedAction(Coast coast1, Coast coast2, FermerVariant SelectedVariant) { if (coast1.isFarmare) { switch (SelectedVariant) { case FermerVariant.BackFarmer: case FermerVariant.BackFarmerAndGoat: case FermerVariant.BackFarmerAndCabbage: case FermerVariant.BackFarmerAndWolf: ShowError("You can't do it, farmer on first coast"); return(true); } } else if (coast2.isFarmare) { switch (SelectedVariant) { case FermerVariant.ThereFarmer: case FermerVariant.ThereFarmerAndCabbage: case FermerVariant.ThereFarmerAndGoat: case FermerVariant.ThereFarmerAndWolf: ShowError("You can't do it, farmer on second coast"); return(true); } } return(false); }
public override void Run() { Console.Clear(); ShowTheCondition(); string UserAnswer; FermerVariant SelectedVariant; Coast coast1 = new Coast(true); Coast coast2 = new Coast(); FarmerProperty?farmerProperty; while (true) { UserAnswer = AskUser("Please, type numbers by step (0 to repeat the rules)"); if (UserAnswer.ToLower() == "q") { return; } else if (!Enum.TryParse(UserAnswer, out SelectedVariant) || !Enum.IsDefined(typeof(FermerVariant), SelectedVariant)) { continue; } if (SelectedVariant == FermerVariant.Repeat) { ShowTheCondition(); continue; } if (ProhibitedAction(coast1, coast2, SelectedVariant)) { continue; } switch (SelectedVariant) { case FermerVariant.ThereFarmer: case FermerVariant.BackFarmer: farmerProperty = null; break; case FermerVariant.ThereFarmerAndWolf: case FermerVariant.BackFarmerAndWolf: farmerProperty = FarmerProperty.wolf; break; case FermerVariant.ThereFarmerAndGoat: case FermerVariant.BackFarmerAndGoat: farmerProperty = FarmerProperty.goat; break; case FermerVariant.ThereFarmerAndCabbage: case FermerVariant.BackFarmerAndCabbage: farmerProperty = FarmerProperty.cabbage; break; case FermerVariant.ShowFirstCoast: coast1.ShowCoast(); continue; case FermerVariant.ShowSecondCoast: coast2.ShowCoast(); continue; default: ShowError("unknown error, try again"); continue; } if (coast1.StepCheck(farmerProperty) && coast2.StepCheck(farmerProperty)) { coast1.StepRun(farmerProperty); coast2.StepRun(farmerProperty); forReturn = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Step was success"); Console.ForegroundColor = forReturn; if (coast2.AllIn()) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("You WIN!!!"); Console.ReadLine(); return; } } } }