Automatic Refactor UwU

This commit is contained in:
JFronny 2020-06-12 20:16:11 +02:00
parent 26131b1c4d
commit 199a27bcad
11 changed files with 129 additions and 108 deletions

8
.idea/.idea.Lemonade/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/modules.xml
/projectSettingsUpdater.xml
/.idea.Lemonade.iml
/contentModel.xml

View File

@ -9,20 +9,23 @@ namespace Lemonade
{ {
public class AnimationScreen : CenteredScreen public class AnimationScreen : CenteredScreen
{ {
public event OkDelegate Ok;
public delegate void OkDelegate(); public delegate void OkDelegate();
private Image imgControl;
private readonly Image imgControl;
public AnimationScreen(Settings set) : base(100, 20, Black, set.Color) public AnimationScreen(Settings set) : base(100, 20, Black, set.Color)
{ {
ContentPanel.ForeColor = DarkGray; ContentPanel.ForeColor = DarkGray;
Title = "Lemonade - Anim"; Title = "Lemonade - Anim";
imgControl = new Image(new Pixel[0,0]); imgControl = new Image(new Pixel[0, 0]);
SetWeather(new Weather()); SetWeather(new Weather());
ContentPanel.Controls.Add(imgControl); ContentPanel.Controls.Add(imgControl);
Input += (screen, args) => Ok?.Invoke(); Input += (screen, args) => Ok?.Invoke();
Close += (screen, args) => Ok?.Invoke(); Close += (screen, args) => Ok?.Invoke();
} }
public event OkDelegate Ok;
public void SetWeather(Weather w) public void SetWeather(Weather w)
{ {
Title = $"Lemonade - Weather: {w}"; Title = $"Lemonade - Weather: {w}";

View File

@ -4,14 +4,11 @@ using CC_Functions.Commandline.TUI;
namespace Lemonade namespace Lemonade
{ {
//Mostly kang from Stackoverflow
public static class EllipseDrawer public static class EllipseDrawer
{ {
private static PointF GetEllipsePointFromX(float x, float a, float b) => private static PointF GetEllipsePointFromX(float x, float a, float b) =>
//(x/a)^2 + (y/b)^2 = 1 new PointF(x, b * -(float) Math.Sqrt(1 - x * x / a / a));
//(y/b)^2 = 1 - (x/a)^2
//y/b = -sqrt(1 - (x/a)^2) --Neg root for upper portion of the plane
//y = b*-sqrt(1 - (x/a)^2)
new PointF(x, b * -(float)Math.Sqrt(1 - x * x / a / a));
public static void DrawEllipse(this Pixel[,] target, Rectangle area, Pixel basePixel) public static void DrawEllipse(this Pixel[,] target, Rectangle area, Pixel basePixel)
{ {
@ -27,52 +24,47 @@ namespace Lemonade
private static void DrawEllipse(bool[,] pixels, Rectangle area) private static void DrawEllipse(bool[,] pixels, Rectangle area)
{ {
// Get the size of the matrix
int matrixWidth = pixels.GetLength(0); int matrixWidth = pixels.GetLength(0);
int matrixHeight = pixels.GetLength(1); int matrixHeight = pixels.GetLength(1);
int offsetY = area.Top; int offsetY = area.Top;
int offsetX = area.Left; int offsetX = area.Left;
// Figure out how big the ellipse is
float ellipseWidth = area.Width; float ellipseWidth = area.Width;
float ellipseHeight = area.Height; float ellipseHeight = area.Height;
// Figure out the radiuses of the ellipses
float radiusX = ellipseWidth / 2; float radiusX = ellipseWidth / 2;
float radiusY = ellipseHeight / 2; float radiusY = ellipseHeight / 2;
//Keep track of the previous y position
int prevY = 0; int prevY = 0;
bool firstRun = true; bool firstRun = true;
// Loop through the points in the matrix
for (int x = 0; x <= radiusX; ++x) for (int x = 0; x <= radiusX; ++x)
{ {
int xPos = x + offsetX; int xPos = x + offsetX;
int rxPos = (int)ellipseWidth - x - 1 + offsetX; int rxPos = (int) ellipseWidth - x - 1 + offsetX;
if (xPos < 0 || rxPos < xPos || xPos >= matrixWidth) continue; if (xPos < 0 || rxPos < xPos || xPos >= matrixWidth) continue;
PointF pointOnEllipseBoundCorrespondingToXMatrixPosition = GetEllipsePointFromX(x - radiusX, radiusX, radiusY); PointF pointOnEllipseBoundCorrespondingToXMatrixPosition =
int y = (int) Math.Floor(pointOnEllipseBoundCorrespondingToXMatrixPosition.Y + (int)radiusY); GetEllipsePointFromX(x - radiusX, radiusX, radiusY);
int y = (int) Math.Floor(pointOnEllipseBoundCorrespondingToXMatrixPosition.Y + (int) radiusY);
int yPos = y + offsetY; int yPos = y + offsetY;
int ryPos = (int)ellipseHeight - y - 1 + offsetY; int ryPos = (int) ellipseHeight - y - 1 + offsetY;
if (yPos >= 0) if (yPos >= 0)
{ {
if (xPos < matrixWidth && yPos < matrixHeight) pixels[xPos, yPos] = true; if (xPos < matrixWidth && yPos < matrixHeight) pixels[xPos, yPos] = true;
if(xPos < matrixWidth && ryPos > -1 && ryPos < matrixHeight) pixels[xPos, ryPos] = true; if (xPos < matrixWidth && ryPos > -1 && ryPos < matrixHeight) pixels[xPos, ryPos] = true;
if (rxPos < matrixWidth) if (rxPos < matrixWidth)
{ {
if (yPos < matrixHeight) pixels[rxPos, yPos] = true; if (yPos < matrixHeight) pixels[rxPos, yPos] = true;
if (ryPos > -1 && ryPos < matrixHeight) pixels[rxPos, ryPos] = true; if (ryPos > -1 && ryPos < matrixHeight) pixels[rxPos, ryPos] = true;
} }
} }
//While there's a >1 jump in y, fill in the gap (assumes that this is not the first time we've tracked y, x != 0)
for (int j = prevY - 1; !firstRun && j > y - 1 && y > 0; --j) for (int j = prevY - 1; !firstRun && j > y - 1 && y > 0; --j)
{ {
int jPos = j + offsetY; int jPos = j + offsetY;
int rjPos = (int)ellipseHeight - j - 1 + offsetY; int rjPos = (int) ellipseHeight - j - 1 + offsetY;
if(jPos == rjPos - 1) continue; if (jPos == rjPos - 1) continue;
if(jPos > -1 && jPos < matrixHeight) pixels[xPos, jPos] = true; if (jPos > -1 && jPos < matrixHeight) pixels[xPos, jPos] = true;
if(rjPos > -1 && rjPos < matrixHeight) pixels[xPos, rjPos] = true; if (rjPos > -1 && rjPos < matrixHeight) pixels[xPos, rjPos] = true;
if (rxPos < matrixWidth) if (rxPos < matrixWidth)
{ {
if(jPos > -1 && jPos < matrixHeight) pixels[rxPos, jPos] = true; if (jPos > -1 && jPos < matrixHeight) pixels[rxPos, jPos] = true;
if(rjPos > -1 && rjPos < matrixHeight) pixels[rxPos, rjPos] = true; if (rjPos > -1 && rjPos < matrixHeight) pixels[rxPos, rjPos] = true;
} }
} }
firstRun = false; firstRun = false;
@ -82,14 +74,12 @@ namespace Lemonade
{ {
++yPos; ++yPos;
--ryPos; --ryPos;
// Set all four points in the matrix we just learned about if (yPos > -1 && yPos < matrixHeight) pixels[xPos, yPos] = true;
// also, make the indication that for the rest of this row, we need to fill the body of the ellipse if (ryPos > -1 && ryPos < matrixHeight) pixels[xPos, ryPos] = true;
if(yPos > -1 && yPos < matrixHeight) pixels[xPos, yPos] = true;
if(ryPos > -1 && ryPos < matrixHeight) pixels[xPos, ryPos] = true;
if (rxPos < matrixWidth) if (rxPos < matrixWidth)
{ {
if(yPos > -1 && yPos < matrixHeight) pixels[rxPos, yPos] = true; if (yPos > -1 && yPos < matrixHeight) pixels[rxPos, yPos] = true;
if(ryPos > -1 && ryPos < matrixHeight) pixels[rxPos, ryPos] = true; if (ryPos > -1 && ryPos < matrixHeight) pixels[rxPos, ryPos] = true;
} }
} }
} }

View File

@ -7,8 +7,8 @@ namespace Lemonade
public Pixel[,] Img; public Pixel[,] Img;
public Image(Pixel[,] img) => Img = img; public Image(Pixel[,] img) => Img = img;
public override Pixel[,] Render() => Img;
public override bool Selectable { get; } = false; public override bool Selectable { get; } = false;
public override Pixel[,] Render() => Img;
} }
} }

View File

@ -5,13 +5,13 @@ namespace Lemonade
public class PlayerState public class PlayerState
{ {
public int Budget; public int Budget;
public int Glasses;
public int Signs;
public int GlassPrice;
public int Expenses;
public int Earnings; public int Earnings;
public int Sales; public int Expenses;
public int Glasses;
public int GlassPrice;
public int Number; public int Number;
public int Sales;
public int Signs;
public PlayerState(int number) public PlayerState(int number)
{ {
@ -22,13 +22,21 @@ namespace Lemonade
public void CalculateIncome(int signCost, int glassCost, Weather weather, Settings settings) public void CalculateIncome(int signCost, int glassCost, Weather weather, Settings settings)
{ {
Expenses = signCost * Signs + glassCost * Glasses; 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 weatherFactor =
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 (weather.Factor * 2 + 1d) / (settings.DifficultyFactor * 2d + 1d) /
double priceFactor = 3 / (GlassPrice / 2 + 1); //calculate a scalar between (basically) 0 and 3 based on the price of lemonades 2d; //calculate a scalar for sales between 0.2 and 1.5 based on the weather factor
Sales = (int)Math.Max(Math.Min(weatherFactor * signFactor * priceFactor * Glasses, Glasses), 0); //Multiply the factors and sanitize results double signFactor =
Earnings = (int)Math.Floor((double)Sales * GlassPrice); //Convert result to integer 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
Budget += Earnings - Expenses; Budget += Earnings - Expenses;
} }
} }

View File

@ -2,9 +2,9 @@
namespace Lemonade namespace Lemonade
{ {
class Program internal class Program
{ {
static void Main(string[] args) private static void Main(string[] args)
{ {
Console.BackgroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.White;

View File

@ -1,7 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using CC_Functions.Commandline; using CC_Functions.Commandline;
using CC_Functions.Commandline.TUI; using CC_Functions.Commandline.TUI;
@ -10,9 +8,10 @@ namespace Lemonade
{ {
public class ResultScreen : CenteredScreen public class ResultScreen : CenteredScreen
{ {
public event OkDelegate Ok;
public delegate void OkDelegate(); public delegate void OkDelegate();
private Label lab;
private readonly Label lab;
public ResultScreen(Settings settings) : base(200, 20, ConsoleColor.Black, settings.Color) public ResultScreen(Settings settings) : base(200, 20, ConsoleColor.Black, settings.Color)
{ {
ContentPanel.ForeColor = ConsoleColor.DarkGray; ContentPanel.ForeColor = ConsoleColor.DarkGray;
@ -23,18 +22,25 @@ namespace Lemonade
Close += (screen, args) => Ok?.Invoke(); Close += (screen, args) => Ok?.Invoke();
} }
public event OkDelegate Ok;
public void Setup(IEnumerable<PlayerState> players) public void Setup(IEnumerable<PlayerState> players)
{ {
lab.Content = players.ToStringTable(new[] {"Player", "Glasses made", "Earnings per glass", "Glasses sold", "Signs made", "Income", "Expenses", "Profit", "Budget"}, lab.Content = players.ToStringTable(
(s) => s.Number, new[]
(s) => s.Glasses, {
(s) => s.GlassPrice, "Player", "Glasses made", "Earnings per glass", "Glasses sold", "Signs made", "Income", "Expenses",
(s) => s.Sales, "Profit", "Budget"
(s) => s.Signs, },
(s) => s.Earnings, s => s.Number,
(s) => s.Expenses, s => s.Glasses,
(s) => s.Earnings - s.Expenses, s => s.GlassPrice,
(s) => s.Budget); s => s.Sales,
s => s.Signs,
s => s.Earnings,
s => s.Expenses,
s => s.Earnings - s.Expenses,
s => s.Budget);
lab.Render(); lab.Render();
ActualSize = new Size(lab.Size.Width, lab.Size.Height); ActualSize = new Size(lab.Size.Width, lab.Size.Height);
} }

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using CC_Functions.Commandline.TUI;
namespace Lemonade namespace Lemonade
{ {
@ -12,15 +11,13 @@ namespace Lemonade
private readonly ResultScreen _result; private readonly ResultScreen _result;
private readonly Settings _settings; private readonly Settings _settings;
private readonly TransactionScreen _transaction; private readonly TransactionScreen _transaction;
private GameState _state;
private bool _running;
private List<PlayerState> _players;
private int _currentPlayer; private int _currentPlayer;
private bool _initialEvent = true;
private int _day; private int _day;
private bool _initialEvent = true;
private readonly List<PlayerState> _players;
private bool _running;
private GameState _state;
private Weather _weather; private Weather _weather;
private int signCost => 15;
private int GlassCost => _day < 5 ? 2 : 4;
public ScreenManager(Settings settings) public ScreenManager(Settings settings)
{ {
@ -31,7 +28,8 @@ namespace Lemonade
_state = GameState.Transaction; _state = GameState.Transaction;
_currentPlayer = 0; _currentPlayer = 0;
_initialEvent = true; _initialEvent = true;
_transaction.SetUp(_players[_currentPlayer], _settings, _currentPlayer, _day, _weather, signCost, GlassCost); _transaction.SetUp(_players[_currentPlayer], _settings, _currentPlayer, _day, _weather, signCost,
GlassCost);
}; };
_transaction = new TransactionScreen(settings); _transaction = new TransactionScreen(settings);
_transaction.Ok += (glasses, price, signs) => _transaction.Ok += (glasses, price, signs) =>
@ -49,7 +47,7 @@ namespace Lemonade
} }
else else
{ {
_transaction.Tab(true); _transaction.Tab();
_transaction.Tab(false); _transaction.Tab(false);
} }
}; };
@ -64,12 +62,14 @@ namespace Lemonade
for (int i = 0; i < settings.PlayerCount; i++) _players.Add(new PlayerState(i + 1)); for (int i = 0; i < settings.PlayerCount; i++) _players.Add(new PlayerState(i + 1));
} }
private int signCost => 15;
private int GlassCost => _day < 5 ? 2 : 4;
public void Run() public void Run()
{ {
_running = true; _running = true;
_state = GameState.Setup; _state = GameState.Setup;
while (_running) while (_running)
{
switch (_state) switch (_state)
{ {
case GameState.Setup: case GameState.Setup:
@ -87,7 +87,8 @@ namespace Lemonade
case GameState.Transaction: case GameState.Transaction:
if (_initialEvent) if (_initialEvent)
{ {
_transaction.SetUp(_players[_currentPlayer], _settings, _currentPlayer, _day, _weather, signCost, GlassCost); _transaction.SetUp(_players[_currentPlayer], _settings, _currentPlayer, _day, _weather,
signCost, GlassCost);
_transaction.Render(); _transaction.Render();
_initialEvent = false; _initialEvent = false;
} }
@ -107,7 +108,6 @@ namespace Lemonade
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
}
} }
} }
} }

View File

@ -7,14 +7,15 @@ namespace Lemonade
{ {
public class Settings public class Settings
{ {
public bool Color { get; private set; } = true;
public int PlayerCount { get; private set; }
public float DifficultyFactor { get; private set; }
public Settings() public Settings()
{ {
Configure(); Configure();
} }
public bool Color { get; private set; } = true;
public int PlayerCount { get; private set; }
public float DifficultyFactor { get; private set; }
public void Configure() public void Configure()
{ {
CenteredScreen settingsScreen = new CenteredScreen(200, 20, ConsoleColor.Black, Color) CenteredScreen settingsScreen = new CenteredScreen(200, 20, ConsoleColor.Black, Color)
@ -22,12 +23,12 @@ namespace Lemonade
TabPoint = 0, TabPoint = 0,
Title = "Lemonade - Settings" Title = "Lemonade - Settings"
#if DEBUG #if DEBUG
+ "[R to redraw]" + "[R to redraw]"
#endif #endif
}; };
Panel scr = settingsScreen.ContentPanel; Panel scr = settingsScreen.ContentPanel;
scr.ForeColor = ConsoleColor.DarkGray; scr.ForeColor = ConsoleColor.DarkGray;
Label playerLabel = new Label("Players"); Label playerLabel = new Label("Players");
playerLabel.Point = new Point(scr.Size.Width / 2 - playerLabel.Content.Length / 2, 3); playerLabel.Point = new Point(scr.Size.Width / 2 - playerLabel.Content.Length / 2, 3);
scr.Controls.Add(playerLabel); scr.Controls.Add(playerLabel);
@ -35,7 +36,7 @@ namespace Lemonade
Slider playerSlider = new Slider {MinValue = 1, Value = 2, Size = new Size(100, 1)}; Slider playerSlider = new Slider {MinValue = 1, Value = 2, Size = new Size(100, 1)};
playerSlider.Point = new Point(scr.Size.Width / 2 - playerSlider.Size.Width / 2, 4); playerSlider.Point = new Point(scr.Size.Width / 2 - playerSlider.Size.Width / 2, 4);
scr.Controls.Add(playerSlider); scr.Controls.Add(playerSlider);
Label difficultyLabel = new Label("Difficulty"); Label difficultyLabel = new Label("Difficulty");
difficultyLabel.Point = new Point(scr.Size.Width / 2 - difficultyLabel.Content.Length / 2, 7); difficultyLabel.Point = new Point(scr.Size.Width / 2 - difficultyLabel.Content.Length / 2, 7);
scr.Controls.Add(difficultyLabel); scr.Controls.Add(difficultyLabel);
@ -46,23 +47,23 @@ namespace Lemonade
CheckBox colorBox = new CheckBox("Color") {Checked = true}; CheckBox colorBox = new CheckBox("Color") {Checked = true};
colorBox.Point = new Point(scr.Size.Width / 2 - (colorBox.Content.Length + 4) / 2, 12); colorBox.Point = new Point(scr.Size.Width / 2 - (colorBox.Content.Length + 4) / 2, 12);
colorBox.CheckedChanged += (screen, args) => colorBox.CheckedChanged += (screen, args) => { settingsScreen.Color = colorBox.Checked; };
{
settingsScreen.Color = colorBox.Checked;
};
#if DEBUG #if DEBUG
settingsScreen.Input += (screen, args) => { if (args.Info.Key == ConsoleKey.R) DiffDraw.Draw(Color, true); }; settingsScreen.Input += (screen, args) =>
{
if (args.Info.Key == ConsoleKey.R) DiffDraw.Draw(Color, true);
};
#endif #endif
scr.Controls.Add(colorBox); scr.Controls.Add(colorBox);
Button okButton = new Button("OK"); Button okButton = new Button("OK");
okButton.Point = new Point(scr.Size.Width / 2 - okButton.Content.Length / 2, 16); okButton.Point = new Point(scr.Size.Width / 2 - okButton.Content.Length / 2, 16);
scr.Controls.Add(okButton); scr.Controls.Add(okButton);
bool visible = true; bool visible = true;
okButton.Click += (screen, args) => visible = false; okButton.Click += (screen, args) => visible = false;
settingsScreen.Close += (screen, args) => visible = false; settingsScreen.Close += (screen, args) => visible = false;
settingsScreen.Render(); settingsScreen.Render();
while (visible) while (visible)
{ {

View File

@ -7,37 +7,38 @@ namespace Lemonade
{ {
public class TransactionScreen : CenteredScreen public class TransactionScreen : CenteredScreen
{ {
public event OkDelegate Ok;
public delegate void OkDelegate(int glasses, int price, int signs); public delegate void OkDelegate(int glasses, int price, int signs);
private readonly Label _infoLabel;
private readonly Label _glassesLabel;
private readonly Slider _glasses; private readonly Slider _glasses;
private readonly Label _priceLabel; private readonly Label _glassesLabel;
private readonly Slider _price;
private readonly Label _signsLabel; private readonly Label _infoLabel;
private readonly Slider _signs;
private readonly Label _infoLabelBottom; private readonly Label _infoLabelBottom;
private readonly Slider _price;
private readonly Label _priceLabel;
private readonly Slider _signs;
private readonly Label _signsLabel;
private int _lemonadeCost;
private PlayerState _player; private PlayerState _player;
private int _signCost; private int _signCost;
private int _lemonadeCost;
public TransactionScreen(Settings set) : base(200, 20, ConsoleColor.Black, set.Color) public TransactionScreen(Settings set) : base(200, 20, ConsoleColor.Black, set.Color)
{ {
ContentPanel.ForeColor = ConsoleColor.DarkGray; ContentPanel.ForeColor = ConsoleColor.DarkGray;
_infoLabel = new Label("[DAY 1]"); _infoLabel = new Label("[DAY 1]");
_infoLabel.Point = new Point(ContentPanel.Size.Width / 2 - _infoLabel.Content.Length / 2, 0); _infoLabel.Point = new Point(ContentPanel.Size.Width / 2 - _infoLabel.Content.Length / 2, 0);
ContentPanel.Controls.Add(_infoLabel); ContentPanel.Controls.Add(_infoLabel);
_glassesLabel = new Label("How many glasses of lemonade do you wish to make?"); _glassesLabel = new Label("How many glasses of lemonade do you wish to make?");
_glassesLabel.Point = new Point(ContentPanel.Size.Width / 2 - _glassesLabel.Content.Length / 2, 2); _glassesLabel.Point = new Point(ContentPanel.Size.Width / 2 - _glassesLabel.Content.Length / 2, 2);
ContentPanel.Controls.Add(_glassesLabel); ContentPanel.Controls.Add(_glassesLabel);
_glasses = new Slider {Size = new Size(100, 1)}; _glasses = new Slider {Size = new Size(100, 1)};
_glasses.Point = new Point(ContentPanel.Size.Width / 2 - _glasses.Size.Width / 2, 3); _glasses.Point = new Point(ContentPanel.Size.Width / 2 - _glasses.Size.Width / 2, 3);
_glasses.ValueChanged += (screen, args) => CalculateMax(); _glasses.ValueChanged += (screen, args) => CalculateMax();
ContentPanel.Controls.Add(_glasses); ContentPanel.Controls.Add(_glasses);
_priceLabel = new Label("What price (in cents) do you wish to charge for lemonade?"); _priceLabel = new Label("What price (in cents) do you wish to charge for lemonade?");
_priceLabel.Point = new Point(ContentPanel.Size.Width / 2 - _priceLabel.Content.Length / 2, 6); _priceLabel.Point = new Point(ContentPanel.Size.Width / 2 - _priceLabel.Content.Length / 2, 6);
ContentPanel.Controls.Add(_priceLabel); ContentPanel.Controls.Add(_priceLabel);
@ -46,7 +47,7 @@ namespace Lemonade
_price.Point = new Point(ContentPanel.Size.Width / 2 - _price.Size.Width / 2, 7); _price.Point = new Point(ContentPanel.Size.Width / 2 - _price.Size.Width / 2, 7);
_price.ValueChanged += (screen, args) => CalculateMax(); _price.ValueChanged += (screen, args) => CalculateMax();
ContentPanel.Controls.Add(_price); ContentPanel.Controls.Add(_price);
_signsLabel = new Label("How many advertising signs do you want to make?"); _signsLabel = new Label("How many advertising signs do you want to make?");
_signsLabel.Point = new Point(ContentPanel.Size.Width / 2 - _signsLabel.Content.Length / 2, 10); _signsLabel.Point = new Point(ContentPanel.Size.Width / 2 - _signsLabel.Content.Length / 2, 10);
ContentPanel.Controls.Add(_signsLabel); ContentPanel.Controls.Add(_signsLabel);
@ -55,11 +56,11 @@ namespace Lemonade
_signs.Point = new Point(ContentPanel.Size.Width / 2 - _signs.Size.Width / 2, 11); _signs.Point = new Point(ContentPanel.Size.Width / 2 - _signs.Size.Width / 2, 11);
_signs.ValueChanged += (screen, args) => CalculateMax(); _signs.ValueChanged += (screen, args) => CalculateMax();
ContentPanel.Controls.Add(_signs); ContentPanel.Controls.Add(_signs);
_infoLabelBottom = new Label("Total Expenses: 0/0"); _infoLabelBottom = new Label("Total Expenses: 0/0");
_infoLabelBottom.Point = new Point(ContentPanel.Size.Width / 2 - _infoLabelBottom.Content.Length / 2, 14); _infoLabelBottom.Point = new Point(ContentPanel.Size.Width / 2 - _infoLabelBottom.Content.Length / 2, 14);
ContentPanel.Controls.Add(_infoLabelBottom); ContentPanel.Controls.Add(_infoLabelBottom);
Button okButton = new Button("OK"); Button okButton = new Button("OK");
okButton.Point = new Point(ContentPanel.Size.Width / 2 - okButton.Size.Width / 2, 16); okButton.Point = new Point(ContentPanel.Size.Width / 2 - okButton.Size.Width / 2, 16);
okButton.Click += (sender, e) => Ok?.Invoke(_glasses.Value, 10, 0); okButton.Click += (sender, e) => Ok?.Invoke(_glasses.Value, 10, 0);
@ -68,7 +69,10 @@ namespace Lemonade
Close += (screen, args) => Ok?.Invoke(_glasses.Value, 10, 0); Close += (screen, args) => Ok?.Invoke(_glasses.Value, 10, 0);
} }
public void SetUp(PlayerState player, Settings settings, int playerIndex, int day, Weather weather, int signCost, int lemonadeCost) public event OkDelegate Ok;
public void SetUp(PlayerState player, Settings settings, int playerIndex, int day, Weather weather,
int signCost, int lemonadeCost)
{ {
TabPoint = 0; TabPoint = 0;
_signCost = signCost; _signCost = signCost;
@ -90,9 +94,9 @@ namespace Lemonade
private void CalculateMax() private void CalculateMax()
{ {
int leftover = _player.Budget - CalculateExpenses(); int leftover = _player.Budget - CalculateExpenses();
_glasses.MaxValue = (int)Math.Floor(leftover / (double)_lemonadeCost) + _glasses.Value; _glasses.MaxValue = (int) Math.Floor(leftover / (double) _lemonadeCost) + _glasses.Value;
_price.MaxValue = 200; _price.MaxValue = 200;
_signs.MaxValue = (int)Math.Floor(leftover / (double)_signCost) + _signs.Value; _signs.MaxValue = (int) Math.Floor(leftover / (double) _signCost) + _signs.Value;
_infoLabelBottom.Content = $"Leftover: ${leftover / 100f}/${_player.Budget / 100f}"; _infoLabelBottom.Content = $"Leftover: ${leftover / 100f}/${_player.Budget / 100f}";
_infoLabelBottom.Point = new Point(ContentPanel.Size.Width / 2 - _infoLabelBottom.Content.Length / 2, 14); _infoLabelBottom.Point = new Point(ContentPanel.Size.Width / 2 - _infoLabelBottom.Content.Length / 2, 14);
} }

View File

@ -4,8 +4,9 @@ namespace Lemonade
{ {
public class Weather public class Weather
{ {
private static Random rnd = new Random(); private static readonly Random rnd = new Random();
public override string ToString() => W.ToString().Replace('_', ' ');
public double Factor = rnd.NextDouble();
public W W public W W
{ {
@ -19,7 +20,7 @@ namespace Lemonade
} }
} }
public double Factor = rnd.NextDouble(); public override string ToString() => W.ToString().Replace('_', ' ');
} }
public enum W public enum W