123 lines
4.6 KiB
C#
123 lines
4.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Caisses
|
|
{
|
|
public class GraphicalClient : Client
|
|
{
|
|
const int MAX_CLIENT_SPEED = 5;
|
|
const int MIN_CLIENT_SPEED = -5;
|
|
|
|
private Point _speed;
|
|
private Point _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 Color Color { get => _color; set => _color = value; }
|
|
public Size Size { get => _size; set => _size = value; }
|
|
public Rectangle Area { get => _area; set => _area = value; }
|
|
|
|
public GraphicalClient(Point Entrance,Random random):base(random)
|
|
{
|
|
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));
|
|
Color = Color.FromArgb(ShoppingTime * 2, 0, 0);
|
|
int clientWidth = Random.Next(20, 30);
|
|
Size = new Size(clientWidth, clientWidth);
|
|
}
|
|
public void Update(Size area)
|
|
{
|
|
//base.Tick();
|
|
Position = checkBounds(Position,area);
|
|
Color = Color.FromArgb(ShoppingTime * 2, 0, 0);
|
|
}
|
|
public void Draw(Bitmap storeImage)
|
|
{
|
|
Update(storeImage.Size);
|
|
Graphics g = Graphics.FromImage(storeImage);
|
|
switch (State)
|
|
{
|
|
case ClientState.Shopping:
|
|
g.FillEllipse(new SolidBrush(Color), new Rectangle(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.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));
|
|
break;
|
|
case ClientState.Checkout:
|
|
g.FillEllipse(new SolidBrush(Color.Green), new Rectangle(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)
|
|
{
|
|
Point newPosition = new Point(position.X,position.Y);
|
|
/*
|
|
if (position.X < 0)
|
|
{
|
|
newPosition.X = 0;
|
|
Speed = new Point(Speed.X * -1, Speed.Y);
|
|
}
|
|
if (position.X > area.Width)
|
|
{
|
|
newPosition.X = area.Width;
|
|
Speed = new Point(Speed.X * -1, Speed.Y);
|
|
}
|
|
|
|
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
|
|
{
|
|
int 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.X += -1;
|
|
}
|
|
if (position.Y + Speed.Y > 0 && position.Y + Size.Height + Speed.Y < area.Height)
|
|
{
|
|
newPosition.Y = position.Y + Speed.Y;
|
|
}
|
|
else
|
|
{
|
|
int 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.Y *= -1;
|
|
}
|
|
|
|
return newPosition;
|
|
}
|
|
}
|
|
}
|