From 56efa700e493886f28a889284000170ef22a88e0 Mon Sep 17 00:00:00 2001 From: cdruk <36283689+cdruk@users.noreply.github.com> Date: Thu, 24 May 2018 17:51:29 -0400 Subject: [PATCH 01/20] Create README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..34b28cc --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Tetris +This is a Tetris game that can be played on your computer by running the eclipse project. It is easy to play using simple keyboard controls that allow you to move pieces side to side, rotate pieces, drop pieces quickly to the bottom, and switch the current piece with the next one. From cd011607c3e637e4c425efc133c8a1a4c5638953 Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 24 May 2018 17:55:22 -0400 Subject: [PATCH 02/20] edit side panel --- bin/.gitignore | 1 + bin/org/psnbtech/BoardPanel.class | Bin 6479 -> 6479 bytes bin/org/psnbtech/SidePanel.class | Bin 3686 -> 3802 bytes bin/org/psnbtech/Tetris$1.class | Bin 2231 -> 2225 bytes bin/org/psnbtech/Tetris.class | Bin 6527 -> 6524 bytes src/org/psnbtech/SidePanel.java | 16 +++++++++------- 6 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 bin/.gitignore diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..cf1db2e --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/org/ diff --git a/bin/org/psnbtech/BoardPanel.class b/bin/org/psnbtech/BoardPanel.class index 142911a031b4c4a8e3b140c43b7e2b353ae2d9b2..fb784d53520b72b9a745f7c23a76658d68f647a7 100644 GIT binary patch delta 351 zcmWO2Jtzcl9LDkI`>zu&$~g{6ao)~?a|=!~$Xj`vP8^q%mqm&5QX<6U3}-X2cq!$j zGu=1V$xFDY=F>2^7?m4!22?i$CP*mOObjbb?{ zm6LK6P@z)1@=~d4s?on6Qn|YH%*m#JVGL}sxE2fTB6J*WwTZim6$(EUA+bpr8puPS<`I3n$q!C+IzcQ6UEtVEFMLi z3(O6`)$8p(wFq5zx>_ZOKP}E&vQAllz}r|?i$0L*l<0X^%6NK zQx=uVr%EMMtAZL;Q>#`y3gFcUbqe9r0u9=xQM)whl4d>8qG$YirA;Z?^-hOA=+w8( zzxaV(GUy|Reu^2OfJT*)jes1cj2aFQ*Q v=y31g*i#<+@l?T==SXQBE0+@$aVjro_J%8UajhN_3Ui~F^%l4B&%*hC5;92X diff --git a/bin/org/psnbtech/SidePanel.class b/bin/org/psnbtech/SidePanel.class index 01ce5fbdc788893d6291b2c796c26e116aaa8a01..484f8143d446a14d2ffe713af235c3631348a96e 100644 GIT binary patch delta 1303 zcmZ8hYitx%6#nk+%syss&7^jON*BhUu~?Uw*scbfYSUs_Qns}ZOllLl?oR21WvAKQ zvIKu@ApJoMF~Dextq-b&DuP;CM=6Nn0|n8FLPZoof0*bm6BB$%$piJR=~cfar4 z^PPLno&CM+YEU`<@6>4kmH2gBS;CeKGu&3!6m4s1YHZyUiMFn7a|2A8c$m2)eQC8G z(p#)-ENkessjL}KTJbG8Gh_I$o1vt}-YIMOXBqBjG`h2TZ8~k`Xu}3;o1qKFhdm5S zTg=Tp{}T(856@AK_TI&P>tgAIUZ1vleb`Gm>#baBQERoxU{2f5aC>WyN$Zf_nlm5D z#(VUrv7OwWr?WH@+Z^l57kW^Ag9)c*Xup ze(>&t93yy*K`}F8XVW$#&EPIy)uCV%hrKw&pxH66mgg8lAA@(Zk*%|m86m&Pab$sO zv2q3OD916uaf+)qw;HL8X{AK)I~?y~oXR4h&FYP$GDem`Dvzv+2zi2IQpjSTXktMZ zg2VAXK48n>F*9vu(qQnEMXIjw^7t*{vibBE1KpjC16||a80J^4rOrr#s5Tq-4KMm^`=o%sV4j9I4FG2L`@Zu4VvA}}u->U4fg-Is22iu*ABF#6N~W{U4Apf|baKIeJAp7XvZ z_locLTKDOH=1u^(2iK?E)vS7wp&}fQB@^-X&L^U=&eo(2VD&SrnPd-o9`rZ(A2GJ* z{&sz!pkNz0N0zBXW^f~MFEFfl)NGM!iZ3!$wvshr6jBA@eewK=E~sH?Wt%oym*D@hy6e!4?R1yHUcMPV8gw8o9y7 z;rvivLGRz#n9OALl+PGL z!uc@AdpNS1jzN~BF&rJr>!jEohz6s=KFRR`jw}X>W|r;3FwHT8qvl=CDu=}}i(_V+ zb6zRoTaME>W7a8w*g1~#A{a2KVf{Pq`0Izq~G9xhelnj3(exO&@@^sJWih`3%#LR(pu%sm^9D3yIH*%R5z?! zHoT-&Y7bc$2x)0;mDZwBlv#HaVGFxri{CxFv8~}0#u_Y4G}~!C&@9vXwmGk^R1P(} z8f+HcHy6|@Hf2`v+iw4Gj59CyI`%DG7*m;773ky?T~QkzpmjS|nO!_w+)2kB$5rgY zAJ~gOF@e9apV@GLxp0u(ghQ+rhgkqqtP#_!8MCYf$Jja?XEDsNCkYpbdlsK!EoB{B zJUcd^i+0on9LF3Oe5?;2L4`yWcHm=t0vpwM1}BO{+NsnCB~T$#K?9!=a!}bmoFwF= z;$8ThkU|pT_=1p&gglHd3Ax$5XvJ5ARJImPI7Nu#YpUG@#{y~PPB15W=q<6O2e?6% z?v(z5Yr&lGc)CmEE{QurO6y4Vtu#XianIM-Ll(ZF0oK@SeHz!eg|lVuyZ^XeIjwQI z%-3q1c0T!kw~MBuV&#g<6z!FJedUFGymH!}ws6_JzoI617A~AaB`(5;OQ@$ib{|b6 zf@^5Qb)@hMwi130znaC0>WJtZ6Us182bId`XF~LIAx`w#j`diBE5ym=HaH>OKpVT8 L!mg5&glqo-6-_8i diff --git a/bin/org/psnbtech/Tetris$1.class b/bin/org/psnbtech/Tetris$1.class index a5b3ea1ec31d38be760130d6413161d2011e42ed..e4dd11249870b6f693df669928d9ce9c38f31c40 100644 GIT binary patch delta 88 zcmdlkxKU8x)W2Q(7#J8#81mQ|m>3yECk6^{R1Rfj?ATn%YR<$Pz`*~T!9(dcg9{K% oKEN)@#2PdCAiIb-YbrZ~%zvOxCUyo!b_OvJEyE}_nU!M`04YNhng9R* delta 125 zcmdlexLr`-)W2Q(7#J9g8S>Z}m>3yECk6^{R1Rfj?Au()YR(iI#vuBe!9$+uH-jS> pN3%1?{Ab``U}9%rWM>cq(K3uoOflGnQ^CRvsH%mTCjV#O1OTd67B~O^ diff --git a/bin/org/psnbtech/Tetris.class b/bin/org/psnbtech/Tetris.class index 26c5acbe91c012f64e7eb4078df747e7d3f2ceec..5d7475dd9d12bc9c61a5edefa71d4a4358376015 100644 GIT binary patch delta 37 tcmexw^v8(f)W2Q(7#J8#Hgde=Wi;CSiC2n|S)74oGC#lQW_A7uE&vqE3%URR delta 41 xcmexk^xuf%)W2Q(7#J9gH*&n>Wi;LViC2n|S&D&mGC#j4^G^o0%_{s6TmVMm48H&X diff --git a/src/org/psnbtech/SidePanel.java b/src/org/psnbtech/SidePanel.java index 4c8da70..5a8c660 100644 --- a/src/org/psnbtech/SidePanel.java +++ b/src/org/psnbtech/SidePanel.java @@ -64,12 +64,12 @@ public class SidePanel extends JPanel { /** * The y coordinate of the stats category. */ - private static final int STATS_INSET = 175; + private static final int STATS_INSET = 155; /** * The y coordinate of the controls category. */ - private static final int CONTROLS_INSET = 300; + private static final int CONTROLS_INSET = 260; /** * The number of pixels to offset between each string. @@ -136,11 +136,13 @@ public void paintComponent(Graphics g) { g.setFont(LARGE_FONT); g.drawString("Controls", SMALL_INSET, offset = CONTROLS_INSET); g.setFont(SMALL_FONT); - g.drawString("A - Move Left", LARGE_INSET, offset += TEXT_STRIDE); - g.drawString("D - Move Right", LARGE_INSET, offset += TEXT_STRIDE); - g.drawString("Q - Rotate Anticlockwise", LARGE_INSET, offset += TEXT_STRIDE); - g.drawString("E - Rotate Clockwise", LARGE_INSET, offset += TEXT_STRIDE); - g.drawString("S - Drop", LARGE_INSET, offset += TEXT_STRIDE); + g.drawString("< - Rotate Anticlockwise", LARGE_INSET, offset += TEXT_STRIDE); + g.drawString("> - Rotate Clockwise", LARGE_INSET, offset += TEXT_STRIDE); + g.drawString("Left Arrow - Move Left", LARGE_INSET, offset += TEXT_STRIDE); + g.drawString("Right Arrow - Move Right", LARGE_INSET, offset += TEXT_STRIDE); + g.drawString("Up Arrow - Hard Drop", LARGE_INSET, offset += TEXT_STRIDE); + g.drawString("Down Arrow - Soft Drop", LARGE_INSET, offset += TEXT_STRIDE); + g.drawString("Shift - Switch Next", LARGE_INSET, offset += TEXT_STRIDE); g.drawString("P - Pause Game", LARGE_INSET, offset += TEXT_STRIDE); /* From 1478511d953ec8eeb69e069acb6dfd940fb3aad7 Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 24 May 2018 17:56:48 -0400 Subject: [PATCH 03/20] change shadow color --- bin/org/psnbtech/BoardPanel.class | Bin 6479 -> 6479 bytes src/org/psnbtech/BoardPanel.java | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/org/psnbtech/BoardPanel.class b/bin/org/psnbtech/BoardPanel.class index fb784d53520b72b9a745f7c23a76658d68f647a7..88256b45808db581dc3b97ada9ede6caa5403c59 100644 GIT binary patch delta 14 VcmX?ablzx#mk6WLW^WM|Rsbpm1YZCE delta 14 VcmX?ablzx#mk6WCW^WM|Rsbnc1VI1* diff --git a/src/org/psnbtech/BoardPanel.java b/src/org/psnbtech/BoardPanel.java index 2951ce5..e0f7ba0 100644 --- a/src/org/psnbtech/BoardPanel.java +++ b/src/org/psnbtech/BoardPanel.java @@ -345,7 +345,7 @@ public void paintComponent(Graphics g) { * down until we hit a row that would cause a collision. */ Color base = type.getBaseColor(); - base = new Color(base.getRed(), base.getGreen(), base.getBlue(), 20); + base = new Color(base.getRed(), base.getGreen(), base.getBlue(), 50); for(int lowest = pieceRow; lowest < ROW_COUNT; lowest++) { //If no collision is detected, try the next row. if(isValidAndEmpty(type, pieceCol, lowest, rotation)) { From b31844db8ee6f6c7b2077e21a1b501d370779f40 Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 24 May 2018 18:01:05 -0400 Subject: [PATCH 04/20] update controls --- bin/org/psnbtech/Tetris$1.class | Bin 2225 -> 2225 bytes src/org/psnbtech/Tetris.java | 12 ++++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/org/psnbtech/Tetris$1.class b/bin/org/psnbtech/Tetris$1.class index e4dd11249870b6f693df669928d9ce9c38f31c40..7ca5c061f9246de67f61395f5ce096969abb2e08 100644 GIT binary patch delta 68 zcmdlexKVJ!99CUb1_p+7AXW$BH9)KZ#4bRr1H>PJSdW2$Q3gl{0BMiSCs|{eSV2lO JCTnxF0RVHw3Qzz5 delta 68 zcmdlexKVJ!99CUN1_p+7Aa()bH9+jjz`!U2qyvDo2apZ~;*UTa48$&*PqM}`v4WVv IleIb80Es6HMgRZ+ diff --git a/src/org/psnbtech/Tetris.java b/src/org/psnbtech/Tetris.java index b9813df..a654511 100644 --- a/src/org/psnbtech/Tetris.java +++ b/src/org/psnbtech/Tetris.java @@ -153,7 +153,7 @@ public void keyPressed(KeyEvent e) { * paused and that there is no drop cooldown, then set the * logic timer to run at a speed of 25 cycles per second. */ - case KeyEvent.VK_S: + case KeyEvent.VK_DOWN: if(!isPaused && dropCooldown == 0) { logicTimer.setCyclesPerSecond(25.0f); } @@ -164,7 +164,7 @@ public void keyPressed(KeyEvent e) { * not paused and that the position to the left of the current * position is valid. If so, we decrement the current column by 1. */ - case KeyEvent.VK_A: + case KeyEvent.VK_LEFT: if(!isPaused && board.isValidAndEmpty(currentType, currentCol - 1, currentRow, currentRotation)) { currentCol--; } @@ -175,7 +175,7 @@ public void keyPressed(KeyEvent e) { * not paused and that the position to the right of the current * position is valid. If so, we increment the current column by 1. */ - case KeyEvent.VK_D: + case KeyEvent.VK_RIGHT: if(!isPaused && board.isValidAndEmpty(currentType, currentCol + 1, currentRow, currentRotation)) { currentCol++; } @@ -187,7 +187,7 @@ public void keyPressed(KeyEvent e) { * complexity of the rotation code, as well as it's similarity to clockwise * rotation, the code for rotating the piece is handled in another method. */ - case KeyEvent.VK_Q: + case KeyEvent.VK_COMMA: if(!isPaused) { rotatePiece((currentRotation == 0) ? 3 : currentRotation - 1); } @@ -199,7 +199,7 @@ public void keyPressed(KeyEvent e) { * complexity of the rotation code, as well as it's similarity to anticlockwise * rotation, the code for rotating the piece is handled in another method. */ - case KeyEvent.VK_E: + case KeyEvent.VK_PERIOD: if(!isPaused) { rotatePiece((currentRotation == 3) ? 0 : currentRotation + 1); } @@ -242,7 +242,7 @@ public void keyReleased(KeyEvent e) { * back to whatever the current game speed is and clear out * any cycles that might still be elapsed. */ - case KeyEvent.VK_S: + case KeyEvent.VK_DOWN: logicTimer.setCyclesPerSecond(gameSpeed); logicTimer.reset(); break; From 861df9da6844a89293a2c9a79ece037f6168696a Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 24 May 2018 18:03:47 -0400 Subject: [PATCH 05/20] fix drops --- bin/org/psnbtech/Tetris$1.class | Bin 2225 -> 2387 bytes bin/org/psnbtech/Tetris.class | Bin 6524 -> 6588 bytes src/org/psnbtech/Tetris.java | 18 +++++++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bin/org/psnbtech/Tetris$1.class b/bin/org/psnbtech/Tetris$1.class index 7ca5c061f9246de67f61395f5ce096969abb2e08..ee56b7fca0598d3076860d47fa29799997baeebc 100644 GIT binary patch delta 1030 zcmZ8gOH30{6g_u3w51eu8gU_!G*yf)FeYLQ26tjut1&JV69EI>>8sF?_P%r8o%7DU^Kxe-^`j+aV)6M) z04^v7NQCrYecH&TDyg7=U~Fq|_bN(((*!GAW|U+5O43Cr4f@vKk=CfYbfzq~rrBXe zC3dc8$_XVgO_wfFotLKQfcjqND9j@y#>~sMX(x}H(TJwFtdo!x^kt~IvSDkB87FX( zA1YpdU0aXh^$_HursAX8$yPJkV2nHIQXAy_Bz;HMRj=YFP>t%B^DXDixPXgsvhrYO zc4D;&4qP&$Q++2t4(JR>fDWK}M;PhDd@Ia<^J3&MG5^G9;~3*831a%6i5a6~7 z+#SZAULkcv#ytM&On`5gZKR&wm&E z5Nx$et4PPYV0_u6l}%JdZ>L&yK<`Me4WUKo>-!Kb6+weKqt6T+6KR`(oG_Y0$X%8u z3)avJlVGPt_*QjT%j*?v;Po!waX&m5KsN@VAcSjph+BAsVg5a3{sK?%3K7iW84<=v z#yC~tHC5vc)dVm}NAQ7sm?A%>={i1BKW1nUUuYCxX#(G98sBLKzvw4sX%2Hp;j(#R zRFDb_?|5i%8tps_H&MaOcp>2oryG&BfV%v@SVwkg9>xXi<$tpQ)+HV*$pBK{8r*bN zO)ysUoa0dtFKG*-W92<9klAVxnWRTC8Q`R(XbTx!MEi7OEie-;XoY1+nc3W;Hlq^X Tj4ztAA{m#NnYhvD*aH6mfOzMl delta 842 zcmZ9KOGs2v7{`C-&dnKzYwF}UrWR%nH8UaAjA@C1AY~|_5tff^Y&0L0AyQjuQ_*g^ zw3va!7Bz(iNiqyADq8j;YE#j!TGT=)=s`mE*^x%N-2eIizwP5qD7^9ZHM1KV3@fZ~^~GWXM)ynS)qzR@}!@rPlOv|mBBAV*V zel6-X?M~B}P_8ATGlO_D>`n1gJIj*HYxRGTsGhF3U*r_!)R|GqvOnhpRg3L)h9+84 z^yq;7Ne*b$p5$-)+A2%nbfhrN3Y0_paF8!!FFqNs z(9BhOm}H14PH>ZnDQfACXK$HhNOnly{!T MDN%0eNeRpM2R?1L{r~^~ diff --git a/bin/org/psnbtech/Tetris.class b/bin/org/psnbtech/Tetris.class index 5d7475dd9d12bc9c61a5edefa71d4a4358376015..8e8b82df9c9a4ee41a1087f60a620f81b329c375 100644 GIT binary patch delta 809 zcmZ8f*>B8I7(Hj2GFzvu`TgcMqo(a>&C*hxX@{t_(V>KR5mdBM>x-zQLaY(-Af*rH zL+yRFORWhaLPC@WTFZ-8h^_Gtco2M@AQSgKoO92;=j49(em@d-Yn;75Z{Gt@%LzTs z8&0>qb@l4C?d|2YM76X!Eji=#9J-MAPfrq6e|70}xTMNumwMNX>4f8tHD2umS?b0o zG-RpqES|{XHAFxYee%fVv1*5{5jXk~$vTph7UyWmbq}&kKDyuMd9joRR?tK%ebSeA zKUD%3OHsfOOh!=7D8_R630t@oJGl${xfchyPh15n9UU0S1Mu*m zY%bUn6XfzRoIHYj9z}>41Mpzyxt}-H$WBR1qh)TWUfUb8djy5B5 zM{%j*chiux8Dl~U4MU!rQPwH*irW`=%!b|80JkkAb9}d1D73tC$qMF}`cbs1b1eEZ z+FUCrU6xO_EB0FRZC85aid7_WzbT{qC9z_T0TI>448x`q7*SDlizPkEY={r9bsxMd zo&J#Q@CS3oGCvc1S$P@D(|$uf_=6mm4w$9k|7~d`GC?S?Gs;-T*cb>}6~ihkwRHgP JL^Lbv_ziHwwb1|o delta 764 zcmZ8fOGuPa7(Hivq`#xiF#kXQKkDfCn3qb;j5C6A-x+R8lj~MO0(LASn5M?1TPqT$J;e%HwtvdcKsz(Bi&^MpwxseOH5MX|4mjw9 zK@(N9P|FfTScZD~v5^5ZvKm`hgEp>1C*#<|1opEYgItdzY`}3A$(MpZi6)e=83DE+ z%xy?=Cz{!&obBjfw{q=9KYMVP`!K`<7~w&TaZpT0Pwr8y;V~3&NQNE5;giVXDQG;6 zLY_f6&#KH3)bJc)97O}qt7jTh*%u`2yjXr2IlKZFucDOKP|52^@Fuo%0l}^p3 zoF2B^R-v;h^geXXsiO}N;=Brcj17E(CO$rzg?=L>i@IC-jG#CS zx7<*;RpCd4qbkXAM|10tV~fLXOUMrQ91TgDkqkFY889QXWYUbugy|Na>6ImOv$R^? zgjanO5mKENfK5#xySn%uOJ@|bA-b|w``|QUs|p-B^vRSJlUtTsepud&3RX(e(xt-V jWtAj7hR^@M`9zvI$dDZJM9lC?9II7N0IKcKrBIE(oTQ{m diff --git a/src/org/psnbtech/Tetris.java b/src/org/psnbtech/Tetris.java index a654511..0911b48 100644 --- a/src/org/psnbtech/Tetris.java +++ b/src/org/psnbtech/Tetris.java @@ -149,7 +149,7 @@ public void keyPressed(KeyEvent e) { switch(e.getKeyCode()) { /* - * Drop - When pressed, we check to see that the game is not + * Soft Drop - When pressed, we check to see that the game is not * paused and that there is no drop cooldown, then set the * logic timer to run at a speed of 25 cycles per second. */ @@ -159,6 +159,22 @@ public void keyPressed(KeyEvent e) { } break; + /* + * Hard Drop - When pressed, we check to see that the game is not paused and + * then check for the lowest available row and drop the piece to there. + */ + case KeyEvent.VK_UP: + if (!isPaused) { + for (int lowest = currentRow; lowest < board.ROW_COUNT; lowest++) { + // If no collision is detected, try the next row. + if (board.isValidAndEmpty(currentType, currentCol, lowest, currentRotation)) { + currentRow = lowest; + } + + } + } + break; + /* * Move Left - When pressed, we check to see that the game is * not paused and that the position to the left of the current From e89aabc9ae3d06c05809b3452b94012bb858375f Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 24 May 2018 18:06:11 -0400 Subject: [PATCH 06/20] add piece switch control --- bin/org/psnbtech/Tetris$1.class | Bin 2387 -> 2624 bytes bin/org/psnbtech/Tetris.class | Bin 6588 -> 6829 bytes src/org/psnbtech/Tetris.java | 14 ++++++++++++++ 3 files changed, 14 insertions(+) diff --git a/bin/org/psnbtech/Tetris$1.class b/bin/org/psnbtech/Tetris$1.class index ee56b7fca0598d3076860d47fa29799997baeebc..294c966a72ff002b5cd14a7c347c4bdc91f21e6b 100644 GIT binary patch delta 1018 zcmY*YTS!z<6kYqy&3SZvO^$COwK2U~W?J_6Nr;L{Ni!QC`5H&f@~x?<%~yQ{L2`+3 zpa=@4lpsrnDIo%-AgC<;P5O%@{H#!m_VMa8UhY0??X~wgXPOq3J*6DP0b#2eyZ9yW66`VmykeW@%8t#bJY7H^&^iq*hs^Hv) zls!T%Q&5f*K@)R?TB+bXwgsuVLakO%vq9Y})H(%D)CcA6BgCbhYU^ywYVT^T>vjzf zSwhQ24H;-q(1<22UyiXhE4T<#(6l_QS%ZOqenFtb^hhcZS0RKRFwn_^34>t)-) zx`|Qbm#}5B-^aL%@d4v$#*gX*EPf<-=)KO8JT#>9O0MwaY(NB zfN&mfAeqP8aNsU3;U4;M9|Q2heGQLr3!`|BF-$U_##6k7A1io4W=xWTDayw*72*vQ z;R97*hMf3B9r#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<@^LTF@A7Ov5PJORG*-Q1!ZJ8Bxup zbERJFq7QqiBS*hVl|9c^p@boL7=}&*QN~cqTGVkJHZYCNT#qapu$>#x#wP4x2K$-C z0dB=%w%{0Bae@g|Up}91!wT+3HQNzqCpNJgE$k6xFWT8Bs($qI5RULD26-Ikc?Lr~ zs}6ehIWJ%-FQSY?YQ}RauCSQHaPczAIf5`p#q$bkcoi0}p`O>}Rc?s)O?7hFaCi(3 z-hr2Qv6A-?;eDj}5IdO1PCk;P6Zup{fUPgY^re`-fsX|_`W7)xiQ#)RavIJ2fDV3? zNS`FmXSv)gZu1K!_zkc59aH>)cl?PN{!$~}TN;0>Io+qW`3#MJY&_?SQM2ilkjp0O zF;)oas!2B(v}sUil}%5C5<-o%?0M2}utCVH`uwJI3mjSoZY`T1^M^H+TkZ`#X4SaV zhz3*oB_O~_SoR7$4u;iez!L95z*-bxRLuuWu2yDH4^{s!yHq5LF|K-ob(M()Bi6{@ L15!%pkWtz{%Se@! diff --git a/src/org/psnbtech/Tetris.java b/src/org/psnbtech/Tetris.java index 0911b48..bd1c44f 100644 --- a/src/org/psnbtech/Tetris.java +++ b/src/org/psnbtech/Tetris.java @@ -197,6 +197,20 @@ public void keyPressed(KeyEvent e) { } break; + /* + * Switch Piece - When pressed, we check to see that the game is not paused and + * then switch the current piece with the next piece. + */ + + case KeyEvent.VK_SHIFT: + if (!isPaused) { + TileType bufferType; + bufferType = currentType; + currentType = nextType; + nextType = bufferType; + } + break; + /* * Rotate Anticlockwise - When pressed, check to see that the game is not paused * and then attempt to rotate the piece anticlockwise. Because of the size and From 20cd0b37c6e156067048dc98c13eff9e2569b076 Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 24 May 2018 18:53:43 -0400 Subject: [PATCH 07/20] key adapter class --- bin/org/psnbtech/Tetris$1.class | Bin 2624 -> 0 bytes bin/org/psnbtech/Tetris.class | Bin 6829 -> 4856 bytes src/org/psnbtech/Tetris.java | 141 +----------------------- src/org/psnbtech/TetrisKeyAdapter.java | 146 +++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 140 deletions(-) delete mode 100644 bin/org/psnbtech/Tetris$1.class create mode 100644 src/org/psnbtech/TetrisKeyAdapter.java diff --git a/bin/org/psnbtech/Tetris$1.class b/bin/org/psnbtech/Tetris$1.class deleted file mode 100644 index 294c966a72ff002b5cd14a7c347c4bdc91f21e6b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2624 zcma)8U2IfU5dP+N>1~%&D5aE^E{H&3`$M;dLcxV~c?kRr*cOU}tPVo8H!q@oh~Vmq24yJ-^9AOi*o`8T3Fufr zDDo=6!ro9s?wLG3B4dNbNLUgodZVTh9x`GfwVyS*lrw~-`7T=1%FejQWuiYO<8c`z zc)Yz22iC13^w$r$QH5$9OPQ?zNT3GGm~vEFoDda(?QOsf4_4?{PFS2LBLa_MC85MH zO?E>iu25cv711hz)mW3kw-(0R7q1mq2X6+yfzVhW@3~3p3P;UxzpL{bz>P+%*U`jD z&I!PV2sFdTPvX+*N|<38@0YOwX+|TQP?xtyCC-CZfeqPSZ&b!Mflb()ajlKe@<^`j zh#IkAzY&pPzv9^2E~3r zU|2blzSDlehXh_wwVk%MDeQ{^M{=y2lyyYF1eZ)2%Y{)O_+jNqBaRA;VvJ94<@Fnr zb_ct>_CpVj35=s8i>{qO+>bQ{JDdkoI65Wc76Sv^#UqnPkMeNg@_2ZD%)L26*??u3 z<9)`&?7*4N^JJe4OM~4}VND90#8j3a{7wt?caMrHA@GtKbMts8N%qA(5S@&fvWKta zY3NMhW;KAg#JVG9I2sQ{M*E~S7UkrLKqMk#U15XgSsW{QeirdSr}A<&L|Ici9VKip zWo-*I{^Ry;X#AAFK7+W#I}Hn!&3?je;BA!iUho-ZU4#mjJjqb$uoN9&4D)L18)vZO zB0pr^%U|jSH|u3AnSuIP*73T=Yb~!SUhCLi!cyS}c{TC=6w79oAF%9ad86S9+$q#f z(|3;c_%vN}w7QD=88js6N*Z#((OR}A(dwuh9nt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hX4Qo diff --git a/src/org/psnbtech/Tetris.java b/src/org/psnbtech/Tetris.java index bd1c44f..99cf239 100644 --- a/src/org/psnbtech/Tetris.java +++ b/src/org/psnbtech/Tetris.java @@ -141,146 +141,7 @@ private Tetris() { /* * Adds a custom anonymous KeyListener to the frame. */ - addKeyListener(new KeyAdapter() { - - @Override - public void keyPressed(KeyEvent e) { - - switch(e.getKeyCode()) { - - /* - * Soft Drop - When pressed, we check to see that the game is not - * paused and that there is no drop cooldown, then set the - * logic timer to run at a speed of 25 cycles per second. - */ - case KeyEvent.VK_DOWN: - if(!isPaused && dropCooldown == 0) { - logicTimer.setCyclesPerSecond(25.0f); - } - break; - - /* - * Hard Drop - When pressed, we check to see that the game is not paused and - * then check for the lowest available row and drop the piece to there. - */ - case KeyEvent.VK_UP: - if (!isPaused) { - for (int lowest = currentRow; lowest < board.ROW_COUNT; lowest++) { - // If no collision is detected, try the next row. - if (board.isValidAndEmpty(currentType, currentCol, lowest, currentRotation)) { - currentRow = lowest; - } - - } - } - break; - - /* - * Move Left - When pressed, we check to see that the game is - * not paused and that the position to the left of the current - * position is valid. If so, we decrement the current column by 1. - */ - case KeyEvent.VK_LEFT: - if(!isPaused && board.isValidAndEmpty(currentType, currentCol - 1, currentRow, currentRotation)) { - currentCol--; - } - break; - - /* - * Move Right - When pressed, we check to see that the game is - * not paused and that the position to the right of the current - * position is valid. If so, we increment the current column by 1. - */ - case KeyEvent.VK_RIGHT: - if(!isPaused && board.isValidAndEmpty(currentType, currentCol + 1, currentRow, currentRotation)) { - currentCol++; - } - break; - - /* - * Switch Piece - When pressed, we check to see that the game is not paused and - * then switch the current piece with the next piece. - */ - - case KeyEvent.VK_SHIFT: - if (!isPaused) { - TileType bufferType; - bufferType = currentType; - currentType = nextType; - nextType = bufferType; - } - break; - - /* - * Rotate Anticlockwise - When pressed, check to see that the game is not paused - * and then attempt to rotate the piece anticlockwise. Because of the size and - * complexity of the rotation code, as well as it's similarity to clockwise - * rotation, the code for rotating the piece is handled in another method. - */ - case KeyEvent.VK_COMMA: - if(!isPaused) { - rotatePiece((currentRotation == 0) ? 3 : currentRotation - 1); - } - break; - - /* - * Rotate Clockwise - When pressed, check to see that the game is not paused - * and then attempt to rotate the piece clockwise. Because of the size and - * complexity of the rotation code, as well as it's similarity to anticlockwise - * rotation, the code for rotating the piece is handled in another method. - */ - case KeyEvent.VK_PERIOD: - if(!isPaused) { - rotatePiece((currentRotation == 3) ? 0 : currentRotation + 1); - } - break; - - /* - * Pause Game - When pressed, check to see that we're currently playing a game. - * If so, toggle the pause variable and update the logic timer to reflect this - * change, otherwise the game will execute a huge number of updates and essentially - * cause an instant game over when we unpause if we stay paused for more than a - * minute or so. - */ - case KeyEvent.VK_P: - if(!isGameOver && !isNewGame) { - isPaused = !isPaused; - logicTimer.setPaused(isPaused); - } - break; - - /* - * Start Game - When pressed, check to see that we're in either a game over or new - * game state. If so, reset the game. - */ - case KeyEvent.VK_ENTER: - if(isGameOver || isNewGame) { - resetGame(); - } - break; - - } - } - - @Override - public void keyReleased(KeyEvent e) { - - switch(e.getKeyCode()) { - - /* - * Drop - When released, we set the speed of the logic timer - * back to whatever the current game speed is and clear out - * any cycles that might still be elapsed. - */ - case KeyEvent.VK_DOWN: - logicTimer.setCyclesPerSecond(gameSpeed); - logicTimer.reset(); - break; - } - - } - - }); + addKeyListener( /* * Here we resize the frame to hold the BoardPanel and SidePanel instances, diff --git a/src/org/psnbtech/TetrisKeyAdapter.java b/src/org/psnbtech/TetrisKeyAdapter.java new file mode 100644 index 0000000..007e91c --- /dev/null +++ b/src/org/psnbtech/TetrisKeyAdapter.java @@ -0,0 +1,146 @@ +package org.psnbtech; + +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; + +public class TetrisKeyAdapter {{ + + new KeyAdapter() { + + public void keyPressed(KeyEvent e) { + + switch(e.getKeyCode()) { + + /* + * Soft Drop - When pressed, we check to see that the game is not + * paused and that there is no drop cooldown, then set the + * logic timer to run at a speed of 25 cycles per second. + */ + case KeyEvent.VK_DOWN: + if(!isPaused && dropCooldown == 0) { + logicTimer.setCyclesPerSecond(25.0f); + } + break; + + /* + * Hard Drop - When pressed, we check to see that the game is not paused and + * then check for the lowest available row and drop the piece to there. + */ + case KeyEvent.VK_UP: + if (!isPaused) { + for (int lowest = currentRow; lowest < board.ROW_COUNT; lowest++) { + // If no collision is detected, try the next row. + if (board.isValidAndEmpty(currentType, currentCol, lowest, currentRotation)) { + currentRow = lowest; + } + + } + } + break; + + /* + * Move Left - When pressed, we check to see that the game is + * not paused and that the position to the left of the current + * position is valid. If so, we decrement the current column by 1. + */ + case KeyEvent.VK_LEFT: + if(!isPaused && board.isValidAndEmpty(currentType, currentCol - 1, currentRow, currentRotation)) { + currentCol--; + } + break; + + /* + * Move Right - When pressed, we check to see that the game is + * not paused and that the position to the right of the current + * position is valid. If so, we increment the current column by 1. + */ + case KeyEvent.VK_RIGHT: + if(!isPaused && board.isValidAndEmpty(currentType, currentCol + 1, currentRow, currentRotation)) { + currentCol++; + } + break; + + /* + * Switch Piece - When pressed, we check to see that the game is not paused and + * then switch the current piece with the next piece. + */ + + case KeyEvent.VK_SHIFT: + if (!isPaused) { + TileType bufferType; + bufferType = currentType; + currentType = nextType; + nextType = bufferType; + } + break; + + /* + * Rotate Anticlockwise - When pressed, check to see that the game is not paused + * and then attempt to rotate the piece anticlockwise. Because of the size and + * complexity of the rotation code, as well as it's similarity to clockwise + * rotation, the code for rotating the piece is handled in another method. + */ + case KeyEvent.VK_COMMA: + if(!isPaused) { + rotatePiece((currentRotation == 0) ? 3 : currentRotation - 1); + } + break; + + /* + * Rotate Clockwise - When pressed, check to see that the game is not paused + * and then attempt to rotate the piece clockwise. Because of the size and + * complexity of the rotation code, as well as it's similarity to anticlockwise + * rotation, the code for rotating the piece is handled in another method. + */ + case KeyEvent.VK_PERIOD: + if(!isPaused) { + rotatePiece((currentRotation == 3) ? 0 : currentRotation + 1); + } + break; + + /* + * Pause Game - When pressed, check to see that we're currently playing a game. + * If so, toggle the pause variable and update the logic timer to reflect this + * change, otherwise the game will execute a huge number of updates and essentially + * cause an instant game over when we unpause if we stay paused for more than a + * minute or so. + */ + case KeyEvent.VK_P: + if(!isGameOver && !isNewGame) { + isPaused = !isPaused; + logicTimer.setPaused(isPaused); + } + break; + + /* + * Start Game - When pressed, check to see that we're in either a game over or new + * game state. If so, reset the game. + */ + case KeyEvent.VK_ENTER: + if(isGameOver || isNewGame) { + resetGame(); + } + break; + + } + } + + public void keyReleased(KeyEvent e) { + + switch(e.getKeyCode()) { + + /* + * Drop - When released, we set the speed of the logic timer + * back to whatever the current game speed is and clear out + * any cycles that might still be elapsed. + */ + case KeyEvent.VK_DOWN: + logicTimer.setCyclesPerSecond(gameSpeed); + logicTimer.reset(); + break; + } + + } + + );} +} From c3ad372e07a665415f8feeb1c7a7639f60e0cd13 Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 24 May 2018 18:55:06 -0400 Subject: [PATCH 08/20] delete .class --- bin/.gitignore | 1 - bin/org/psnbtech/BoardPanel.class | Bin 6479 -> 0 bytes bin/org/psnbtech/Clock.class | Bin 1515 -> 0 bytes bin/org/psnbtech/SidePanel.class | Bin 3802 -> 0 bytes bin/org/psnbtech/Tetris.class | Bin 4856 -> 0 bytes bin/org/psnbtech/TileType.class | Bin 4669 -> 0 bytes 6 files changed, 1 deletion(-) delete mode 100644 bin/.gitignore delete mode 100644 bin/org/psnbtech/BoardPanel.class delete mode 100644 bin/org/psnbtech/Clock.class delete mode 100644 bin/org/psnbtech/SidePanel.class delete mode 100644 bin/org/psnbtech/Tetris.class delete mode 100644 bin/org/psnbtech/TileType.class diff --git a/bin/.gitignore b/bin/.gitignore deleted file mode 100644 index cf1db2e..0000000 --- a/bin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/org/ diff --git a/bin/org/psnbtech/BoardPanel.class b/bin/org/psnbtech/BoardPanel.class deleted file mode 100644 index 88256b45808db581dc3b97ada9ede6caa5403c59..0000000000000000000000000000000000000000 GIT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E$Y`W$Os9AHtHr$_e-^y#ShAZ?ixP z=VVf{^9zyo^s5I3-mTX>XknNNDx%(&>diFesMjrq&W zEAsX|Vw9l$gByB|7dP=fS7}^}{)xFo>*6Wtsjr_?`WIuq7Dv7o@d2ACjWS6i#cCvH z4w2}5M$lZMK>7(h8FQ^La;-Ufyqz^=hL0D2K_xLs@6j6lSzf?WJJLZKP|R197t-{2 z40t937P;)PH2n6cLMx+JPAe2n;ie?N8^b!Dp$u!1TKE$ohS*k1It)x4p*4+m|2M|Q Q)&7tGiLn~)C3l_w09LEyO8@`> diff --git a/bin/org/psnbtech/SidePanel.class b/bin/org/psnbtech/SidePanel.class deleted file mode 100644 index 484f8143d446a14d2ffe713af235c3631348a96e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3802 zcmZ`+dw5gj9e%$yY0~r*)6xJ%z=+%I#ZoU&HmJ;yUI>P^B%x5oRu0K&duW;yPEIMp zHnDaaDk{1S6n2q~!7jQfU^?mMbQkBGn{z{VSLc7*zx!{G&)EB&T)C{z)8u#ie%JT= zeeG-iz3?J{mH3AX6#@$kbF@93N$s+<_*i>XPiO;bN=v%n5UAg+?p61-XQuSjX!}N6 zF5t~*rmiLjH8Z0dsV$){0kKh_HfW?WmYT8#)#Rk+T-LMZ*|Ce6ae?YsDBL|94Q=nH zVW^U!6@i-QhCo;M@YYaQY=aar5sz&b?BCKClM<)EbFq9wnxs`M5Q~;XCj{mN`}<;%{%}bu z*p8Z5_qNz@G!_YU*%2C<&6!wO_N!f;vf6u$l(m-XT(q3p(-jG99S-(~`y=dP z$u?*t4U@)ImS&lHM!*-oY$h>VOapgkJgKL2Yn?!4Q}dvJBWNTv7j9wqFN^HP3c8D_ zW5$H)K`U-ma2sx?s55_jVN))AQsrQyjG7u<8wxcKRzqN=f*Y}1QXL9z!g3cr%7zsE z+u3@s8f&CenRZjCaP&?EAHs)aBlMKkH#xCOGh^zmq(&r#jW{u*5;^4a!bMHjEVOyh zgG#KI?we&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yXPZY&r9 zqswU=R2d?woFA|i;}}{o%FqW#ue*a`lj~ZAmWS$#1rp6oW(u!fa}*6ZJhWsON93$Y zejW>6ew>2_X&h{Mbb{1cOm0C19CE{CL@<4l6c7XV*Z;5a1!-~3?PLS}7LRo5 zjfHk0N@@H#C{c@0ti{tLOHy&qb6)sM(@FFEihrz3hl7;b2U@shIu^PS2M-3Rt7ih8x@XNmD72H7MQRp zH;An|ujbC9#mu^@`Z)shJb`>JLokM1J8LggGsE7(u(z>ct|xl!s8t&n@=aK-y3nF7 z$2N5Ze6<~W)ea_wiMv%daw>^aY8PHnyYae8;SJ?zggXN0@(2?|ys8r=jGy5roE5PP zy^7a3D`r=D9zW$Q#D4K4Ugs>#`hSFy@Bn_!StMVC!l%)S5|*F*9}C&^`uU7m zHMZxO*T7MjC$ag(!<>xk9I9^|1HyUx*p~|`KQ>wUs)EWj1(lm7D<3GR{043=VD>GO zm2W7h{ANMrLz9(nE2#V{yj9@kJ&#TT?9PJ9zb>eJWU}%D1(n|}X!hR8W(R#LXx3w) zdZ(cBzRAkN1z-M6LFN6Em7gh~T#Db~cX_~CNhxV_WhbEcmGJwvbB^KN$rb$t)}m7| e)QkGEpmmhtkN6W6OUUs*^Xo&1`WFrOU;hhUD;0?V diff --git a/bin/org/psnbtech/TileType.class b/bin/org/psnbtech/TileType.class deleted file mode 100644 index ac590aeb7836aae141ca6f898aa03a516c3c8d48..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4669 zcmb7He{fV+75?sf`y<)Bz>+plAZg35k}M>l{IVq>1pJfTcwpb#&}F<2cSZ)vEvLjMJHpGdhkI!SCFCyIGf) z&XgfJ_nv#tz2EunckX@p<;}OR16YM;{4f;C6UqL%;nYx1I@&u>*Aa_HJI02ies~mS z?6(ivb#Z&Bzi!LW$e@B(hFTQnw7Le>J2M`3Y^!5;IyUUs4###W6!+MvXj3AdNGb$d z^?vqfx=wqzTp%9nA4ogn#eH`2fYUBY4cntb>?kM#%5>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~8t>ypFvWhF%6snoT zmQc-QG*4o?*tSXR3YB{%(H@%XpF~Hf+&hWRP`PgsdqPF!9?#*vNpyum=4CuKiM=@? z@z_ha?8khFZm{)VeiYs0<8ccM6tGk&9=D1!8Phn!TVf;cNGR#x(4@SfLQpdvQnmCw_hlLy~H&*<{I2p7+m8Tyx%o=Z(;Bn z*Wd%L!FvjW8(o9ruECv!!OgD0{62LE+e3YbE`mJgj>?r4H0=ZP_pT~jr(LfT%FN9v zEQka(BsvLVm@PxMKF5|xZxT;9yS&0U*`?N8|0))mjjy6CR8cwqGEy(VTXEsIsVZgT z^S3@cZYYi6{H+fR!C-3H-A#3Z7nN7p2&f+1sd_P+?FIBLSN(a|YIE3XAvpM#9g5s8l{O5t~?Xo8(i=P|H3XY{=@oKyt}i2zv}>AEwDU&M7>l{&&i<<$UsG39`wH+ zH*QtDc8uM$VPmD8@LS_{>!mqDLwxP^LmxaqLG>)5jS&p;!1KKMrK2 GQ~v`OBwL;U From a16a6d67172eca423ba1296b4247d0fc43464652 Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 24 May 2018 20:32:05 -0400 Subject: [PATCH 09/20] added getters and setters --- src/org/psnbtech/Tetris.java | 91 +++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 7 deletions(-) diff --git a/src/org/psnbtech/Tetris.java b/src/org/psnbtech/Tetris.java index 99cf239..e5440b5 100644 --- a/src/org/psnbtech/Tetris.java +++ b/src/org/psnbtech/Tetris.java @@ -141,7 +141,8 @@ private Tetris() { /* * Adds a custom anonymous KeyListener to the frame. */ - addKeyListener( + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(this); + addKeyListener(tetrisKeyAdapter); /* * Here we resize the frame to hold the BoardPanel and SidePanel instances, @@ -214,7 +215,7 @@ private void updateGame() { /* * Check to see if the piece's position can move down to the next row. */ - if(board.isValidAndEmpty(currentType, currentCol, currentRow + 1, currentRotation)) { + if(board.isValidAndEmpty(currentType, currentCol, currentRow + 1, getCurrentRotation())) { //Increment the current row if it's safe to do so. currentRow++; } else { @@ -222,7 +223,7 @@ private void updateGame() { * We've either reached the bottom of the board, or landed on another piece, so * we need to add the piece to the board. */ - board.addPiece(currentType, currentCol, currentRow, currentRotation); + board.addPiece(currentType, currentCol, currentRow, getCurrentRotation()); /* * Check to see if adding the new piece resulted in any cleared lines. If so, @@ -299,14 +300,14 @@ private void spawnPiece() { this.currentType = nextType; this.currentCol = currentType.getSpawnColumn(); this.currentRow = currentType.getSpawnRow(); - this.currentRotation = 0; + this.setCurrentRotation(0); this.nextType = TileType.values()[random.nextInt(TYPE_COUNT)]; /* * If the spawn point is invalid, we need to pause the game and flag that we've lost * because it means that the pieces on the board have gotten too high. */ - if(!board.isValidAndEmpty(currentType, currentCol, currentRow, currentRotation)) { + if(!board.isValidAndEmpty(currentType, currentCol, currentRow, getCurrentRotation())) { this.isGameOver = true; logicTimer.setPaused(true); } @@ -359,7 +360,7 @@ private void rotatePiece(int newRotation) { * position of the piece. */ if(board.isValidAndEmpty(currentType, newColumn, newRow, newRotation)) { - currentRotation = newRotation; + setCurrentRotation(newRotation); currentRow = newRow; currentCol = newColumn; } @@ -442,7 +443,7 @@ public int getPieceRow() { * @return The rotation. */ public int getPieceRotation() { - return currentRotation; + return getCurrentRotation(); } /** @@ -454,5 +455,81 @@ public static void main(String[] args) { Tetris tetris = new Tetris(); tetris.startGame(); } + + public BoardPanel getBoard() { + return board; + } + + public void setBoard(BoardPanel board) { + this.board = board; + } + + public Clock getLogicTimer() { + return logicTimer; + } + + public void setLogicTimer(Clock logicTimer) { + this.logicTimer = logicTimer; + } + + public TileType getCurrentType() { + return currentType; + } + + public void setCurrentType(TileType currentType) { + this.currentType = currentType; + } + + public TileType getNextType() { + return nextType; + } + + public void setNextType(TileType nextType) { + this.nextType = nextType; + } + + public int getCurrentCol() { + return currentCol; + } + + public void setCurrentCol(int currentCol) { + this.currentCol = currentCol; + } + + public int getCurrentRow() { + return currentRow; + } + + public void setCurrentRow(int currentRow) { + this.currentRow = currentRow; + } + + public int getDropCooldown() { + return dropCooldown; + } + + public void setDropCooldown(int dropCooldown) { + this.dropCooldown = dropCooldown; + } + + public void setPaused(boolean isPaused) { + this.isPaused = isPaused; + } + + public void setNewGame(boolean isNewGame) { + this.isNewGame = isNewGame; + } + + public void setGameOver(boolean isGameOver) { + this.isGameOver = isGameOver; + } + + public int getCurrentRotation() { + return currentRotation; + } + + public void setCurrentRotation(int currentRotation) { + this.currentRotation = currentRotation; + } } From a6cba94774aada25d768e0f85a65b47a6b4c8f6d Mon Sep 17 00:00:00 2001 From: cdruk Date: Sun, 27 May 2018 12:36:34 -0400 Subject: [PATCH 10/20] game not starting --- .gitignore | 1 + src/org/psnbtech/Tetris.java | 46 +++- src/org/psnbtech/TetrisKeyAdapter.java | 286 +++++++++++++------------ 3 files changed, 196 insertions(+), 137 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/src/org/psnbtech/Tetris.java b/src/org/psnbtech/Tetris.java index e5440b5..9ed3728 100644 --- a/src/org/psnbtech/Tetris.java +++ b/src/org/psnbtech/Tetris.java @@ -275,7 +275,7 @@ private void renderGame() { * Resets the game variables to their default values at the start * of a new game. */ - private void resetGame() { + void resetGame() { this.level = 1; this.score = 0; this.gameSpeed = 1.0f; @@ -315,9 +315,9 @@ private void spawnPiece() { /** * Attempts to set the rotation of the current piece to newRotation. - * @param newRotation The rotation of the new peice. + * @param newRotation The rotation of the new piece. */ - private void rotatePiece(int newRotation) { + void rotatePiece(int newRotation) { /* * Sometimes pieces will need to be moved when rotated to avoid clipping * out of the board (the I piece is a good example of this). Here we store @@ -445,7 +445,39 @@ public int getPieceRow() { public int getPieceRotation() { return getCurrentRotation(); } + + /** + * Increments current row. + * @return The row. + */ + public int incrementCurrentRow() { + return currentRow++; + } + + /** + * Decrements current row. + * @return The row. + */ + public int decrementCurrentRow() { + return currentRow--; + } + /** + * Increments current column. + * @return The column. + */ + public int incrementCurrentCol() { + return currentCol++; + } + + /** + * Decrements current column. + * @return The column. + */ + public int decrementCurrentCol() { + return currentCol--; + } + /** * Entry-point of the game. Responsible for creating and starting a new * game instance. @@ -532,4 +564,12 @@ public void setCurrentRotation(int currentRotation) { this.currentRotation = currentRotation; } + public float getGameSpeed() { + return gameSpeed; + } + + public void setGameSpeed(float gameSpeed) { + this.gameSpeed = gameSpeed; + } + } diff --git a/src/org/psnbtech/TetrisKeyAdapter.java b/src/org/psnbtech/TetrisKeyAdapter.java index 007e91c..8f7afa3 100644 --- a/src/org/psnbtech/TetrisKeyAdapter.java +++ b/src/org/psnbtech/TetrisKeyAdapter.java @@ -2,145 +2,163 @@ import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; -public class TetrisKeyAdapter {{ - - new KeyAdapter() { - - public void keyPressed(KeyEvent e) { - - switch(e.getKeyCode()) { - - /* - * Soft Drop - When pressed, we check to see that the game is not - * paused and that there is no drop cooldown, then set the - * logic timer to run at a speed of 25 cycles per second. - */ - case KeyEvent.VK_DOWN: - if(!isPaused && dropCooldown == 0) { - logicTimer.setCyclesPerSecond(25.0f); - } - break; - - /* - * Hard Drop - When pressed, we check to see that the game is not paused and - * then check for the lowest available row and drop the piece to there. - */ - case KeyEvent.VK_UP: - if (!isPaused) { - for (int lowest = currentRow; lowest < board.ROW_COUNT; lowest++) { - // If no collision is detected, try the next row. - if (board.isValidAndEmpty(currentType, currentCol, lowest, currentRotation)) { - currentRow = lowest; - } +public class TetrisKeyAdapter implements KeyListener { + + private Tetris tetris; + + public TetrisKeyAdapter(Tetris tetris) { + tetris = this.tetris; + } + + @Override + public void keyPressed(KeyEvent e) { + + switch (e.getKeyCode()) { + /* + * Soft Drop - When pressed, we check to see that the game is not paused and + * that there is no drop cooldown, then set the logic timer to run at a speed of + * 25 cycles per second. + */ + case KeyEvent.VK_S: + case KeyEvent.VK_DOWN: + if (!tetris.isPaused() && tetris.getDropCooldown() == 0) { + tetris.getLogicTimer().setCyclesPerSecond(25.0f); + } + break; + + /* + * Hard Drop - When pressed, we check to see that the game is not paused and + * then check for the lowest available row and drop the piece to there. + */ + case KeyEvent.VK_W: + case KeyEvent.VK_UP: + if (!tetris.isPaused()) { + tetris.getBoard(); + for (int lowest = tetris.getCurrentRow(); lowest < BoardPanel.ROW_COUNT; lowest++) { + // If no collision is detected, try the next row. + if (tetris.getBoard().isValidAndEmpty(tetris.getCurrentType(), tetris.getCurrentCol(), lowest, tetris.getCurrentRotation())) { + tetris.setCurrentRow(lowest); } + } - break; - - /* - * Move Left - When pressed, we check to see that the game is - * not paused and that the position to the left of the current - * position is valid. If so, we decrement the current column by 1. - */ - case KeyEvent.VK_LEFT: - if(!isPaused && board.isValidAndEmpty(currentType, currentCol - 1, currentRow, currentRotation)) { - currentCol--; - } - break; - - /* - * Move Right - When pressed, we check to see that the game is - * not paused and that the position to the right of the current - * position is valid. If so, we increment the current column by 1. - */ - case KeyEvent.VK_RIGHT: - if(!isPaused && board.isValidAndEmpty(currentType, currentCol + 1, currentRow, currentRotation)) { - currentCol++; - } - break; - - /* - * Switch Piece - When pressed, we check to see that the game is not paused and - * then switch the current piece with the next piece. - */ - - case KeyEvent.VK_SHIFT: - if (!isPaused) { - TileType bufferType; - bufferType = currentType; - currentType = nextType; - nextType = bufferType; - } - break; - - /* - * Rotate Anticlockwise - When pressed, check to see that the game is not paused - * and then attempt to rotate the piece anticlockwise. Because of the size and - * complexity of the rotation code, as well as it's similarity to clockwise - * rotation, the code for rotating the piece is handled in another method. - */ - case KeyEvent.VK_COMMA: - if(!isPaused) { - rotatePiece((currentRotation == 0) ? 3 : currentRotation - 1); - } - break; - - /* - * Rotate Clockwise - When pressed, check to see that the game is not paused - * and then attempt to rotate the piece clockwise. Because of the size and - * complexity of the rotation code, as well as it's similarity to anticlockwise - * rotation, the code for rotating the piece is handled in another method. - */ - case KeyEvent.VK_PERIOD: - if(!isPaused) { - rotatePiece((currentRotation == 3) ? 0 : currentRotation + 1); - } - break; - - /* - * Pause Game - When pressed, check to see that we're currently playing a game. - * If so, toggle the pause variable and update the logic timer to reflect this - * change, otherwise the game will execute a huge number of updates and essentially - * cause an instant game over when we unpause if we stay paused for more than a - * minute or so. - */ - case KeyEvent.VK_P: - if(!isGameOver && !isNewGame) { - isPaused = !isPaused; - logicTimer.setPaused(isPaused); - } - break; - - /* - * Start Game - When pressed, check to see that we're in either a game over or new - * game state. If so, reset the game. - */ - case KeyEvent.VK_ENTER: - if(isGameOver || isNewGame) { - resetGame(); - } - break; - } - } - - public void keyReleased(KeyEvent e) { - - switch(e.getKeyCode()) { - - /* - * Drop - When released, we set the speed of the logic timer - * back to whatever the current game speed is and clear out - * any cycles that might still be elapsed. - */ - case KeyEvent.VK_DOWN: - logicTimer.setCyclesPerSecond(gameSpeed); - logicTimer.reset(); - break; + break; + + /* + * Move Left - When pressed, we check to see that the game is not paused and + * that the position to the left of the current position is valid. If so, we + * decrement the current column by 1. + */ + case KeyEvent.VK_A: + case KeyEvent.VK_LEFT: + if (!tetris.isPaused() && tetris.getBoard().isValidAndEmpty(tetris.getCurrentType(), tetris.getCurrentCol() - 1, tetris.getCurrentRow(), tetris.getCurrentRotation())) { + tetris.decrementCurrentCol(); + } + break; + + /* + * Move Right - When pressed, we check to see that the game is not paused and + * that the position to the right of the current position is valid. If so, we + * increment the current column by 1. + */ + case KeyEvent.VK_D: + case KeyEvent.VK_RIGHT: + if (!tetris.isPaused() && tetris.getBoard().isValidAndEmpty(tetris.getCurrentType(), tetris.getCurrentCol() + 1, tetris.getCurrentRow(), tetris.getCurrentRotation())) { + tetris.incrementCurrentCol(); } - + break; + + /* + * Switch Piece - When pressed, we check to see that the game is not paused and + * then switch the current piece with the next piece. + */ + case KeyEvent.VK_R: + case KeyEvent.VK_SHIFT: + if (!tetris.isPaused()) { + TileType bufferType; + bufferType = tetris.getCurrentType(); + tetris.setCurrentType(tetris.getNextType()); + tetris.setNextType(bufferType); + } + break; + + /* + * Rotate Anticlockwise - When pressed, check to see that the game is not paused + * and then attempt to rotate the piece anticlockwise. Because of the size and + * complexity of the rotation code, as well as it's similarity to clockwise + * rotation, the code for rotating the piece is handled in another method. + */ + case KeyEvent.VK_Q: + case KeyEvent.VK_COMMA: + if (!tetris.isPaused()) { + tetris.rotatePiece((tetris.getCurrentRotation() == 0) ? 3 : tetris.getCurrentRotation() - 1); + } + break; + + /* + * Rotate Clockwise - When pressed, check to see that the game is not paused and + * then attempt to rotate the piece clockwise. Because of the size and + * complexity of the rotation code, as well as it's similarity to anticlockwise + * rotation, the code for rotating the piece is handled in another method. + */ + case KeyEvent.VK_E: + case KeyEvent.VK_PERIOD: + if (!tetris.isPaused()) { + tetris.rotatePiece((tetris.getCurrentRotation() == 3) ? 0 : tetris.getCurrentRotation() + 1); + } + break; + + /* + * Pause Game - When pressed, check to see that we're currently playing a game. + * If so, toggle the pause variable and update the logic timer to reflect this + * change, otherwise the game will execute a huge number of updates and + * essentially cause an instant game over when we unpause if we stay paused for + * more than a minute or so. + */ + case KeyEvent.VK_P: + if (!tetris.isGameOver() && !tetris.isNewGame()) { + tetris.setPaused(!tetris.isPaused()); + tetris.getLogicTimer().setPaused(tetris.isPaused()); + } + break; + + /* + * Start Game - When pressed, check to see that we're in either a game over or + * new game state. If so, reset the game. + */ + case KeyEvent.VK_ENTER: + if (tetris.isGameOver() || tetris.isNewGame()) { + tetris.resetGame(); + } + break; + } - - );} + } + + @Override + public void keyReleased(KeyEvent e) { + + switch (e.getKeyCode()) { + + /* + * Drop - When released, we set the speed of the logic timer back to whatever + * the current game speed is and clear out any cycles that might still be + * elapsed. + */ + case KeyEvent.VK_S: + case KeyEvent.VK_DOWN: + tetris.getLogicTimer().setCyclesPerSecond(tetris.getGameSpeed()); + tetris.getLogicTimer().reset(); + break; + } + + } + + @Override + public void keyTyped(KeyEvent e) { + + } } From 3a854656d04df8f4c957220c18b73dbe72fc48b3 Mon Sep 17 00:00:00 2001 From: cdruk Date: Mon, 28 May 2018 23:09:55 -0400 Subject: [PATCH 11/20] null pointer exception thrown --- src/org/psnbtech/TetrisKeyAdapter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/org/psnbtech/TetrisKeyAdapter.java b/src/org/psnbtech/TetrisKeyAdapter.java index 8f7afa3..5ea0942 100644 --- a/src/org/psnbtech/TetrisKeyAdapter.java +++ b/src/org/psnbtech/TetrisKeyAdapter.java @@ -1,6 +1,5 @@ package org.psnbtech; -import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; From e410d9984a040f600276457c18dc476e9b168e9a Mon Sep 17 00:00:00 2001 From: cdruk Date: Wed, 30 May 2018 22:52:47 -0400 Subject: [PATCH 12/20] fixed that bug --- .classpath | 2 ++ src/org/psnbtech/TetrisKeyAdapter.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.classpath b/.classpath index fb565a5..406022b 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,8 @@ + + diff --git a/src/org/psnbtech/TetrisKeyAdapter.java b/src/org/psnbtech/TetrisKeyAdapter.java index 5ea0942..3b99954 100644 --- a/src/org/psnbtech/TetrisKeyAdapter.java +++ b/src/org/psnbtech/TetrisKeyAdapter.java @@ -8,7 +8,7 @@ public class TetrisKeyAdapter implements KeyListener { private Tetris tetris; public TetrisKeyAdapter(Tetris tetris) { - tetris = this.tetris; + this.tetris = tetris; } @Override From c6ff652eebd6a66361491e6f6e3847f68bdd8c03 Mon Sep 17 00:00:00 2001 From: cdruk Date: Wed, 30 May 2018 23:54:49 -0400 Subject: [PATCH 13/20] test setup began --- .classpath | 36 ++++++++++++++++++--- .gitignore | 1 + .project | 6 ++++ .settings/org.eclipse.jdt.core.prefs | 5 +++ .settings/org.eclipse.m2e.core.prefs | 4 +++ pom.xml | 28 ++++++++++++++++ test/org/psnbtech/TetrisKeyAdapterTest.java | 23 +++++++++++++ 7 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 pom.xml create mode 100644 test/org/psnbtech/TetrisKeyAdapterTest.java diff --git a/.classpath b/.classpath index 406022b..e055c44 100644 --- a/.classpath +++ b/.classpath @@ -1,8 +1,36 @@ - - - + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore index ae3c172..09e3bc9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /bin/ +/target/ diff --git a/.project b/.project index ddf9a01..d83a904 100644 --- a/.project +++ b/.project @@ -10,8 +10,14 @@ + + org.eclipse.m2e.core.maven2Builder + + + + org.eclipse.m2e.core.maven2Nature org.eclipse.jdt.core.javanature diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..714351a --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3d05433 --- /dev/null +++ b/pom.xml @@ -0,0 +1,28 @@ + + 4.0.0 + Tetris + Tetris + 0.0.1-SNAPSHOT + + src + test + + + maven-compiler-plugin + 3.7.0 + + + org.mockito + mockito-core + 2.18.3 + + + + 1.8 + 1.8 + + + + + \ No newline at end of file diff --git a/test/org/psnbtech/TetrisKeyAdapterTest.java b/test/org/psnbtech/TetrisKeyAdapterTest.java new file mode 100644 index 0000000..db2757d --- /dev/null +++ b/test/org/psnbtech/TetrisKeyAdapterTest.java @@ -0,0 +1,23 @@ +package org.psnbtech; + +import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +class TetrisKeyAdapterTest { + + @Test + public void testKeyPressed() { + //given mock + Tetris tetris = Mockito.mock(Tetris.class); + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + + + //when button pressed + + //then method tetris called + } + +} From 8d11303646387e612935f9468cf3ccd6d4d4cd3e Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 31 May 2018 15:46:10 -0400 Subject: [PATCH 14/20] button press failing --- test/org/psnbtech/TetrisKeyAdapterTest.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/org/psnbtech/TetrisKeyAdapterTest.java b/test/org/psnbtech/TetrisKeyAdapterTest.java index db2757d..3e24aeb 100644 --- a/test/org/psnbtech/TetrisKeyAdapterTest.java +++ b/test/org/psnbtech/TetrisKeyAdapterTest.java @@ -3,21 +3,26 @@ import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.*; +import java.awt.event.KeyEvent; + import org.junit.jupiter.api.Test; import org.mockito.Mockito; class TetrisKeyAdapterTest { @Test - public void testKeyPressed() { - //given mock + public void testDownKeyPressed() { + //given Tetris tetris = Mockito.mock(Tetris.class); TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); - //when button pressed - + @SuppressWarnings("deprecation") + KeyEvent e = new KeyEvent(tetris, 0, 0, KeyEvent.VK_DOWN, 0); + tetrisKeyAdapter.keyPressed(e); + //then method tetris called + Mockito. verify(tetris.getLogicTimer()); } } From be8e90b071ebb28fd9cc86b3b5b18ca00a846266 Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 31 May 2018 16:10:13 -0400 Subject: [PATCH 15/20] edit and enlarge side panel --- src/org/psnbtech/SidePanel.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/org/psnbtech/SidePanel.java b/src/org/psnbtech/SidePanel.java index 5a8c660..8415b4b 100644 --- a/src/org/psnbtech/SidePanel.java +++ b/src/org/psnbtech/SidePanel.java @@ -103,7 +103,7 @@ public class SidePanel extends JPanel { public SidePanel(Tetris tetris) { this.tetris = tetris; - setPreferredSize(new Dimension(200, BoardPanel.PANEL_HEIGHT)); + setPreferredSize(new Dimension(250, BoardPanel.PANEL_HEIGHT)); setBackground(Color.BLACK); } @@ -136,13 +136,13 @@ public void paintComponent(Graphics g) { g.setFont(LARGE_FONT); g.drawString("Controls", SMALL_INSET, offset = CONTROLS_INSET); g.setFont(SMALL_FONT); - g.drawString("< - Rotate Anticlockwise", LARGE_INSET, offset += TEXT_STRIDE); - g.drawString("> - Rotate Clockwise", LARGE_INSET, offset += TEXT_STRIDE); - g.drawString("Left Arrow - Move Left", LARGE_INSET, offset += TEXT_STRIDE); - g.drawString("Right Arrow - Move Right", LARGE_INSET, offset += TEXT_STRIDE); - g.drawString("Up Arrow - Hard Drop", LARGE_INSET, offset += TEXT_STRIDE); - g.drawString("Down Arrow - Soft Drop", LARGE_INSET, offset += TEXT_STRIDE); - g.drawString("Shift - Switch Next", LARGE_INSET, offset += TEXT_STRIDE); + g.drawString("< or Q - Rotate Anticlockwise", LARGE_INSET, offset += TEXT_STRIDE); + g.drawString("> or E- Rotate Clockwise", LARGE_INSET, offset += TEXT_STRIDE); + g.drawString("Left Arrow or D- Move Left", LARGE_INSET, offset += TEXT_STRIDE); + g.drawString("Right Arrow or A- Move Right", LARGE_INSET, offset += TEXT_STRIDE); + g.drawString("Up Arrow or W- Hard Drop", LARGE_INSET, offset += TEXT_STRIDE); + g.drawString("Down Arrow or S- Soft Drop", LARGE_INSET, offset += TEXT_STRIDE); + g.drawString("Shift or R- Switch Next", LARGE_INSET, offset += TEXT_STRIDE); g.drawString("P - Pause Game", LARGE_INSET, offset += TEXT_STRIDE); /* From 222a9cd1e03e5102a661516e78516f293030511d Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 31 May 2018 16:54:03 -0400 Subject: [PATCH 16/20] no compiler error but test still failing --- test/org/psnbtech/TetrisKeyAdapterTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/org/psnbtech/TetrisKeyAdapterTest.java b/test/org/psnbtech/TetrisKeyAdapterTest.java index 3e24aeb..052daf6 100644 --- a/test/org/psnbtech/TetrisKeyAdapterTest.java +++ b/test/org/psnbtech/TetrisKeyAdapterTest.java @@ -1,7 +1,5 @@ package org.psnbtech; -import static org.junit.Assert.assertEquals; -import static org.junit.jupiter.api.Assertions.*; import java.awt.event.KeyEvent; @@ -15,10 +13,10 @@ public void testDownKeyPressed() { //given Tetris tetris = Mockito.mock(Tetris.class); TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + KeyEvent e = Mockito.mock(KeyEvent.class); + Mockito.when(e.getKeyCode()).thenReturn(KeyEvent.VK_DOWN); //when button pressed - @SuppressWarnings("deprecation") - KeyEvent e = new KeyEvent(tetris, 0, 0, KeyEvent.VK_DOWN, 0); tetrisKeyAdapter.keyPressed(e); //then method tetris called From 1df734a14fa7197671675f59e41f4b6efa6e5419 Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 31 May 2018 18:09:43 -0400 Subject: [PATCH 17/20] two working tests --- .DS_Store | Bin 0 -> 8196 bytes pom.xml | 15 ++--- src/.DS_Store | Bin 0 -> 6148 bytes src/org/.DS_Store | Bin 0 -> 6148 bytes src/org/psnbtech/.DS_Store | Bin 0 -> 6148 bytes test/org/psnbtech/TetrisKeyAdapterTest.java | 64 +++++++++++++++++--- 6 files changed, 64 insertions(+), 15 deletions(-) create mode 100644 .DS_Store create mode 100644 src/.DS_Store create mode 100644 src/org/.DS_Store create mode 100644 src/org/psnbtech/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..576dddd95d827463a44508fe058a318f1be76d7a GIT binary patch literal 8196 zcmeI1-)qxQ6vxkP>y}O&5ful%rip>i7Owv8j6+$iRExp6|`Q=Opdtrb$jpM65CJZV{~zk%7k5ya@Lf zY&eBg$$i!F05Ru55G%)m{_O1pZ3` z{Q6*_ajh%Oq>4)ioG1aHB@7EgUp)LnEj|FPE6t>01jb}4RHiajVlY)ZFqw||x{A-F z%5-Al$k>lMGE)@_Q>6#9L^!d!RP8kZO<&Vlso42(P+JPzhbT58&|ARtyZmAx7Y8E$L1TuxN-B&#`crm`1RX&?>~I} z^!dwI@qLM@OATF-+f)AyJw@Zl?nhx99b$w>FVaKWqD^YiBeJQLBl;Z?s}o`9@#r4K z^n%vtC44v=&31CpW!k}hH>gS5&^2Uuxr`sVj3On}r-Ruj;_G^h#-{5kqV&3wTvtIO zx2_A6k^`29RK#wgk35&eR-NasD4qe=UqMFveM{@Be~> zcACIh2^8fHR(Sp2I{p3sSr4Q0H33cF91~!rrrm7d1D-ta=07X1wJo&gXxw;QCRL=s kiETetris Tetris 0.0.1-SNAPSHOT + + + org.mockito + mockito-core + 2.18.3 + test + + src test @@ -11,13 +19,6 @@ maven-compiler-plugin 3.7.0 - - - org.mockito - mockito-core - 2.18.3 - - 1.8 1.8 diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6a8d515cb51d1d493b6bad85e8750f7a5cca760e GIT binary patch literal 6148 zcmeHKU5nE|6rE|SrYkHF6$M}NsL+Q>)#_WUtKfrBi0mS+)Wn4CK**FN-6ExsXP^BA ze*X^9AK^doZ9Ow{ySS{r>MHlZopW<@?<8{)GPyzsIhv=}h46(C9?Wp7i{TeA=Zzgh ziz02XG;`<|Nv;zdndun+f&%8*wS^X?*n5~Cd43OY<|<4c9N2|WRP1w?^}HIzq~}Fi?M80C9hKJ8iGOiiX8R}|$3?cSDwU{Q)i1k%*PZy6 zmdnBLPA?eTUiE_IaMEC03UUAcDi?xQEO)vGse-@X6v@zduocD+L4owhhn zyr!>kNR9odEOK4!A+pY1XECz^tN<%;auuL2mUs5#-Xh-_E5Hi;B?Zj)A%GbUi5tiE z(}BUZ0N@V77Vz!QKR7S}a7f%ZMg)+q6zobRwHT6m2kFXjKBWA{u`3tSUK#Vyl_hm3 zl3EWL*mNO7$2_tEtiVwPOz#KyX8*tc`~Kf1@xThO0{^E1va=O!jj%S_TaT^M?6m>x rIn2Q1HI5HU;MlDgxn?WA46{HyFb+5*ZX6>5@Q;9%fd^LLk1Fs321sZe literal 0 HcmV?d00001 diff --git a/src/org/.DS_Store b/src/org/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ed21fa7fb8c0cc72c8f51c5414e7e05bff88e3f3 GIT binary patch literal 6148 zcmeHK-D(p-6h4!tx~WiBR4jNimlbl65;gU18>`R@A+V)Iti;{!Vg{C-kli$t5ZG(4 zeFFd5=Ma4e-^9E6%}+`t_0|@d1Lu4vXU>_)e7nr-AtKftCmTdQ5qVIBwFb;3qQ;dj zNXGPMbC#T=O z>zxzBd#>e<#X0P#+yIx&;8%5!M1*LnNpxBWwym&rW|o@^8$;NK~ql5 zHXqEc%xs6k^y-+O>vUp)L1!HUj)6ZJP`w|-SNH$(zxV$-$r;ChW8nW}fYrCd?Jo9a z@79G~s=Jm$-$IqByvpEt2^@VDBUfF;YfvqSbL9X7iS5dNkXsTQ>t!DEh|1m7UWDu@@ceE`!ohiEY3AM}>T@S%JF-$uXLT}qmm zs}z}m*>5x1Z#MI7$YudZ^0qhyMgRtM#oi8^Urg_-x2zW;+eC3W7Pvu*M`S2kqb;zB z3h3G$AVJA>dq#czPH@lIJJPG7oX?7K#*zA(T+)xfov{b(;+(5pVvYxNaXuTIeN2#Z zwygHPba3Ui!5v~s-YcIr$4l3Y^3`A+uCcC}VTm(7L5e5l%9yQVepl~Dt=>Im%2{zn zT#}u2GPUYDlb2?ufGJ=KY=i>bv(*MekJg$3rhqB1Qb4~C5nVA3Sb21x4mR!xKr^LVP**@6mhdNf8>TkVvp9E z0;a&a0$cuar2GFx_xXRFWLKtuDe$ipkp6fwPFPadTU*8HUK`Qx=xREy^0=a~I$ literal 0 HcmV?d00001 diff --git a/test/org/psnbtech/TetrisKeyAdapterTest.java b/test/org/psnbtech/TetrisKeyAdapterTest.java index 052daf6..e8a437f 100644 --- a/test/org/psnbtech/TetrisKeyAdapterTest.java +++ b/test/org/psnbtech/TetrisKeyAdapterTest.java @@ -1,26 +1,74 @@ package org.psnbtech; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + import java.awt.event.KeyEvent; +import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +public class TetrisKeyAdapterTest { + + @Mock + Tetris tetris; + @Mock + Clock clock; + @Mock + BoardPanel boardPanel; + @Mock + KeyEvent keyEvent; + + TetrisKeyAdapter tetrisKeyAdapter; -class TetrisKeyAdapterTest { + @BeforeEach + public void before() { + initMocks(this); + tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + when(tetris.getLogicTimer()).thenReturn(clock); + doReturn(boardPanel).when(tetris).getBoard(); + } @Test public void testDownKeyPressed() { //given - Tetris tetris = Mockito.mock(Tetris.class); + doReturn(false).when(tetris).isPaused(); + doReturn(0).when(tetris).getDropCooldown(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_DOWN); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).isPaused(); + verify(tetris).getDropCooldown(); + verify(clock).setCyclesPerSecond(25.0f); + } + + @Test + public void testLeftKeyPressed() { + //given TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); - KeyEvent e = Mockito.mock(KeyEvent.class); - Mockito.when(e.getKeyCode()).thenReturn(KeyEvent.VK_DOWN); + doReturn(false).when(tetris).isPaused(); + Mockito.when(boardPanel.isValidAndEmpty(Mockito.any(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(true); + Mockito.when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_LEFT); - //when button pressed - tetrisKeyAdapter.keyPressed(e); + //when + tetrisKeyAdapter.keyPressed(keyEvent); - //then method tetris called - Mockito. verify(tetris.getLogicTimer()); + //then + Mockito.verify(tetris).isPaused(); + Mockito.verify(tetris).getBoard(); + Mockito.verify(tetris).decrementCurrentCol(); } } + From e6afe02f7b0fd59c65f38b5f94f8977841ea4348 Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 31 May 2018 19:06:27 -0400 Subject: [PATCH 18/20] all key presses tested once --- test/org/psnbtech/TetrisKeyAdapterTest.java | 141 ++++++++++++++++++-- 1 file changed, 133 insertions(+), 8 deletions(-) diff --git a/test/org/psnbtech/TetrisKeyAdapterTest.java b/test/org/psnbtech/TetrisKeyAdapterTest.java index e8a437f..70cb12a 100644 --- a/test/org/psnbtech/TetrisKeyAdapterTest.java +++ b/test/org/psnbtech/TetrisKeyAdapterTest.java @@ -1,20 +1,18 @@ package org.psnbtech; +import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import java.awt.event.KeyEvent; -import org.junit.Before; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; public class TetrisKeyAdapterTest { @@ -53,21 +51,148 @@ public void testDownKeyPressed() { verify(clock).setCyclesPerSecond(25.0f); } + @Test + public void testUpKeyPressed() { + //given + doReturn(false).when(tetris).isPaused(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_UP); + when(boardPanel.isValidAndEmpty(Mockito.any(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(true); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).isPaused(); + verify(tetris, atLeast(1)).getBoard(); + verify(tetris).getCurrentRow(); + verify(tetris).setCurrentRow(0); + } + @Test public void testLeftKeyPressed() { //given TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); doReturn(false).when(tetris).isPaused(); - Mockito.when(boardPanel.isValidAndEmpty(Mockito.any(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(true); - Mockito.when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_LEFT); + when(boardPanel.isValidAndEmpty(Mockito.any(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(true); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_LEFT); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).isPaused(); + verify(tetris).getBoard(); + verify(tetris).decrementCurrentCol(); + } + + @Test + public void testRightKeyPressed() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(false).when(tetris).isPaused(); + when(boardPanel.isValidAndEmpty(Mockito.any(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(true); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_RIGHT); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).isPaused(); + verify(tetris).getBoard(); + verify(tetris).incrementCurrentCol(); + } + + @Test + public void testShiftKeyPressed() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(false).when(tetris).isPaused(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_SHIFT); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + TileType bufferType = verify(tetris).getCurrentType(); + verify(tetris).getCurrentType(); + verify(tetris).setCurrentType(tetris.getNextType()); + verify(tetris).setNextType(bufferType); + } + + @Test + public void testCommaKeyPressed() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(false).when(tetris).isPaused(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_COMMA); //when tetrisKeyAdapter.keyPressed(keyEvent); //then - Mockito.verify(tetris).isPaused(); - Mockito.verify(tetris).getBoard(); - Mockito.verify(tetris).decrementCurrentCol(); + verify(tetris, atLeast(1)).rotatePiece((tetris.getCurrentRotation() == 0) ? 3 : tetris.getCurrentRotation() - 1); + } + + @Test + public void testPeriodKeyPressed() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(false).when(tetris).isPaused(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_PERIOD); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris, atLeast(1)).rotatePiece((tetris.getCurrentRotation() == 3) ? 0 : tetris.getCurrentRotation() + 1); + } + + @Test + public void testPauseKeyPressed() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(false).when(tetris).isPaused(); + doReturn(false).when(tetris).isGameOver(); + doReturn(false).when(tetris).isNewGame(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_P); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).setPaused(true); + verify(tetris).getLogicTimer(); + verify(clock).setPaused(tetris.isPaused()); + } + + @Test + public void testEnterKeyPressed() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(true).when(tetris).isGameOver(); + doReturn(true).when(tetris).isNewGame(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_ENTER); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).resetGame(); + } + + @Test + public void testDownKeyReleased() { + //given + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_DOWN); + + //when + tetrisKeyAdapter.keyReleased(keyEvent); + + //then + verify(tetris, atLeast(1)).getLogicTimer(); + verify(clock).setCyclesPerSecond(tetris.getGameSpeed()); + verify(tetris, atLeast(1)).getLogicTimer(); + verify(clock).reset(); } } From 94d6d2a4f943ddefec423409da04c18d06773d2d Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 31 May 2018 19:30:51 -0400 Subject: [PATCH 19/20] added pause tests --- test/org/psnbtech/TetrisKeyAdapterTest.java | 204 ++++++++++++++++++++ 1 file changed, 204 insertions(+) diff --git a/test/org/psnbtech/TetrisKeyAdapterTest.java b/test/org/psnbtech/TetrisKeyAdapterTest.java index 70cb12a..3f3c500 100644 --- a/test/org/psnbtech/TetrisKeyAdapterTest.java +++ b/test/org/psnbtech/TetrisKeyAdapterTest.java @@ -3,6 +3,7 @@ import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; @@ -51,6 +52,38 @@ public void testDownKeyPressed() { verify(clock).setCyclesPerSecond(25.0f); } + @Test + public void testDownKeyPressedPaused() { + //given + doReturn(true).when(tetris).isPaused(); + doReturn(0).when(tetris).getDropCooldown(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_DOWN); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).isPaused(); + verify(tetris, never()).getDropCooldown(); + verify(clock, never()).setCyclesPerSecond(25.0f); + } + + @Test + public void testDownKeyPressedCooldown() { + //given + doReturn(false).when(tetris).isPaused(); + doReturn(1).when(tetris).getDropCooldown(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_DOWN); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).isPaused(); + verify(tetris).getDropCooldown(); + verify(clock, never()).setCyclesPerSecond(25.0f); + } + @Test public void testUpKeyPressed() { //given @@ -68,6 +101,23 @@ public void testUpKeyPressed() { verify(tetris).setCurrentRow(0); } + @Test + public void testUpKeyPressedPaused() { + //given + doReturn(true).when(tetris).isPaused(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_UP); + when(boardPanel.isValidAndEmpty(Mockito.any(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(true); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).isPaused(); + verify(tetris, never()).getBoard(); + verify(tetris, never()).getCurrentRow(); + verify(tetris, never()).setCurrentRow(0); + } + @Test public void testLeftKeyPressed() { //given @@ -85,6 +135,23 @@ public void testLeftKeyPressed() { verify(tetris).decrementCurrentCol(); } + @Test + public void testLeftKeyPressedPaused() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(true).when(tetris).isPaused(); + when(boardPanel.isValidAndEmpty(Mockito.any(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(true); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_LEFT); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).isPaused(); + verify(tetris, never()).getBoard(); + verify(tetris, never()).decrementCurrentCol(); + } + @Test public void testRightKeyPressed() { //given @@ -101,6 +168,23 @@ public void testRightKeyPressed() { verify(tetris).getBoard(); verify(tetris).incrementCurrentCol(); } + + @Test + public void testRightKeyPressedPaused() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(true).when(tetris).isPaused(); + when(boardPanel.isValidAndEmpty(Mockito.any(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(true); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_RIGHT); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).isPaused(); + verify(tetris, never()).getBoard(); + verify(tetris, never()).incrementCurrentCol(); + } @Test public void testShiftKeyPressed() { @@ -113,12 +197,31 @@ public void testShiftKeyPressed() { tetrisKeyAdapter.keyPressed(keyEvent); //then + verify(tetris).isPaused(); TileType bufferType = verify(tetris).getCurrentType(); verify(tetris).getCurrentType(); verify(tetris).setCurrentType(tetris.getNextType()); verify(tetris).setNextType(bufferType); } + @Test + public void testShiftKeyPressedPaused() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(true).when(tetris).isPaused(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_SHIFT); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).isPaused(); + TileType bufferType = verify(tetris, never()).getCurrentType(); + verify(tetris, never()).getCurrentType(); + verify(tetris, never()).setCurrentType(tetris.getNextType()); + verify(tetris, never()).setNextType(bufferType); + } + @Test public void testCommaKeyPressed() { //given @@ -130,9 +233,25 @@ public void testCommaKeyPressed() { tetrisKeyAdapter.keyPressed(keyEvent); //then + verify(tetris).isPaused(); verify(tetris, atLeast(1)).rotatePiece((tetris.getCurrentRotation() == 0) ? 3 : tetris.getCurrentRotation() - 1); } + @Test + public void testCommaKeyPressedPaused() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(true).when(tetris).isPaused(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_COMMA); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).isPaused(); + verify(tetris, never()).rotatePiece((tetris.getCurrentRotation() == 0) ? 3 : tetris.getCurrentRotation() - 1); + } + @Test public void testPeriodKeyPressed() { //given @@ -144,9 +263,25 @@ public void testPeriodKeyPressed() { tetrisKeyAdapter.keyPressed(keyEvent); //then + verify(tetris).isPaused(); verify(tetris, atLeast(1)).rotatePiece((tetris.getCurrentRotation() == 3) ? 0 : tetris.getCurrentRotation() + 1); } + @Test + public void testPeriodKeyPressedPaused() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(true).when(tetris).isPaused(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_PERIOD); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).isPaused(); + verify(tetris, never()).rotatePiece((tetris.getCurrentRotation() == 3) ? 0 : tetris.getCurrentRotation() + 1); + } + @Test public void testPauseKeyPressed() { //given @@ -165,6 +300,60 @@ public void testPauseKeyPressed() { verify(clock).setPaused(tetris.isPaused()); } + @Test + public void testPauseKeyPressedPaused() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(true).when(tetris).isPaused(); + doReturn(false).when(tetris).isGameOver(); + doReturn(false).when(tetris).isNewGame(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_P); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris).setPaused(false); + verify(tetris).getLogicTimer(); + verify(clock).setPaused(tetris.isPaused()); + } + + @Test + public void testPauseKeyPressedGameOver() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(false).when(tetris).isPaused(); + doReturn(true).when(tetris).isGameOver(); + doReturn(false).when(tetris).isNewGame(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_P); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris, never()).setPaused(true); + verify(tetris, never()).getLogicTimer(); + verify(clock, never()).setPaused(tetris.isPaused()); + } + + @Test + public void testPauseKeyPressedNewGame() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(false).when(tetris).isPaused(); + doReturn(false).when(tetris).isGameOver(); + doReturn(true).when(tetris).isNewGame(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_P); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris, never()).setPaused(true); + verify(tetris, never()).getLogicTimer(); + verify(clock, never()).setPaused(tetris.isPaused()); + } + @Test public void testEnterKeyPressed() { //given @@ -180,6 +369,21 @@ public void testEnterKeyPressed() { verify(tetris).resetGame(); } + @Test + public void testEnterKeyPressedDuringGame() { + //given + TetrisKeyAdapter tetrisKeyAdapter = new TetrisKeyAdapter(tetris); + doReturn(false).when(tetris).isGameOver(); + doReturn(false).when(tetris).isNewGame(); + when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_ENTER); + + //when + tetrisKeyAdapter.keyPressed(keyEvent); + + //then + verify(tetris, never()).resetGame(); + } + @Test public void testDownKeyReleased() { //given From 0805cf12eccd5277f96ec01c821cd066ea2ec862 Mon Sep 17 00:00:00 2001 From: cdruk Date: Thu, 31 May 2018 19:38:09 -0400 Subject: [PATCH 20/20] move main --- src/org/psnbtech/Tetris.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/org/psnbtech/Tetris.java b/src/org/psnbtech/Tetris.java index 9ed3728..fe09908 100644 --- a/src/org/psnbtech/Tetris.java +++ b/src/org/psnbtech/Tetris.java @@ -478,16 +478,6 @@ public int decrementCurrentCol() { return currentCol--; } - /** - * Entry-point of the game. Responsible for creating and starting a new - * game instance. - * @param args Unused. - */ - public static void main(String[] args) { - Tetris tetris = new Tetris(); - tetris.startGame(); - } - public BoardPanel getBoard() { return board; } @@ -572,4 +562,14 @@ public void setGameSpeed(float gameSpeed) { this.gameSpeed = gameSpeed; } + /** + * Entry-point of the game. Responsible for creating and starting a new + * game instance. + * @param args Unused. + */ + public static void main(String[] args) { + Tetris tetris = new Tetris(); + tetris.startGame(); + } + }