Added a waiting room and now the checkouts also take the number of people waiting in count for when to open

This commit is contained in:
2023-01-11 16:06:47 +01:00
parent 780f9a8c28
commit a891033a25
5 changed files with 71 additions and 62 deletions
+38 -51
View File
@@ -24,7 +24,7 @@ namespace Caisses
public Size Size { get => _size; set => _size = value; }
public Rectangle Area { get => _area; set => _area = value; }
public GraphicalClient(Point Entrance,Random random):base(random)
public GraphicalClient(Point Entrance, Random random) : base(random)
{
Random = random;
Position = Entrance;
@@ -39,21 +39,24 @@ namespace Caisses
double val = (Random.NextDouble() * (max - min) + min);
return (float)val;
}
public void Update(Size area)
public void Update(Size StoreArea, Size WaitingRoomArea)
{
//base.Tick();
Position = checkBounds(Position,area);
Position = checkBounds(Position, StoreArea, WaitingRoomArea);
Color = Color.FromArgb(ShoppingTime * 2, 0, 0);
}
public void Draw(Bitmap storeImage)
public void Draw(Bitmap storeImage, Bitmap waitingRoomImage)
{
Update(storeImage.Size);
Update(storeImage.Size, waitingRoomImage.Size);
Graphics g = Graphics.FromImage(storeImage);
if (this.State == Client.ClientState.Waiting)
g = Graphics.FromImage(waitingRoomImage);
switch (State)
{
case ClientState.Shopping:
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));
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 RectangleF(Position, Size));
@@ -70,57 +73,41 @@ namespace Caisses
break;
}
}
public PointF checkBounds(PointF position, Size area)
public PointF checkBounds(PointF position, Size StoreArea, Size WaitingArea)
{
PointF newPosition = new PointF(position.X,position.Y);
/*
if (position.X < 0)
PointF newPosition = new PointF(position.X, position.Y);
Size area = StoreArea;
if (this.State == Client.ClientState.Waiting)
area = WaitingArea;
if (Position.X + Size.Width / 2 > area.Width || Position.Y + Size.Height / 2 > area.Height)
{
newPosition.X = 0;
Speed = new Point(Speed.X * -1, Speed.Y);
//Its just that sometimes when transfered from the store to the waiting room, the clients ar stuck outside the bounds
newPosition = new PointF(0,0);
}
if (position.X > area.Width)
else
{
newPosition.X = area.Width;
Speed = new Point(Speed.X * -1, Speed.Y);
if (position.X + Speed.X > 0 && position.X + Size.Width + Speed.X < area.Width)
{
newPosition.X = position.X + Speed.X;
}
else
{
float diff = Math.Abs(position.X + Speed.X);
newPosition.X = diff;
Speed = new PointF(Speed.X * -1, Speed.Y);
}
if (position.Y + Speed.Y > 0 && position.Y + Size.Height + Speed.Y < area.Height)
{
newPosition.Y = position.Y + Speed.Y;
}
else
{
float diff = Math.Abs(position.Y + Speed.Y);
newPosition.Y = diff;
Speed = new PointF(Speed.X, Speed.Y * -1);
}
}
if (position.Y < 0)
{
newPosition.Y = 0;
Speed = new Point(Speed.X, Speed.Y * -1);
}
if (position.Y > area.Height)
{
newPosition.Y = area.Height;
Speed = new Point(Speed.X, Speed.Y * -1);
}*/
if (position.X + Speed.X > 0 && position.X + Size.Width + Speed.X < area.Width)
{
newPosition.X = position.X + Speed.X;
}
else
{
float diff = Math.Abs(position.X + Speed.X);
newPosition.X = diff;
//newPosition = new Point(0, position.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)
{
newPosition.Y = position.Y + Speed.Y;
}
else
{
float diff = Math.Abs(position.Y + Speed.Y);
newPosition.Y = diff;
//newPosition = new Point(position.X, 0);
Speed = new PointF(Speed.X,Speed.Y * -1);
//speed.Y *= -1;
}
return newPosition;
}
}