You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.0 KiB
86 lines
2.0 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Threading;
|
|
|
|
namespace WorkField.Model
|
|
{
|
|
/// <summary>
|
|
/// Стадион
|
|
/// </summary>
|
|
public class CStadium
|
|
{
|
|
private System.Threading.Timer _timer;
|
|
private string _mapFilename;
|
|
|
|
public CBlockList BlockList;
|
|
/// <summary>
|
|
/// Список работников
|
|
/// </summary>
|
|
public List<CPlayerBlock> PlayerList;
|
|
|
|
|
|
public CStadium(string sFn)
|
|
{
|
|
_mapFilename = sFn;
|
|
PlayerList = new List<CPlayerBlock>();
|
|
BlockList = new CBlockList();
|
|
|
|
h_FillField();
|
|
|
|
_timer = new Timer(h_tick, null,
|
|
new TimeSpan(0, 0, 0, 0, 300),
|
|
new TimeSpan(0, 0, 0, 0, 1000)
|
|
);
|
|
}
|
|
|
|
private void h_FillField()
|
|
{
|
|
Bitmap pB = new Bitmap(_mapFilename);
|
|
for (int xx = 0; xx < pB.Width; xx++) {
|
|
for (int yy = 0; yy < pB.Height; yy++) {
|
|
Color pColor = pB.GetPixel(xx, yy);
|
|
bool isWall = h_IsColor(pColor, Color.Black);
|
|
bool isField = !isWall; // h_IsColor(pColor, Color.White);
|
|
if (isWall) BlockList.Add(xx, yy, EBlockType.Wall);
|
|
if (isField) BlockList.Add(xx, yy, EBlockType.Field);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static bool h_IsColor(Color pC1, Color pC2)
|
|
{
|
|
return pC2.R == pC1.R
|
|
&& pC2.G == pC1.G
|
|
&& pC2.B == pC1.B;
|
|
}
|
|
|
|
private void h_tick(object x)
|
|
{
|
|
this.Move();
|
|
}
|
|
|
|
internal void Move()
|
|
{
|
|
foreach (CPlayerBlock pPlayer in PlayerList) {
|
|
pPlayer.Move();
|
|
}
|
|
}
|
|
|
|
public bool IsPosition(int newX, int newY)
|
|
{
|
|
CBlock pBlock = BlockList.Find(newX, newY);
|
|
if (pBlock == null) return false;
|
|
if (pBlock is CWallBlock) return false;
|
|
return true;
|
|
}
|
|
|
|
public void AddNewStandardPlayer()
|
|
{
|
|
int iNum = PlayerList.Count + 1;
|
|
PlayerList.Add(
|
|
new CPlayerBlock($"player{iNum}",
|
|
10, 10 + iNum * 2, IsPosition));
|
|
}
|
|
}
|
|
}
|
|
|