码迷,mamicode.com
首页 > 其他好文 > 详细

棋盘覆盖(绘图版)

时间:2016-05-13 08:59:13      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

 1 #include<graphics.h>
 2 #include<stdlib.h>
 3 #include<stdio.h>
 4 #include<conio.h>
 5 #include<time.h>
 6 #include<cmath>
 7 
 8 int tile=1;
 9 int board[100][100];
10 int color[16] = { BLACK,GREEN,BLUE,CYAN,RED,YELLOW,WHITE,LIGHTMAGENTA,11 LIGHTRED,LIGHTCYAN,LIGHTGREEN,LIGHTBLUE,DARKGRAY,LIGHTGRAY,BROWN,MAGENTA};
12 
13 void chessBoard(int tr, int tc, int dr, int dc, int size)
14 {
15        if(size==1)
16               return;
17        int t=tile++;
18        int s=size/2;
19        if(dr<tr+s && dc<tc+s)
20               chessBoard(tr, tc, dr, dc, s);
21        else
22        {
23               board[tr+s-1][tc+s-1]=t;
24               chessBoard(tr, tc, tr+s-1, tc+s-1, s);
25        }
26        if(dr<tr+s && dc>=tc+s)
27               chessBoard(tr, tc+s, dr, dc, s);
28        else
29        {
30               board[tr+s-1][tc+s]=t;
31               chessBoard(tr, tc+s, tr+s-1, tc+s, s);
32        }
33        if(dr>=tr+s && dc<tc+s)
34               chessBoard(tr+s, tc, dr, dc, s);
35        else
36        {
37               board[tr+s][tc+s-1]=t;
38               chessBoard(tr+s, tc, tr+s, tc+s-1, s);
39        }
40        if(dr>=tr+s && dc>=tc+s)
41               chessBoard(tr+s, tc+s, dr, dc, s);
42        else
43        {
44               board[tr+s][tc+s]=t;
45               chessBoard(tr+s, tc+s, tr+s, tc+s, s);
46        }
47 }
48 
49 void main()
50 {
51        int i,j;
52        int size;
53        int index_x,index_y;
54        printf("请输入棋盘边长(必须是2的K次幂)\n");
55        scanf("%d",&size);
56        printf("请输入棋盘中要覆盖点的坐标:\n");
57        scanf("%d%d",&index_x,&index_y);
58        initgraph(640,640);
59        chessBoard(0,0,index_x,index_y,size);
60        BeginBatchDraw();
61        int S=size*size;
62    for(int k=0;k<S;k++)
63    {
64     i=k/size;
65     j=k%size;
66    setfillcolor(color[board[i][j]%15]);
67    solidrectangle(40*j,(40+40*i),(40+40*j),40*i);
68    }
69 FlushBatchDraw();
70 EndBatchDraw();
71 getch();
72 closegraph();
73 }

技术分享

棋盘覆盖(绘图版)

标签:

原文地址:http://www.cnblogs.com/wxdjss/p/5485659.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!