zoukankan      html  css  js  c++  java
  • 画一个五子棋盘

    注意横向线条和纵向线条的规律,横向DrawLine(Pen, x1, y1 ,x2 ,y2),纵向规律是DrawLine(Pen,y1,x1,y2,x2)

    代码如下:

    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 WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                
            }
    
            protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);
                ChessBoard cb = new ChessBoard(e.Graphics);
                cb.DrawBoard();
            }
        }
    
         class ChessBoard 
         { 
            private const int num = 15; 
            private const int initialPoint = 10; 
            private const int chessLength = 30; 
            private int[,] arr = new int[num, num];//0空,1黑,2白 
            private Graphics g; 
            private bool black = true; 
            private int stoneSize = 10;//棋子半径 
            public ChessBoard(Graphics g) 
            { 
               this.g = g; 
            } 
            //绘制棋盘 
            public void DrawBoard() 
            { 
               SolidBrush myBrush = new SolidBrush(Color.Orange); 
               Rectangle rect = new Rectangle(initialPoint, initialPoint, chessLength * (num - 1), chessLength * (num - 1)); 
               g.DrawRectangle(new Pen(myBrush), rect);//绘制棋盘背景 
               Pen myPen = new Pen(Color.Black, 2); 
               for (int i = 0; i < num; i++) 
               { 
                  //绘制横向的线条 
                  g.DrawLine(myPen, initialPoint, initialPoint + i * chessLength, chessLength * (num - 1) + initialPoint,initialPoint + i * chessLength); 
                  //绘制纵向的线条 
                  g.DrawLine(myPen, initialPoint + i * chessLength, initialPoint, initialPoint + i * chessLength, chessLength * (num - 1) + initialPoint);
                } 
             } 
         }
    }

    效果:

  • 相关阅读:
    MySQL中redo日志
    MySQL中事务的分类
    MySQL中事务的概述ACID了解
    MySQL中UNSIGNED和ZEROFILL的介绍
    MySQL中死锁
    谈谈当前火热的“车联网”
    线性代数回顾:矩阵运算
    Spark作业调度阶段分析
    Spark——共享变量
    Spark编译与打包
  • 原文地址:https://www.cnblogs.com/gmth/p/2516469.html
Copyright © 2011-2022 走看看