Advertisement
atanasovetr

Checkers

Jun 21st, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.17 KB | None | 0 0
  1. int x = 0;
  2. int y = 0;
  3. int z = 0;
  4. color RED = color(255, 0, 0);
  5. color WHITE = color(255, 255, 255);
  6. color BLACK = color(0, 0, 0);
  7. int wr = 100;
  8. circle[] r1 = {new circle (wr/2 + wr, wr/2, wr, RED, BLACK),
  9.   new circle (wr/2 + wr*3, wr/2, wr, RED, BLACK),
  10.   new circle (wr/2 + wr*5, wr/2, wr, RED, BLACK),
  11.   new circle (wr/2 + wr*7, wr/2, wr, RED, BLACK)};
  12.  
  13. circle[] r2 = {new circle (wr/2, wr*1.5, wr, RED, BLACK),
  14.   new circle (wr/2 + wr*2, wr*1.5, wr, RED, BLACK),
  15.   new circle (wr/2 + wr*4, wr*1.5, wr, RED, BLACK),
  16.   new circle (wr/2 + wr*6, wr*1.5, wr, RED, BLACK)};
  17.  
  18. circle[] r3 = {new circle (wr/2 + wr, wr*2.5, wr, RED, BLACK),
  19.   new circle (wr/2 + wr*3, wr*2.5, wr, RED, BLACK),
  20.   new circle (wr/2 + wr*5, wr*2.5, wr, RED, BLACK),
  21.   new circle (wr/2 + wr*7, wr*2.5, wr, RED, BLACK)};    
  22.  
  23. circle[] b1 = {new circle (wr/2, wr*5.5, wr, BLACK, WHITE),
  24.   new circle (wr/2 + wr*2, wr*5.5, wr, BLACK, WHITE),
  25.   new circle (wr/2 + wr*4, wr*5.5, wr, BLACK, WHITE),
  26.   new circle (wr/2 + wr*6, wr*5.5, wr, BLACK, WHITE)};  
  27.  
  28. circle[] b2 = {new circle (wr/2 + wr, wr*6.5, wr, BLACK, WHITE),
  29.   new circle (wr/2 + wr*3, wr*6.5, wr, BLACK, WHITE),
  30.   new circle (wr/2 + wr*5, wr*6.5, wr, BLACK, WHITE),
  31.   new circle (wr/2 + wr*7, wr*6.5, wr, BLACK, WHITE)};
  32.  
  33. circle[] b3 = {new circle (wr/2, wr*7.5, wr, BLACK, WHITE),
  34.   new circle (wr/2 + wr*2, wr*7.5, wr, BLACK, WHITE),
  35.   new circle (wr/2 + wr*4, wr*7.5, wr, BLACK, WHITE),
  36.   new circle (wr/2 + wr*6, wr*7.5, wr, BLACK, WHITE)};
  37.  
  38.  
  39.  
  40.  
  41.  
  42. void setup() {
  43.  
  44.   background(WHITE);
  45.   size(800, 800);
  46.  
  47.   starting_table();
  48. }
  49. void draw () {
  50.   if (keyPressed && key == 'r') {
  51.     starting_table();
  52.   }
  53. }
  54.  
  55. void mousePressed() {
  56.  
  57.   for (int i = 0; i <=3; i++) {
  58.    
  59.     r3[i].move_cherveni();
  60.   }
  61. }
  62.  
  63.  
  64. class circle {
  65.   float coorX;
  66.   float coorY;
  67.   float radius;
  68.   color c;
  69.   color b;
  70.  
  71.   circle (float tempCoorX, float tempCoorY, float tempRadius, color tempC, color tempB ) {
  72.     coorX = tempCoorX;
  73.     coorY = tempCoorY;
  74.     radius = tempRadius;
  75.     c = tempC;
  76.     b = tempB;
  77.   }
  78.  
  79.   void draw_ellipse () {
  80.     fill(c);
  81.     stroke(b);
  82.     ellipse(coorX, coorY, radius, radius);
  83.   }
  84.  
  85.   void move_cherveni() {
  86.     //can_move();
  87.     nadolu_lqvo();
  88.     nadolu_dqsno();
  89.     if (coorY == height - radius/2) {
  90.       fill(255, 255, 255);
  91.       ellipse(coorX, coorY, radius/2, radius/2);
  92.       nagore_dqsno();
  93.       nagore_lqvo();
  94.     }
  95.   }
  96.  
  97.   void move_cherni() {
  98.     nagore_lqvo();
  99.     nagore_dqsno();
  100.  
  101.     if (coorY == 0 + radius/2) {
  102.       fill(255, 255, 255);
  103.       ellipse(coorX, coorY, radius/2, radius/2);
  104.       nagore_dqsno();
  105.       nagore_lqvo();
  106.     }
  107.   }
  108.  
  109.   void nadolu_dqsno() {
  110.     if ( mouseX>coorX-radius/2+100 && mouseX<coorX+radius/2+100 && mouseY>coorY-radius/2+100 && mouseY<coorY+radius/2+100)
  111.     {
  112.       noStroke();
  113.       fill(0, 0, 0);
  114.       ellipse(coorX, coorY, radius, radius);
  115.       println(" raboti");
  116.       coorX +=100;
  117.       coorY+=100;
  118.       draw_ellipse();
  119.     }
  120.   }
  121.   void nadolu_lqvo() {
  122.     if ( mouseX>coorX-radius/2-100 && mouseX<coorX+radius/2-100 && mouseY>coorY-radius/2+100 && mouseY<coorY+radius/2+100)
  123.     {
  124.       noStroke();
  125.       fill(0, 0, 0);
  126.       ellipse(coorX, coorY, radius, radius);
  127.       println(" raboti");
  128.       coorX -=100;
  129.       coorY+=100;
  130.       draw_ellipse();
  131.     }
  132.   }
  133.   void nagore_dqsno() {
  134.     if (mouseX>coorX+radius/2 && mouseX<coorX +radius/2 + 100 && mouseY>coorY-radius/2 -100 && mouseY<coorY-radius/2) {
  135.       noStroke();
  136.       fill(0, 0, 0);
  137.       ellipse(coorX, coorY, radius, radius);
  138.       println(" raboti");
  139.       coorX +=100;
  140.       coorY-=100;
  141.       draw_ellipse();
  142.     }
  143.   }
  144.   void nagore_lqvo() {
  145.  
  146.  
  147.     if (mouseX>coorX-radius/2-100 && mouseX<coorX -radius/2 && mouseY>coorY-radius/2 -100 && mouseY<coorY-radius/2) {
  148.       noStroke();
  149.       fill(0, 0, 0);
  150.       ellipse(coorX, coorY, radius, radius);
  151.       println(" raboti");
  152.       coorX -=100;
  153.       coorY-=100;
  154.       draw_ellipse();
  155.     }
  156.   }
  157. }
  158.  
  159. void can_move() {
  160.  
  161.  
  162.   /* for (int j =0; j <=2; j++) {
  163.    for (int i = 0; i <=3; i++){
  164.    
  165.    float [] red_coorsX = {r1[i].coorX,
  166.    r2[i].coorX,
  167.    r3[i].coorX};
  168.    float [] red_coorsY = {r1[i].coorY,
  169.    r2[i].coorY,
  170.    r3[i].coorY};
  171.    
  172.    if (//dist(coorX, coorY, red_coorsX[j], red_coorsY[j] ) > 142)
  173.    red_coorsX[j] == coorX - 100 && red_coorsY[j] == coorY -100 ||
  174.    red_coorsX[j] == coorX - 100 && red_coorsY[j] == coorY +100 ||
  175.    red_coorsX[j] == coorX - 100 && red_coorsY[j] == coorY +100 ||
  176.    red_coorsX[j] == coorX + 100 && red_coorsY[j] == coorY +100)
  177.    {
  178.    println(red_coorsX);
  179.    println(red_coorsY);
  180.    nadolu_dqsno();
  181.    
  182.    }
  183.    }
  184.    }*/
  185. }
  186.  
  187.  
  188.  
  189.  
  190.  
  191. void starting_table() {
  192.   int wr=width/8;
  193.   background(WHITE);
  194.  
  195.   for ( x = 0; x<width; x+=wr) {
  196.     for (y = 0; y< height; y+= wr) {
  197.       if ((z) % 2 != 0) {
  198.         fill(BLACK);
  199.       } else {
  200.         fill(WHITE);
  201.       }
  202.       z++;
  203.       rect(x, y, wr, wr);
  204.     }
  205.     z++;
  206.   }
  207.  
  208.   for (int i = 0; i<=3; i++) {
  209.     r1[i].draw_ellipse();  
  210.     r2[i].draw_ellipse();  
  211.     r3[i].draw_ellipse();  
  212.  
  213.     b1[i].draw_ellipse();  
  214.     b2[i].draw_ellipse();  
  215.     b3[i].draw_ellipse();
  216.   }
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement