PDA

View Full Version : درخواست کد شطرنج



محمدامین شریفی
چهارشنبه 18 اردیبهشت 1387, 11:09 صبح
آیا کسی کد شطرنج رو داره که attach کنه ؟
برای کمک به یکی از برنامه نویسان می خواهم:متعجب:

Mahdi.Kiani
چهارشنبه 18 اردیبهشت 1387, 11:30 صبح
سلام
در کتاب دایتل اگه اشتباه نکنم یه نمونه سادش هست،
موفق باشید

رضا عربلو
چهارشنبه 18 اردیبهشت 1387, 17:05 عصر
این هم Valil Chess معروف :
http://channel9.msdn.com/ShowPost.aspx?PostID=23020
دانلود :
http://channel9.msdn.com/Photos/ZippedFiles/7bd4681b-f6ce-42c2-a4b0-008228e7e0f3.zip


نسخه winfx اش را هم می توانی از اینجا بگیری :
http://www.valil.com/winfx/

محمدامین شریفی
پنج شنبه 19 اردیبهشت 1387, 07:37 صبح
سلام
در کتاب دایتل اگه اشتباه نکنم یه نمونه سادش هست،
موفق باشید
خیلی ممنون کتاب دیتل در سال 2002 نوشته شده وحالا 2008 است . 1 یا 2 تا کدش اجرا نمی شه .می خواستم یه نمونه ساده وجدید بهش بدم.
از آقای عربلو هم کمال سپاس را دارم.نتیجه برنامه رو می گم که به درد همه برنامه نویسان بخورد.:تشویق:

محمدامین شریفی
پنج شنبه 19 اردیبهشت 1387, 07:46 صبح
آقا مهدی من تمام آموزش wpf شما رو قبلا خوانده بودم.بی نظیر است

محمدامین شریفی
پنج شنبه 19 اردیبهشت 1387, 20:28 عصر
من از وقتی این سبک بازی کردن رو دیدم تا الان که این پست رو می فرستم هیجان زده شدم!
این رو از codeproject گرفتمhttp://www.codeproject.com/KB/aspnet/circular_chess.aspx ,گذاشتم که با هم امتحانش کنیم.
بچه ها اگه تونستم اجراش کنم تو وبگاه : http://www.beladerang.com
میزارمش.

محمدامین شریفی
یک شنبه 22 اردیبهشت 1387, 23:12 عصر
این کد به وسیله یکی از همکاران این وبگاه گرد آوری شده که نامشان را فراموش کرده ام.این کار بسیار الهام گرفته از دیتل است ولی دارای قسمت load & save است کلاس ChessPiece.cs

[

using System;//فضای نام اصلی
using System.Drawing;//فضای نامی برای رسم شکل ها و تصاویر

namespace Chess
{
//طراحی مهره های شطرنج
public class ChessPiece
{
//تعریف ثابت های مهره های شطرنج
//کلمه کلیدی انیوم برای ذخیره ی شئی های دلخواه ماست
public enum Types
{
KING,//[kıŋ]پادشاه
QUEEN,//[kwi:n]وزیر
BISHOP,//['bıʃəp]پیل
KNIGHT,//[naıt]اسب
ROOK,//[rʋk]رخ
PAWN//[pɔ:n]سزباز
}

private int currentType; // شئیی از نوع اینت
private Bitmap pieceImage; // شئیی از نوع تصویر بیت مپ
//

// مکان پیش فرض
private Rectangle targetRectangle =
new Rectangle(0, 0, 75, 75);//رسم مستطیلی در مختصات (0و0)با طول و عرض 75 پیکسل

// مهره ها را می سازد
//تصویر ها در یک بیت مپ بزرگ است و کلاس هر بار قسمتی از آن را فراخوانی می کند
public ChessPiece( int type, int xLocation,
int yLocation, Bitmap sourceImage )//دو تا تصویر کلی داریم یکی برای مهره های سپید و دیگری مشکی
{
currentType = type; //درست کردن نوع مهره
targetRectangle.X = xLocation; // تنظیمات مختصات اکس
targetRectangle.Y = yLocation; // تنظیمات مختصات ایگرگ
//درست کردن تصویر مهره ها و تنظیمات قالب پیکسلی آن
pieceImage = sourceImage.Clone(
new Rectangle( type * 75, 0, 75, 75 ),
System.Drawing.Imaging.PixelFormat.DontCare);//ثابت (DontCare)باعث می شوداین فرمت بدون تغییر باقی بماند
}

// مهره ها را ترسیم می کند
//تصویر مهره ها در مستطیلی می گذارد که مختصات آن قبلا مشخص شده بود
public void Draw( Graphics graphicsObject )
{
graphicsObject.DrawImage( pieceImage, targetRectangle );

}
//مکانی که مهره در آن قرار دارد به شکل مستطیل(75و75)است
public Rectangle GetBounds()
{
return targetRectangle;

} //پایان متد باند

// محل قرار گیری مهره ها را تنظیم می کند
public void SetLocation( int xLocation, int yLocation )
{
targetRectangle.X = xLocation;
targetRectangle.Y = yLocation;

} // پایان متد

} // پایان کلاس
}

amirsadeghi
سه شنبه 24 اردیبهشت 1387, 16:27 عصر
اون لینکه کد کامل هست؟

محمدامین شریفی
چهارشنبه 25 اردیبهشت 1387, 10:28 صبح
namespace Chess
{

public class chessForm : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pieceBox;
private System.Windows.Forms.MainMenu GameMenu;
private System.Windows.Forms.MenuItem gameItem;
private System.Windows.Forms.MenuItem newGameItem;
private IContainer components;
//لیست آرایه ها برای تصاویر کاشی های شطرنج
//.صرفا برای تنوعچهار تصویر کاشی شطرنج داریم که دوتای آن ها برای برای سپید و دو تای دیگر برای مهره های مشکی
ArrayList chessTile = new ArrayList();

// لیست آرایه تمام اشیا مهره های فعال را ذخیره می کند
ArrayList chessPieces = new ArrayList();
//تعریف ایندکس برای مهره های انتخابی
int selectedIndex = -1;
int[,] board = new int[8, 8]; // آرایه صفحه
int[,] PiecesTile = new int[8,8];
int[,] storedValue = new int[8, 8];
private Label label1;
private Label label2;

//برای صدا کردن کشیدن خونه سپید
int CurrentColumn = 4;
int CurrentRow = 4;
Point NewPoint= new Point();
Point PrePoint = new Point();
Point NowPoint = new Point();
bool CheckMove = false;
bool TurnMove = false;
int NextTile = -1;
int LoadPiece = -1;
private MenuItem SaveItem;
private MenuItem LoadItem;
private ListBox listBox1;

// تعریف اندازه کاشی شطرنج
private const int TILESIZE = 75;

public chessForm()
{
//
// تنضیمات لازم فرم
//
InitializeComponent();
}

// . پاک کردن تمام منابع بکار گرفته شده

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.pieceBox = new System.Windows.Forms.PictureBox();
this.GameMenu = new System.Windows.Forms.MainMenu(this.components);
this.gameItem = new System.Windows.Forms.MenuItem();
this.newGameItem = new System.Windows.Forms.MenuItem();
this.SaveItem = new System.Windows.Forms.MenuItem();
this.LoadItem = new System.Windows.Forms.MenuItem();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.listBox1 = new System.Windows.Forms.ListBox();
((System.ComponentModel.ISupportInitialize)(this.p ieceBox)).BeginInit();
this.SuspendLayout();
//
// pieceBox
//
this.pieceBox.BackColor = System.Drawing.Color.Transparent;
this.pieceBox.Location = new System.Drawing.Point(0, 0);
this.pieceBox.Name = "pieceBox";
this.pieceBox.Size = new System.Drawing.Size(600, 600);
this.pieceBox.TabIndex = 1;
this.pieceBox.TabStop = false;
this.pieceBox.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pieceB ox_MouseMove);
this.pieceBox.Click += new System.EventHandler(this.pieceBox_Click);
this.pieceBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pieceB ox_MouseDown);
this.pieceBox.Paint += new System.Windows.Forms.PaintEventHandler(this.pieceB ox_Paint);
this.pieceBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pieceB ox_MouseUp);
//
// GameMenu
//
this.GameMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.gameItem,
this.SaveItem,
this.LoadItem});
//
// gameItem
//
this.gameItem.Index = 0;
this.gameItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.newGameItem});
this.gameItem.Text = "Game";
//
// newGameItem
//
this.newGameItem.Index = 0;
this.newGameItem.Shortcut = System.Windows.Forms.Shortcut.F2;
this.newGameItem.Text = "New Game";
this.newGameItem.Click += new System.EventHandler(this.newGameItem_Click);
//
// SaveItem
//
this.SaveItem.Index = 1;
this.SaveItem.Text = "Save";
this.SaveItem.Click += new System.EventHandler(this.SaveItem_Click);
//
// LoadItem
//
this.LoadItem.Index = 2;
this.LoadItem.Text = "Load";
this.LoadItem.Click += new System.EventHandler(this.LoadItem_Click);
//
// label1
//
this.label1.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label1.Location = new System.Drawing.Point(609, 92);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(61, 122);
this.label1.TabIndex = 2;
//
// label2
//
this.label2.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label2.Location = new System.Drawing.Point(609, 236);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(61, 122);
this.label2.TabIndex = 3;
//
// listBox1
//
this.listBox1.Location = new System.Drawing.Point(601, -2);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(69, 602);
this.listBox1.TabIndex = 0;
//
// chessForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.AutoScroll = true;
this.AutoSize = true;
this.ClientSize = new System.Drawing.Size(670, 563);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.pieceBox);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.Menu = this.GameMenu;
this.Name = "chessForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n;
this.Text = "Chess";
this.Load += new System.EventHandler(this.ChessGame_Load);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.ChessG ame_Paint);
((System.ComponentModel.ISupportInitialize)(this.p ieceBox)).EndInit();
this.ResumeLayout(false);

}
#endregion

محمدامین شریفی
چهارشنبه 25 اردیبهشت 1387, 10:34 صبح
[STAThread]
static void Main()
{
Application.Run( new chessForm() );
}
//بارگیری صفحه شطرنج و نقشه بیتی
private void ChessGame_Load(
object sender, System.EventArgs e)
{
// بارگیری تصاویر کاشی های شطرنج
chessTile.Add( Bitmap.FromFile( "lightTile1.png" ) );
chessTile.Add( Bitmap.FromFile( "lightTile2.png" ) );
chessTile.Add( Bitmap.FromFile( "darkTile1.png" ) );
chessTile.Add( Bitmap.FromFile( "darkTile2.png" ) );
chessTile.Add(Bitmap.FromFile("AllowTile.png"));

ResetBoard(); // آماده کردن صفحه
Invalidate(); // به روز کردن صفحه

} // پایان متد
// آماده کردن مهره ها و درست کردن صفحه
private void ResetBoard()
{
int current = -1;
ChessPiece piece;
Random random = new Random();
bool light = true;
int type;

// آماده کردن و خالی کردن آرایه
chessPieces = new ArrayList();

// بارگیری مهره های سپید
Bitmap whitePieces =
( Bitmap )Image.FromFile( "whitePieces.png" );

//بارگیری مهره های سیاه
Bitmap blackPieces =
( Bitmap )Image.FromFile( "blackPieces.png" );

// تنظیم کردن شروع کننده مهره
Bitmap selected = whitePieces;


for ( int row = 0;
row <= board.GetUpperBound( 0 ); row++ )
{
//برای ردیف های پایین رنگ مهره ها مشکی انتخاب شده است
if ( row > 5 )
selected = blackPieces;

//تابع از پیش تعریف شده ی(GetUpperBound( 1 ))
//برای برگرداندن تعداد خانه های آرایه که پر شده اند.چون آرایه دو بعدی است پس دارای دو ستون است
for ( int column = 0;
column <= board.GetUpperBound( 1 ); column++ )
{

//قرار دادن مهره های ردیف اول و آخر
if ( row == 0 || row == 7 )
{
switch( column )
{
case 0:
case 7:
current =
( int )ChessPiece.Types.ROOK;//رخ
break;

case 1:
case 6:
current =
( int )ChessPiece.Types.KNIGHT;//اسب
break;

case 2:
case 5:
current =
( int )ChessPiece.Types.BISHOP;//پیل
break;

case 3:
current =
( int )ChessPiece.Types.KING;//شاه
break;

case 4:
current =
( int )ChessPiece.Types.QUEEN;//وزیر
break;
}

// ساختن مهره و گذاشتن آن در جایگاه
piece = new ChessPiece( current,
column * TILESIZE, row * TILESIZE,
selected );

// قرار دادن مهره در آرایه
chessPieces.Add( piece );
}

// برای ردیف دوم هر رنگ
if ( row == 1 || row == 6 )
{
piece = new ChessPiece(
(int) ChessPiece.Types.PAWN,
column * TILESIZE, row * TILESIZE,
selected );

//قرار دادن مهره در آرایه
chessPieces.Add( piece );
}

//با توجه به اینکه کاشی های شطرنج یکی در میان سیاه و سپید است
type = random.Next( 0, 2 );

if ( light )
{

board[ row, column ] = type;
light = false;
}
else
{

board[ row, column ] = type + 2;
light = true;
}
}


light = !light;

}

} // payane metode ResetBoard


