我可以在c#的8皇后程序上得到帮助吗?(让皇后类在棋盘上移动)
本文关键字:移动 帮助 程序上 我可以 | 更新日期: 2023-09-27 18:17:29
我是c#的新手,需要帮助我的8个皇后项目。(第一学期)
到目前为止,我已经有了主窗体、程序类、Board类和Queens类。我已经建立了棋盘,但问题是我不知道在哪里放置代码,使女王在棋盘上移动。我见过很多这样的应用程序,但不是用c#编写的。
这是我目前为止写的:
Board.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Resources;
namespace _8_Queens
{
class Board:UserControl
{
public Board()
{
}
protected override void OnPaintBackground(PaintEventArgs chess)
{
Graphics color = chess.Graphics;
int size = this.Height / 8;
bool isBlack = true;
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
Brush paint;
if (isBlack)
paint = Brushes.Black;
else
paint = Brushes.Gray;
color.FillRectangle(paint, new Rectangle(j * size, i * size, size, size));
isBlack = !isBlack;
}
isBlack = !isBlack;
}
}
}
}
我没有皇后类,因为我不知道从哪里开始,希望帮助:
使皇后显示在棋盘上(需要知道把它放在什么类中,以及当窗体上的按钮被点击时如何显示它)
另外,我想知道我是否需要一个皇后类,而是在棋盘类上做所有事情。
谢谢!这将是有帮助的,因为我不是很好与8queens算法,并在尝试键入代码时感到困惑。
欢迎使用Stackoverflow !
请参考
- 这个关于SO的问题也和象棋编程有关
- 国际象棋游戏stararer套件