Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.awt.BorderLayout;
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.image.BufferStrategy;
- import java.util.LinkedList;
- import java.util.List;
- import javax.swing.JFrame;
- public class Main<tablica> extends Canvas implements Runnable{
- public static final String TITLE="Chinczyk";
- public static final int WIDTH = 1000, HEIGHT = 800;
- private boolean RUNNING=false;
- private JFrame frame;
- public Main(){
- setPreferredSize(new Dimension(WIDTH,HEIGHT));
- setMinimumSize(new Dimension(WIDTH,HEIGHT));
- setMaximumSize(new Dimension(WIDTH,HEIGHT));
- frame= new JFrame(TITLE);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.add(this,new BorderLayout().CENTER);
- frame.pack();
- frame.setLocationRelativeTo(null);
- frame.setResizable(false);
- frame.setVisible(true);
- }
- private void start(){
- if(RUNNING)return;
- RUNNING=true;
- new Thread(this,"Gra " + TITLE).start();
- }
- private void stop() {
- if (!RUNNING) return;
- RUNNING = false;
- System.exit(0);
- }
- public void run(){
- while(RUNNING){
- Mapka();
- }
- stop();
- }
- private void Mapka() {
- BufferStrategy bs = getBufferStrategy();
- if (bs == null) {
- createBufferStrategy(3);
- return;
- }
- Graphics g = bs.getDrawGraphics();
- g.setColor(Color.BLACK);
- g.fillRect(0, 0, WIDTH, HEIGHT);
- // OD TEGO MOMENTU JEST RYSOWANIE MAPY ( BEZ OBIEKTOW)
- g.setColor(Color.RED);
- g.fillRect(40, 40, 245, 245);
- for (int x = 81; x < 280; x = x + 40) {
- g.fillRect(x, 326, 40, 40);
- x = x + 1;
- }
- g.setColor(Color.GREEN);
- g.fillRect(40, 408, 245, 245);
- for (int y = 408; y < 610; y = y + 40) {
- g.fillRect(326, y, 40, 40);
- y = y + 1;
- }
- g.setColor(Color.BLUE);
- g.fillRect(408, 40, 245, 245);
- for (int y = 81; y < 280; y = y + 40) {
- g.fillRect(326, y, 40, 40);
- y = y + 1;
- }
- g.setColor(Color.YELLOW);
- g.fillRect(408, 408, 245, 245);
- for (int x = 408; x < 610; x = x + 40) {
- g.fillRect(x, 326, 40, 40);
- x = x + 1;
- }
- g.setColor(Color.PINK);
- g.fillRect(285, 285, 123, 123);
- g.setColor(Color.WHITE);
- //LEWA STRONA
- for (int x = 40; x < 280; x = x + 40) {
- g.fillRect(x, 285, 40, 40);
- x = x + 1;
- }
- g.fillRect(40, 326, 40, 40);
- for (int x = 40; x < 280; x = x + 40) {
- g.fillRect(x, 367, 40, 40);
- x = x + 1;
- }
- //Gorna strona
- for (int y = 40; y < 280; y = y + 40) {
- g.fillRect(285, y, 40, 40);
- y = y + 1;
- }
- g.fillRect(326, 40, 40, 40);
- for (int y = 40; y < 280; y = y + 40) {
- g.fillRect(367, y, 40, 40);
- y = y + 1;
- }
- //dolna strona
- for (int y = 408; y < 640; y = y + 40) {
- g.fillRect(285, y, 40, 40);
- y = y + 1;
- }
- g.fillRect(326, 613, 40, 40);
- for (int y = 408; y < 640; y = y + 40) {
- g.fillRect(367, y, 40, 40);
- y = y + 1;
- }
- //PRAWO
- for (int x = 408; x < 640; x = x + 40) {
- g.fillRect(x, 285, 40, 40);
- x = x + 1;
- }
- g.fillRect(613, 326, 40, 40);
- for (int x = 408; x < 640; x = x + 40) {
- g.fillRect(x, 367, 40, 40);
- x = x + 1;
- }
- g.setColor(Color.WHITE);
- g.fillRect(700,50,200,200);
- g.fillRect(700,300,200,300);
- // OD TEGO MOMENTU TWORZENIE OBIEKTOW NA PORUSZANIE PIONKAMI
- class Pole {
- private int x;
- private int y;
- public Pole(int x, int y) {
- this.x = x;
- this.y = y;
- }
- }
- List<Pole> obiekty = new LinkedList<>();
- for (int j = 44; j <= 249; j = j + 41)
- obiekty.add(new Pole(j, 290));
- for (int j = 249; j >= 44; j = j - 41)
- obiekty.add(new Pole(290, j));
- obiekty.add(new Pole(331, 44));
- for (int j = 44; j <= 249; j = j + 41)
- obiekty.add(new Pole(372, j));
- for (int j = 413; j <= 618; j = j + 41)
- obiekty.add(new Pole(j, 290));
- obiekty.add(new Pole(618, 331));
- for (int j = 618; j >= 413; j = j - 41)
- obiekty.add(new Pole(j, 372));
- for (int j = 413; j <= 618; j = j + 41)
- obiekty.add(new Pole(372, j));
- obiekty.add(new Pole(331, 618));
- for (int j = 618; j >= 413; j = j - 41)
- obiekty.add(new Pole(290, j));
- for (int j = 249; j >= 44; j = j - 41)
- obiekty.add(new Pole(j, 372));
- obiekty.add(new Pole(44, 331));
- for (int j = 85; j <= 290; j = j + 41)
- obiekty.add(new Pole(j, 331));
- for (int j = 85; j <= 290; j = j + 41)
- obiekty.add(new Pole(331, j));
- for (int j = 577; j >= 372; j = j - 41)
- obiekty.add(new Pole(j, 331));
- for (int j = 577; j >= 372; j = j - 41)
- obiekty.add(new Pole(331, j));
- int kostka=4;
- // miejsca startu czerwony 0 , niebieski 13 , zolty 26 , zielony 39
- g.setColor(Color.PINK);
- for(int i=0;i<=51;i++)
- g.fillOval(obiekty.get(i).x,obiekty.get(i).y,30,30);
- g.setColor(Color.BLACK);
- for(int i=52;i<=75;i++)
- g.fillOval(obiekty.get(i).x,obiekty.get(i).y,30,30);
- g.dispose();
- bs.show();
- }
- public static void main(String[] args) {
- new Main().start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement