Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package project;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Label;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
- import javax.swing.JPanel;
- import javax.swing.text.LayoutQueue;
- public class Panel extends JPanel implements KeyListener{
- int x;
- int y;
- final static int width = 20;
- final static int height = 20;
- int [][]array = new int[20][20];
- int smerX;
- int smerY;
- final static int rychlost = 20;
- public Panel(){
- this.setBackground(Color.WHITE);
- this.setPreferredSize(new Dimension(600,400));
- this.setVisible(true);
- // fillArray();
- /*
- Label l1 = new Label();
- l1.setText("Piskvorky 1.0");
- l1.setVisible(true);
- l1.setBounds(500, 500, 30, 30);
- this.add(l1);
- */
- }
- public void fillArray(){
- array[5][3] = 1;
- array[12][1] = 1;
- array[0][0] = 1;
- array[11][3] = 2;
- array[2][1] = 2;
- array[0][7] = 2;
- array[14][14] = 2;
- }
- public void checkRowforWin(){
- for (int i = 0; i < 20; i++) {
- for (int j = 0; j < 20; j++) {
- }
- }
- }
- public void paint(Graphics g){
- for (int i = 0; i < 20; i++) {
- for (int j = 0; j < 20; j++) {
- if(array[i][j] == 1){
- g.setColor(Color.RED);
- g.fillRect(x+i*20, y+j*20, width, height);
- }
- else if(array[i][j] == 2){
- g.setColor(Color.BLUE);
- g.fillRect(x+i*20, y+j*20, width, height);
- }
- else{
- g.setColor(Color.WHITE);
- g.fillRect(x+i*20, y+j*20, width, height);
- }
- g.setColor(Color.BLACK);
- g.drawRect(x+i*20, y+j*20, width, height);
- }
- }
- }
- @Override
- public void keyTyped(KeyEvent e) {
- // TODO Auto-generated method stub
- }
- @Override
- public void keyPressed(KeyEvent e) {
- // TODO Auto-generated method stub
- int klavesa = e.getKeyCode();
- if (klavesa == KeyEvent.VK_LEFT) {
- smerX = -rychlost;
- } else if (klavesa == KeyEvent.VK_UP) {
- smerY = -rychlost;
- } else if (klavesa == KeyEvent.VK_RIGHT) {
- smerX = rychlost;
- } else if (klavesa == KeyEvent.VK_DOWN) {
- smerY = rychlost;
- } else if (klavesa == KeyEvent.VK_SPACE){
- array[5][5] = 1;
- }
- }
- @Override
- public void keyReleased(KeyEvent e) {
- // TODO Auto-generated method stub
- int klavesa = e.getKeyCode();
- if (klavesa == KeyEvent.VK_LEFT) {
- smerX = 0;
- } else if (klavesa == KeyEvent.VK_UP) {
- smerY = 0;
- } else if (klavesa == KeyEvent.VK_RIGHT) {
- smerX = 0;
- } else if (klavesa == KeyEvent.VK_DOWN) {
- smerY = 0;
- } else if (klavesa == KeyEvent.VK_SPACE){
- array[5][5] = 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement