Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MAIN FORM CODE
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- List<Tile> tiles = new List<Tile>();
- List<Piece> pieces = new List<Piece>();
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void panel1_Paint(object sender, PaintEventArgs e)
- {
- int c = 1;
- Graphics g = panel1.CreateGraphics();
- for (int i = 0; i <= 7; i++)
- {
- for (int i1 = 0; i1 <= 7; i1++)
- {
- Tile newtile = new Tile(i1, i);
- if (c == 1)
- {
- newtile.BackColor = Color.White;
- g.FillRectangle(new SolidBrush(Color.White), new Rectangle(new Point(64 * i1, 64 * i), new Size(64, 64)));
- c -= 1;
- }
- else {
- newtile.BackColor = Color.Gray;
- g.FillRectangle(new SolidBrush(Color.Gray), new Rectangle(new Point(64 * i1, 64 * i), new Size(64, 64)));
- c += 1;
- }
- newtile.Size = new Size(64, 64);
- newtile.Location = new Point(64 * newtile.x, 64 * newtile.y);
- newtile.Paint += newtile_paint;
- newtile.Click += newtile_click;
- tiles.Add(newtile);
- }
- if (c==0)
- {
- c = 1;
- }
- else
- {
- c = 0;
- }
- }
- foreach (Tile t in tiles)
- {
- if (t.y == 0)
- {
- if (t.x == 0 | t.x == 7)
- {
- pieces.Add(new Piece(Piece.type.rook, Color.Black, t));
- }
- else if (t.x == 1 | t.x == 6)
- {
- pieces.Add(new Piece(Piece.type.knight, Color.Black, t));
- }
- else if (t.x == 2 | t.x == 5)
- {
- pieces.Add(new Piece(Piece.type.bishop, Color.Black, t));
- }
- else if (t.x == 3)
- {
- pieces.Add(new Piece(Piece.type.queen, Color.White, t));
- }
- }
- else if (t.y == 1)
- {
- pieces.Add(new Piece(Piece.type.pawn, Color.Black, t));
- }
- else if (t.y == 6)
- {
- pieces.Add(new Piece(Piece.type.pawn, Color.White, t));
- }
- else if (t.y == 7)
- {
- if (t.x == 0 | t.x == 7)
- {
- pieces.Add(new Piece(Piece.type.rook, Color.White, t));
- }
- else if (t.x == 1 | t.x == 6)
- {
- pieces.Add(new Piece(Piece.type.knight, Color.White, t));
- }
- else if (t.x == 2 | t.x == 5)
- {
- pieces.Add(new Piece(Piece.type.bishop, Color.White, t));
- }
- else if (t.x == 3)
- {
- pieces.Add(new Piece(Piece.type.queen, Color.White, t));
- }
- }
- panel1.Controls.Add(t);
- }
- }
- private void newtile_paint(object sender, PaintEventArgs e)
- {
- foreach (Tile t in tiles)
- {
- foreach (Piece p in pieces)
- {
- if (p.tile == t)
- {
- if (p.color == Color.White)
- {
- if (p.rank == Piece.type.pawn)
- {
- Graphics g1 = t.CreateGraphics();
- g1.DrawString("♙", new Font("Arial", 25), Brushes.Black, new Point(11, 16));
- } else if (p.rank == Piece.type.rook)
- {
- Graphics g1 = t.CreateGraphics();
- g1.DrawString("♖", new Font("Arial", 25), Brushes.Black, new Point(11, 16));
- } else if (p.rank == Piece.type.knight)
- {
- Graphics g1 = t.CreateGraphics();
- g1.DrawString("♘", new Font("Arial", 25), Brushes.Black, new Point(11, 16));
- } else if (p.rank == Piece.type.bishop)
- {
- Graphics g1 = t.CreateGraphics();
- g1.DrawString("♗", new Font("Arial", 25), Brushes.Black, new Point(11, 16));
- } else if (p.rank == Piece.type.queen)
- {
- Graphics g1 = t.CreateGraphics();
- g1.DrawString("♕", new Font("Arial", 25), Brushes.Black, new Point(11, 16));
- } else if (p.rank == Piece.type.king)
- {
- Graphics g1 = t.CreateGraphics();
- g1.DrawString("♔", new Font("Arial", 25), Brushes.Black, new Point(11, 16));
- }
- } else if (p.color == Color.Black)
- {
- if (p.rank == Piece.type.pawn)
- {
- Graphics g1 = t.CreateGraphics();
- g1.DrawString("♟", new Font("Arial", 25), Brushes.Black, new Point(11, 16));
- } else if (p.rank == Piece.type.rook)
- {
- Graphics g1 = t.CreateGraphics();
- g1.DrawString("♜", new Font("Arial", 25), Brushes.Black, new Point(11, 16));
- } else if (p.rank == Piece.type.knight)
- {
- Graphics g1 = t.CreateGraphics();
- g1.DrawString("♞", new Font("Arial", 25), Brushes.Black, new Point(11, 16));
- } else if (p.rank == Piece.type.bishop)
- {
- Graphics g1 = t.CreateGraphics();
- g1.DrawString("♝", new Font("Arial", 25), Brushes.Black, new Point(11, 16));
- } else if (p.rank == Piece.type.queen)
- {
- Graphics g1 = t.CreateGraphics();
- g1.DrawString("♛", new Font("Arial", 25), Brushes.Black, new Point(11, 16));
- } else if (p.rank == Piece.type.king)
- {
- Graphics g1 = t.CreateGraphics();
- g1.DrawString("♚", new Font("Arial", 25), Brushes.Black, new Point(11, 16));
- }
- }
- }
- }
- }
- }
- private void newtile_click(object sender, EventArgs e)
- {
- Tile t = (Tile)sender;
- t.Image = Chess.Properties.Resources.green;
- }
- }
- }
- //PIECE CLASS CODE
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Drawing;
- namespace WindowsFormsApplication1
- {
- class Piece
- {
- public enum type
- {
- pawn = 0,
- rook = 1,
- knight = 2,
- bishop = 3,
- queen = 4,
- king = 5
- }
- private Tile m_tile;
- public Tile tile
- {
- get { return m_tile; }
- set { m_tile = value; }
- }
- private Color m_color;
- public Color color
- {
- get { return m_color; }
- set { m_color = value; }
- }
- private type m_type;
- public type rank
- {
- get { return m_type; }
- set { m_type = value; }
- }
- public Piece(type rank, Color c, Tile t)
- {
- m_type = rank;
- m_color = c;
- m_tile = t;
- }
- }
- }
- //TILE CLASS CODE
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Drawing;
- namespace WindowsFormsApplication1
- {
- public partial class Tile : PictureBox
- {
- private int m_x;
- private int m_y;
- public int x
- {
- get { return m_x; }
- set { m_x = value; }
- }
- public int y
- {
- get { return m_y; }
- set { m_y = value; }
- }
- public Tile(int xc, int yc) : base()
- {
- m_x = xc;
- m_y = yc;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment