From ccec3490d93d6de1cca259d2c6fa6ac185fb50b9 Mon Sep 17 00:00:00 2001 From: JFronny <33260128+JFronny@users.noreply.github.com> Date: Sat, 13 Jun 2020 12:15:11 +0200 Subject: [PATCH] Stuffs --- Lemonade/AnimationScreen.cs | 5 ++- Lemonade/PlayerState.cs | 65 ++++++++++++++++++++++++++--------- Lemonade/ResultScreen.cs | 13 +++++-- Lemonade/ScreenManager.cs | 22 +++++++++--- Lemonade/TransactionScreen.cs | 4 +++ Lemonade/Weather.cs | 12 ++++++- 6 files changed, 93 insertions(+), 28 deletions(-) diff --git a/Lemonade/AnimationScreen.cs b/Lemonade/AnimationScreen.cs index 5d5b090..356c73a 100644 --- a/Lemonade/AnimationScreen.cs +++ b/Lemonade/AnimationScreen.cs @@ -13,12 +13,12 @@ namespace Lemonade private readonly Image imgControl; - public AnimationScreen(Settings set) : base(100, 20, Black, set.Color) + public AnimationScreen(Settings settings) : base(100, 20, Black, settings.Color) { ContentPanel.ForeColor = DarkGray; Title = "Lemonade - Anim"; imgControl = new Image(new Pixel[0, 0]); - SetWeather(new Weather()); + SetWeather(new Weather(settings)); ContentPanel.Controls.Add(imgControl); Input += (screen, args) => Ok?.Invoke(); Close += (screen, args) => Ok?.Invoke(); @@ -29,7 +29,6 @@ namespace Lemonade public void SetWeather(Weather w) { Title = $"Lemonade - Weather: {w}"; - //TODO weather events (storm (no sales), heat wave (more sales)) Pixel sky = new Pixel(w.W switch { Rainy => Black, diff --git a/Lemonade/PlayerState.cs b/Lemonade/PlayerState.cs index 39a1d15..9ca6dab 100644 --- a/Lemonade/PlayerState.cs +++ b/Lemonade/PlayerState.cs @@ -1,15 +1,45 @@ using System; +using System.Collections.Generic; namespace Lemonade { public class PlayerState { +#region Autogenerated equality comparison stuff + protected bool Equals(PlayerState other) => Number == other.Number; + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((PlayerState) obj); + } + + public override int GetHashCode() => Number; + + private sealed class NumberEqualityComparer : IEqualityComparer + { + public bool Equals(PlayerState x, PlayerState y) + { + if (ReferenceEquals(x, y)) return true; + if (ReferenceEquals(x, null)) return false; + if (ReferenceEquals(y, null)) return false; + if (x.GetType() != y.GetType()) return false; + return x.Number == y.Number; + } + + public int GetHashCode(PlayerState obj) => obj.Number; + } + + public static IEqualityComparer NumberComparer { get; } = new NumberEqualityComparer(); +#endregion + public readonly int Number; public int Budget; public int Earnings; public int Expenses; public int Glasses; public int GlassPrice; - public int Number; public int Sales; public int Signs; @@ -19,24 +49,27 @@ namespace Lemonade Number = number; } + //TODO (maybe) balance, increase difficulty? public void CalculateIncome(int signCost, int glassCost, Weather weather, Settings settings) { + //Calculate combined expenses Expenses = signCost * Signs + glassCost * Glasses; - - double weatherFactor = - (weather.Factor * 2 + 1d) / (settings.DifficultyFactor * 2d + 1d) / - 2d; //calculate a scalar for sales between 0.2 and 1.5 based on the weather factor - double signFactor = - 2.5d - (settings.DifficultyFactor + 0.1) * 2d / - (Signs + 1d); //calculate a scalar between 0.3 and (basically) 2.5 based on the amount of signs - double - priceFactor = - 3 / (GlassPrice / 2 + - 1); //calculate a scalar between (basically) 0 and 3 based on the price of lemonades - Sales = (int) Math.Max(Math.Min(weatherFactor * signFactor * priceFactor * Glasses, Glasses), - 0); //Multiply the factors and sanitize results - Earnings = (int) Math.Floor((double) Sales * GlassPrice); //Convert result to integer - + //Calculate a scalar for sales between 0.2 and 1.5 based on the weather factor + double weatherFactor = (weather.Factor * 2 + 1d) / (settings.DifficultyFactor * 2d + 1d) / 2d; + //Calculate a scalar between 0.3 and (basically) 2.5 based on the amount of signs + double signFactor = 2.5d - (settings.DifficultyFactor + 0.1) * 2d / (Signs + 1d); + //Calculate a scalar between (basically) 0 and 3 based on the price of lemonades + double priceFactor = 3 / (GlassPrice / 2d + 1); + //Multiply the factors and sanitize results + Sales = (int) (weatherFactor * signFactor * priceFactor * Glasses); + //Apply weather events to Sales + if (weather.Heatwave) Sales = (int) (Sales * 1.2); + if (weather.Thunderstorm) Sales = 0; + //Sanitize sales + Sales = Math.Max(Math.Min(Sales, Glasses), 0); + //Calculate earnings from sales + Earnings = (int) Math.Floor((double) Sales * GlassPrice); + //Calculate new budget Budget += Earnings - Expenses; } } diff --git a/Lemonade/ResultScreen.cs b/Lemonade/ResultScreen.cs index 1e6bd7d..e582710 100644 --- a/Lemonade/ResultScreen.cs +++ b/Lemonade/ResultScreen.cs @@ -24,12 +24,19 @@ namespace Lemonade public event OkDelegate Ok; - public void Setup(IEnumerable players) + public void Setup(IEnumerable players, Weather weather) { - lab.Content = players.ToStringTable( + if (weather.Heatwave) + lab.Content = "There was a heatwave"; + else if (weather.Thunderstorm) + lab.Content = "Lightning struck your table while you were setting it up. Nothing was sold"; + else + lab.Content = $"The weather was {weather}. Nothing out of the ordinary happened"; + lab.Content += Environment.NewLine + players.ToStringTable( new[] { - "Player", "Glasses made", "Earnings per glass", "Glasses sold", "Signs made", "Income", "Expenses", + "Player", "Glasses made", "Earnings per glass", "Glasses sold", "Signs made", + "Income", "Expenses", "Profit", "Budget" }, s => s.Number, diff --git a/Lemonade/ScreenManager.cs b/Lemonade/ScreenManager.cs index 31bb689..16eced0 100644 --- a/Lemonade/ScreenManager.cs +++ b/Lemonade/ScreenManager.cs @@ -1,20 +1,22 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading; +using CC_Functions.Commandline.TUI; namespace Lemonade { - //TODO implement thunderstorm chance on bad weather + //TODO implement visual feedback for weather events public class ScreenManager { private readonly AnimationScreen _animator; + private readonly List _players; private readonly ResultScreen _result; private readonly Settings _settings; private readonly TransactionScreen _transaction; private int _currentPlayer; private int _day; private bool _initialEvent = true; - private readonly List _players; private bool _running; private GameState _state; private Weather _weather; @@ -75,8 +77,7 @@ namespace Lemonade case GameState.Setup: if (_initialEvent) { - _day++; - _weather = new Weather(); + _weather = new Weather(_settings); _animator.SetWeather(_weather); _animator.Render(); _initialEvent = false; @@ -98,8 +99,19 @@ namespace Lemonade case GameState.Event: if (_initialEvent) { - _result.Setup(_players); + _result.Setup(_players, _weather); _result.Render(); + _day++; + if (_players.Any(s => s.Budget < GlassCost)) + { + Console.Clear(); + IEnumerable lost = _players.Where(s => s.Budget < GlassCost); + Console.WriteLine($"The following players are out: {string.Join(", ", lost.Select(s => s.Number.ToString()))}"); + Thread.Sleep(2000); + Console.Clear(); + _players.RemoveAll(s => lost.Contains(s)); + } + DiffDraw.Draw(_settings.Color, true); _initialEvent = false; } _result.ReadInput(); diff --git a/Lemonade/TransactionScreen.cs b/Lemonade/TransactionScreen.cs index 344e3fe..cf90260 100644 --- a/Lemonade/TransactionScreen.cs +++ b/Lemonade/TransactionScreen.cs @@ -84,6 +84,10 @@ namespace Lemonade _signs.Value = 0; CalculateMax(); _infoLabel.Content = $"It is day {day}, the weather is {weather}"; + if (weather.W == W.Hot_and_dry) + _infoLabel.Content += ". There is a chance of heatwaves"; + else if (weather.W == W.Rainy) + _infoLabel.Content += ". There is a chance of thunderstorms"; _infoLabel.Point = new Point(ContentPanel.Size.Width / 2 - _infoLabel.Content.Length / 2, 0); _glassesLabel.Content = $"How many glasses of lemonade do you wish to make? {lemonadeCost}ct each"; _glassesLabel.Point = new Point(ContentPanel.Size.Width / 2 - _glassesLabel.Content.Length / 2, 2); diff --git a/Lemonade/Weather.cs b/Lemonade/Weather.cs index 11284c7..30695a5 100644 --- a/Lemonade/Weather.cs +++ b/Lemonade/Weather.cs @@ -6,7 +6,17 @@ namespace Lemonade { private static readonly Random rnd = new Random(); - public double Factor = rnd.NextDouble(); + public readonly bool Heatwave; + public readonly bool Thunderstorm; + + public double Factor; + + public Weather(Settings settings) + { + Factor = rnd.NextDouble(); + Heatwave = W == W.Hot_and_dry && rnd.NextDouble() > settings.DifficultyFactor; + Thunderstorm = W == W.Rainy && rnd.NextDouble() < settings.DifficultyFactor; + } public W W {