private void ChessGame_Paint(
object sender, System.Windows.Forms.PaintEventArgs e)
{

Graphics graphicsObject = e.Graphics;//تعریف شئی از نوع گرافیک

for (int row = 0;
row <= board.GetUpperBound(0); row++)
{
for (int column = 0;
column <= board.GetUpperBound(1); column++)
{
//کشیدن عکس تعیین شده در آرایه
graphicsObject.DrawImage(
(Image)chessTile[board[row, column]],
new Point(TILESIZE * column,
TILESIZE * row));
}

}

} // payane metode ChessGame_Paint


//شماره مهره ای که موشواره روی آن است را بار می گذارد
private int CheckBounds( Point point, int exclude )
{
Rectangle rectangle;

for ( int i = 0; i < chessPieces.Count; i++ )
{
// مختصات مهره را بر می گرداند
rectangle = GetPiece( i ).GetBounds();

// اگر مختصات شامل مهره بود
if ( rectangle.Contains( point ) && i != exclude )
return i;
}
return -1;

} // payane metode CheckBounds



// tarsime roydadhaye pieceBox
private void pieceBox_Paint(
object sender, System.Windows.Forms.PaintEventArgs e)
{
// برای کشیدن تمام مهره ها
for ( int i = 0; i < chessPieces.Count; i++ )
GetPiece( i ).Draw( e.Graphics );

} // payane metode pieceBox_Paint

private void pieceBox_MouseDown(
object sender, System.Windows.Forms.MouseEventArgs e )
{
// شماره ی مهره های انتخاب شده را بر می گرداند
selectedIndex =
CheckBounds( new Point( e.X, e.Y ), -1 );

//selectedIndex shomareye mohreii ke rosh click shodaroo bar migardone
label1.Text = selectedIndex.ToString();


if (selectedIndex > -1)
{
//این شرط برای فهمیدن نوبت حرکت است
//TurnMove == false yani nobate harekate mohreye sefid
if (TurnMove == false)
{
//اگر مهره انتخابی سپید بود
if (selectedIndex >= 0 && selectedIndex <= 15)
{
Rectangle rectangle;
rectangle = GetPiece(selectedIndex).GetBounds();
CurrentRow = rectangle.Y / TILESIZE;
CurrentColumn = rectangle.X / TILESIZE;
NowPoint = new Point(rectangle.X, rectangle.Y);
label2.Text = "[" + CurrentRow.ToString() + "," + CurrentColumn.ToString() + "]";
LicensedMove(selectedIndex);
Invalidate();
}
else
{
MessageBox.Show("شما باید مهره سپید را گزینش کنید", "انتخاب غلط", MessageBoxButtons.OK, MessageBoxIcon.Error);
selectedIndex = -1;
}
}
else
{
if (selectedIndex >= 16 && selectedIndex <= 31)
{
Rectangle rectangle;
rectangle = GetPiece(selectedIndex).GetBounds();
CurrentRow = rectangle.Y / TILESIZE;
CurrentColumn = rectangle.X / TILESIZE;
NowPoint = new Point(rectangle.X, rectangle.Y);
label2.Text = "[" + CurrentRow.ToString() + "," + CurrentColumn.ToString() + "]";
LicensedMove(selectedIndex);
Invalidate();//صفحه را بروزرسانی می کند
}
else
{
MessageBox.Show("شما باید مهره سیاه را گزینش کنید", "انتخاب غلط", MessageBoxButtons.OK, MessageBoxIcon.Error);
selectedIndex = -1;
}
}



}



} // end method pieceBox_MouseDown


