From 2c0aa0a3738a82d1b8741a50a5c42338d6ed54d7 Mon Sep 17 00:00:00 2001 From: Fred Trimble Date: Wed, 16 Dec 2015 23:52:35 -0500 Subject: [PATCH 1/7] Modify HuntTheWumpusGame to use streams and lambda expressions --- HTW/src/htw/game/HuntTheWumpusGame.java | 89 +++++++++++++++++-------- 1 file changed, 60 insertions(+), 29 deletions(-) diff --git a/HTW/src/htw/game/HuntTheWumpusGame.java b/HTW/src/htw/game/HuntTheWumpusGame.java index f0311bd..eae3b24 100644 --- a/HTW/src/htw/game/HuntTheWumpusGame.java +++ b/HTW/src/htw/game/HuntTheWumpusGame.java @@ -5,6 +5,7 @@ import java.util.*; import java.util.function.Predicate; +import java.util.stream.Collectors; public class HuntTheWumpusGame implements HuntTheWumpus { private List connections = new ArrayList<>(); @@ -41,17 +42,21 @@ private void reportStatus() { } private boolean reportNearby(Predicate nearTest) { - for (Connection c : connections) - if (playerCavern.equals(c.from) && nearTest.test(c)) - return true; - return false; + return connections.stream() + .filter(c -> playerCavern.equals(c.from) && nearTest.test(c)) + .findAny() + .isPresent(); } private void reportAvailableDirections() { - for (Connection c : connections) { - if (playerCavern.equals(c.from)) - messageReceiver.passage(c.direction); - } + connections.stream() + .filter(isFromPlayerCavern()) + .map(c -> c.direction) + .forEach(messageReceiver::passage); + } + + private Predicate isFromPlayerCavern() { + return c -> playerCavern.equals(c.from); } public void addBatCavern(String cavern) { @@ -71,24 +76,40 @@ public String getWumpusCavern() { } protected void moveWumpus() { - List wumpusChoices = new ArrayList<>(); - for (Connection c : connections) - if (wumpusCavern.equals(c.from)) - wumpusChoices.add(c.to); + List wumpusChoices = connections.stream() + .filter(isFromWumpusCavern()) + .map(c -> c.to) + .collect(Collectors.toList()); wumpusChoices.add(wumpusCavern); - int nChoices = wumpusChoices.size(); - int choice = (int) (Math.random() * nChoices); - wumpusCavern = wumpusChoices.get(choice); + wumpusCavern = wumpusChoices.stream() + .skip(randomCavernIndex(wumpusChoices.size())) + .findFirst() + .get(); + } + + private Predicate isFromWumpusCavern() { + return c -> wumpusCavern.equals(c.from); + } + + private int randomCavernIndex() { + return randomCavernIndex(caverns.size() - 1); + } + + private int randomCavernIndex(int size) { + return new Random().nextInt(size); } private void randomlyTransportPlayer() { - Set transportChoices = new HashSet<>(caverns); - transportChoices.remove(playerCavern); - int nChoices = transportChoices.size(); - int choice = (int) (Math.random() * nChoices); - String[] choices = new String[nChoices]; - playerCavern = transportChoices.toArray(choices)[choice]; + playerCavern = caverns.stream() + .filter(excludePlayerCavern()) + .skip(randomCavernIndex()) + .findFirst() + .get(); + } + + private Predicate excludePlayerCavern() { + return c -> !playerCavern.equals(c); } public void setQuiver(int arrows) { @@ -129,10 +150,15 @@ public void connectCavern(String from, String to, Direction direction) { } public String findDestination(String cavern, Direction direction) { - for (Connection c : connections) - if (c.from.equals(cavern) && c.direction == direction) - return c.to; - return null; + Connection destination = connections.stream() + .filter(isDestination(cavern, direction)) + .findFirst() + .orElse(null); + return destination != null ? destination.to : null; + } + + private Predicate isDestination(String cavern, Direction direction) { + return c -> c.from.equals(cavern) && c.direction == direction; } public Command makeRestCommand() { @@ -242,10 +268,15 @@ private boolean shotSelfInBack() { } private String nextCavern(String cavern, Direction direction) { - for (Connection c : connections) - if (cavern.equals(c.from) && direction.equals(c.direction)) - return c.to; - return null; + Connection connection = connections.stream() + .filter(isFromDirection(cavern, direction)) + .findFirst() + .orElse(null); + return connection != null ? connection.to : null; + } + + private Predicate isFromDirection(String cavern, Direction direction) { + return c -> cavern.equals(c.from) && direction.equals(c.direction); } } } From 2c3356e443be39d629a2514e478869d832dd9db4 Mon Sep 17 00:00:00 2001 From: Fred Trimble Date: Thu, 17 Dec 2015 00:17:33 -0500 Subject: [PATCH 2/7] Modify ArrowKillsWumpus test to use a decision table and new fixture to test all directions --- HTW/src/htw/game/HuntTheWumpusGame.java | 24 ++++++ .../htw/fixtures/DoesArrowKillWumpus.java | 54 +++++++++++++ .../ArrowKillsWumpus/20151216232211.zip | Bin 0 -> 571 bytes .../ArrowKillsWumpus/content.txt | 76 ++++++++++++++++-- .../RecentChanges/20151216232211.zip | Bin 0 -> 1128 bytes .../FitNesseRoot/RecentChanges/content.txt | 2 +- 6 files changed, 149 insertions(+), 7 deletions(-) create mode 100644 HTW/test/htw/fixtures/DoesArrowKillWumpus.java create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/HuntingWithArrows/ArrowKillsWumpus/20151216232211.zip create mode 100644 fitnesse/FitNesseRoot/RecentChanges/20151216232211.zip diff --git a/HTW/src/htw/game/HuntTheWumpusGame.java b/HTW/src/htw/game/HuntTheWumpusGame.java index eae3b24..afb20f6 100644 --- a/HTW/src/htw/game/HuntTheWumpusGame.java +++ b/HTW/src/htw/game/HuntTheWumpusGame.java @@ -23,6 +23,10 @@ public HuntTheWumpusGame(HtwMessageReceiver receiver) { this.messageReceiver = receiver; } + public void initializeArrowsIn() { + arrowsIn = new HashMap<>(); + } + public void setPlayerCavern(String playerCavern) { this.playerCavern = playerCavern; } @@ -131,6 +135,26 @@ private int zeroIfNull(Integer integer) { return integer.intValue(); } + public String farthestCavern(String startingCavern, Direction direction) { + String cavern = startingCavern; + String furthestCavern = null; + for (int count = 0; count < 100 && (cavern = nextCavern(cavern, direction)) != null; count++) + furthestCavern = cavern; + return furthestCavern; + } + + private String nextCavern(String cavern, Direction direction) { + Connection connection = connections.stream() + .filter(isFromDirection(cavern, direction)) + .findFirst() + .orElse(null); + return connection != null ? connection.to : null; + } + + private Predicate isFromDirection(String cavern, Direction direction) { + return c -> cavern.equals(c.from) && direction.equals(c.direction); + } + private class Connection { String from; String to; diff --git a/HTW/test/htw/fixtures/DoesArrowKillWumpus.java b/HTW/test/htw/fixtures/DoesArrowKillWumpus.java new file mode 100644 index 0000000..717424d --- /dev/null +++ b/HTW/test/htw/fixtures/DoesArrowKillWumpus.java @@ -0,0 +1,54 @@ +package htw.fixtures; + +import htw.HuntTheWumpus; + +import static htw.fixtures.TestContext.game; + +public class DoesArrowKillWumpus { + + private String playerCavern; + private String wumpusCavern; + private int arrowsForPlayer; + private HuntTheWumpus.Direction shootingDirection; + + public void setPlayerCavern(String playerCavern) { + this.playerCavern = playerCavern; + } + + public void setWumpusCavern(String wumpusCavern) { + this.wumpusCavern = wumpusCavern; + } + + public void setArrowsForPlayer(int arrowsForPlayer) { + this.arrowsForPlayer = arrowsForPlayer; + } + + public void setShootingDirection(HuntTheWumpus.Direction shootingDirection) { + this.shootingDirection = shootingDirection; + } + + public void reset() { + TestContext.messages.clear(); + TestContext.game.initializeArrowsIn(); + } + + public void execute() { + game.setPlayerCavern(playerCavern); + game.setWumpusCavern(wumpusCavern); + game.setQuiver(arrowsForPlayer); + game.makeShootCommand(shootingDirection).execute(); + } + + public String farthestCavern() { + return game.farthestCavern(playerCavern, shootingDirection); + } + + public int arrowsInFarthestCavern() { + return game.getArrowsInCavern(farthestCavern()); + } + + public String wumpusKilledMessage() { + return TestContext.messages.contains("WUMPUS_KILLED") ? "Yes" : "No"; + } + +} diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/HuntingWithArrows/ArrowKillsWumpus/20151216232211.zip b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/HuntingWithArrows/ArrowKillsWumpus/20151216232211.zip new file mode 100644 index 0000000000000000000000000000000000000000..2f1384820b5ca909ed165aedde41b07703261960 GIT binary patch literal 571 zcmWIWW@Zs#;Nak3IKnW|odF4O1KG*>c_pcNC3+_Cb zFoN;6Q>SeqH+zcf`3)c1)_t6-v-eC`sPF$*JX|@9Gw&KaI;68w;(3!pm(kxH^_rI@ z6mHZc*;lU%n;m&9;>k_b{kG@SmtLyP@nA9aef(vMiduevH#&SMIkzoYdu+b` zrB4Oc_btD79({gOHGh+z|OI^?lbUNZYtQE@`&=NRvMlD?9c+e9rB@_qfU zX%{iiS@LP;cKt&oQyP}OYEy}DWDfK8=2-Q$$C&fdzZ*q=XK?@98-I2#cm5k0ca}W@ z+ZXlLu^gCnr{uZ@Hr~oPc&^00(3JMzpI1gl^hE#wzD;r3j2?$Gp^ah|q7#ILR5Xvb4 literal 0 HcmV?d00001 diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/HuntingWithArrows/ArrowKillsWumpus/content.txt b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/HuntingWithArrows/ArrowKillsWumpus/content.txt index 9e55692..fa5b85e 100644 --- a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/HuntingWithArrows/ArrowKillsWumpus/content.txt +++ b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/HuntingWithArrows/ArrowKillsWumpus/content.txt @@ -1,8 +1,72 @@ -!|script| |Given Cross Map| -|Given the player is in cavern FarLeft| -|Given the wumpus is in cavern Middle| -|Given the player has 1 arrow| -|When the player shoots East| -|Then there are 0 arrows in cavern FarRight| -|Then a|WUMPUS_KILLED|message is given| + +{{{ +Cross Map +''Links are bidirectional'' + + + [ Top ] + + [Above ] + +[FarLeft] [Left] [Middle] [Right] [FarRight] + + [Below ] + + [Bottom] + +}}} + +!|Does arrow kill wumpus| +|player cavern|wumpus cavern|arrows for player|shooting direction|farthest cavern?|arrows in farthest cavern?|wumpus killed message?| +|FarLeft|Left|1|East|FarRight|0|Yes| +|FarLeft|Middle|1|East|FarRight|0|Yes| +|FarLeft|Right|1|East|FarRight|0|Yes| +|FarLeft|FarRight|1|East|FarRight|0|Yes| +|FarLeft|Top|1|East|FarRight|1|No| +|FarRight|Right|1|West|FarLeft|0|Yes| +|FarRight|Middle|1|West|FarLeft|0|Yes| +|FarRight|Left|1|West|FarLeft|0|Yes| +|FarRight|FarLeft|1|West|FarLeft|0|Yes| +|FarRight|Bottom|1|West|FarLeft|1|No| +|Top|Above|1|South|Bottom|0|Yes| +|Top|Middle|1|South|Bottom|0|Yes| +|Top|Below|1|South|Bottom|0|Yes| +|Top|Bottom|1|South|Bottom|0|Yes| +|Top|FarLeft|1|South|Bottom|1|No| +|Bottom|Below|1|North|Top|0|Yes| +|Bottom|Middle|1|North|Top|0|Yes| +|Bottom|Above|1|North|Top|0|Yes| +|Bottom|Top|1|North|Top|0|Yes| +|Bottom|FarRight|1|North|Top|1|No| + +-!|script| +|Given Donut Map| + +{{{ +Donut Map + +[3]<-[2]<-[1] + | A + V | +[4] [8] + | A + V | +[5]->[6]->[7] +}}} + +!|Does arrow kill wumpus| +|player cavern|wumpus cavern|arrows for player|shooting direction|farthest cavern?|arrows in farthest cavern?|wumpus killed message?| +|1|2|1|West|3|0|Yes| +|1|3|1|West|3|0|Yes| +|1|5|1|West|3|1|No| +|3|4|1|South|5|0|Yes| +|3|5|1|South|5|0|Yes| +|3|7|1|South|5|1|No| +|5|6|1|East|7|0|Yes| +|5|7|1|East|7|0|Yes| +|5|8|1|East|7|1|No| +|7|8|1|North|1|0|Yes| +|7|1|1|North|1|0|Yes| +|7|3|1|North|1|1|No| diff --git a/fitnesse/FitNesseRoot/RecentChanges/20151216232211.zip b/fitnesse/FitNesseRoot/RecentChanges/20151216232211.zip new file mode 100644 index 0000000000000000000000000000000000000000..1cafebdc6e7a24ad420e654abd1846cbdf6b454b GIT binary patch literal 1128 zcmWIWW@Zs#;Nak3IKnW|odF4O1KG*>c_pcNC3+ns;Heou^v)Z(GjHE6WR?*gDlcyxYCj{Y0zy50!iMxBu6cGm09p8uRU~JX)q8 zK4Izx)~#23u4_eRPPne4eJScw+@{pjqw}<87%#nHyu#%WlbKW2iHTD$RJbf|oPMp~ z;aQ`%6F0DCuRNZ^J!y3_W3cH{ZN=*o)cqG-6AlYit)Ew<`{701`^Cx3Qm)H4S+vY( zlYP4<<^3(o=-6T&;i#WQCpNN}NX$ExB)CYB_fZ~48nbStPU%Ds%{tR(ahw6)oz99dkT++;=Q>K*dHyJ`ZDXxk~^0BLUbg~AKlf--l^HC zAz39HX%$d^Wt*BW?+RyD6`TE9jE9>u67RF@5Pneo&~V>sHG?ommSlU2qqqKRo|qf4 zj#0MgyX^G~Ex)~YL{N$PMQ$ro=c1DXi-C&O3>0|!w zJDWwb5PcUC>ytatl_**vR))a`kUrAz9r zsIKBvE$F`G5wI37D&tNyuJ-QV>WPfY3eo*9}@sWiXsUuDIyp2s{J zb<+5cfA&7C5>e*HkQpdn(Wd?(LLujM#G$zjeJ(GL`EAYqCG7MoP2_l;`3Zh$c_wy~ zEpvaTI{p5;?SO<=a$b~2puKp-hrZk@y?ySl`EAL!I6EH59Ut% zkzpA5D4Xp{&R2a+HzS^Np0|!&pRg!xHdoxCW1klr|N5o1E<*E3vR-tk;JL{UcfQ%w z;n;F^z3`&lZfB~$t<4tJ+%fNQ^xb)f%_qz6DSc-i;LXl)@POBor%VhCK|Bl$0XTC9 zA24?m6y+DB7L{bC7VA~y=J@t)+Yg?Dt;5* zOiZ)1n7_Jmo1KEF#lLk&{Wd( Date: Thu, 17 Dec 2015 21:59:36 -0500 Subject: [PATCH 3/7] Modify ArrowsAccumulateInFarthestCavern test to use a decision table and new fixture to test all directions --- .../DoArrowsAccumulateInFarthestCavern.java | 59 ++++++++++++++++++ .../20151217213807.zip | Bin 0 -> 741 bytes .../content.txt | 45 ++++++++++--- .../RecentChanges/20151217213807.zip | Bin 0 -> 1145 bytes .../FitNesseRoot/RecentChanges/content.txt | 2 +- 5 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 HTW/test/htw/fixtures/DoArrowsAccumulateInFarthestCavern.java create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/HuntingWithArrows/ArrowsAccumulateInFarthestCavern/20151217213807.zip create mode 100644 fitnesse/FitNesseRoot/RecentChanges/20151217213807.zip diff --git a/HTW/test/htw/fixtures/DoArrowsAccumulateInFarthestCavern.java b/HTW/test/htw/fixtures/DoArrowsAccumulateInFarthestCavern.java new file mode 100644 index 0000000..114ce5c --- /dev/null +++ b/HTW/test/htw/fixtures/DoArrowsAccumulateInFarthestCavern.java @@ -0,0 +1,59 @@ +package htw.fixtures; + +import htw.HuntTheWumpus.Direction; + +import static htw.fixtures.TestContext.game; + +public class DoArrowsAccumulateInFarthestCavern { + + private String playerCavern; + private int arrowCount; + private Direction shootingDirection; + private int NUM_SHOTS = 3; + private int[] shotCount = new int[NUM_SHOTS]; + + public void setPlayerCavern(String playerCavern) { + this.playerCavern = playerCavern; + } + + public void setArrowCount(int arrowCount) { + this.arrowCount = arrowCount; + } + + public void setShootingDirection(Direction shootingDirection) { + this.shootingDirection = shootingDirection; + } + + public String farthestCavern() { + return game.farthestCavern(playerCavern, shootingDirection); + } + + public void reset() { + TestContext.messages.clear(); + TestContext.game.initializeArrowsIn(); + } + + public void execute() { + game.setPlayerCavern(playerCavern); + game.setQuiver(arrowCount); + for (int i = 0; i < NUM_SHOTS; i++) + recordShotCountAfterShooting(i, farthestCavern()); + } + + private void recordShotCountAfterShooting(int i, String farthestCavern) { + game.makeShootCommand(shootingDirection).execute(); + shotCount[i] = game.getArrowsInCavern(farthestCavern); + } + + public int countAfterFirstShot() { + return shotCount[0]; + } + + public int countAfterSecondShot() { + return shotCount[1]; + } + + public int countAfterThirdShot() { + return shotCount[2]; + } +} diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/HuntingWithArrows/ArrowsAccumulateInFarthestCavern/20151217213807.zip b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/HuntingWithArrows/ArrowsAccumulateInFarthestCavern/20151217213807.zip new file mode 100644 index 0000000000000000000000000000000000000000..ac0c2e280da60a77d54e58b3bad31074024e15dd GIT binary patch literal 741 zcmWIWW@Zs#;Nak3xV2`YI|CBn2C|d$^GZ_lO7u!9N@^$B79TR;X)FKFReI{m!l&$C zy!MN|xbSTq^YH|s_8(Gf=B#C~JyO5^1iSbOMQ;_`^?z<{%Fnl0axd&i*ZnuQEGj-p zF!_`o^?F-oU3w;TlFypooD23gww_&Mt{GXf%SULb$eeoPABVUS zXn8jA+TUenr@fR9w#SOKH)-55*mmK@lpUSbJrg;?o4)2%HqJH4);HuTd!C@Ul@H~LXd}N z@s|4;JpUL2yxBP>Epm`^U}RvZW@carz!~s-z<@6($}dPQD#=VO)~m?P3GKJ$Z!!>R z{r+3qqukZJotwukZP9|_%W+FNw=G$FY`*@bPX*TZEx&gjeST9lf0Li&+>L+BjtgBn zF8kW9lQ;Be74)gZr zSoO8XnDf%V8%2L-aR1vIe|9c+{u>#0mOTR77xmV$9GG>d?qW|<1QEy}#S zK;z_uqaRo5$SEcUy4&mjY_IbRzs{8Eq#xgF<9*`Lmk_abf%pvuFWWwtZQrvyTI~k>LFryJW}Hyf;L(#W#6IePnl z=!ESv)<0ZvNjE&}=|8b`(ht0LpW0{>VX5xAK(+sDBXgk0Ty>*u+J`hpVVl7- zkNLOnY=*N3Z>&+1@IU2o=d5=9Bdg8j>GehGfxJ4B<7bL%YU?t8CGl$*C5&{$ep9;gwyUnHaAxOwgR_ZNRI zj&O=AWIa7mgsCXl%Q{TgaO3HVlAZm0n=SL07A#*~?-_Vf!$v)G_I5X(>~9ke7T;h| zv3neS|3%kKC;R6`k)px7@60=?-=1OqEK%L%zvR~4531+)P8CUOt6sPHaBXwT`cyhRo6r zl5TGTUi_+jGeAEH40PN^AP(?mWD;ROlK+65- g8j%eJ`5XcCnbE@`z?+o~B+mqdr9k=}Pz3`60K@g{fdBvi literal 0 HcmV?d00001 diff --git a/fitnesse/FitNesseRoot/RecentChanges/content.txt b/fitnesse/FitNesseRoot/RecentChanges/content.txt index f23c1d9..f587dbd 100644 --- a/fitnesse/FitNesseRoot/RecentChanges/content.txt +++ b/fitnesse/FitNesseRoot/RecentChanges/content.txt @@ -1,3 +1,4 @@ +|HuntTheWumpus.ReleaseOne.HuntingWithArrows.ArrowsAccumulateInFarthestCavern||21:38:52 Thu, Dec 17, 2015| |HuntTheWumpus.ReleaseOne.HuntingWithArrows.ArrowKillsWumpus||24:06:08 Thu, Dec 17, 2015| |HuntTheWumpus.ScenarioLibrary||13:46:54 Wed, Nov 11, 2015| |HuntTheWumpus.ReleaseOne.PlayerRecievesStatusAfterEachTurn.AvailablePassagesAreReported||11:59:47 Tue, Oct 13, 2015| @@ -16,7 +17,6 @@ |HuntTheWumpus.SetUp||09:21:04 Fri, Oct 09, 2015| |HuntTheWumpus.ReleaseOne.WumpusKillsPlayer.WumpusMovesToPlayer||09:16:17 Fri, Oct 09, 2015| |HuntTheWumpus.ReleaseOne.HuntingWithArrows.AfterShootingPlayersArrowLeavesQuiverAndLandsInFarthestCavern||09:08:42 Fri, Oct 09, 2015| -|HuntTheWumpus.ReleaseOne.HuntingWithArrows.ArrowsAccumulateInFarthestCavern||09:07:49 Fri, Oct 09, 2015| |HuntTheWumpus.ReleaseOne.WumpusKillsPlayer.PlayerMovesIntoWumpus||09:04:35 Fri, Oct 09, 2015| |HuntTheWumpus.ReleaseOne.WumpusKillsPlayer||08:59:43 Fri, Oct 09, 2015| |HuntTheWumpus.WumpusKillsPlayer||08:58:56 Fri, Oct 09, 2015| From 5e8cd7ad92487348b25168e7c18e0f271a3561b2 Mon Sep 17 00:00:00 2001 From: Fred Trimble Date: Thu, 17 Dec 2015 22:35:32 -0500 Subject: [PATCH 4/7] Modify PlayerCanNotShootWithoutArrows test to use a decision table and new fixture to test all directions --- .../fixtures/CanPlayerShootWithoutArrows.java | 33 +++++++++++++++ .../20151217222400.zip | Bin 0 -> 635 bytes .../content.txt | 40 +++++++++++++++--- .../RecentChanges/20151217222400.zip | Bin 0 -> 1148 bytes .../FitNesseRoot/RecentChanges/content.txt | 2 +- 5 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 HTW/test/htw/fixtures/CanPlayerShootWithoutArrows.java create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/HuntingWithArrows/PlayerCanNotShootWithoutArrows/20151217222400.zip create mode 100644 fitnesse/FitNesseRoot/RecentChanges/20151217222400.zip diff --git a/HTW/test/htw/fixtures/CanPlayerShootWithoutArrows.java b/HTW/test/htw/fixtures/CanPlayerShootWithoutArrows.java new file mode 100644 index 0000000..f2126d8 --- /dev/null +++ b/HTW/test/htw/fixtures/CanPlayerShootWithoutArrows.java @@ -0,0 +1,33 @@ +package htw.fixtures; + +import htw.HuntTheWumpus.Direction; + +import static htw.fixtures.TestContext.game; + +public class CanPlayerShootWithoutArrows { + + private String playerCavern; + private Direction shootingDirection; + + public void setPlayerCavern(String playerCavern) { + this.playerCavern = playerCavern; + } + + public void setShootingDirection(Direction shootingDirection) { + this.shootingDirection = shootingDirection; + } + + public void reset() { + TestContext.messages.clear(); + } + + public void execute() { + game.setPlayerCavern(playerCavern); + game.setQuiver(0); + game.makeShootCommand(shootingDirection).execute(); + } + + public String noArrowsMessageGiven() { + return TestContext.messages.contains("NO_ARROWS") ? "Yes" : "No"; + } +} diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/HuntingWithArrows/PlayerCanNotShootWithoutArrows/20151217222400.zip b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/HuntingWithArrows/PlayerCanNotShootWithoutArrows/20151217222400.zip new file mode 100644 index 0000000000000000000000000000000000000000..70c52fe34493fdf6b1e0fa04c253fe29a1de6093 GIT binary patch literal 635 zcmWIWW@Zs#;Nak3NZdTpodF4O1KG*>c_pcNC3++MJoeWY>HLHOZaX|7ePx?+<4|Ce{4e}A$5oErj)b>7F>w)^cpJ}rku zqK)y{KL@c*Ir`6DO_X^Y=~WoR66owZjgevBJem3{O7pI*IlsBgCi18FPTTlHoS&as zc|@Ac=~^7}Rb|PMn036j3KswUB`?kEcsr%{F~Ia7rJ!FW2wAk_N$`e zgwD?~-uEPZB`>#$S|;TC`d`y7VxF_))6VVshf1b2EPd6c65+@k=Iza~>T8cN=cRu) zivG^v{|E~rH!|)ldjz&G>aAlrFzZgqbq&V#4=-jO>}l9OO~c_pcNC3+KHL7}%d@lN;h@Yq&-?#xWfZzkoY*H1Ied;N7; z*k8+#10p__U(ULnjGylvyCkT~ewF>|8+=bXKDsXyZxy)prZZ~y+hv?gQZ84%?@bN- zzDN3mjnSLRM*m08+>2TIe|v9U6L($ovcbb-wNgf}{u^Q{?rKhlTaF!col!R}bm^T; zmt!n!SNyFM^o<_)OnbDiW}?r#S#2#QQWq>f%~O0|*`M@U@Kb4s-&M;L)f`7%lgnGZ z!lj<*p6*K3t+cp9@gC^zZ&lXX#vYnnN->}^zU{kJ?ZH)74hxtDpvlb-w&TW6gR6!~02uH>Aj=!+A{ zRSQ(P4xbJ=cBgAX{QEbq`Fsh+7JPg1cZp;$-YVJJ|5fEme_!{hwKrzpY~37RDX@Yq z>e#x-g4eT(gSVa9Hq)vgb^ANU+9h>YRd;df7WCf>lAo{4bJ#yaWX|lxzc*V--QGGk z>%qm+k261TOu4aqk$1by52^a*_b=CT%1<>~ec+Re9q(V`$~UJw!b7*r7t#s16lxyL zQa&|o_qAe^9_u{QvRh}#ig<3D9|z28&6n+s zu76~iB070OKg;t8FN0=0KPT`zEn}y`$K6Lu8ud+9ynGcO6k^1q=Xp!@`h-Q(Z=H)e zaP0G9?q|Oo!{3N}GM)Z*RmY5lpPdRLU5roi^*fc!7c^d6`|V}~*Sd6z`dh^o>^}~s zKmW%R;LXmV!nWV%Cldoh5Dx=G0L~o42h1@AMfnA(MJ1W3#d;OFIlg@x`3@QIxRmcx z`o!1TyKo`%B4Z}5;wdt@ORlV(!}0N_iGsl7`qF zztVeKPm}xQ##@;LXS+!hp!~$X)|wc~pQ@ i0HA9`HWcJ@1TbPo4~GD6RyL446A+dH>5o7a3=9DMn&_+m literal 0 HcmV?d00001 diff --git a/fitnesse/FitNesseRoot/RecentChanges/content.txt b/fitnesse/FitNesseRoot/RecentChanges/content.txt index f587dbd..6e44ecc 100644 --- a/fitnesse/FitNesseRoot/RecentChanges/content.txt +++ b/fitnesse/FitNesseRoot/RecentChanges/content.txt @@ -1,3 +1,4 @@ +|HuntTheWumpus.ReleaseOne.HuntingWithArrows.PlayerCanNotShootWithoutArrows||22:27:02 Thu, Dec 17, 2015| |HuntTheWumpus.ReleaseOne.HuntingWithArrows.ArrowsAccumulateInFarthestCavern||21:38:52 Thu, Dec 17, 2015| |HuntTheWumpus.ReleaseOne.HuntingWithArrows.ArrowKillsWumpus||24:06:08 Thu, Dec 17, 2015| |HuntTheWumpus.ScenarioLibrary||13:46:54 Wed, Nov 11, 2015| @@ -21,7 +22,6 @@ |HuntTheWumpus.ReleaseOne.WumpusKillsPlayer||08:59:43 Fri, Oct 09, 2015| |HuntTheWumpus.WumpusKillsPlayer||08:58:56 Fri, Oct 09, 2015| |HuntTheWumpus.ReleaseOne.HuntingWithArrows.PlayerKilledByShootingInCircle||08:40:30 Fri, Oct 09, 2015| -|HuntTheWumpus.ReleaseOne.HuntingWithArrows.PlayerCanNotShootWithoutArrows||11:42:17 Thu, Oct 08, 2015| |HuntTheWumpus.ReleaseOne.HuntingWithArrows||11:36:42 Thu, Oct 08, 2015| |HuntTheWumpus.ReleaseOne.WumpusMovesRandomlyEachTurn||10:52:50 Thu, Oct 08, 2015| |HuntTheWumpus.ReleaseOne.PlayerRecievesStatusAfterEachTurn||12:38:11 Tue, Oct 06, 2015| From 41d1fab237817cd080def3e3e5700b0affb3b2f5 Mon Sep 17 00:00:00 2001 From: Fred Trimble Date: Sat, 19 Dec 2015 09:04:18 -0500 Subject: [PATCH 5/7] Add new feature that allows player to add a pit cover to an adjacent cavern, so they won't fall into the pit if it exists --- HTW/src/htw/HtwMessageReceiver.java | 7 +++- HTW/src/htw/HuntTheWumpus.java | 1 + HTW/src/htw/console/Main.java | 23 +++++++++++++ HTW/src/htw/game/HuntTheWumpusGame.java | 31 +++++++++++++++++- HTW/test/htw/fixtures/HtwFixture.java | 5 +++ HTW/test/htw/fixtures/TestContext.java | 19 +++++++++-- .../20151218013821.zip | Bin 0 -> 554 bytes .../20151218014036.zip | Bin 0 -> 577 bytes .../20151218020603.zip | Bin 0 -> 554 bytes .../20151218020651.zip | Bin 0 -> 554 bytes .../20151219083843.zip | Bin 0 -> 551 bytes .../content.txt | 5 +++ .../properties.xml | 12 +++++++ .../20151216232211.zip | Bin 0 -> 400 bytes .../20151218020928.zip | Bin 0 -> 447 bytes .../20151218021119.zip | Bin 0 -> 567 bytes .../content.txt | 7 ++++ .../properties.xml | 12 +++++++ .../20151216232211.zip | Bin 0 -> 400 bytes .../20151218020538.zip | Bin 0 -> 447 bytes .../content.txt | 5 +++ .../properties.xml | 12 +++++++ .../20151216232211.zip | Bin 0 -> 400 bytes .../20151218021401.zip | Bin 0 -> 447 bytes .../20151218021459.zip | Bin 0 -> 545 bytes .../content.txt | 7 ++++ .../properties.xml | 12 +++++++ .../HuntTheWumpus/ScenarioLibrary/content.txt | 3 ++ .../RecentChanges/20151219084224.zip | Bin 0 -> 1225 bytes .../FitNesseRoot/RecentChanges/content.txt | 6 +++- 30 files changed, 162 insertions(+), 5 deletions(-) create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/20151218013821.zip create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/20151218014036.zip create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/20151218020603.zip create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/20151218020651.zip create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/20151219083843.zip create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/content.txt create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/properties.xml create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/20151216232211.zip create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/20151218020928.zip create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/20151218021119.zip create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/content.txt create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/properties.xml create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverToNonAdjacentCavern/20151216232211.zip create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverToNonAdjacentCavern/20151218020538.zip create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverToNonAdjacentCavern/content.txt create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverToNonAdjacentCavern/properties.xml create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerVisitsAdjacentCavernWithPitAndPitCoverAndLives/20151216232211.zip create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerVisitsAdjacentCavernWithPitAndPitCoverAndLives/20151218021401.zip create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerVisitsAdjacentCavernWithPitAndPitCoverAndLives/20151218021459.zip create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerVisitsAdjacentCavernWithPitAndPitCoverAndLives/content.txt create mode 100644 fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerVisitsAdjacentCavernWithPitAndPitCoverAndLives/properties.xml create mode 100644 fitnesse/FitNesseRoot/RecentChanges/20151219084224.zip diff --git a/HTW/src/htw/HtwMessageReceiver.java b/HTW/src/htw/HtwMessageReceiver.java index b99a475..c386c64 100644 --- a/HTW/src/htw/HtwMessageReceiver.java +++ b/HTW/src/htw/HtwMessageReceiver.java @@ -1,11 +1,13 @@ package htw; +import htw.HuntTheWumpus.Direction; + public interface HtwMessageReceiver { void noPassage(); void hearBats(); void hearPit(); void smellWumpus(); - void passage(HuntTheWumpus.Direction direction); + void passage(Direction direction); void noArrows(); void arrowShot(); void playerShootsSelfInBack(); @@ -16,4 +18,7 @@ public interface HtwMessageReceiver { void playerMovesToWumpus(); void wumpusMovesToPlayer(); void batsTransport(); + void addPitCoverToAdjacentCavern(Direction direction); + void cavernNotAdjacentForPitCover(); + void noPitCover(); } diff --git a/HTW/src/htw/HuntTheWumpus.java b/HTW/src/htw/HuntTheWumpus.java index 95529f4..dccd2bb 100644 --- a/HTW/src/htw/HuntTheWumpus.java +++ b/HTW/src/htw/HuntTheWumpus.java @@ -42,6 +42,7 @@ public Direction opposite() { HuntTheWumpusGame.Command makeRestCommand(); HuntTheWumpusGame.Command makeShootCommand(Direction direction); HuntTheWumpusGame.Command makeMoveCommand(Direction direction); + HuntTheWumpusGame.Command makeAddPitCoverCommand(Direction direction); public interface Command { void execute(); diff --git a/HTW/src/htw/console/Main.java b/HTW/src/htw/console/Main.java index 411597d..5554220 100644 --- a/HTW/src/htw/console/Main.java +++ b/HTW/src/htw/console/Main.java @@ -99,6 +99,14 @@ else if (command.equalsIgnoreCase("sn")) c = game.makeShootCommand(NORTH); else if (command.equalsIgnoreCase("ss")) c = game.makeShootCommand(SOUTH); + else if (command.equalsIgnoreCase("pce")) + c = game.makeAddPitCoverCommand(EAST); + else if (command.equalsIgnoreCase("pcw")) + c = game.makeAddPitCoverCommand(WEST); + else if (command.equalsIgnoreCase("pcn")) + c = game.makeAddPitCoverCommand(NORTH); + else if (command.equalsIgnoreCase("pcs")) + c = game.makeAddPitCoverCommand(SOUTH); else if (command.equalsIgnoreCase("q")) return; @@ -236,6 +244,21 @@ public void batsTransport() { System.out.println("Some bats carried you away."); } + @Override + public void addPitCoverToAdjacentCavern(Direction direction) { + System.out.println("Pit cover added to cavern to the " + direction); + } + + @Override + public void cavernNotAdjacentForPitCover() { + System.out.println("You cannot add a pit cover in that direction"); + } + + @Override + public void noPitCover() { + System.out.println("You have no more pit covers"); + } + private void hit(int points) { hitPoints -= points; if (hitPoints <= 0) { diff --git a/HTW/src/htw/game/HuntTheWumpusGame.java b/HTW/src/htw/game/HuntTheWumpusGame.java index afb20f6..221760b 100644 --- a/HTW/src/htw/game/HuntTheWumpusGame.java +++ b/HTW/src/htw/game/HuntTheWumpusGame.java @@ -1,5 +1,6 @@ package htw.game; +import com.sun.corba.se.spi.legacy.connection.GetEndPointInfoAgainException; import htw.HtwMessageReceiver; import htw.HuntTheWumpus; @@ -18,6 +19,7 @@ public class HuntTheWumpusGame implements HuntTheWumpus { private String wumpusCavern = "NONE"; private int quiver = 0; private Map arrowsIn = new HashMap<>(); + private String cavernWithPitCover = "NONE"; public HuntTheWumpusGame(HtwMessageReceiver receiver) { this.messageReceiver = receiver; @@ -197,6 +199,10 @@ public Command makeMoveCommand(Direction direction) { return new MoveCommand(direction); } + public Command makeAddPitCoverCommand(Direction direction) { + return new AddPitCoverCommand(direction); + } + public abstract class GameCommand implements Command { public void execute() { processCommand(); @@ -344,7 +350,7 @@ public boolean movePlayer(Direction direction) { } private void checkForPit() { - if (pitCaverns.contains(playerCavern)) + if (pitCaverns.contains(playerCavern) && !cavernWithPitCover.equals(playerCavern)) messageReceiver.fellInPit(); } @@ -356,4 +362,27 @@ private void checkForArrows() { arrowsIn.put(playerCavern, 0); } } + + private class AddPitCoverCommand implements Command { + private Direction direction; + + public AddPitCoverCommand(Direction direction) { + this.direction = direction; + } + + public void execute() { + if (cavernWithPitCover.equals("NONE")) { + String destination = findDestination(playerCavern, direction); + if (destination != null) { + cavernWithPitCover = destination; + messageReceiver.addPitCoverToAdjacentCavern(direction); + } else { + messageReceiver.cavernNotAdjacentForPitCover(); + } + } + else { + messageReceiver.noPitCover(); + } + } + } } diff --git a/HTW/test/htw/fixtures/HtwFixture.java b/HTW/test/htw/fixtures/HtwFixture.java index 236fb36..763f5c4 100644 --- a/HTW/test/htw/fixtures/HtwFixture.java +++ b/HTW/test/htw/fixtures/HtwFixture.java @@ -125,4 +125,9 @@ public int arrowsInQuiver() { public int arrowsInCavern(String cavern) { return game.getArrowsInCavern(cavern); } + + public boolean addPitCover(String dir) { + game.makeAddPitCoverCommand(toDirection(dir)).execute(); + return true; + } } diff --git a/HTW/test/htw/fixtures/TestContext.java b/HTW/test/htw/fixtures/TestContext.java index d297644..61ee527 100644 --- a/HTW/test/htw/fixtures/TestContext.java +++ b/HTW/test/htw/fixtures/TestContext.java @@ -1,7 +1,7 @@ package htw.fixtures; import htw.HtwMessageReceiver; -import htw.HuntTheWumpus; +import htw.HuntTheWumpus.Direction; import htw.factory.HtwFactory; import java.util.HashMap; @@ -60,7 +60,7 @@ public void arrowsFound(Integer arrowsFound) { messages.add(String.format("%d_ARROW_FOUND", arrowsFound)); } - public void passage(HuntTheWumpus.Direction direction) { + public void passage(Direction direction) { messages.add(direction.name() + "_PASSAGE"); } @@ -83,4 +83,19 @@ public void playerKillsWumpus() { public void playerShootsWall() { messages.add("PLAYER_SHOOTS_WALL"); } + + @Override + public void addPitCoverToAdjacentCavern(Direction cavern) { + messages.add("PIT_COVER_ADDED_TO_CAVERN_" + cavern.name()); + } + + @Override + public void cavernNotAdjacentForPitCover() { + messages.add("CAVERN_NOT_ADJACENT_FOR_PIT_COVER"); + } + + @Override + public void noPitCover() { + messages.add("NO_PIT_COVER"); + } } diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/20151218013821.zip b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/20151218013821.zip new file mode 100644 index 0000000000000000000000000000000000000000..f1406279cb230f3df4ab5da01cae617b4c938c86 GIT binary patch literal 554 zcmWIWW@Zs#;Nak35aONW&VU5Cf$Ze`ypq(s61|d&lF&X!u0sYQF5hjBRxt1fUQ%e< z8q}qCc=^w5jkDVR1PByWNQ*a}o>_VL%*P3-J$g%Go=(1f!}(|^i*D=u$!Ts8FU|`3 zJ+N`RWl-pr@)%ut+f2^>|L29$!+IWR80@R zY?Up3tlKr?k&)$8>7BnA0=(Hd`i-adv;y6>28aW2x}FaxTTql=kXlrdnOdw@k((3R zZ_VFiAkzB%x3)*Qt9d&&k6YTJ1;v-+mU3=evi8_~{Y#$;tnXWX?>zearfU8sKgqcp z|CSvWx^&26sk~(NtD@qB&d)L4_auEKFSm(WCgl72U(+sPp0niB&h7e#N~Sa{ebuHC z;m923?ai_3YmYJKrGGby{?6e3w>SRmT<-igGVUyU1hy~gtz$Vb>rTma4aW5kFJ>O> zY1lqZ$Fwh{M~uzq`u#dakOwu7O%qxQbiNTI$b*bbA`FNKLiRi;f=~fcbfIfRHWU;# c2(S;xL=C9`Z&o&tJQEO>0_pichcGYz0FB?d^8f$< literal 0 HcmV?d00001 diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/20151218014036.zip b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/20151218014036.zip new file mode 100644 index 0000000000000000000000000000000000000000..d182bbd5c6b7ad23c3e8a439305d22d72ec0accf GIT binary patch literal 577 zcmWIWW@Zs#;Nak3I4Cg5odF4O1KG*>c_pcNC3+dpGon1hIYF@@$V{ms_37wx~yzfc+N?vXg zwM@wO^}nWF#5`xor=8pN50y-5So*3>CBl(8%-fq|)z=l%#fA70En*we6mnvQ8-N{<+u&-MFtj35tc9-Ah#6zF^- zMvw;?nM4>6@rLYqP`sf6q*z4Ph-@e*Y!Kiokck>n0p6@^AbBPrECtfrfDU0`000Kz B%C!Ih literal 0 HcmV?d00001 diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/20151218020603.zip b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/20151218020603.zip new file mode 100644 index 0000000000000000000000000000000000000000..af3d0f4c6ae20c4caf9d5dbf8e993631b1b61b17 GIT binary patch literal 554 zcmWIWW@Zs#;Nak3xG6BnodF4O1KG*>c_pcNC3+|hV#)-7TwnQlhfQHUYr&5 zdtl>s%c3ggM`Tw2&-sektSt|Oj+L@cyq3SllgmzIPJuPQTWR^-*}F1JlH1O$sG1&r z*(zK7Shs7&BO}YH(mQ`K1bDM^^czp@X$87%4G;(5bUhzXwxB4#AhoC@GqqT+A~z?r z-Z{hh)6Z*TnBx!n10WZYTy2y9=}TgP%>)}4~;8jR~7Ud%k$ z)3AM-j%i;?j~JWJ_4{>LeegzR}x1fc??=t9?sY$zyf c5MUpWi5gM?-mGjOc_tt%1=90@4q;#b0PY688vpc_pcNC3+|hV#)-7TwnQlhfQHUYr&5 zdtl>s%c3ggM`Tw2&-sektSt|Oj+L@cyq3SllgmzIPJuPQTWR^-*}F1JlH1O$sG1&r z*(zK7Shs7&BO}YH(mQ`K1bDM^^czp@X$87%4G;(5bUhzXwxB4#AhoC@GqqT+A~z?r z-Z{hh)6Z*TnBx!n10WZYTy2y9=}TgP%>)}4~;8jR~7Ud%k$ z)3AM-j%i;?j~JWJ_4{>LeegzR}x1fc??=t9?sY$zyf c5MUpWi5gM?-mGjOc_tt%1=90@4q;#b0KU|{-v9sr literal 0 HcmV?d00001 diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/20151219083843.zip b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/20151219083843.zip new file mode 100644 index 0000000000000000000000000000000000000000..bd1d4f973dc21812e5611385db6b4ffe0276e83a GIT binary patch literal 551 zcmWIWW@Zs#;Nak3@Nu2&&VU5Cf$Ze`ypq(s61|d&lF)OGT!#z ZflSnp3h-uS1IaT1VJVQF19S)j0|3Gxxu^gD literal 0 HcmV?d00001 diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/content.txt b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/content.txt new file mode 100644 index 0000000..0696aca --- /dev/null +++ b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/content.txt @@ -0,0 +1,5 @@ +-!|script| +|Given Cross Map| +|Given the player is in cavern Left| +|When the player adds a pit cover to the East| +|Then a PIT_COVER_ADDED_TO_CAVERN_EAST message is given| diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/properties.xml b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/properties.xml new file mode 100644 index 0000000..55bd9cd --- /dev/null +++ b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanAddPitCoverToAdjacentCavern/properties.xml @@ -0,0 +1,12 @@ + + +true +true +true +true +true +true +true +true +true + diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/20151216232211.zip b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/20151216232211.zip new file mode 100644 index 0000000000000000000000000000000000000000..1b37b1a78c60d15dcd9b4ebd26e04299f7813d6b GIT binary patch literal 400 zcmWIWW@Zs#;Nak3&=Z{G&VU5Cf$Ze`ypq(s61|d&lFgc)x_W^c9zOnCnHd7S**Vw_ zo-5`BssX7Bz-bB}P`02bzaX`!Br~;GuOc_cw{IigAp;(l@_kC5_*#1xE@WP0%*0hZ zMJ9L2m6dZiKK?XO5SV;_v%l5#v&B5G7(MMaEjyd#%aybE^PTKhdT)!owNekCYdLY@ z$i!K97tK@goA730nx)13)s@@q6htlltvl+s;lUnxp6~aM-n}8S^n;|^n}8R;Dj&_= z!7EV0xz6Kj{5K|$^N+gpG&KVqw-M}oMkWykL@*$G4dgvkfD|YJ-l!Up4F&le0o;I0 V)Nly!W@Q7(GXY^KkY;5B@c^o`Z~_1T literal 0 HcmV?d00001 diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/20151218020928.zip b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/20151218020928.zip new file mode 100644 index 0000000000000000000000000000000000000000..77b1208f5fe52a53a938a1b852693778d1e1be09 GIT binary patch literal 447 zcmWIWW@Zs#;Nak3$P}F9&VU5Cf$Ze`ypq(s61|d&lFgc)x_W^c9zOnCnHd7S**Vw_ zo-5`BssX7Bz-bB}P`02bzaX`!Br~;GuOc@mwErw$lYv0X`&zC`yBC@BbIbG`Q4YLN ze0kjkmgq}jj~_=b_*3z!#`toc_@?)}d+jpTT+v#1{BNV%iXCD>S2@?7swrPIvDAn2 zT2?D(=&Ur&#&a+DdM9Vt#a1ZLEFWCNtIA z+~=zI!~4=!`p4#)dCN>VAUpG+?+50J?bG?*8titl{$DbMMeg#e&ns9tZKO>iB1IIV zW;*P-`=1@;+q_G+ZfpYj#f1^%TSg`k21KYKhXg1zPytdHqH9Dp6ckVh;09!(23vqP SD;r3j2?$Gpvi~AGHuqW zB`52qEt{6eQ?WsdS7xsBpU3=x$LBBFWYqrp_$%%JZ+4D^iTqBJfDUD5WMBxu=@mYp zih`p2g4Cjt%+zANirk#gerx_F1CiG6zqLKeUCrCMdEC+#EhxSmx0G|+lC{U?>tFg* zV13{6d*{*TH&ydD`AN>*__yr1(4|8jOXVfAUlkQ6bbgNUz9;D`dAUv0G9lmB|C)9Y z^PDB0c5c@{R5GPu>8m!C2uJ2HZ*PuOUwe!>Fa5hw^mhjLzrFEi=W^%2k#T3)Bd~o@ zZyn2lS$9gVYcQ^Vcro)}Ps8?UI;MRoJz{J=*YDRcf;^~sY?{zgp!1Eu9%N(^VL-$d tvgbjug$j`3F2EaABeJ2Out9*+KqhKP1$eWvf#jKhuoOtI0Xl?%0Ra9j!&LwP literal 0 HcmV?d00001 diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/content.txt b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/content.txt new file mode 100644 index 0000000..267d64f --- /dev/null +++ b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/content.txt @@ -0,0 +1,7 @@ +-!|script| +|Given Cross Map| +|Given the player is in cavern Middle| +|When the player adds a pit cover to the East| +|Then a PIT_COVER_ADDED_TO_CAVERN_EAST message is given| +|When the player adds a pit cover to the West| +|Then a NO_PIT_COVER message is given| diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/properties.xml b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/properties.xml new file mode 100644 index 0000000..55bd9cd --- /dev/null +++ b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverOnceAdded/properties.xml @@ -0,0 +1,12 @@ + + +true +true +true +true +true +true +true +true +true + diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverToNonAdjacentCavern/20151216232211.zip b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerCanNotAddPitCoverToNonAdjacentCavern/20151216232211.zip new file mode 100644 index 0000000000000000000000000000000000000000..e5495c89515207473b975704c97efdc2834f99a7 GIT binary patch literal 400 zcmWIWW@Zs#;Nak3*eo!~odF4O1KG*>c_pcNC3+Z{J3~Lk2u9<@=OA@wN6YT*$o0n2D=+ zicId3D=X)4eEeymATaseXN!4WF?!l* zk%_bJE}Ey}H{s31G)s&5t1GwJDTrG9TX)oN!-GBYJm2phy?aAu=?6)-HvunxRX&=# zgIA!0bDhW6_-{-g=O1S2@?7swrPIvDAn2 zT2?D(=&Ur&#&a+DdM9Vt#a1ZLEFWCNtIA z+~=zI!~4=!`p4#)dCN>VAUpG+?+50J?bG?*8titl{$DbMMeg#e&ns9tZKO>iB1IIV zW;*P-`=1@;+q_G+ZfpYj#f1^%TSg`k21KYKhXg1zPytdHqH9Dp6ckVh;09!(23vqP SD;r3j2?$Gpv + +true +true +true +true +true +true +true +true +true + diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerVisitsAdjacentCavernWithPitAndPitCoverAndLives/20151216232211.zip b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerVisitsAdjacentCavernWithPitAndPitCoverAndLives/20151216232211.zip new file mode 100644 index 0000000000000000000000000000000000000000..48c368a2572f1bd5b228a4197436bd7c6ec3caed GIT binary patch literal 400 zcmWIWW@Zs#;Nak3I3PI5odF4O1KG*>c_pcNC3+Z{J3~Lk2u9<@=OA@wN6YT*$o0n2D=+ zicId3D=X)4eEeymATaseXN!4WF?!l* zk%_bJE}Ey}H{s31G)s&5t1GwJDTrG9TX)oN!-GBYJm2phy?aAu=?6)-HvunxRX&=# zgIA!0bDhW6_-{-g=O1c_pcNC3+99cZQXw(*Mu*3+F1L#O=haK zxzAPahxete^pDLo^Ol)#Kz8Os-w(_c+o$urHQ4Q9{l8=ii`?Z`pI5MQ+DMy3M2aXz z&2-pv_dh$xw|SRt-Pi>5iwh&jw~S0842V!e4hc|bpaP^YMAwLHC@7#1zzxVm4YmMp SRyL446A+dHX%nDB7#ILS$c6L( literal 0 HcmV?d00001 diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerVisitsAdjacentCavernWithPitAndPitCoverAndLives/20151218021459.zip b/fitnesse/FitNesseRoot/HuntTheWumpus/ReleaseOne/PitCaverns/PlayerVisitsAdjacentCavernWithPitAndPitCoverAndLives/20151218021459.zip new file mode 100644 index 0000000000000000000000000000000000000000..c1ba3fe0c6c259a3fbfc5c9dccee4ac2a83e5ccc GIT binary patch literal 545 zcmWIWW@Zs#;Nak3;1!zW&VU5Cf$Ze`ypq(s61|d&lF+k`T!#z&SMIkzoYdu+b`rB4Oc_btD79({gOHGh+z|OI^?lb zUNZYtQE@`&=NRvMlD?9c+e9rB@_qfUX%{iiS@LP;cKt&oQyP}OYEy}DWDfK8=2-Q$ z$C&fdzZ*q=XK?@98-I2#cm5k0ca}W@+ZXlLu^gCnr{uZ@ + +true +true +true +true +true +true +true +true +true + diff --git a/fitnesse/FitNesseRoot/HuntTheWumpus/ScenarioLibrary/content.txt b/fitnesse/FitNesseRoot/HuntTheWumpus/ScenarioLibrary/content.txt index eb14300..2cad4ed 100644 --- a/fitnesse/FitNesseRoot/HuntTheWumpus/ScenarioLibrary/content.txt +++ b/fitnesse/FitNesseRoot/HuntTheWumpus/ScenarioLibrary/content.txt @@ -15,6 +15,9 @@ |scenario|Given the _ cavern has a pit|cavern| |set cavern|@cavern|as pit| +|scenario|When the player adds a pit cover to the|dir| +|add pit cover|@dir| + !3 Player Scenarios |scenario|Given the player is in cavern|c| diff --git a/fitnesse/FitNesseRoot/RecentChanges/20151219084224.zip b/fitnesse/FitNesseRoot/RecentChanges/20151219084224.zip new file mode 100644 index 0000000000000000000000000000000000000000..51880aafc10f593e43a601be28461b37ca6f2f5d GIT binary patch literal 1225 zcmWIWW@Zs#;Nak3D07|c&VU5Cf$Ze`ypq(s61|d&lC5F4^Bx%p)ZSlzf;~hdT(8bM zGw|ZJ*4#^PH_zrdy8EEpw#%YI^81se1@2DEWeRa(dh^lJ__6Wh$op4fo)=fF5P^5S1lelg}{+esq`~4qHXxTVDu=ZiB z<3rYFZv8LKDSvbC&UvOD?6Z3N1Am|M7Y&|TSN*9x9p|W+>(Qjgx%-~SCf?lt98o>* z;$G}!P~XGwhkNN_4i5thb6350to756O-NAtyM!^a?fHt7N7HP*wZh-&JX>`AT;S$| zKe|1Ow3hz(eC>XYUW-}vqHB58d-*=jt3JZNwxuH1^Qf1)ZPIyHcg^?5*s+L_|?4#O2c z<{YW+&TP{+S#k1Be9)N`k$IE1c&-sV7dI|)3ZfSO)*bcR@L-QT&-eRB@7|DE`a#m|O~8v^m5=7`;1ww0T<7sM{u>j> z`A1!Pnwo)*+X%z~-i%Bl42bdr*=wNk0~H{ZCg>WG4F&le0qTJvg&Gb4-mGjOc_tt% K1=4mbARYjSbqM$X literal 0 HcmV?d00001 diff --git a/fitnesse/FitNesseRoot/RecentChanges/content.txt b/fitnesse/FitNesseRoot/RecentChanges/content.txt index 6e44ecc..e09742d 100644 --- a/fitnesse/FitNesseRoot/RecentChanges/content.txt +++ b/fitnesse/FitNesseRoot/RecentChanges/content.txt @@ -1,7 +1,11 @@ +|HuntTheWumpus.ReleaseOne.PitCaverns.PlayerCanNotAddPitCoverOnceAdded||08:43:44 Sat, Dec 19, 2015| +|HuntTheWumpus.ReleaseOne.PitCaverns.PlayerCanAddPitCoverToAdjacentCavern||08:42:24 Sat, Dec 19, 2015| +|HuntTheWumpus.ReleaseOne.PitCaverns.PlayerVisitsAdjacentCavernWithPitAndPitCoverAndLives||02:16:26 Fri, Dec 18, 2015| +|HuntTheWumpus.ReleaseOne.PitCaverns.PlayerCanNotAddPitCoverToNonAdjacentCavern||02:08:05 Fri, Dec 18, 2015| +|HuntTheWumpus.ScenarioLibrary||02:06:27 Fri, Dec 18, 2015| |HuntTheWumpus.ReleaseOne.HuntingWithArrows.PlayerCanNotShootWithoutArrows||22:27:02 Thu, Dec 17, 2015| |HuntTheWumpus.ReleaseOne.HuntingWithArrows.ArrowsAccumulateInFarthestCavern||21:38:52 Thu, Dec 17, 2015| |HuntTheWumpus.ReleaseOne.HuntingWithArrows.ArrowKillsWumpus||24:06:08 Thu, Dec 17, 2015| -|HuntTheWumpus.ScenarioLibrary||13:46:54 Wed, Nov 11, 2015| |HuntTheWumpus.ReleaseOne.PlayerRecievesStatusAfterEachTurn.AvailablePassagesAreReported||11:59:47 Tue, Oct 13, 2015| |HuntTheWumpus.ReleaseOne.PitCaverns.PlayerIsInformedAboutFallingIntoPit||06:57:44 Tue, Oct 13, 2015| |HuntTheWumpus.ReleaseOne.PitCaverns||06:55:37 Tue, Oct 13, 2015| From 9fb79c056a80ab9968865d606a9bd0fe9072e407 Mon Sep 17 00:00:00 2001 From: Fred Trimble Date: Wed, 23 Dec 2015 23:35:38 -0500 Subject: [PATCH 6/7] Removed unused import from HuntTheWumpusGame --- HTW/src/htw/game/HuntTheWumpusGame.java | 1 - 1 file changed, 1 deletion(-) diff --git a/HTW/src/htw/game/HuntTheWumpusGame.java b/HTW/src/htw/game/HuntTheWumpusGame.java index 221760b..5fe9a65 100644 --- a/HTW/src/htw/game/HuntTheWumpusGame.java +++ b/HTW/src/htw/game/HuntTheWumpusGame.java @@ -1,6 +1,5 @@ package htw.game; -import com.sun.corba.se.spi.legacy.connection.GetEndPointInfoAgainException; import htw.HtwMessageReceiver; import htw.HuntTheWumpus; From 0999babd2f88230ab9b04685de7ed5fe8638137d Mon Sep 17 00:00:00 2001 From: Fred Trimble Date: Wed, 23 Dec 2015 23:38:50 -0500 Subject: [PATCH 7/7] Add Swing GUI for hunt the wumpus game --- HTW/src/htw/gui/Main.java | 647 +++++++++++++++++++++++++++++ HTW/src/htw/gui/images/down24.gif | Bin 0 -> 366 bytes HTW/src/htw/gui/images/left24.gif | Bin 0 -> 422 bytes HTW/src/htw/gui/images/right24.gif | Bin 0 -> 434 bytes HTW/src/htw/gui/images/up24.gif | Bin 0 -> 429 bytes 5 files changed, 647 insertions(+) create mode 100644 HTW/src/htw/gui/Main.java create mode 100755 HTW/src/htw/gui/images/down24.gif create mode 100755 HTW/src/htw/gui/images/left24.gif create mode 100755 HTW/src/htw/gui/images/right24.gif create mode 100755 HTW/src/htw/gui/images/up24.gif diff --git a/HTW/src/htw/gui/Main.java b/HTW/src/htw/gui/Main.java new file mode 100644 index 0000000..8ad1a04 --- /dev/null +++ b/HTW/src/htw/gui/Main.java @@ -0,0 +1,647 @@ +package htw.gui; + +import htw.HtwMessageReceiver; +import htw.HuntTheWumpus; +import htw.HuntTheWumpus.Direction; +import htw.factory.HtwFactory; + +import javax.swing.*; +import javax.swing.border.Border; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +import static htw.HuntTheWumpus.Direction.EAST; +import static htw.HuntTheWumpus.Direction.NORTH; +import static htw.HuntTheWumpus.Direction.SOUTH; +import static htw.HuntTheWumpus.Direction.WEST; + +public class Main extends JPanel implements HtwMessageReceiver { + + private static HuntTheWumpus game; + private static List caverns = new ArrayList<>(); + + private JPanel warningPanel; + private JPanel cavernControlPanel; + private JPanel historyPanel; + private JPanel buttonPanel; + + private JTextArea historyTextArea; + private JTextArea warningTextArea; + + private JRadioButton moveRadioButton = new JRadioButton("Move"); + private JRadioButton shootRadioButton = new JRadioButton("Shoot"); + private JRadioButton addPitCoverRadioButton = new JRadioButton("Add Pit Cover"); + + private JSeparator quiverSeparator = getVerticalSeparator(); + private JSeparator healthSeparator = getVerticalSeparator(); + + private JLabel currentCavernLabel = new JLabel(); + private JLabel quiverCount = new JLabel(); + private JLabel healthLabel = new JLabel(); + + private JButton northButton = new JButton(); + private JButton southButton = new JButton(); + private JButton westButton = new JButton(); + private JButton eastButton = new JButton(); + private JButton startButton = new JButton("Start"); + private JButton quitButton = new JButton("Quit"); + + private static List warnings = new ArrayList<>(); + private static List passageDirections = new ArrayList<>(); + private static boolean playerMovesToWumpus = false; + private static boolean wumpusMovesToPlayer = false; + private static boolean playerKillsWumpus = false; + private static int health = 10; + private static Direction pitCoverDirection; + + private static final String[] environments = new String[]{ + "bright", + "humid", + "dry", + "creepy", + "ugly", + "foggy", + "hot", + "cold", + "drafty", + "dreadful" + }; + + private static final String[] shapes = new String[]{ + "round", + "square", + "oval", + "irregular", + "long", + "craggy", + "rough", + "tall", + "narrow" + }; + + private static final String[] cavernTypes = new String[]{ + "cavern", + "room", + "chamber", + "catacomb", + "crevasse", + "cell", + "tunnel", + "passageway", + "hall", + "expanse" + }; + + private static final String[] adornments = new String[]{ + "smelling of sulphur", + "with engravings on the walls", + "with a bumpy floor", + "", + "littered with garbage", + "spattered with guano", + "with piles of Wumpus droppings", + "with bones scattered around", + "with a corpse on the floor", + "that seems to vibrate", + "that feels stuffy", + "that fills you with dread" + }; + + public Main() { + super(new BorderLayout()); + add(createWarningsPanel(), BorderLayout.NORTH); + add(getCavernPanel(), BorderLayout.CENTER); + add(createButtonPanel(), BorderLayout.SOUTH); + initializeNavigationButtons(); + disableAllComponents(); + } + + public static void main(String[] args) { + javax.swing.SwingUtilities.invokeLater(() -> createAndShowGUI()); + } + + private static void createAndShowGUI() { + JFrame frame = new JFrame("Hunt The Wumpus"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + JComponent newContentPane = new Main(); + newContentPane.setOpaque(true); + frame.setContentPane(newContentPane); + frame.pack(); + frame.setVisible(true); + } + + private JPanel getCavernPanel() { + JPanel gamePanel = new JPanel(); + gamePanel.setLayout(new GridLayout(2, 1)); + gamePanel.add(createCavernControlPanel(), BorderLayout.CENTER); + gamePanel.add(createHistoryPanel()); + return gamePanel; + } + + private JPanel createWarningsPanel() { + initializeWarningPanel(); + initializeWarningPanelTextArea(); + warningPanel.add(warningTextArea, BorderLayout.WEST); + return warningPanel; + } + + private void initializeWarningPanel() { + warningPanel = new JPanel(); + warningPanel.setLayout(new BorderLayout()); + warningPanel.setBorder(BorderFactory.createTitledBorder("Warnings")); + warningPanel.setPreferredSize(new Dimension(500, 100)); + } + + private void initializeWarningPanelTextArea() { + warningTextArea = new JTextArea(5, 30); + warningTextArea.setEditable(false); + warningTextArea.setForeground(Color.RED); + warningTextArea.setBorder(javax.swing.BorderFactory.createEmptyBorder()); + warningTextArea.setOpaque(false); + warningTextArea.setAlignmentX(JTextArea.LEFT_ALIGNMENT); + } + + private void initializeNavigationButtons() { + initializeNavigationButtonIcons(); + initializeNavigationButtonListeners(); + setNavigationButtonLabels(); + setNavigationButtonToolTips(); + } + + private void initializeNavigationButtonIcons() { + northButton.setIcon(new ImageIcon(getClass().getResource("images/up24.gif"))); + southButton.setIcon(new ImageIcon(getClass().getResource("images/down24.gif"))); + eastButton.setIcon(new ImageIcon(getClass().getResource("images/right24.gif"))); + westButton.setIcon(new ImageIcon(getClass().getResource("images/left24.gif"))); + } + + private void initializeNavigationButtonListeners() { + northButton.addActionListener(e -> navigationButtonHandler(Direction.NORTH)); + southButton.addActionListener(e -> navigationButtonHandler(Direction.SOUTH)); + eastButton.addActionListener(e -> navigationButtonHandler(Direction.EAST)); + westButton.addActionListener(e -> navigationButtonHandler(Direction.WEST)); + } + + private void navigationButtonHandler(Direction direction) { + if (moveRadioButton.isSelected()) + moveButtonHandler(direction); + else if (shootRadioButton.isSelected()) + shootButtonHandler(direction); + else if (addPitCoverRadioButton.isSelected()) + addPitCoverButtonHandler(direction); + } + + private void setNavigationButtonLabels() { + northButton.setText(getNavigationButtonLabel(Direction.NORTH)); + southButton.setText(getNavigationButtonLabel(Direction.SOUTH)); + eastButton.setText(getNavigationButtonLabel(Direction.EAST)); + westButton.setText(getNavigationButtonLabel(Direction.WEST)); + } + + private String getNavigationButtonLabel(Direction direction) { + String command; + if (shootRadioButton.isSelected()) + command = "Shoot"; + else if (addPitCoverRadioButton.isSelected()) + command = "Add Pit Cover"; + else + command = "Move"; + return command + " " + direction.name(); + } + + private void setNavigationButtonToolTips() { + northButton.setToolTipText(getNavigationButtonToolTip(Direction.NORTH)); + southButton.setToolTipText(getNavigationButtonToolTip(Direction.SOUTH)); + eastButton.setToolTipText(getNavigationButtonToolTip(Direction.EAST)); + westButton.setToolTipText(getNavigationButtonToolTip(Direction.WEST)); + } + + private String getNavigationButtonToolTip(Direction direction) { + String toolTip; + if (shootRadioButton.isSelected()) + toolTip = "Shoot an arrow in the " + direction.name() + " direction"; + else if (addPitCoverRadioButton.isSelected()) + toolTip = "Add a pit cover in the " + direction.name() + " direction"; + else + toolTip = "Move the player in the " + direction.name() + " direction"; + return toolTip; + } + + private void moveButtonHandler(Direction direction) { + warnings.clear(); + passageDirections.clear(); + game.makeMoveCommand(direction).execute(); + updateHistory("Moved " + direction.name() + " to cavern \"" + game.getPlayerCavern() + "\""); + updatePresentation(); + } + + private void updateHistory(String message) { + historyTextArea.append(message + "\n"); + historyTextArea.validate(); + } + + private void shootButtonHandler(Direction direction) { + warnings.clear(); + updateHistory("Shot in direction " + direction.name()); + game.makeShootCommand(direction).execute(); + updatePresentation(); + } + + private void addPitCoverButtonHandler(Direction direction) { + game.makeAddPitCoverCommand(direction).execute(); + addPitCoverRadioButton.setEnabled(false); + moveRadioButton.doClick(); + if (pitCoverDirection != null) { + updateHistory("Pit cover added to cavern to the " + direction); + pitCoverDirection = null; + } + } + + private void updatePresentation() { + if (playerKillsWumpus) + gameOverWon("You killed the Wumpus."); + else if (health <= 0) + gameOverLose("You have died from your wounds"); + else if (playerMovesToWumpus) + gameOverLose("You walked into the waiting arms of the Wumpus."); + else if (wumpusMovesToPlayer) + gameOverLose("The Wumpus has found you."); + else + updatePanels(); + } + + private void updatePanels() { + updateCurrentCavern(); + enableButtonsForExistingPassages(); + updateQuiver(); + updateWarnings(); + updateHealth(); + showSeparators(); + } + + private void gameOverWon(String message) { + updateHistory(message); + disableAllComponents(); + warningTextArea.setText("You won! " + message); + } + + private void gameOverLose(String message) { + updateHistory(message); + disableAllComponents(); + warningTextArea.setText("You lost. " + message); + } + + private void updateCurrentCavern() { + currentCavernLabel.setText(game.getPlayerCavern()); + setBoldItalicFont(currentCavernLabel); + } + + private void setBoldItalicFont(JLabel label) { + Font font = new Font(label.getFont().getName(), Font.ITALIC + Font.BOLD, label.getFont().getSize()); + label.setFont(font); + } + + private void enableButtonsForExistingPassages() { + northButton.setEnabled(passageDirections.contains(Direction.NORTH)); + southButton.setEnabled(passageDirections.contains(Direction.SOUTH)); + eastButton.setEnabled(passageDirections.contains(Direction.EAST)); + westButton.setEnabled(passageDirections.contains(Direction.WEST)); + } + + private void updateQuiver() { + quiverCount.setText(String.format("Quiver Count: %d ", game != null ? game.getQuiver() : 0)); + if (game.getQuiver() <= 0) { + shootRadioButton.setEnabled(false); + moveRadioButton.doClick(); + } + else { + shootRadioButton.setEnabled(true); + } + } + + private void updateWarnings() { + warningTextArea.setText(""); + if (warnings.size() > 0) { + for (String warning : warnings) { + warningTextArea.append(warning + "\n"); + } + } else { + warningTextArea.append("No warnings at this time."); + } + } + + private void updateHealth() { + healthLabel.setText(String.format("Health: %d", health)); + } + + private void showSeparators() { + quiverSeparator.setVisible(true); + healthSeparator.setVisible(true); + } + + private JPanel createCavernControlPanel() { + cavernControlPanel = new JPanel(); + cavernControlPanel.setBorder(BorderFactory.createTitledBorder("Cavern")); + cavernControlPanel.setLayout(new BorderLayout()); + cavernControlPanel.add(createCavernPanel(), BorderLayout.CENTER); + cavernControlPanel.add(createOptionPanel(), BorderLayout.SOUTH); + + moveRadioButton.setSelected(true); + + return cavernControlPanel; + } + + private JPanel createCavernPanel() { + JPanel cavernPanel = new JPanel(); + cavernPanel.setLayout(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + + Border paddingBorder = BorderFactory.createEmptyBorder(20, 20, 20, 20); + currentCavernLabel.setBorder(paddingBorder); + + gbc.gridy = 0; + gbc.gridx = 1; + cavernPanel.add(northButton, gbc); + + gbc.gridy = 2; + cavernPanel.add(southButton, gbc); + + gbc.gridy = 1; + gbc.gridx = 0; + cavernPanel.add(westButton, gbc); + + gbc.gridx++; + cavernPanel.add(currentCavernLabel, gbc); + + gbc.gridx++; + cavernPanel.add(eastButton, gbc); + + return cavernPanel; + } + + private JPanel createOptionPanel() { + JPanel optionPanel = new JPanel(); + optionPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); + addComponentsToOptionPanel(optionPanel); + createRadioButtonGroup(); + initializeRadioButtonListeners(); + return optionPanel; + } + + public void addComponentsToOptionPanel(JPanel optionPanel) { + optionPanel.add(moveRadioButton); + optionPanel.add(shootRadioButton); + optionPanel.add(addPitCoverRadioButton); + optionPanel.add(quiverSeparator); + optionPanel.add(quiverCount); + optionPanel.add(healthSeparator); + optionPanel.add(healthLabel); + } + + private void createRadioButtonGroup() { + ButtonGroup bg = new ButtonGroup(); + bg.add(moveRadioButton); + bg.add(shootRadioButton); + bg.add(addPitCoverRadioButton); + } + + private void initializeRadioButtonListeners() { + moveRadioButton.addActionListener(e -> {setNavigationButtonLabels(); setNavigationButtonToolTips();}); + shootRadioButton.addActionListener(e -> {setNavigationButtonLabels(); setNavigationButtonToolTips();}); + addPitCoverRadioButton.addActionListener(e -> {setNavigationButtonLabels(); setNavigationButtonToolTips();}); + } + + private JSeparator getVerticalSeparator() { + JSeparator separator = new JSeparator(SwingConstants.VERTICAL); + separator.setPreferredSize(new Dimension(10, 15)); + separator.setVisible(false); + return separator; + } + + private JPanel createHistoryPanel() { + initializeHistoryPanel(); + initializeHistoryTextArea(); + historyPanel.add(getHistoryScrollPane(), BorderLayout.WEST); + return historyPanel; + } + + private void initializeHistoryPanel() { + historyPanel = new JPanel(); + historyPanel.setLayout(new BorderLayout()); + historyPanel.setBorder(BorderFactory.createTitledBorder("History")); + } + + private void initializeHistoryTextArea() { + historyTextArea = new JTextArea(15, 80); + historyTextArea.setEditable(false); + historyTextArea.setBorder(javax.swing.BorderFactory.createEmptyBorder()); + historyTextArea.setOpaque(false); + historyTextArea.setAlignmentX(JTextArea.LEFT_ALIGNMENT); + } + + private JScrollPane getHistoryScrollPane() { + JScrollPane scrollPane = new JScrollPane(historyTextArea); + scrollPane.setOpaque(false); + scrollPane.setBorder(BorderFactory.createEmptyBorder()); + scrollPane.setAlignmentX(JScrollPane.LEFT_ALIGNMENT); + return scrollPane; + } + + private JPanel createButtonPanel() { + buttonPanel = new JPanel(); + buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); + + initializeStartButton(); + initializeQuitButton(); + + buttonPanel.add(startButton); + buttonPanel.add(quitButton); + + return buttonPanel; + } + + private void initializeStartButton() { + startButton.setPreferredSize(new Dimension(80, 40)); + startButton.addActionListener(e -> startGame()); + } + + private void initializeQuitButton() { + quitButton.setPreferredSize(new Dimension(80, 40)); + quitButton.addActionListener(e -> System.exit(0)); + } + + private void disableAllComponents() { + disableNavigationButtons(); + disableOptionRadioButtons(); + } + + private void disableNavigationButtons() { + northButton.setEnabled(false); + southButton.setEnabled(false); + eastButton.setEnabled(false); + westButton.setEnabled(false); + } + + private void disableOptionRadioButtons() { + moveRadioButton.setEnabled(false); + shootRadioButton.setEnabled(false); + addPitCoverRadioButton.setEnabled(false); + } + + private void startGame() { + startButton.setEnabled(false); + initializeGame(); + } + + private void initializeGame() { + game = HtwFactory.makeGame("htw.game.HuntTheWumpusGame", new Main()); + createMap(); + game.makeRestCommand().execute(); + updateHistory("Started in cavern \"" + game.getPlayerCavern() + "\""); + enableOptionRadioButtons(); + updatePresentation(); + } + + private static void createMap() { + int ncaverns = (int) (Math.random() * 30.0 + 10.0); + while (ncaverns-- > 0) + caverns.add(makeName()); + + for (String cavern : caverns) { + maybeConnectCavern(cavern, NORTH); + maybeConnectCavern(cavern, SOUTH); + maybeConnectCavern(cavern, EAST); + maybeConnectCavern(cavern, WEST); + } + + String playerCavern = anyCavern(); + game.setPlayerCavern(playerCavern); + game.setWumpusCavern(anyOther(playerCavern)); + game.addBatCavern(anyOther(playerCavern)); + game.addBatCavern(anyOther(playerCavern)); + game.addBatCavern(anyOther(playerCavern)); + + game.addPitCavern(anyOther(playerCavern)); + game.addPitCavern(anyOther(playerCavern)); + game.addPitCavern(anyOther(playerCavern)); + + game.setQuiver(5); + } + + private static String makeName() { + + return "A " + chooseName(environments) + " " + + chooseName(shapes) + " " + + chooseName(cavernTypes) + " " + + chooseName(adornments); + } + + private static String chooseName(String[] names) { + int n = names.length; + int choice = (int) (Math.random() * (double) n); + return names[choice]; + } + + private static void maybeConnectCavern(String cavern, Direction direction) { + if (Math.random() > .2) { + String other = anyOther(cavern); + connectIfAvailable(cavern, direction, other); + connectIfAvailable(other, direction.opposite(), cavern); + } + } + + private static String anyCavern() { + return caverns.get((int) (Math.random() * caverns.size())); + } + + private static String anyOther(String cavern) { + String otherCavern = cavern; + while (cavern.equals(otherCavern)) { + otherCavern = anyCavern(); + } + return otherCavern; + } + + private static void connectIfAvailable(String from, Direction direction, String to) { + if (game.findDestination(from, direction) == null) { + game.connectCavern(from, to, direction); + } + } + + private void enableOptionRadioButtons() { + addPitCoverRadioButton.setEnabled(true); + moveRadioButton.setEnabled(true); + shootRadioButton.setEnabled(true); + } + + public void noPassage() { + throw new RuntimeException("noPassage"); + } + + public void hearBats() { + warnings.add("You hear chirping."); + } + + public void hearPit() { + warnings.add("You hear wind."); + } + + public void smellWumpus() { + warnings.add("There is a terrible smell."); + } + + public void passage(Direction direction) { + passageDirections.add(direction); + } + + public void noArrows() { + } + + public void arrowShot() { + } + + public void playerShootsSelfInBack() { + warnings.add("Ow! You shot yourself in the back."); + health -= 3; + } + + public void playerKillsWumpus() { + playerKillsWumpus = true; + } + + public void playerShootsWall() { + warnings.add("You shot the wall and the ricochet hurt you."); + health -= 3; + } + + public void arrowsFound(Integer value) { + warnings.add("You found " + value + " arrow(s)"); + } + + public void fellInPit() { + warnings.add("You fell into a pit and hurt yourself"); + health -= 4; + } + + public void playerMovesToWumpus() { + playerMovesToWumpus = true; + } + + public void wumpusMovesToPlayer() { + wumpusMovesToPlayer = true; + } + + public void batsTransport() { + } + + public void addPitCoverToAdjacentCavern(Direction direction) { + pitCoverDirection = direction; + } + + public void noPitCover() { + } + + public void cavernNotAdjacentForPitCover() { + } +} diff --git a/HTW/src/htw/gui/images/down24.gif b/HTW/src/htw/gui/images/down24.gif new file mode 100755 index 0000000000000000000000000000000000000000..cabf7728466be1ab205ef777a2a28c889af75ad6 GIT binary patch literal 366 zcmZ?wbhEHblwgoxSjxcg|Ns974}RXg`|b9v=eKTszIp4}&703|-1v0$>ibKV-dwow z>fE{Kr%yjQdGhhGV-JoTxqJBV-9v}Y9XxpZ;K5r551u`6;LN`LH}>tjzGu(X-MfM4 z%C23PckaBrW5=cK+b?e4eqr0T3tP9I-@5hOmMv#DZ$7hp`N1Vi_RXKabIzP?GiGj@ zHf{aHiL3hhmUnkA>Fiw8*|DgtZGLm}+@_{EjZL!}8fP{%%rrJmV*tAo=u}Lg_)pNe zC^fMpHASI3vm`^o-P1RKLGdRGBNu}`gAPz5(3=tr3~Xfw<`;PANcEpsQgkxMYQF1% zpjj*oIajqWWeMNuyK~&UN_5Jel-aGNlES;yj$}T378fz^!~xqqiUHgW@nr^zRW&Z= z+**7(N#TmE?Ox{mI@xk&6WgkN%*9(5s!sMbpQt)%uK%)?9ZTn|^D|!+(7AQ{j-9)9 J`#CaL0|23A&z1lH literal 0 HcmV?d00001 diff --git a/HTW/src/htw/gui/images/left24.gif b/HTW/src/htw/gui/images/left24.gif new file mode 100755 index 0000000000000000000000000000000000000000..787518c8ce9b57f2abc04a5679f71be7031bc089 GIT binary patch literal 422 zcmZ?wbhEHblwgoxxcZ;r|Ns9_p8k9M`0vAqzaQNHdH3G;+qb{my!q+o&1cuIf4Fkx z-K9&f&!2yJ_T2N+r=OlY`S|#;2S<!ukYS{b?45@+qYlb zy6ybdt>?FFIlFoDnRV-quUT_!#fpQ=mhE4-VAs5PJ7&$=JY&YjDO1)?oVcpDcUf20 z;6Rvz`$_ezyTmhBvAax!pOj2$e;sK5Au@(Tfu=D1s*z5 z{Vozsivla-7#NDUf?L+G-Y8j}lC|9_!Y$P?a^C}!kXdevZaXhsx-znPcZs!)jG?Iq zZ+>+miyUKBb7xnsS5rZSR%!JF|G*ya%4wMsN@q<@trhI+spnPZT0EOok+n^~+n{}3 zS59|=BZJ~Uf9L#y%A(Blj1mPS0|Ntvq)LV0(mVy<%;ci{;>zNZ)ZAhn1<$->Jq5>{ o9EBi|!eWJ>)Z)~lveXnkUM?>mHwE_~g|O5j1w%apUM>b}04xEyoB#j- literal 0 HcmV?d00001 diff --git a/HTW/src/htw/gui/images/right24.gif b/HTW/src/htw/gui/images/right24.gif new file mode 100755 index 0000000000000000000000000000000000000000..1936fd4bf9d300479fddb665d2650445adbe9f23 GIT binary patch literal 434 zcmV;j0Zsl#Nk%w1VHf}y0M-8h|NsBy=Ktm8{^R5P;o-}&C%_ubw1+uQZq+w|Gl z^4Zzu*VgdV)b7&K>(J2Y(9h}3&F9O@<;lt8$H(Br#NNWf+`z!hzrfkOzSq0E)VaCS zx3|!>wa>J)&a<=3u&~LluE(sb#j2{qsHnlGr@^JAzoVnQqocf`pt_);x}Ki6oSe0q znzNRcuauOnkB_L0ji!i*p@xQ^f`glZftrATnKLtH0002Mz`y_i000000000000000 z00000A^8LW0021vEC2ui02lxm06+$Oz?^VMEEU}`xbf-g)%TY!y}5AV z)wy%ePoI8r^5o-V#~vIxa`*7zyN3>)J9zN+!GpIB9z1*Cz?psfZ|vK5eb1h&yLSW8 zm0i0o@7#HL$Bs+ew_n`8{ld0w7q)Iazjf=mEnCiR-h5{H@`Fp3?3+J-=bSm)X3X3) zZQA;Y6Ib>1E${AL(%HGFvtvc zvM@3*STN{-q(FXhU@Lc+Q{bT^)qmu+f>2Xy-ib$V6PX$M%pJcG+Lv<+PI~S?(3`;jdXwxuF?9~LsKA)k+>Xw!?z$d}1pm$n2E`NeynPkTs>F2o z%Y$YZ)P(hOYb@tj;AAeYBUbClq#CuW+oTq7grXSq~;duD0t>2>nS+q