From c4a4708ab1d11f4b8dedd2cce0e83033c5cb16a8 Mon Sep 17 00:00:00 2001 From: zhe Date: Wed, 17 Nov 2021 19:31:18 +0100 Subject: [PATCH] bausteine fallen --- out/production/Tetris/Tetris/GameGui.class | Bin 2248 -> 1426 bytes src/Tetris/Board.java | 43 +++++++++++++++++++-- src/Tetris/GameGui.java | 25 +++++------- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/out/production/Tetris/Tetris/GameGui.class b/out/production/Tetris/Tetris/GameGui.class index 33443e067b0562f4fff29fd23ad4df3691cab383..5b67cdb30fdbc0cf6c640daa4c487d1edee4d3d5 100644 GIT binary patch delta 722 zcmYk4%TH556vltk*KIFDrA1JDP*4;okBfkyq9Pz7P!$EiijUl+SFO<+X$9Tby$hrE zFTu#gNaEVKck9NTYuCgxfRWtX@6313H|NYZnQw^?RpsxSU%mqU+_!0<&!XQZKwpfL z4A=~E%FxpmXQB+*Se%U!=bXj)D8q(duoy9M)WDd5iw4FmF4@$YMsX%g=5mxtTZoL9 zQiNCXxzZ!W`=385oq=pu3&#}6$L_NG(kZUw3lE*C8Moj)v6$9mxMFctbB!6zb#7GN z2AiTS%xaEsw6Yp(9+~5&B0lGpmhwes!hPyZyvS?jSlF6i9w%) zi6Nh)?5&l)d)KHlDf#Ps>i;dv$$ipjb?a!Yf&)|wR*AK0wAf71N+)fSZ)c1&({wN^ znMJyIKsV2EcukKepnltnDAU3;MbUPO)tG3zcPtNzMoBfcL0nF?zjxvPZ1V`AkElFU S(@$?JWkQcI#R19${q z8Q6^x9is+97^%k?o;5IzQ;I#UBNf3J13D%Y|D2BJBY45UDoiNLvx<6AQ9@B^9hnHS z24a}dAq_NRQZcy*rXsL(OdHs!L?N70hw_Tzp_vG51Fg#E4mdhyBX~*iu8xA*J+&0o za$YTSIxZN9t7LcJVg#2A?yTTt4YhMt)|=9x4QOcSb?kyCY;RoTi?RmLZfmHUl2&fY zBNw_#^Ry$}tcKOeG3mKhAhGim9LiFBTlSklRe{J3x}#V-iM-jr3)5M7MfPoMooOGTX( zw#?rXby!K2Ixo`qQ74sDCFM;H`AKi6PI^pU@cJy7S9R&>qUSmG9u3XaMm@fK*<$aK z?LO8wBP?6Py7meGP$Dnbj8Qhs&UO3s3pdA#n(m|4V2nCNHzWHj)ev)`*j=ivCc1Hm zO{!|KU#yN-OuUMD9j}>q9dDR;6K~yZ>DNvFZ39zoo2vYva`?81%Xo*$R(W0O0kiC} zJWu)u+9WHGX=$5y7xO0G!xa-(74<%@(6Y)!&>^BQ>Iv6dNG2iXyu?v!M%o3-p_^`e zVB$l3M6+R0EU@C*(TwAA_nrCX{jQZwii=LsGx0I5nfL_rch}|*8X*nF(!>EABxEWd z-$jq(W~CcAAw0)Kfxa%|Q%>^2ATRXU#Ahm_&+&zc>$qX!OWYs|E2rJWV|bjQdZq12 zmviYy@gY8$o|YMwx_T*auakFZQ=86<%sDl~)f&!Ei;^sUFhQPuBI7ykMGcJ^R|-!K z3IY(QH0*C5;LqKDI;y5K?U$QaagKrN3({M3vbFtw_JP))(B{D4p2@8dS$_VV3t9zc zuQN02*z84jkb~dvWg%;yo3cCt+Q9gIgf{0oMVn5Vs+_P*!KcwbawHWP_poJ)#DwDqh5V(+aCVHYjY7lR;D?InaN6>}(LbV}12&KxXNyZzsYf&S*Hfr2N_(#;1P*;JTibcw(AB^uT!8ldHs#MG@qhYA)CRUfQ zhFi3R#&}ntjiq8uWvo3IZV6Y=oNB~%{+6+>g!L6rxj`vweX>Q7b@2)|rfR}vY${=M z{3f=Pur=NiR^H+*%s_2*YU`|^H5F?sW7{ok@B9JV^B)e;_742|2> zUQ!eFZyMbK=x;k?Q{j;4nlu2r2 delayTime){ + y++; + beginTime=System.currentTimeMillis(); + } + + repaint(); + //System.out.println(n++); } }); loop.start(); @@ -44,7 +61,7 @@ public class Board extends JPanel if(shape[row][col] !=null){ g.setColor(shape[row][col]); // - g.fillRect(col*BLOCK_SIZE,row*BLOCK_SIZE,BLOCK_SIZE,BLOCK_SIZE); + g.fillRect(col*BLOCK_SIZE+x*BLOCK_SIZE,row*BLOCK_SIZE+y*BLOCK_SIZE,BLOCK_SIZE,BLOCK_SIZE); } } @@ -59,4 +76,22 @@ public class Board extends JPanel } + @Override + public void keyTyped(KeyEvent e) { + + } + + @Override + public void keyPressed(KeyEvent e) { + if(e.getKeyChar() == KeyEvent.VK_SPACE){ + delayTime=fast; + } + } + + @Override + public void keyReleased(KeyEvent e) { + if(e.getKeyChar() == KeyEvent.VK_SPACE){ + delayTime=normal; + } + } } diff --git a/src/Tetris/GameGui.java b/src/Tetris/GameGui.java index b33b061..05fc7e3 100644 --- a/src/Tetris/GameGui.java +++ b/src/Tetris/GameGui.java @@ -7,24 +7,26 @@ public class GameGui { private Board board; private JFrame frame; + //Zhe Wang-Holkenbrink public GameGui(){ JPanel panel = new JPanel(); - panel.setBorder(BorderFactory.createMatteBorder(400, 10, 20, 10,Color.black)); + panel.setBorder(BorderFactory.createMatteBorder(400, 10, 10, 10,Color.black)); + /* //Label JLabel label = new JLabel(" Ihr Name:"); panel.add(label); //Textfeld - JTextField tfName = new JTextField("Bitte Name eingeben"); - tfName.setForeground(Color.white); + //JTextField tfName = new JTextField("Bitte Name eingeben"); + //tfName.setForeground(Color.white); // Hintergrundfarbe wird gesetzt - tfName.setBackground(Color.GRAY); + //tfName.setBackground(Color.GRAY); // Textfeld wird unserem Panel hinzugefĆ¼gt - panel.add(tfName); + //panel.add(tfName); //Button JButton button1 = new JButton("Start"); - button1.setPreferredSize( new Dimension(150,150)); + button1.setPreferredSize( new Dimension(150,50)); JButton button2 = new JButton("Pause"); JButton button3 = new JButton("Score"); @@ -33,16 +35,6 @@ public class GameGui { panel.add(button1); panel.add(button2); panel.add(button3); - /* - window.add(panel, BorderLayout.EAST); - frame.add(window,BorderLayout.WEST); - window.setSize(width,height); - //window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - window.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - window.setResizable(false); - window.setVisible(true); - board = new Board(); - window.add(board); */ frame = new JFrame("Tetris"); frame.add(panel,BorderLayout.EAST); @@ -51,6 +43,7 @@ public class GameGui { frame.setResizable(false); frame.setVisible(true); board = new Board(); + frame.addKeyListener(board); frame.add(board,BorderLayout.CENTER); } public static void main(String [] args)