private void pieceBox_MouseMove(
object sender, System.Windows.Forms.MouseEventArgs e )
{
if ( selectedIndex > -1 )
{
Rectangle region = new Rectangle(
e.X - TILESIZE * 2, e.Y - TILESIZE * 2,
TILESIZE * 4, TILESIZE * 4 );

//برای قرار دادن موشواره در وسط مهره
GetPiece( selectedIndex ).SetLocation(
e.X - TILESIZE / 2, e.Y - TILESIZE / 2 );

// به روز کردن ناحیه انتخابی
pieceBox.Invalidate( region );
label1.Text = selectedIndex.ToString() + region.ToString();
}

} // payane metod epieceBox_MouseMove


private void pieceBox_MouseUp(
object sender, System.Windows.Forms.MouseEventArgs e )
{
int remove = -1;

listBox1.Items.Clear();

Rectangle rectangle;


if ( selectedIndex > -1 )
{
PrePoint = NowPoint;

//برای پاک کردن خانه های سپید
ResetTile();


Point current = new Point( e.X, e.Y );//مختصات موشواره
//مختصات کاشی که موشواره روی آن است
Point newPoint = new Point(
current.X - ( current.X % TILESIZE ),
current.Y - ( current.Y % TILESIZE ) );

//بررسی می کند در مختصات جدید مهره هست یا نه
remove = CheckBounds( current, selectedIndex );

//قرار دادن مهره در وسط کاشی
GetPiece( selectedIndex ).SetLocation( newPoint.X,
newPoint.Y );
//نقطه جدید که مهره در آن است
rectangle = GetPiece(selectedIndex).GetBounds();
NewPoint = new Point(rectangle.X, rectangle.Y);
//شرطی برای اینکه دریابیم مهره جابجا شده است یا نه

if (NewPoint != NowPoint)
{
CheckMove = true;
}
else
{
CheckMove = false;
}

//اگر مهره مورد نظر حرکتی داشته باشد
if (CheckMove == true)
{
//برای تنظیم نوبت حرکت
TurnMove = !TurnMove;
}

//خارج کردن مهره از حالت انتخاب
selectedIndex = -1;

//از این کد استفاده نشده چون شماره مهره ها رو بهم می ریخت
//و در ذخیره و بار گذاری ما را دچار مشکل می کرد

//if ( remove > -1 )
//chessPieces.RemoveAt( remove );


//برای بیرون بردن مهره از درون صفحه شطرنج
if (remove > -1)
GetPiece(remove).SetLocation(pieceBox.Width +TILESIZE, 0);


}

//بروز کردن ناحیه
Invalidate();

} // payane metode pieceBox_MouseUp

محمدامین شریفی
چهارشنبه 25 اردیبهشت 1387, 10:45 صبح
part3


private void WhitePawnMove(int SelectedPiece)
{

CurrentColumn = NowPoint.X / TILESIZE;
CurrentRow = NowPoint.Y / TILESIZE;
NextTile = -1;
if (CurrentRow == 1)
{
CurrentRow += 1;
NextTile = CheckBounds(new Point((CurrentColumn * TILESIZE), (CurrentRow * TILESIZE)), SelectedPiece);
if (NextTile == -1)
{
board[CurrentRow, CurrentColumn] = 4;
listBox1.Items.Add("[" + CurrentRow.ToString() + "," + CurrentColumn.ToString() + "]");

CurrentColumn = NowPoint.X / TILESIZE;
CurrentRow = NowPoint.Y / TILESIZE;
NextTile = -1;
CurrentRow += 2;
NextTile = CheckBounds(new Point((CurrentColumn * TILESIZE), (CurrentRow * TILESIZE)), SelectedPiece);
if (NextTile == -1)
{
board[CurrentRow, CurrentColumn] = 4;
listBox1.Items.Add("[" + CurrentRow.ToString() + "," + CurrentColumn.ToString() + "]");

}
}

}
else
{
if (CurrentRow < 7 && NextTile == -1)
{
CurrentRow += 1;
NextTile = CheckBounds(new Point((CurrentColumn * TILESIZE), (CurrentRow * TILESIZE)), SelectedPiece);
if (NextTile == -1)
{
board[CurrentRow, CurrentColumn] = 4;
listBox1.Items.Add("[" + CurrentRow.ToString() + "," + CurrentColumn.ToString() + "]");

}
}
}


CurrentColumn = NowPoint.X / TILESIZE;
CurrentRow = NowPoint.Y / TILESIZE;
NextTile = -1;
if (CurrentRow <7 && CurrentColumn > 0)
{
CurrentColumn -= 1;
CurrentRow += 1;
NextTile = CheckBounds(new Point((CurrentColumn * TILESIZE), (CurrentRow * TILESIZE)), SelectedPiece);
if (NextTile > 15 && NextTile != -1)
{
board[CurrentRow, CurrentColumn] = 4;
listBox1.Items.Add("[" + CurrentRow.ToString() + "," + CurrentColumn.ToString() + "]");

}
}


CurrentColumn = NowPoint.X / TILESIZE;
CurrentRow = NowPoint.Y / TILESIZE;
NextTile = -1;
if (CurrentRow < 7 && CurrentColumn < 7)
{
CurrentColumn += 1;
CurrentRow += 1;
NextTile = CheckBounds(new Point((CurrentColumn * TILESIZE), (CurrentRow * TILESIZE)), SelectedPiece);
if (NextTile > 15 && NextTile != -1)
{
board[CurrentRow, CurrentColumn] = 4;
listBox1.Items.Add("[" + CurrentRow.ToString() + "," + CurrentColumn.ToString() + "]");

}
}

}

private void BlackPawnMove(int SelectedPiece)
{

CurrentColumn = NowPoint.X / TILESIZE;
CurrentRow = NowPoint.Y / TILESIZE;
NextTile = -1;
if (CurrentRow == 6)
{
CurrentRow -= 1;
NextTile = CheckBounds(new Point((CurrentColumn * TILESIZE), (CurrentRow * TILESIZE)), SelectedPiece);
if (NextTile == -1)
{
board[CurrentRow, CurrentColumn] = 4;
listBox1.Items.Add("[" + CurrentRow.ToString() + "," + CurrentColumn.ToString() + "]");

CurrentColumn = NowPoint.X / TILESIZE;
CurrentRow = NowPoint.Y / TILESIZE;
NextTile = -1;
CurrentRow -= 2;
NextTile = CheckBounds(new Point((CurrentColumn * TILESIZE), (CurrentRow * TILESIZE)), SelectedPiece);
if (NextTile == -1)
{
board[CurrentRow, CurrentColumn] = 4;
listBox1.Items.Add("[" + CurrentRow.ToString() + "," + CurrentColumn.ToString() + "]");

}
}

}
else
{
if (CurrentRow > 0 && NextTile == -1)
{
CurrentRow -= 1;
NextTile = CheckBounds(new Point((CurrentColumn * TILESIZE), (CurrentRow * TILESIZE)), SelectedPiece);
if (NextTile == -1)
{
board[CurrentRow, CurrentColumn] = 4;
listBox1.Items.Add("[" + CurrentRow.ToString() + "," + CurrentColumn.ToString() + "]");

}
}
}


CurrentColumn = NowPoint.X / TILESIZE;
CurrentRow = NowPoint.Y / TILESIZE;
NextTile = -1;
if (CurrentRow >0 && CurrentColumn > 0)
{
CurrentColumn -= 1;
CurrentRow -= 1;
NextTile = CheckBounds(new Point((CurrentColumn * TILESIZE), (CurrentRow * TILESIZE)), SelectedPiece);
if (NextTile < 16 && NextTile != -1)
{
board[CurrentRow, CurrentColumn] = 4;
listBox1.Items.Add("[" + CurrentRow.ToString() + "," + CurrentColumn.ToString() + "]");

}
}


CurrentColumn = NowPoint.X / TILESIZE;
CurrentRow = NowPoint.Y / TILESIZE;
NextTile = -1;
if (CurrentRow > 0 && CurrentColumn < 7)
{
CurrentColumn += 1;
CurrentRow -= 1;
NextTile = CheckBounds(new Point((CurrentColumn * TILESIZE), (CurrentRow * TILESIZE)), SelectedPiece);
if (NextTile < 16 && NextTile != -1)
{
board[CurrentRow, CurrentColumn] = 4;
listBox1.Items.Add("[" + CurrentRow.ToString() + "," + CurrentColumn.ToString() + "]");

}
}

}

private void SaveItem_Click(object sender, EventArgs e)
{
int SaveIndex;
//Save
using (FileStream fs = File.Create("D:\\output.dat"))
{
for (int row = 0; row <= PiecesTile.GetUpperBound(0); row++)
{
for (int column = 0; column <= PiecesTile.GetUpperBound(1); column++)
{
SaveIndex = CheckBounds(new Point((column * TILESIZE), (row * TILESIZE)), -1);
PiecesTile[row, column] = SaveIndex;
}

}

BinaryFormatter fmt = new BinaryFormatter();
fmt.Serialize(fs, PiecesTile);
}
MessageBox.Show("your game is Saved Succesfully .....", "Save Messeage",MessageBoxButtons.OK, MessageBoxIcon.Information);

}

private void LoadItem_Click(object sender, EventArgs e)
{
//Load
using (FileStream fs = File.Open("D:\\output.dat", FileMode.Open))
{
BinaryFormatter fmt = new BinaryFormatter();
storedValue = (int[,])fmt.Deserialize(fs);
}

for (int row = 0; row <= storedValue.GetUpperBound(0); row++)
{
for (int column = 0; column <= storedValue.GetUpperBound(1); column++)
{
LoadPiece = storedValue[row, column];
if (LoadPiece != -1)
{
GetPiece(LoadPiece).SetLocation(
column * TILESIZE, row * TILESIZE);
}

}
}
Invalidate();
MessageBox.Show("your game is Loaded Succesfully .....", "Load Messeage",MessageBoxButtons.OK,MessageBoxIcon.Information);
}

part3

محمدامین شریفی
چهارشنبه 25 اردیبهشت 1387, 10:47 صبح
کسی کدش هم می خواهد؟

danial82
جمعه 28 تیر 1387, 18:07 عصر
نیکی و پرسش ؟؟؟!!!!!
من که استقبال میکنم

مهدی رحیم زاده
پنج شنبه 11 تیر 1388, 08:07 صبح
کسی کدش هم می خواهد؟
میشه لطف کنی و کدشو بزاری؟

محمدامین شریفی
دوشنبه 29 تیر 1388, 15:06 عصر
میشه لطف کنی و کدشو بزاری؟
واقعا شرمنده هستم که مدت زیادی است که به این تاپیکسر نزده ام.
کد شطرنج،مانند کتاب دیتل بود که خیلی وقت پیش یکمی تغییرش داده بودم.
الان اون کد در اختیارم نیست،ولی در حال حاضر کد و توضیحات برنامه reversi که جزو بازی های تخته ای می شود را در اینجا (http://aminsharifi67.blogspot.com/2009/07/2d-games-by-c-sharp_13.html) گذاشتم.هشت وزیر را هم بر روی آن پیاده سازی کرده ام.اگر دوستان علاقه مند بودند،با هم شطرنج را هم بر روی تخته اش پیاده سازی میکنیم.

ehsan248
دوشنبه 29 تیر 1388, 23:57 عصر
سلام از اینجا دانلود کنید خیلی توپه
http://www.codeproject.com/KB/game/SrcChess/Article_src.zip

saeed hg
شنبه 04 تیر 1390, 01:04 صبح
سورس بازی شطرنج دایتل