Skip to content

Commit

Permalink
Merge pull request #8 from Aregluss/levels
Browse files Browse the repository at this point in the history
AN Level Select
  • Loading branch information
Aregluss authored Mar 12, 2018
2 parents fc87d9b + aa092a6 commit 04748e9
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 19 deletions.
67 changes: 52 additions & 15 deletions src/edu/ucsb/cs56/projects/games/pacman/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum GameType {
private ArrayList<Ghost> ghosts;
private int numGhosts = 4, numBoardsCleared = 0;
private int curSpeed = 3;
private boolean enableLevelSelect = false;
public int numPellet;
private int numPills;
private Timer timer;
Expand Down Expand Up @@ -133,17 +134,20 @@ public void addNotify()
public void playGame(Graphics2D g2d) {
if (!checkAlive()) {
for (PacPlayer player : pacmen) {
if (pacman.getAnimateTimer() > 0)
pacman.decrementAnimateTimer();
pacman.dying(g2d, this);
try {
this.dyingAudio.play();
} catch (Exception e) {
e.printStackTrace();
}
if (pacman.getAnimateTimer() <= 0)
gameOver();
}

if (pacman.getAnimateTimer() > 0)
pacman.decrementAnimateTimer();
pacman.dying(g2d, this);
try {
this.dyingAudio.play();
} catch (Exception e) {
e.printStackTrace();
}

if (pacman.getAnimateTimer() <= 0)
gameOver();

}
}
else
{
Expand Down Expand Up @@ -203,7 +207,7 @@ public void playGame(Graphics2D g2d) {
ghost.draw(g2d, this);
}

if (score >= numPellet)
if (score >= 5)
{
score = 0;
numBoardsCleared++;
Expand All @@ -221,6 +225,9 @@ public void playGame(Graphics2D g2d) {
score += SCORE_WIN;
numBoardsCleared++;

if(numBoardsCleared > 0)
enableLevelSelect = true;

numGhosts = (numGhosts + 1) % MAX_GHOSTS;
curSpeed = (curSpeed + 1) % MAX_SPEED;
grid.levelInit(numBoardsCleared);
Expand Down Expand Up @@ -320,6 +327,12 @@ public void showHelpScreen(Graphics g)
g.drawString("P - Pause Game", bx + 210, by + 40);
g.drawString("M - Mute Game", bx + 210, by + 60);

if(enableLevelSelect)
g.drawString("L - Level Select (Press 1,2,3)", bx + 210, by + 80);
else
g.drawString("L - Level Select (Blocked)", bx + 210, by + 80);


g.drawString("Pacman:", bx + 10, by + 110);
g.drawString("Up Arrow - Move Up", bx + 30, by + 130);
g.drawString("Left Arrow - Move Left", bx + 30, by + 150);
Expand Down Expand Up @@ -418,12 +431,16 @@ public void gameOver() {
sl.writeScore(score);
}
Date d = new Date();
if(gt == GameType.SINGLEPLAYER)
if (gt == GameType.SINGLEPLAYER) {
leaderBoardGui.setVictoryStatus(enableLevelSelect);
leaderBoardGui.showEndGameScreen(this.score, d, 1);
else if(gt == GameType.COOPERATIVE)
} else if (gt == GameType.COOPERATIVE) {
leaderBoardGui.setVictoryStatus(enableLevelSelect);
leaderBoardGui.showEndGameScreen(this.score, d, 2);
else if(gt == GameType.VERSUS)
} else if (gt == GameType.VERSUS) {
leaderBoardGui.setVictoryStatus(enableLevelSelect);
leaderBoardGui.showEndGameScreen(this.score, d, 3);
}
gt = GameType.INTRO;
numBoardsCleared = 0;
grid.levelInit(0);
Expand Down Expand Up @@ -645,20 +662,40 @@ public void keyPressed(KeyEvent e) {
gt = GameType.SINGLEPLAYER;
gameInit();
break;

case KeyEvent.VK_D:
gt = GameType.COOPERATIVE;
gameInit();
break;

case KeyEvent.VK_F:
gt = GameType.VERSUS;
gameInit();
break;

case KeyEvent.VK_H:
gt = GameType.HELP;
break;

case KeyEvent.VK_1:
if(enableLevelSelect == true)
numBoardsCleared = 0;
break;

case KeyEvent.VK_2:
if(enableLevelSelect == true)
numBoardsCleared = 1;
break;

case KeyEvent.VK_3:
if(enableLevelSelect == true)
numBoardsCleared = 2 ;
break;

case KeyEvent.VK_M:
sound = !sound;
break;

}
}
else if(gt == GameType.HELP)
Expand Down
2 changes: 1 addition & 1 deletion src/edu/ucsb/cs56/projects/games/pacman/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Grid
*/
public Grid() {
screenData = new short[Board.NUMBLOCKS][Board.NUMBLOCKS];
mazeColor = new Color(5, 100, 5);
mazeColor = new Color(16, 52, 166);
dotColor = new Color(192, 192, 0);
fruitColor = new Color(255,0,0);

Expand Down
22 changes: 20 additions & 2 deletions src/edu/ucsb/cs56/projects/games/pacman/LeaderboardGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
public class LeaderboardGUI {
private static submitBtnListener submitListener;
private JLabel gameOver = new JLabel();
private JLabel winScreen = new JLabel();
private JFrame frame;
private JPanel panel = new JPanel();
private JTextField field = new JTextField(20);
Expand All @@ -50,11 +51,18 @@ public class LeaderboardGUI {
private singBtnListener SingleListener;
private coopBtnListener CoopListener;
private versBtnListener VersusListener;
private boolean victoryStatus;

private int WIDTH = 380;
private int HEIGHT = 420;
private int displayNum = 1;
private String name = "";


public void setVictoryStatus(boolean status){
victoryStatus = status;
}

/**
* Constructor for LeaderboardGui--initializes the JComponents of leaderboardgui
*/
Expand All @@ -74,12 +82,19 @@ public LeaderboardGUI() {
this.frame.setLocationRelativeTo(null);
this.frame.setVisible(true);

//add GameOver label

this.winScreen.setText("You Win!");
this.gameOver.setText("Game Over!");

this.winScreen.setFont(new Font("Serif", Font.PLAIN, 45));
this.winScreen.setForeground(Color.black);
this.winScreen.setAlignmentX(this.winScreen.CENTER_ALIGNMENT);

this.gameOver.setFont(new Font("Serif", Font.PLAIN, 45));
this.gameOver.setForeground(Color.black);
this.gameOver.setAlignmentX(this.gameOver.CENTER_ALIGNMENT);


this.panel.setBackground(new Color(224, 224, 224));
this.panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
this.frame.setVisible(false);
Expand All @@ -104,7 +119,10 @@ public void showEndGameScreen(int score, Date d, int type) {

//add spacer
this.panel.add(Box.createRigidArea(new Dimension(0, 15)));
this.panel.add(this.gameOver);
if(victoryStatus)
this.panel.add(this.winScreen);
else
this.panel.add(this.gameOver);
//add spacer
this.panel.add(Box.createRigidArea(new Dimension(0, 10)));
this.panel.add(this.scoreLabel);
Expand Down
2 changes: 1 addition & 1 deletion src/edu/ucsb/cs56/projects/games/pacman/PacPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public int getAnimateTimer()
}

/**
* Decrements death animation timer
*
*/
public void decrementAnimateTimer()
{
Expand Down

0 comments on commit 04748e9

Please sign in to comment.