user1091007
user1091007

Reputation: 21

Can I get help on a 8 queens program for C#? (Getting the queens class on the chessboard and moving)

I am really new to c# and need help with my 8 queens project. (First semester)

So far I have the the main form, the program class, Board class, and the Queens class.

I have the chessboard built but the problem is I do not know where to put the code to make the queen move on the chessboard. I have seen many apps like this but not in the C# coding.

This is what I have so far:

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;
        }
    }
  }
}

I have nothing in the queens class because I do not know where to start and would like help in:

  1. making the queens display on the chessboard (need to know what class to put it in and how to display it when the button on the form is clicked)

  2. Also, I was wondering if I even need a queens class and, instead, do everything on the chessboard class.

Thank you! It would be helpful since I'm not great with the8queens algorithm and get confused when trying to type the code in.

Upvotes: 2

Views: 1036

Answers (1)

menjaraz
menjaraz

Reputation: 7575

Welcome to Stackoverflow !

Please refer to

Upvotes: 1

Related Questions