zoukankan      html  css  js  c++  java
  • 棋盘覆盖(绘图版)

     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次幂)
    ");
    55        scanf("%d",&size);
    56        printf("请输入棋盘中要覆盖点的坐标:
    ");
    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 }

  • 相关阅读:
    js之面向对象
    常用功能
    html圆环(该代码非原创,具体出处已不详)
    关于jsonp的一篇文章(传播好的东西)
    当切换select时,获取select选中的值;获取选中的单选按钮的val,判断复选框是否选中
    js类型判断(数字、0、""、undefined、null)
    js获取窗口可视范围的高度、获取窗口滚动条高度、文档内容实际高度
    66
    55
    44
  • 原文地址:https://www.cnblogs.com/wxdjss/p/5485659.html
Copyright © 2011-2022 走看看