2017-02-27 15:15:50 +01:00
using ChessPanel ;
using System ;
using System.Windows.Forms ;
namespace Chess
{
public class ChessGame : Panel
{
ChessBoard board ;
public ChessGame ( )
{
InitializeComponent ( ) ;
RefreshSize ( ) ;
}
private void InitializeComponent ( )
{
2017-11-16 18:06:29 +01:00
this . board = new ChessPanel . ChessBoard ( ) ;
2017-02-27 15:15:50 +01:00
this . SuspendLayout ( ) ;
//
// board
//
2017-11-16 18:06:29 +01:00
this . board . Cursor = System . Windows . Forms . Cursors . Hand ;
2017-02-27 15:15:50 +01:00
this . board . GridSize = 8 ;
this . board . Location = new System . Drawing . Point ( 0 , 0 ) ;
this . board . Name = "board" ;
2017-11-16 18:06:29 +01:00
this . board . Size = new System . Drawing . Size ( 100 , 100 ) ;
2017-02-27 15:15:50 +01:00
this . board . TabIndex = 0 ;
2017-11-16 18:06:29 +01:00
this . board . Paint + = new System . Windows . Forms . PaintEventHandler ( this . board_Paint ) ;
2017-02-27 15:15:50 +01:00
//
// ChessGame
//
this . Controls . Add ( this . board ) ;
this . Resize + = new System . EventHandler ( this . ResizeEvent ) ;
this . ResumeLayout ( false ) ;
2017-11-16 18:06:29 +01:00
2017-02-27 15:15:50 +01:00
}
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 ) ;
}
2017-11-16 18:06:29 +01:00
private void board_Paint ( object sender , PaintEventArgs e )
{
}
2017-02-27 15:15:50 +01:00
}
}