2017-02-27 15:15:50 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using static Chess.Piece;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace Chess
|
|
|
|
|
{
|
|
|
|
|
public class Field : Button
|
|
|
|
|
{
|
|
|
|
|
static readonly FieldColorSet primaryNormalColorSet = new FieldColorSet(Color.FromArgb(204, 204, 204), Color.FromArgb(153, 153, 153), Color.White);
|
|
|
|
|
static readonly FieldColorSet secondaryNormalColorSet = new FieldColorSet(Color.FromArgb(51, 51, 51), Color.FromArgb(102, 102, 102), Color.Black);
|
|
|
|
|
static readonly FieldColorSet primarySelectedColorSet = new FieldColorSet(Color.FromArgb(204, 204, 102), Color.FromArgb(153, 153, 102), Color.FromArgb(255, 255, 102));
|
|
|
|
|
static readonly FieldColorSet secondarySelectedColorSet = new FieldColorSet(Color.FromArgb(204, 204, 51), Color.FromArgb(153, 153, 51), Color.FromArgb(255, 255, 51));
|
|
|
|
|
static readonly FieldColorSet primaryValidFriendlyTargetFieldSet = new FieldColorSet(Color.FromArgb(102, 204, 102), Color.FromArgb(102, 153, 102), Color.FromArgb(102, 255, 102));
|
|
|
|
|
static readonly FieldColorSet secondaryValidFriendlyTargetFieldSet = new FieldColorSet(Color.FromArgb(51, 204, 51), Color.FromArgb(51, 153, 51), Color.FromArgb(51, 255, 51));
|
|
|
|
|
static readonly FieldColorSet primaryValidEnemyTargetFieldSet = new FieldColorSet(Color.FromArgb(204, 102, 102), Color.FromArgb(153, 102, 102), Color.FromArgb(255, 102, 102));
|
|
|
|
|
static readonly FieldColorSet secondaryValidEnemyTargetFieldSet = new FieldColorSet(Color.FromArgb(204, 51, 51), Color.FromArgb(153, 51, 51), Color.FromArgb(255, 51, 51));
|
|
|
|
|
public Vector location;
|
|
|
|
|
private FieldColorSet currentNormalColorSet;
|
|
|
|
|
private FieldColorSet currentEnemyColorSet;
|
|
|
|
|
private FieldColorSet currentSelectedColorSet;
|
|
|
|
|
private FieldColorSet currentAllyColorSet;
|
2017-11-16 18:06:29 +01:00
|
|
|
|
public delegate void ClickEventHandler(Field sender);
|
2017-02-27 15:15:50 +01:00
|
|
|
|
public event ClickEventHandler FieldClick;
|
|
|
|
|
public bool IsEmpty { get { return currentPiece == null; } }
|
|
|
|
|
public Piece currentPiece;
|
|
|
|
|
public Piece CurrentPiece
|
|
|
|
|
{
|
2017-11-16 18:06:29 +01:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return currentPiece;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
currentPiece = value;
|
|
|
|
|
RefreshPiece();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public override string Text
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
var pos = location.ToString();
|
|
|
|
|
if (IsEmpty)
|
|
|
|
|
return pos + Environment.NewLine + "leer";
|
|
|
|
|
return pos + Environment.NewLine + currentPiece.ToString();
|
|
|
|
|
}
|
2017-02-27 15:15:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-16 18:06:29 +01:00
|
|
|
|
public void RefreshPiece()
|
2017-02-27 15:15:50 +01:00
|
|
|
|
{
|
|
|
|
|
if (currentPiece == null)
|
|
|
|
|
this.BackgroundImage = ChessPanel.Properties.Resources.Empty;
|
|
|
|
|
else
|
|
|
|
|
this.BackgroundImage = CurrentPiece.image;
|
|
|
|
|
}
|
|
|
|
|
public void Deselect()
|
|
|
|
|
{
|
2017-11-16 18:06:29 +01:00
|
|
|
|
SetActiveColorSet(currentNormalColorSet);
|
2017-02-27 15:15:50 +01:00
|
|
|
|
}
|
|
|
|
|
public void Highlight(PieceTeam team) // validTargetField
|
|
|
|
|
{
|
|
|
|
|
switch (team)
|
|
|
|
|
{
|
|
|
|
|
case PieceTeam.Enemy:
|
2017-11-16 18:06:29 +01:00
|
|
|
|
SetActiveColorSet(currentEnemyColorSet);
|
2017-02-27 15:15:50 +01:00
|
|
|
|
break;
|
|
|
|
|
case PieceTeam.Ally:
|
2017-11-16 18:06:29 +01:00
|
|
|
|
SetActiveColorSet(currentAllyColorSet);
|
2017-02-27 15:15:50 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public new void Select() // selectedField
|
|
|
|
|
{
|
2017-11-16 18:06:29 +01:00
|
|
|
|
SetActiveColorSet(currentSelectedColorSet);
|
2017-02-27 15:15:50 +01:00
|
|
|
|
}
|
2017-11-16 18:06:29 +01:00
|
|
|
|
private void SetActiveColorSet(FieldColorSet set)
|
2017-02-27 15:15:50 +01:00
|
|
|
|
{
|
|
|
|
|
this.BackColor = set.NormalColor;
|
|
|
|
|
this.FlatAppearance.MouseDownBackColor = set.MouseDownColor;
|
|
|
|
|
this.FlatAppearance.MouseOverBackColor = set.MouseOverColor;
|
|
|
|
|
}
|
|
|
|
|
public Field(int x, int y)
|
|
|
|
|
{
|
2017-11-16 18:06:29 +01:00
|
|
|
|
this.currentNormalColorSet = (x + y) % 2 == 0 ? FieldColorSet.primaryNormalColorSet : FieldColorSet.secondaryNormalColorSet;
|
|
|
|
|
this.currentAllyColorSet = (x + y) % 2 == 0 ? FieldColorSet.primaryValidFriendlyTargetFieldSet : FieldColorSet.secondaryValidFriendlyTargetFieldSet;
|
|
|
|
|
this.currentEnemyColorSet = (x + y) % 2 == 0 ? FieldColorSet.primaryValidEnemyTargetFieldSet : FieldColorSet.secondaryValidEnemyTargetFieldSet;
|
|
|
|
|
this.currentSelectedColorSet = (x + y) % 2 == 0 ? FieldColorSet.primarySelectedColorSet : FieldColorSet.secondarySelectedColorSet;
|
2017-02-27 15:15:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.FlatStyle = FlatStyle.Flat;
|
|
|
|
|
this.FlatAppearance.BorderSize = 0;
|
2017-11-16 18:06:29 +01:00
|
|
|
|
this.SetActiveColorSet(this.currentNormalColorSet);
|
2017-02-27 15:15:50 +01:00
|
|
|
|
this.Cursor = Cursors.Arrow;
|
|
|
|
|
|
|
|
|
|
this.location = new Vector(x, y); // NICHT L(!)ocation, der gibt die Position des Buttons in Pixel auf dem Control an!
|
|
|
|
|
this.Name = string.Format($"field[{x},{y}]");
|
2017-11-16 18:06:29 +01:00
|
|
|
|
this.Text = string.Empty;
|
2017-02-27 15:15:50 +01:00
|
|
|
|
|
|
|
|
|
this.BackgroundImageLayout = ImageLayout.Zoom;
|
|
|
|
|
this.BackgroundImage = ChessPanel.Properties.Resources.Empty;
|
|
|
|
|
|
2017-11-16 18:06:29 +01:00
|
|
|
|
this.Click += Clicked;
|
2017-02-27 15:15:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-16 18:06:29 +01:00
|
|
|
|
private void Clicked(object sender, EventArgs e)
|
2017-02-27 15:15:50 +01:00
|
|
|
|
{
|
2017-11-16 18:06:29 +01:00
|
|
|
|
FieldClick(this);
|
2017-02-27 15:15:50 +01:00
|
|
|
|
}
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2017-11-16 18:06:29 +01:00
|
|
|
|
if (IsEmpty)
|
|
|
|
|
return "leer";
|
|
|
|
|
return this.currentPiece.ToString();
|
2017-02-27 15:15:50 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|