From 1ba25e36dab26aeea5e639f579488f1fc4fc0b59 Mon Sep 17 00:00:00 2001 From: maxluli Date: Mon, 9 Jan 2023 09:47:10 +0100 Subject: [PATCH] Tweaked settings and converted client speed to float so its smoother and more natural --- Caisses/Client.cs | 4 ++-- Caisses/GraphicalClient.cs | 37 +++++++++++++++++++++---------------- Caisses/Store.cs | 4 ++++ 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Caisses/Client.cs b/Caisses/Client.cs index 204d534..e625c61 100644 --- a/Caisses/Client.cs +++ b/Caisses/Client.cs @@ -8,8 +8,8 @@ namespace Caisses { public class Client { - public const int MAX_SHOPPING_TIME = 100; //Original 100 - public const int MIN_SHOPPING_TIME = 10; //Original 10 + public const int MAX_SHOPPING_TIME = 70; //Original 100 + public const int MIN_SHOPPING_TIME = 5; //Original 10 public enum ClientState { diff --git a/Caisses/GraphicalClient.cs b/Caisses/GraphicalClient.cs index 4a6321d..84d2e48 100644 --- a/Caisses/GraphicalClient.cs +++ b/Caisses/GraphicalClient.cs @@ -12,14 +12,14 @@ namespace Caisses const int MAX_CLIENT_SPEED = 5; const int MIN_CLIENT_SPEED = -5; - private Point _speed; - private Point _position; + private PointF _speed; + private PointF _position; private Color _color; private Size _size; private Rectangle _area; - public Point Speed { get => _speed; set => _speed = value; } - public Point Position { get => _position; set => _position = value; } + public PointF Speed { get => _speed; set => _speed = value; } + public PointF Position { get => _position; set => _position = value; } public Color Color { get => _color; set => _color = value; } public Size Size { get => _size; set => _size = value; } public Rectangle Area { get => _area; set => _area = value; } @@ -28,12 +28,17 @@ namespace Caisses { Random = random; Position = Entrance; - Position = new Point(Random.Next(0, 100), Random.Next(0, 100)); - Speed = new Point(Random.Next(MIN_CLIENT_SPEED, MAX_CLIENT_SPEED), Random.Next(MIN_CLIENT_SPEED, MAX_CLIENT_SPEED)); + //Position = new Point(Random.Next(0, 100), Random.Next(0, 100)); + Speed = new PointF(NextFloat(MIN_CLIENT_SPEED, MAX_CLIENT_SPEED), NextFloat(MIN_CLIENT_SPEED, MAX_CLIENT_SPEED)); Color = Color.FromArgb(ShoppingTime * 2, 0, 0); int clientWidth = Random.Next(20, 30); Size = new Size(clientWidth, clientWidth); } + static float NextFloat(float min, float max) + { + double val = (Random.NextDouble() * (max - min) + min); + return (float)val; + } public void Update(Size area) { //base.Tick(); @@ -47,27 +52,27 @@ namespace Caisses switch (State) { case ClientState.Shopping: - g.FillEllipse(new SolidBrush(Color), new Rectangle(Position, Size)); + g.FillEllipse(new SolidBrush(Color), new RectangleF(Position, Size)); g.DrawString(ShoppingTime.ToString(), new Font("Arial", 16), new SolidBrush(Color.White),new PointF(Position.X,Position.Y)); break; case ClientState.Waiting: - g.FillEllipse(new SolidBrush(Color.Red), new Rectangle(Position, Size)); + g.FillEllipse(new SolidBrush(Color.Red), new RectangleF(Position, Size)); g.DrawString(WaitingTime.ToString(), new Font("Arial", 16), new SolidBrush(Color.White), new PointF(Position.X, Position.Y)); break; case ClientState.Inline: - g.FillEllipse(new SolidBrush(Color.Violet), new Rectangle(Position, Size)); + g.FillEllipse(new SolidBrush(Color.Violet), new RectangleF(Position, Size)); break; case ClientState.Checkout: - g.FillEllipse(new SolidBrush(Color.Green), new Rectangle(Position, Size)); + g.FillEllipse(new SolidBrush(Color.Green), new RectangleF(Position, Size)); g.DrawString(CheckoutTime.ToString(), new Font("Arial", 16), new SolidBrush(Color.Black), new PointF(Position.X, Position.Y)); break; default: break; } } - public Point checkBounds(Point position, Size area) + public PointF checkBounds(PointF position, Size area) { - Point newPosition = new Point(position.X,position.Y); + PointF newPosition = new PointF(position.X,position.Y); /* if (position.X < 0) { @@ -97,10 +102,10 @@ namespace Caisses } else { - int diff = Math.Abs(position.X + Speed.X); + float diff = Math.Abs(position.X + Speed.X); newPosition.X = diff; //newPosition = new Point(0, position.Y); - Speed = new Point(Speed.X * -1,Speed.Y); + Speed = new PointF(Speed.X * -1,Speed.Y); //speed.X += -1; } if (position.Y + Speed.Y > 0 && position.Y + Size.Height + Speed.Y < area.Height) @@ -109,10 +114,10 @@ namespace Caisses } else { - int diff = Math.Abs(position.Y + Speed.Y); + float diff = Math.Abs(position.Y + Speed.Y); newPosition.Y = diff; //newPosition = new Point(position.X, 0); - Speed = new Point(Speed.X,Speed.Y * -1); + Speed = new PointF(Speed.X,Speed.Y * -1); //speed.Y *= -1; } diff --git a/Caisses/Store.cs b/Caisses/Store.cs index 73143fb..6aa0b1f 100644 --- a/Caisses/Store.cs +++ b/Caisses/Store.cs @@ -58,6 +58,10 @@ namespace Caisses TimeOfTheDayInMinuts++; if (TimeOfTheDayInMinuts % 60 == 0) { + if (TimeOfTheDayInMinuts >= 24 * 60) + { + TimeOfTheDayInMinuts = 0; + } //Its a new Hour so we can send the new clients int amountOfNewCLients = ATTENDANCE[TimeOfTheDayInHours]; FillStore(amountOfNewCLients);