public void Play() { var thr = new Thread(() => { stats.ActiveWorld = this; stats.ActiveHuman = MainCharacter; stats.ShowDialog(); }); thr.SetApartmentState(ApartmentState.STA); thr.Start(); running = true; Save(false); string input = ""; while (running) { MakeVisible(); Program.UpdateStats(MainCharacter); Program.stats.UpdateWorld(this); switch (CurrentLocation) { case Location.LocationSpot: ActiveBuilding = null; CurrentForestEvent = ForestEvent.None; if (MainCharacter.Health < MainCharacter.MaxHealth) { MainCharacter.AddHealth(MainCharacter.MaxHealth - MainCharacter.Health); WriteLineColor("Your feel rested and now have full health.", ConsoleColor.Green, ConsoleColor.Black); Program.UpdateStats(MainCharacter); Save(); } List <Tuple <string, string, Action> > Commands = new List <Tuple <string, string, Action> >(); Commands.Add(new Tuple <string, string, Action>($"{Commands.Count}: Explore outside.", $"leave,outside,explore,{Commands.Count}", () => { CurrentLocation = Location.Forest; })); if (ActiveLocation == HomeTown) { Commands.Add(new Tuple <string, string, Action>($"{Commands.Count}: Enter your (home) and (sleep).", $"home,sleep,{Commands.Count}", () => { if (!IsDayTime()) { IncrementTime(12); Save(); WriteLineColor("You feel rested...", ConsoleColor.Green, ConsoleColor.Black); } else { WriteLineColor("You don't feel tired it is only " + TimeInDay + ":00. (24 hr time)", ConsoleColor.Red, ConsoleColor.Black); } })); } foreach (var item in ActiveLocation.Buildings) { switch (item.Type) { case BuildingType.Store: Commands.Add(new Tuple <string, string, Action>($"{Commands.Count}: Enter {item.Owner.Name}'s Store.", $"{item.Owner.Name},store,{Commands.Count}", () => { CurrentLocation = Location.Building; ActiveBuilding = item; })); break; case BuildingType.Blacksmith: Commands.Add(new Tuple <string, string, Action>($"{Commands.Count}: Enter {item.Owner.Name}'s Blacksmith.", $"{item.Owner.Name},blacksmith,{Commands.Count}", () => { CurrentLocation = Location.Building; ActiveBuilding = item; })); break; default: break; } } Commands.Add(new Tuple <string, string, Action>($"{Commands.Count}: Close.", $"close,{Commands.Count}", () => { Save(); running = false; Application.Exit(); })); List <string> Options = new List <string>(); var Builder = new StringBuilder($"What would you like to do in {ActiveLocation.Name}?\r\n"); foreach (var item in Commands) { Options.Add(item.Item2); Builder.AppendLine(item.Item1); } input = Question(Builder.ToString(), Options.ToArray()); for (int i = 0; i < Options.Count; i++) { if (input == Commands[i].Item2.ToLower()) { Commands[i].Item3(); break; } } break; case Location.Building: CurrentForestEvent = ForestEvent.None; string Type = ActiveBuilding.Type == BuildingType.Blacksmith ? "Can you make me a " : "Can I buy some "; List <string> Commands4 = new List <string>() { "0,weapon", "1,head", "2,chest", "3,legs", "4,feet", "5,nothing,sorry,leave", "6,sell" }; if (ActiveBuilding.Type == BuildingType.Store) { Commands4.Add("7,tool"); } { Commands4.Add("8,Quests"); } input = Question(string.Format( ActiveBuilding.Owner.Name + @": Welcome to my {1:G}, Can I help you with something? 0: {0}weapon's. 1: {0}head wear. 2: {0}chest wear. 3: {0}leg wear. 4: {0}feet wear. 5: Nothing, Sorry. 6: Sell something." + (ActiveBuilding.Type == BuildingType.Store ? "\r\n7: Buy a Tool." : ""), Type, ActiveBuilding.Type), Commands4.ToArray()); switch (input) { case "0,weapon": ProcessBuyOrMakeItem(Database.Weapons, "Weapons"); break; case "1,head": ProcessBuyOrMakeItem(Database.HeadWear, "Head Wear"); break; case "2,chest": ProcessBuyOrMakeItem(Database.ChestWear, "Chest Wear"); break; case "3,legs": ProcessBuyOrMakeItem(Database.LegWear, "leg Wear"); break; case "4,feet": ProcessBuyOrMakeItem(Database.FeetWear, "feet Wear"); break; case "5,nothing,sorry,leave": WriteLine($"You shut {ActiveBuilding.Owner.Name}'s door and leave the {ActiveBuilding.Type.ToString("G").ToLower()}."); CurrentLocation = Location.LocationSpot; ActiveBuilding = null; break; case "6,sell": stats.ToSellSomething = true; Question($"What do you want to sell? Double click on the item you wish to sell", "yes", "no"); CurrentLocation = Location.LocationSpot; ActiveBuilding = null; break; case "7,tool": ProcessBuyOrMakeItem(Database.Tools, "Tools"); break; } break; case Location.Forest: // some kind of person has appeared. CurrentForestEvent = ForestEvent.None; List <Tuple <string, string, Action> > Commands3 = new List <Tuple <string, string, Action> >(); // get town From X Y var mapItem = Map[CurrentX, CurrentY]; mapItem.Visible = true; Commands3.Add(new Tuple <string, string, Action>($"{Commands3.Count}: Go West?", $"west,left,{Commands3.Count}", () => { stats.ProcessMovement(CurrentX - 1, CurrentY); })); Commands3.Add(new Tuple <string, string, Action>($"{Commands3.Count}: Go North?", $"north,up,{Commands3.Count}", () => { stats.ProcessMovement(CurrentX, CurrentY - 1); })); Commands3.Add(new Tuple <string, string, Action>($"{Commands3.Count}: Go East?", $"east,up,{Commands3.Count}", () => { stats.ProcessMovement(CurrentX + 1, CurrentY); })); Commands3.Add(new Tuple <string, string, Action>($"{Commands3.Count}: Go South?", $"south,up,{Commands3.Count}", () => { stats.ProcessMovement(CurrentX, CurrentY + 1); })); if (mapItem is LocationSpot) { ActiveLocation = mapItem as LocationSpot; WriteLineColor($"You have found a town called {ActiveLocation.Name}", ConsoleColor.Yellow, ConsoleColor.Black); Commands3.Add(new Tuple <string, string, Action>($"{Commands3.Count}: Would you like to enter {ActiveLocation.Name}?", $"{ActiveLocation.Name},yes,{Commands3.Count}", () => { CurrentLocation = Location.LocationSpot; })); } else { ActiveLocation = null; } List <string> Options3 = new List <string>(); var Builder3 = new StringBuilder($"which direction do you want to go?\r\n"); foreach (var item in Commands3) { Options3.Add(item.Item2); Builder3.AppendLine(item.Item1); } if (mapItem is Ground) { ProcessRandomEvent(); if (CurrentLocation == Location.LocationSpot) { continue; } } input = Question(Builder3.ToString(), Options3.ToArray()); for (int i = 0; i < Options3.Count; i++) { if (input == Commands3[i].Item2.ToLower()) { Commands3[i].Item3(); break; } } if (CurrentLocation == Location.Forest) { WriteLine($"Your current location is now {CurrentX}, {CurrentY}."); } break; } } }
public void ProcessAttackScreen(Humanoid Enemy) { stats.UpdateWorld(this); while (Enemy.IsAlive() && MainCharacter.IsAlive()) { Humanoid FirstAttacker = MainCharacter.GetWearablePower().Defence <= Enemy.GetWearablePower().Defence ? MainCharacter : Enemy; Humanoid SecondAttacker = FirstAttacker == MainCharacter ? Enemy : MainCharacter; int damage = 0; if (FirstAttacker == MainCharacter) { if (GetMainCharacterAttackAnswer(out damage)) { return; } else { MainCharacter.AttackOther(Enemy, damage); } if (Enemy.IsAlive()) { AttackMainPlayWithEnemy(Enemy); } } else { AttackMainPlayWithEnemy(Enemy); if (MainCharacter.IsAlive()) { if (GetMainCharacterAttackAnswer(out damage)) { return; } else { MainCharacter.AttackOther(Enemy, damage); } } } } double distance = (new System.Windows.Point(CurrentX, CurrentY) - new System.Windows.Point(HomeTown.X, HomeTown.Y)).LengthSquared; if (distance < 0) { distance = -distance; } int Income = (int)(distance * 0.25d); if (Enemy.IsAlive()) { if (Income > 0) { MainCharacter.Orens -= Income; WriteLineColor($"You have been defeated in battle.", ConsoleColor.DarkMagenta, ConsoleColor.Black); WriteLineColor($"You woke in your bed.", ConsoleColor.DarkMagenta, ConsoleColor.Black); WriteLineColor($"{GetOrenLabel(Income)} have been deducted from your bag...", ConsoleColor.DarkMagenta, ConsoleColor.Black); WriteLineColor($"You now have {GetOrenLabel(MainCharacter.Orens)}", ConsoleColor.Yellow, ConsoleColor.Black); } CurrentLocation = Location.LocationSpot; CurrentX = HomeTown.X; CurrentY = HomeTown.Y; ActiveLocation = HomeTown; ActiveWorld.IncrementTime(12, false); } else { WriteLineColor($"You have defeated your enemy in battle!", ConsoleColor.DarkMagenta, ConsoleColor.Black); switch (Enemy.Race) { case Race.Orc: TotalOrcsDefeated += 1; break; case Race.Human: TotalHumansDefeated += 1; break; case Race.Elf: TotalElfsDefeated += 1; break; default: break; } if (Income > 0) { MainCharacter.Orens += Income; WriteLineColor($"You found {GetOrenLabel(Income)} while searching the enemies body!!!", ConsoleColor.Yellow, ConsoleColor.Black); if (Enemy.Hands != null && Percent(50)) { WriteLineColor($"You have found {Enemy.Hands.Name}.", ConsoleColor.Yellow, ConsoleColor.Black); MainCharacter.Inventory.Items.Add(WeaponItem.Clone(Enemy.Hands)); } WriteLineColor($"You now have {GetOrenLabel(MainCharacter.Orens)}", ConsoleColor.Yellow, ConsoleColor.Black); } ActiveWorld.IncrementTime(1, false); } }
// Base Color 111, 185, 66 // Trees Color 41, 98, 40 // water color 79, 117, 247 // cities color 255, 15, 15 // path, 147, 147, 147 public MapItem[,] GetMapData() { if (RawData == null) { return(null); } var map = new MapItem[RawData.Width, RawData.Height]; for (int x = 0; x < RawData.Width; x++) { for (int y = 0; y < RawData.Height; y++) { var color = RawData.GetPixel(x, y); if (IsTree(color)) { map[x, y] = new Tree() { X = x, Y = y }; } else if (IsWater(color)) { map[x, y] = new Water() { X = x, Y = y }; } else if (IsCity(color)) { bool found = false; for (int i = 0; i < Locations.Count; i++) { if (Locations[i].X == x && Locations[i].Y == y) { map[x, y] = Locations[i]; found = true; break; } } if (!found) { map[x, y] = new LocationSpot() { X = x, Y = y }; Locations.Add((LocationSpot)map[x, y]); } } else if (IsPath(color)) { map[x, y] = new Road() { X = x, Y = y }; } else { map[x, y] = new Ground() { X = x, Y = y }; } } } return(map); }