88 lines
2.6 KiB
C#
88 lines
2.6 KiB
C#
using ChessPanel;
|
|
using System;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Chess
|
|
{
|
|
public class ChessGame : Panel
|
|
{
|
|
ChessBoard board;
|
|
public ChessGame()
|
|
{
|
|
InitializeComponent();
|
|
RefreshSize();
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
this.board = new ChessPanel.ChessBoard();
|
|
this.SuspendLayout();
|
|
//
|
|
// board
|
|
//
|
|
this.board.Cursor = System.Windows.Forms.Cursors.Hand;
|
|
this.board.GridSize = 8;
|
|
this.board.Location = new System.Drawing.Point(0, 0);
|
|
this.board.Name = "board";
|
|
this.board.Size = new System.Drawing.Size(100, 100);
|
|
this.board.TabIndex = 0;
|
|
this.board.Paint += new System.Windows.Forms.PaintEventHandler(this.board_Paint);
|
|
//
|
|
// ChessGame
|
|
//
|
|
this.Controls.Add(this.board);
|
|
this.Resize += new System.EventHandler(this.ResizeEvent);
|
|
this.ResumeLayout(false);
|
|
|
|
}
|
|
|
|
private void ResizeEvent(object sender, EventArgs e)
|
|
{
|
|
RefreshSize();
|
|
}
|
|
|
|
internal void FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if (board.isSaved)
|
|
{
|
|
e.Cancel = false;
|
|
}
|
|
else
|
|
{
|
|
switch (MessageBox.Show("Das aktuelle Spiel ist noch nicht gespeichert!\nMöchtest du es jetzt speichern?", "Speichern?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation))
|
|
{
|
|
case DialogResult.Cancel:
|
|
e.Cancel = true;
|
|
break;
|
|
case DialogResult.Yes:
|
|
SaveGame();
|
|
e.Cancel = false;
|
|
break;
|
|
case DialogResult.No:
|
|
e.Cancel = false;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SaveGame()
|
|
{
|
|
MessageBox.Show("TODO: SaveGame here!");
|
|
}
|
|
|
|
private void RefreshSize()
|
|
{
|
|
int size = Math.Min(this.Size.Width, this.Size.Height);
|
|
board.Size = new System.Drawing.Size(size, size);
|
|
board.Location = this.Size.Width > this.Size.Height ? new System.Drawing.Point((this.Size.Width - size) / 2, 0) : new System.Drawing.Point(0, (this.Size.Height - size) / 2);
|
|
}
|
|
|
|
private void board_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|