Advertisement
Guest User

Untitled

a guest
May 21st, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.04 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Canvas;
  5. import java.awt.Color;
  6. import java.awt.Dimension;
  7. import java.awt.Graphics;
  8. import java.awt.image.BufferStrategy;
  9. import java.util.LinkedList;
  10. import java.util.List;
  11.  
  12.  
  13.  
  14. import javax.swing.JFrame;
  15.  
  16. public class Main<tablica> extends Canvas implements Runnable{
  17.  
  18.     public static final String TITLE="Chinczyk";
  19.     public static  final int WIDTH = 1000, HEIGHT = 800;
  20.  
  21.     private boolean RUNNING=false;
  22.     private JFrame frame;
  23.  
  24.  
  25.  
  26.  
  27.     public Main(){
  28.         setPreferredSize(new Dimension(WIDTH,HEIGHT));
  29.         setMinimumSize(new Dimension(WIDTH,HEIGHT));
  30.         setMaximumSize(new Dimension(WIDTH,HEIGHT));
  31.  
  32.         frame= new JFrame(TITLE);
  33.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  34.  
  35.         frame.add(this,new BorderLayout().CENTER);
  36.         frame.pack();
  37.  
  38.         frame.setLocationRelativeTo(null);
  39.         frame.setResizable(false);
  40.         frame.setVisible(true);
  41.  
  42.  
  43.     }
  44.  
  45.  
  46.     private void start(){
  47.         if(RUNNING)return;
  48.         RUNNING=true;
  49.  
  50.         new Thread(this,"Gra " + TITLE).start();
  51.     }
  52.  
  53.     private void stop() {
  54.         if (!RUNNING) return;
  55.         RUNNING = false;
  56.         System.exit(0);
  57.     }
  58.  
  59.     public void run(){
  60.  
  61.         while(RUNNING){
  62.  
  63.             Mapka();
  64.  
  65.         }
  66.         stop();
  67.     }
  68.  
  69.     private void Mapka() {
  70.  
  71.         BufferStrategy bs = getBufferStrategy();
  72.         if (bs == null) {
  73.             createBufferStrategy(3);
  74.             return;
  75.         }
  76.         Graphics g = bs.getDrawGraphics();
  77.         g.setColor(Color.BLACK);
  78.         g.fillRect(0, 0, WIDTH, HEIGHT);
  79.  
  80.  
  81.         // OD TEGO MOMENTU JEST RYSOWANIE MAPY ( BEZ OBIEKTOW)
  82.  
  83.         g.setColor(Color.RED);
  84.         g.fillRect(40, 40, 245, 245);
  85.         for (int x = 81; x < 280; x = x + 40) {
  86.             g.fillRect(x, 326, 40, 40);
  87.             x = x + 1;
  88.         }
  89.  
  90.  
  91.         g.setColor(Color.GREEN);
  92.         g.fillRect(40, 408, 245, 245);
  93.         for (int y = 408; y < 610; y = y + 40) {
  94.             g.fillRect(326, y, 40, 40);
  95.             y = y + 1;
  96.         }
  97.  
  98.  
  99.         g.setColor(Color.BLUE);
  100.         g.fillRect(408, 40, 245, 245);
  101.         for (int y = 81; y < 280; y = y + 40) {
  102.             g.fillRect(326, y, 40, 40);
  103.             y = y + 1;
  104.         }
  105.  
  106.         g.setColor(Color.YELLOW);
  107.         g.fillRect(408, 408, 245, 245);
  108.         for (int x = 408; x < 610; x = x + 40) {
  109.             g.fillRect(x, 326, 40, 40);
  110.             x = x + 1;
  111.         }
  112.  
  113.         g.setColor(Color.PINK);
  114.         g.fillRect(285, 285, 123, 123);
  115.  
  116.         g.setColor(Color.WHITE);
  117.         //LEWA STRONA
  118.         for (int x = 40; x < 280; x = x + 40) {
  119.             g.fillRect(x, 285, 40, 40);
  120.             x = x + 1;
  121.         }
  122.         g.fillRect(40, 326, 40, 40);
  123.         for (int x = 40; x < 280; x = x + 40) {
  124.             g.fillRect(x, 367, 40, 40);
  125.             x = x + 1;
  126.         }
  127.  
  128.         //Gorna strona
  129.         for (int y = 40; y < 280; y = y + 40) {
  130.             g.fillRect(285, y, 40, 40);
  131.             y = y + 1;
  132.         }
  133.         g.fillRect(326, 40, 40, 40);
  134.         for (int y = 40; y < 280; y = y + 40) {
  135.             g.fillRect(367, y, 40, 40);
  136.             y = y + 1;
  137.         }
  138.  
  139.         //dolna strona
  140.         for (int y = 408; y < 640; y = y + 40) {
  141.             g.fillRect(285, y, 40, 40);
  142.             y = y + 1;
  143.         }
  144.         g.fillRect(326, 613, 40, 40);
  145.         for (int y = 408; y < 640; y = y + 40) {
  146.             g.fillRect(367, y, 40, 40);
  147.             y = y + 1;
  148.         }
  149.  
  150.         //PRAWO
  151.  
  152.         for (int x = 408; x < 640; x = x + 40) {
  153.             g.fillRect(x, 285, 40, 40);
  154.             x = x + 1;
  155.         }
  156.         g.fillRect(613, 326, 40, 40);
  157.         for (int x = 408; x < 640; x = x + 40) {
  158.             g.fillRect(x, 367, 40, 40);
  159.             x = x + 1;
  160.         }
  161.  
  162.         g.setColor(Color.WHITE);
  163.         g.fillRect(700,50,200,200);
  164.         g.fillRect(700,300,200,300);
  165.  
  166.  
  167.  
  168.         // OD TEGO MOMENTU TWORZENIE OBIEKTOW NA PORUSZANIE PIONKAMI
  169.  
  170.  
  171.         class Pole {
  172.             private int x;
  173.             private int y;
  174.  
  175.             public Pole(int x, int y) {
  176.                 this.x = x;
  177.                 this.y = y;
  178.             }
  179.         }
  180.  
  181.         List<Pole> obiekty = new LinkedList<>();
  182.         for (int j = 44; j <= 249; j = j + 41)
  183.             obiekty.add(new Pole(j, 290));
  184.  
  185.  
  186.         for (int j = 249; j >= 44; j = j - 41)
  187.             obiekty.add(new Pole(290, j));
  188.         obiekty.add(new Pole(331, 44));
  189.         for (int j = 44; j <= 249; j = j + 41)
  190.             obiekty.add(new Pole(372, j));
  191.         for (int j = 413; j <= 618; j = j + 41)
  192.             obiekty.add(new Pole(j, 290));
  193.         obiekty.add(new Pole(618, 331));
  194.         for (int j = 618; j >= 413; j = j - 41)
  195.             obiekty.add(new Pole(j, 372));
  196.         for (int j = 413; j <= 618; j = j + 41)
  197.             obiekty.add(new Pole(372, j));
  198.         obiekty.add(new Pole(331, 618));
  199.         for (int j = 618; j >= 413; j = j - 41)
  200.             obiekty.add(new Pole(290, j));
  201.         for (int j = 249; j >= 44; j = j - 41)
  202.             obiekty.add(new Pole(j, 372));
  203.         obiekty.add(new Pole(44, 331));
  204.  
  205.  
  206.         for (int j = 85; j <= 290; j = j + 41)
  207.             obiekty.add(new Pole(j, 331));
  208.         for (int j = 85; j <= 290; j = j + 41)
  209.             obiekty.add(new Pole(331, j));
  210.         for (int j = 577; j >= 372; j = j - 41)
  211.             obiekty.add(new Pole(j, 331));
  212.         for (int j = 577; j >= 372; j = j - 41)
  213.             obiekty.add(new Pole(331, j));
  214.  
  215.  
  216.  
  217.         int kostka=4;
  218.  
  219.  
  220.  
  221.  // miejsca startu czerwony 0 , niebieski 13 , zolty 26 , zielony 39
  222.  
  223.         g.setColor(Color.PINK);
  224.         for(int i=0;i<=51;i++)
  225.             g.fillOval(obiekty.get(i).x,obiekty.get(i).y,30,30);
  226.         g.setColor(Color.BLACK);
  227.         for(int i=52;i<=75;i++)
  228.             g.fillOval(obiekty.get(i).x,obiekty.get(i).y,30,30);
  229.  
  230.  
  231.         g.dispose();
  232.         bs.show();
  233.  
  234.     }
  235.  
  236.     public static void main(String[] args) {
  237.  
  238.         new Main().start();
  239.     }
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement