المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : i cant get a class i made- description inside- win app



C# Programming
05-22-2009, 01:52 PM
i have a form:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Din_Checkers
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

public Board gameBoard { get; set; }

private void Form1_Load(object sender, EventArgs e)
{
this.Text = "Dins Checkers";
this.Width = 600;
this.Height = 600;
gameBoard = new Board();
for (int i = 0; i < Board.x_bounds; i++)
{
for (int j = 0; j < Board.y_bounds; j++)
{
this.Controls.Add(gameBoard.checkers_board[i, j].checkerCell);
}
}
this.Controls.Add(gameBoard.score);
}
}
}

as you can see i have created new Board instance

the Board class is:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Din_Checkers
{
public class Board
{
public const int x_bounds = 8;
public const int y_bounds = 8;
public CheckerCell[,] checkers_board { get; set; }
public Label score = new Label();
public ImageList imageList1 = new ImageList();
public int goldEaten = 0;
public int silverEaten = 0;
public Image loadGold;
public Image loadSilver;

public Board()
{
checkers_board = new CheckerCell[x_bounds, y_bounds];
imageList1.Images.Add(Image.FromFile("Images\\silver.jpg"));
imageList1.Images.Add(Image.FromFile("Images\\gold.jpg"));
loadSilver = imageList1.Images[0];
loadGold = imageList1.Images[1];

for (int i = 0; i < checkers_board.GetLength(0); i++)
{
for (int j = 0; j < checkers_board.GetLength(1); j++)
{
checkers_board[i, j] = new CheckerCell();
if (i < 3)
{
if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1))
{
checkers_board[i, j].checkerCell.BackgroundImage = loadSilver;
}
}
else if (i > 4)
{
if (((i + j) % 2 == 0) || (i % 2 == 1 && j % 2 == 1))
{
checkers_board[i, j].checkerCell.BackgroundImage = loadGold;
}
}
checkers_board[i, j].checkerCell.BorderStyle = BorderStyle.Fixed3D;
if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1))
{
checkers_board[i, j].checkerCell.BackColor = Color.White;
}
if (checkers_board[i, j].checkerCell.BackColor != Color.White)
{
checkers_board[i, j].checkerCell.BackColor = Color.Black;
}
checkers_board[i, j].checkerCell.Top = 30 + 55 * i;
checkers_board[i, j].checkerCell.Width = 61;
checkers_board[i, j].checkerCell.Height = 53;
checkers_board[i, j].checkerCell.Left = 30 + 65 * j;
}
}

score.Top = 510;
score.Left = 250;
score.Width = 500;

for (int i = 0; i < checkers_board.GetLength(0); i++)
{
for (int j = 0; j < checkers_board.GetLength(1); j++)
{
checkers_board[i, j].checkerCell.Click += new EventHandler(checkers_board[i, j].ChooseEvent_Click);
}
}
}

public void DrawScore()
{
score.Text = "?????: ?????? ??????- " + goldEaten.ToString() + " ?????? ??????- " + silverEaten.ToString();
}
}
}


and i have another class (that is used in Board class)- the CheckerCell class:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Din_Checkers
{
public class CheckerCell
{
public PictureBox checkerCell { get; set; }
public int x = 0;
public int y = 0;

public CheckerCell()
{
checkerCell = new PictureBox();
}

public static void ChooseEvent_Click(object sender, EventArgs e)
{
string eventChoose = "";
for (int i = 0; i < Board.x_bounds; i++)
{
for (int j = 0; j < Board.y_bounds; j++)
{
if (eventChoose == "")
{
if (Form.//Form1.gameBoard.checkers_board[i, j].BackColor == Color.White)
{
eventChoose = "Handle_Board";
}
}
if (checkers_board[i, j].BackColor == Color.Green)
{
eventChoose = "move";
}
}
}
if (eventChoose == "move")
{
MoveChecker_Click(sender, e);
}
else
{
HandleBoard_Click(sender, e);
}
}

public void HandleBoard_Click(object sender, EventArgs e)
{
//????? ????? ?? ???? ?????? )????? ?????? ????? ????? ?? ??? picturebox)
for (int i = 0; i < Board.x_bounds; i++)
{
for (int j = 0; j < Board.y_bounds; j++)
{
if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1))
{
checkers_board[i, j].BackColor = Color.White;
}
if (checkers_board[i, j].BackColor != Color.White)
{
checkers_board[i, j].BackColor = Color.Black;
}
}
}

//????? ?? ???? ??????? ????? checkers_board ???? ????????? ???????? sender ???? ??????? ?????? ???? picturebox
for (int i = 0; i < Board.x_bounds; i++)
{
for (int j = 0; j < Board.y_bounds; j++)
{
if (checkers_board[i, j] == ((PictureBox)sender))
{
x = i;
y = j;
}
}
}
score.Text = x.ToString() + " " + y.ToString() + "fun0"; //???? ?? ????? ???? ????? ??????

//????? ??? ?? ?? ?????? ?? x ? y ?? ?????? ??????
int start_x = x - 1, start_y = y - 1, end_x = x + 1, end_y = y + 1;
if (start_x < 0)
{
start_x = 0;
}
if (start_y < 0)
{
start_y = 0;
}
if (end_x > Board.x_bounds - 1)
{
end_x = Board.x_bounds - 1;
}
if (end_y > Board.y_bounds - 1)
{
end_y = Board.y_bounds - 1;
}
for (int i = start_x; i