private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("MachineOfPlayer")) { MainMachine machine = collision.gameObject.GetComponent <MainMachine>(); machine.AddHealth(damage); } if (collision.gameObject.CompareTag("Enemy") || collision.gameObject.CompareTag("Player")) { MainCharacter character = collision.gameObject.GetComponent <MainCharacter>(); character.AddHealth(damage); } Destroy(gameObject); }
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; } } }