Advertisement
Guest User

Untitled

a guest
May 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.81 KB | None | 0 0
  1. import javax.swing.*;
  2. import javax.swing.plaf.basic.BasicBorders;
  3. import java.awt.*;
  4. import java.util.ArrayList;
  5. import java.util.Random;
  6.  
  7. public class Simulation extends JFrame {
  8.  
  9.     Board simulation_board;
  10.     private JPanel[][] panels;
  11.     int panel_side, animal_side, width_board, height_board;
  12.     ArrayList <Hare> harelist = new ArrayList<>();
  13.     Wolf wolf;
  14.  
  15.     Simulation(int w_b, int h_b, int hares_quantity, int k) {
  16.         width_board = w_b;
  17.         height_board = h_b;
  18.         panel_side = Math.min(850 / width_board, 850 / height_board);
  19.             System.out.println("Panel side: " + panel_side);
  20.         animal_side = (int) (panel_side * 0.8);
  21.             System.out.println("Animal side: " + animal_side);
  22.         /**
  23.          *  Pomocnicza tablica animal_position do zapisania położenia zwierząt na planszy
  24.          *  0 - pole puste
  25.          *  1 - zając
  26.          *  2 - wilk
  27.          **/
  28.  
  29.         setVisible(true);
  30.         setLocation(90, 5);
  31.         setSize(width_board * panel_side, height_board * panel_side);
  32.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  33.         panels = new JPanel[width_board][height_board];
  34.         simulation_board = new Board();
  35.         JPanel mainPanel = new JPanel();
  36.         mainPanel.setLayout(new BorderLayout());
  37.         mainPanel.setSize(width_board * panel_side, height_board * panel_side);
  38.         mainPanel.setLocation(0,0);
  39.         mainPanel.setBackground(Color.ORANGE);
  40.         mainPanel.add(simulation_board,BorderLayout.CENTER);
  41.         add(mainPanel);
  42.         setVisible(true);
  43.  
  44.     }
  45.  
  46.     public class Board extends JPanel {
  47.         Board(){
  48.             setLayout(new GridLayout(height_board, width_board, -1, -1));
  49.             /**
  50.              * Inicjalizacja planszy o podanych (NxM) wymiarach
  51.              */
  52.             System.out.println("Width: "+width_board+", height: "+height_board);
  53.             for(int b=0; b<height_board; b++){
  54.                 for(int a=0; a<width_board; a++){
  55.                     //System.out.println("a="+a+", b="+b);
  56.                     panels[a][b] = new JPanel();
  57.                     panels[a][b].setBorder(new BasicBorders.FieldBorder(Color.black,Color.black,Color.black,Color.black));
  58.                     panels[a][b].setBackground(Color.white);
  59.                     add(panels[a][b]);
  60.                 }
  61.  
  62.             }
  63.  
  64.             /**
  65.              * Wylosowanie pozycji zajęcy i wilka
  66.              */
  67.  
  68.            
  69.  
  70.         }
  71.         public void paintBoard(){
  72.             for(int i =0;i<width_board;i++){
  73.                 for(int j =0 ; j< height_board;j++){
  74.                     panels[i][j].removeAll();
  75.                 }
  76.             }
  77.             for(Hare hare:harelist){
  78.                 //wyświetlanie zająca
  79.  
  80.             }
  81.             //wyświetlanie wilka
  82.         }
  83.     }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement