From 23c795a2e7a0f03fd24c9dc9bbee3589853e412f Mon Sep 17 00:00:00 2001 From: zhe Date: Fri, 12 Nov 2021 17:32:14 +0100 Subject: [PATCH] shape --- out/production/Tetris/Tetris/Board$1.class | Bin 775 -> 775 bytes out/production/Tetris/Tetris/Board.class | Bin 1270 -> 1623 bytes out/production/Tetris/Tetris/GameGui.class | Bin 953 -> 953 bytes src/Tetris/Board.java | 29 +++++++++++++++++---- src/Tetris/GameGui.java | 3 ++- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/out/production/Tetris/Tetris/Board$1.class b/out/production/Tetris/Tetris/Board$1.class index cd36855d74d50084cf9d43a64336af385e22cb29..9671a62a4b61a136ce67f8b7a07b2208077b88b5 100644 GIT binary patch delta 27 icmZo?YiHY##l$Mbz{wyzIiD$*Rh~hRL1FT7CIEbZPJqOtIhpsq-yhF=XMX$Z=?ehY@TH0&Oa*Z> zh>0+Km=0nlh>yeQ!Y5MB1Th;#R)vZ=6=BRv<$~lEW#p1dF(=6_70bxWxZ9GuBgsk- zcLlVZWf@MkrZ*Z!L!f(hB~zH&Sj)|omIOpjpeJiv4Oh3^RlT-rDC|pRRLgB?KDW43 zlDa_wbvD0}UEV0>?$1k2Tp;3k6{Jrqqty2aL_75D6afK$&9>_T1Nn#gBmJ9nW6!j< z(COl!iHoaDn6?9t0pn%&6f<$+*VS$n5$TZZKd z3?`?WpUzSK{xQHY{?`%uMJD4Dp|AR%ZjA^5z;ZqbeBs};30L$q*)1JR7ixnj)X*iDy z8a_i(!xhl5iZu=QuogsF!+or4cpx)>jxRK9V4bLTroVMpw+znTRi4l1SJrqP+Mu1R zEt>c@))K?AD{nSjgO}AqI>0;Wa226#!(B7C+^V;7-q$b{ONO~! zr7?Pn#0lyQ_{yx+3Py$IU?Rt#tQnrm6qYv@3z;$<8U}aGYsIy7?77vlbPjDf`kuT| zILB9Oh<7@KVZ6ylV1$wnXUWGpUU zCBM8ot$sy?k$&p-lc_`Wr4%LEM1)VYiT>0R3^XyQOvhL-^kN@bWoA^e$|Qv=l8a4_ zPQJoe>V&6zDi(=XNBKnJkvOwFR>aSL|NhuV`jn|6XZA6iQX=tKH7YL2qlq(~^$%(7 zmR6ZTktFK7cWRZ>Dv;AIAWAxc0N|5`D-5cJ-PQiPHwk_pyaMIt6(HBhVT($ i;)tK&tFIB@{|G|7#@XY8>2A=?$I@@`R2io7BnELp;wnlK z*HAKWU1Anx19K8La8u$IDiXI*7Kks`pVXgvYa2_ekG>?#_;}O_AhcJK?PO)V_z4Bja9H$q|;L>*6e&N08^xbpZHuk%^?gWs04+Q9R-{4>X zTc1eViI+&ay4{mrjENyb=>Rc*KALI8o@?UOpRbCC4#mTPMVTd=99i^n3H_7<7@;0x z-$`avsPAGZW0e2^ diff --git a/out/production/Tetris/Tetris/GameGui.class b/out/production/Tetris/Tetris/GameGui.class index 978ce99a4ed0a7bcbccfd3ea353e638b9e47f177..75c7ab80ce441b56387b5f73503a69ba729772b3 100644 GIT binary patch delta 23 ecmdnVzLR}JI5VU0O=nPmV<$OTgX diff --git a/src/Tetris/Board.java b/src/Tetris/Board.java index 3995db5..38d85ed 100644 --- a/src/Tetris/Board.java +++ b/src/Tetris/Board.java @@ -12,8 +12,15 @@ public class Board extends JPanel public static final int BOARD_WIDTH=10; public static final int BOARD_HEIGHT=20; public static final int BLOCK_SIZE=30; + + public static final int BOARDRIGHT_WIDTH=15; + public static final int BOARDRIGHT_HEIGHT=5; private Timer loop; private Color[][] board = new Color[BOARD_WIDTH][BOARD_HEIGHT]; + private Color[] [] shape ={ + {Color.YELLOW,Color.YELLOW,Color.YELLOW}, + {null,Color.YELLOW,null} + }; public Board() { loop = new Timer(500, new ActionListener() { @@ -30,16 +37,28 @@ public class Board extends JPanel @Override protected void paintComponent(Graphics g) { super.paintComponent(g); - g.fillRect(0,0,getWidth(),getHeight()); + g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.DARK_GRAY); - for(int row= 0; row< BOARD_HEIGHT;row++) - { + //shape mit 2-Forschleife + for(int i=0;i< shape.length;i++){ + for(int j = 0;j< shape[0].length;j++){ + if(shape[i][j] !=null){ + g.setColor(shape[i][j]); + g.fillRect(i*BLOCK_SIZE,j*BLOCK_SIZE,BLOCK_SIZE,BLOCK_SIZE); + } + } + + } + + for (int row = 0; row < BOARD_HEIGHT+1; row++) { g.drawLine(0, BLOCK_SIZE * row, BLOCK_SIZE * BOARD_WIDTH, BLOCK_SIZE * row); } - for(int col= 0; col< BOARD_WIDTH +1; col++) - { + for (int col = 0; col < BOARD_WIDTH+1; col++) { g.drawLine(col * BLOCK_SIZE, 0, col * BLOCK_SIZE, BLOCK_SIZE * BOARD_HEIGHT); } + } + + } diff --git a/src/Tetris/GameGui.java b/src/Tetris/GameGui.java index a2fd2c1..ef98f26 100644 --- a/src/Tetris/GameGui.java +++ b/src/Tetris/GameGui.java @@ -1,6 +1,6 @@ package Tetris; - import javax.swing.JFrame; +import javax.swing.JLabel; public class GameGui { public static final int width= 500, height =650; @@ -15,6 +15,7 @@ public class GameGui { window.setVisible(true); board = new Board(); window.add(board); + } public static void main(String [] args) {