From 0959949f6c675cb26b18a36e991d001629d0b266 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 29 Apr 2020 09:32:35 +0300 Subject: Implimented difficulty (changes map geenration rates). Updated executable. --- Mundus Build 29-04-2020 No1.exe | Bin 954368 -> 0 bytes Mundus Build 29-04-2020 No2.exe | Bin 0 -> 955904 bytes Mundus/Data/Difficulty.cs | 12 ++++++++++++ Mundus/Data/Tiles/ToolTypes.cs | 6 +++--- Mundus/Data/Windows/WI.cs | 2 +- Mundus/Mundus.csproj | 1 + Mundus/Service/GameGenerator.cs | 15 +++++++++++++++ .../Generators/LandSuperLayerGenerator.cs | 10 ++++++---- Mundus/Views/Windows/NewGameWindow.cs | 20 ++++++++++++++++++++ .../gtk-gui/Mundus.Views.Windows.NewGameWindow.cs | 5 +++++ Mundus/gtk-gui/gui.stetic | 5 +++++ 11 files changed, 68 insertions(+), 8 deletions(-) delete mode 100644 Mundus Build 29-04-2020 No1.exe create mode 100644 Mundus Build 29-04-2020 No2.exe create mode 100644 Mundus/Data/Difficulty.cs diff --git a/Mundus Build 29-04-2020 No1.exe b/Mundus Build 29-04-2020 No1.exe deleted file mode 100644 index d60c607..0000000 Binary files a/Mundus Build 29-04-2020 No1.exe and /dev/null differ diff --git a/Mundus Build 29-04-2020 No2.exe b/Mundus Build 29-04-2020 No2.exe new file mode 100644 index 0000000..df4db7d Binary files /dev/null and b/Mundus Build 29-04-2020 No2.exe differ diff --git a/Mundus/Data/Difficulty.cs b/Mundus/Data/Difficulty.cs new file mode 100644 index 0000000..d109ab9 --- /dev/null +++ b/Mundus/Data/Difficulty.cs @@ -0,0 +1,12 @@ +using System; +namespace Mundus.Data { + public static class Difficulty { + public const int Peaceful = -5; + public const int Easy = 0; + public const int Normal = 10; + public const int Hard = 40; + public const int Insane = 200; + + public static int SelDifficulty { get; set; } + } +} diff --git a/Mundus/Data/Tiles/ToolTypes.cs b/Mundus/Data/Tiles/ToolTypes.cs index 3548af7..1acbb9d 100644 --- a/Mundus/Data/Tiles/ToolTypes.cs +++ b/Mundus/Data/Tiles/ToolTypes.cs @@ -1,7 +1,7 @@ namespace Mundus.Data.Tiles { public static class ToolTypes { - public static int Shovel = 0; - public static int Axe = 1; - public static int Pickaxe = 2; + public const int Shovel = 0; + public const int Axe = 1; + public const int Pickaxe = 2; } } diff --git a/Mundus/Data/Windows/WI.cs b/Mundus/Data/Windows/WI.cs index 71f24d4..a0ed399 100644 --- a/Mundus/Data/Windows/WI.cs +++ b/Mundus/Data/Windows/WI.cs @@ -2,7 +2,7 @@ namespace Mundus.Data.Windows { public static class WI { //stands for Window Instances - public const string BuildName = "Build 29-04-2020 No1"; + public const string BuildName = "Build 29-04-2020 No2"; public static IGameWindow SelWin { get; set; } diff --git a/Mundus/Mundus.csproj b/Mundus/Mundus.csproj index 4f4c787..f3af57b 100644 --- a/Mundus/Mundus.csproj +++ b/Mundus/Mundus.csproj @@ -151,6 +151,7 @@ + diff --git a/Mundus/Service/GameGenerator.cs b/Mundus/Service/GameGenerator.cs index 61c08e9..94e26fe 100644 --- a/Mundus/Service/GameGenerator.cs +++ b/Mundus/Service/GameGenerator.cs @@ -46,5 +46,20 @@ namespace Mundus.Service { WI.SelWin.PrintMainMenu(); WI.SelWin.Show(); } + + /// + /// Sets the game difficulty (that affects map generation). + /// + /// Must be "peaceful", "easy", "normal", "hard" or "insane" + public static void SetDifficulty(string value) { + switch(value.ToLower()) { + case "peaceful": Difficulty.SelDifficulty = Difficulty.Peaceful; break; + case "easy": Difficulty.SelDifficulty = Difficulty.Easy; break; + case "normal": Difficulty.SelDifficulty = Difficulty.Normal; break; + case "hard": Difficulty.SelDifficulty = Difficulty.Hard; break; + case "insane": Difficulty.SelDifficulty = Difficulty.Insane; break; + default: throw new ArgumentException($"Invalid difficulty value {value}. Must be \"peaceful\", \"easy\", \"normal\", \"hard\" or \"insane\""); + } + } } } diff --git a/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs b/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs index d34bd9a..7644958 100644 --- a/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs +++ b/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs @@ -1,4 +1,5 @@ using System; +using Mundus.Data; using Mundus.Data.Superlayers.Mobs; using Mundus.Data.SuperLayers; using Mundus.Service.Mobs.LandMobs; @@ -29,7 +30,7 @@ namespace Mundus.Service.SuperLayers.Generators { MI.Player.XPos = y; tiles[y, x] = MI.Player; } - else if (rnd.Next(0, 20) == 1) { + else if (rnd.Next(0, 20 + Difficulty.SelDifficulty) == 1) { tiles[y, x] = LandMobsPresets.GetACow(); tiles[y, x].YPos = y; tiles[y, x].XPos = x; @@ -46,7 +47,8 @@ namespace Mundus.Service.SuperLayers.Generators { for(int col = 0; col < size; col++) { for(int row = 0; row < size; row++) { - if (rnd.Next(0, 200) == 1) { + // Holes in the ground should be more common with higher difficulties + if (rnd.Next(0, 210 - Difficulty.SelDifficulty) == 1) { tiles[col, row] = null; } else { @@ -63,10 +65,10 @@ namespace Mundus.Service.SuperLayers.Generators { for (int col = 0; col < size; col++) { for (int row = 0; row < size; row++) { if (LI.Land.GetGroundLayerTile(col, row) != null) { - if (rnd.Next(0, 50) == 1) { + if (rnd.Next(0, 40 + Difficulty.SelDifficulty) == 1) { tiles[col, row] = StructurePresets.GetALBoulder(); } - if (rnd.Next(0, 10) == 1) { + if (rnd.Next(0, 10 + Difficulty.SelDifficulty) == 1) { tiles[col, row] = StructurePresets.GetALTree(); } } diff --git a/Mundus/Views/Windows/NewGameWindow.cs b/Mundus/Views/Windows/NewGameWindow.cs index 61999d7..d1e9bec 100644 --- a/Mundus/Views/Windows/NewGameWindow.cs +++ b/Mundus/Views/Windows/NewGameWindow.cs @@ -121,5 +121,25 @@ namespace Mundus.Views.Windows { GameGenerator.GameWindowSizeSetup(gameWindow); } + + protected void OnRbPeacefulToggled(object sender, EventArgs e) { + GameGenerator.SetDifficulty("peaceful"); + } + + protected void OnRbEasyToggled(object sender, EventArgs e) { + GameGenerator.SetDifficulty("easy"); + } + + protected void OnRbNormalToggled(object sender, EventArgs e) { + GameGenerator.SetDifficulty("normal"); + } + + protected void OnRbHardToggled(object sender, EventArgs e) { + GameGenerator.SetDifficulty("hard"); + } + + protected void OnRbInsaneToggled(object sender, EventArgs e) { + GameGenerator.SetDifficulty("insane"); + } } } diff --git a/Mundus/gtk-gui/Mundus.Views.Windows.NewGameWindow.cs b/Mundus/gtk-gui/Mundus.Views.Windows.NewGameWindow.cs index 81f98a1..13f023a 100644 --- a/Mundus/gtk-gui/Mundus.Views.Windows.NewGameWindow.cs +++ b/Mundus/gtk-gui/Mundus.Views.Windows.NewGameWindow.cs @@ -458,8 +458,13 @@ namespace Mundus.Views.Windows this.Show(); this.DeleteEvent += new global::Gtk.DeleteEventHandler(this.OnDeleteEvent); this.rbSmall.Toggled += new global::System.EventHandler(this.OnRbSmallToggled); + this.rbPeaceful.Toggled += new global::System.EventHandler(this.OnRbPeacefulToggled); + this.rbNormal.Toggled += new global::System.EventHandler(this.OnRbNormalToggled); this.rbMedium.Toggled += new global::System.EventHandler(this.OnRbMediumToggled); this.rbLarge.Toggled += new global::System.EventHandler(this.OnRbLargeToggled); + this.rbInsane.Toggled += new global::System.EventHandler(this.OnRbInsaneToggled); + this.rbHard.Toggled += new global::System.EventHandler(this.OnRbHardToggled); + this.rbEasy.Toggled += new global::System.EventHandler(this.OnRbEasyToggled); this.rbCreative.Toggled += new global::System.EventHandler(this.OnRbCreativeToggled); this.btnGenerate.Clicked += new global::System.EventHandler(this.OnBtnGenerateClicked); this.btnBack.Clicked += new global::System.EventHandler(this.OnBtnBackClicked); diff --git a/Mundus/gtk-gui/gui.stetic b/Mundus/gtk-gui/gui.stetic index 5220cf1..9f2ff87 100644 --- a/Mundus/gtk-gui/gui.stetic +++ b/Mundus/gtk-gui/gui.stetic @@ -558,6 +558,7 @@ True True Difficulty + 3 @@ -585,6 +586,7 @@ True True Difficulty + 3 @@ -612,6 +614,7 @@ True True Difficulty + 3 @@ -777,6 +780,7 @@ True True Difficulty + 3 @@ -804,6 +808,7 @@ True True Difficulty + 3 -- cgit v1.2.3