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

    效果:

  • 相关阅读:
    Android App 注射&&Drozer Use
    Burp Suite使用介绍总结
    php截取后台登陆密码的代码
    通用型正方教务(通杀各版本)存在注入(不需登陆)+获得webshell+提权内网漫游
    密码重置漏洞案例
    新闻发布系统<分页>
    通过端口 8080 连接到主机 localhost 的 TCP/IP 连接失败
    九大内置对象
    jsp前3章试题分析
    富文本编辑器
  • 原文地址:https://www.cnblogs.com/gmth/p/2516469.html
Copyright © 2011-2022 走看看