Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H5: three refactoring changes #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified H5_Skunk/bin/Dice.class
Binary file not shown.
Binary file modified H5_Skunk/bin/SkunkApp.class
Binary file not shown.
Binary file modified H5_Skunk/bin/SkunkDomain.class
Binary file not shown.
10 changes: 10 additions & 0 deletions H5_Skunk/src/Dice.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,21 @@ public Die getDie1()
// TODO Auto-generated method stub
return this.die1;
}

public int getDie1LastRoll()
{
return this.die1.getLastRoll();
}

public Die getDie2()
{
return this.die2;
}

public int getDie2LastRoll()
{
return this.die2.getLastRoll();
}

public void setDie1(Die d)
{
Expand Down
4 changes: 3 additions & 1 deletion H5_Skunk/src/SkunkApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ public class SkunkApp
public SkunkDomain skunkDomain;
public int numberOfPlayers;
public String[] playerNames;
private int playNamesLength = 20;

public SkunkApp()
{
skunkUI = new SkunkUI();
skunkDomain = new SkunkDomain(skunkUI);
skunkUI.setDomain(skunkDomain);
this.numberOfPlayers = 0;
this.playerNames = new String[20];
//this.playerNames = new String[20];
this.playerNames = new String[playNamesLength];

}

Expand Down
20 changes: 14 additions & 6 deletions H5_Skunk/src/SkunkDomain.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ public SkunkDomain(SkunkUI ui)
this.wantsToQuit = false;
this.oneMoreRoll = false;
}

public void twoSkunks()
{
ui.println("Two Skunks! You lose the turn, the round score, plus pay 4 chips to the kitty");
kitty += 4;
activePlayer.setNumberChips(activePlayer.getNumberChips() - 4);
activePlayer.setTurnScore(0);
activePlayer.setRoundScore(0);

}

public boolean run()
{
Expand All @@ -48,6 +58,8 @@ public boolean run()

ui.println("Starting game...\n");
boolean gameNotOver = true;



while (gameNotOver)
{
Expand All @@ -61,11 +73,7 @@ public boolean run()
skunkDice.roll();
if (skunkDice.getLastRoll() == 2)
{
ui.println("Two Skunks! You lose the turn, the round score, plus pay 4 chips to the kitty");
kitty += 4;
activePlayer.setNumberChips(activePlayer.getNumberChips() - 4);
activePlayer.setTurnScore(0);
activePlayer.setRoundScore(0);
twoSkunks();
wantsToRoll = false;
break;
}
Expand All @@ -78,7 +86,7 @@ else if (skunkDice.getLastRoll() == 3)
wantsToRoll = false;
break;
}
else if (skunkDice.getDie1().getLastRoll() == 1 || skunkDice.getDie2().getLastRoll() == 1)
else if (skunkDice.getDie1LastRoll() == 1 || skunkDice.getDie2LastRoll() == 1)
{
ui.println("One Skunk! You lose the turn, the turn score, plus pay 1 chip to the kitty");
kitty += 1;
Expand Down