jrtec 8 years ago
parent
commit
ebc79591ab
4 changed files with 12 additions and 37 deletions
  1. +3
    -6
      src/net/jrtechs/setgame/Game.java
  2. +2
    -8
      src/net/jrtechs/setgame/Hand.java
  3. +1
    -5
      src/net/jrtechs/setgame/SetButton.java
  4. +6
    -18
      src/net/jrtechs/setgame/SetGame.java

+ 3
- 6
src/net/jrtechs/setgame/Game.java View File

@ -6,8 +6,8 @@ Game class keeps track of the score hand and deck
package net.jrtechs.setgame; package net.jrtechs.setgame;
import java.awt.Color;//for colors of the buttons
import java.util.ArrayList; //for the arraylist
import java.awt.Color;
import java.util.ArrayList;
public class Game public class Game
{ {
@ -35,12 +35,9 @@ public class Game
timeOnSet = 0; timeOnSet = 0;
} }
public void timerTic() public void timerTic()
{
{
time++; time++;
timeOnSet++; timeOnSet++;
} }
public Card[] getHand() public Card[] getHand()
{ {

+ 2
- 8
src/net/jrtechs/setgame/Hand.java View File

@ -15,11 +15,7 @@ public class Hand
int count = 0; int count = 0;
for(Card c: hand) for(Card c: hand)
{ {
if(c == null)
{
//skip the null cards
}
else
if(c != null)
{ {
transfer[count] = c; transfer[count] = c;
count++; count++;
@ -37,12 +33,10 @@ public class Hand
} }
public void display() public void display()
{ {
for(Card elem : hand) for(Card elem : hand)
System.out.print(elem + " "); System.out.print(elem + " ");
System.out.println(""); System.out.println("");
} }
public Card[] getHand() public Card[] getHand()
{ {

+ 1
- 5
src/net/jrtechs/setgame/SetButton.java View File

@ -33,11 +33,7 @@ public class SetButton extends JButton
} }
public void update() public void update()
{ {
if(card == null)
{
//do nothing
}
else
if(card != null)
{ {
//sets the image of the button baised on its properties //sets the image of the button baised on its properties
//images located in the /src folder, file are named as a 4 digit number //images located in the /src folder, file are named as a 4 digit number

+ 6
- 18
src/net/jrtechs/setgame/SetGame.java View File

@ -21,21 +21,15 @@ public class SetGame extends javax.swing.JFrame implements ActionListener
cmdFindSet.setEnabled(false); cmdFindSet.setEnabled(false);
cmdOpen3.setEnabled(false); cmdOpen3.setEnabled(false);
//creates an event listener for the timer
//creates an event listener for the timer in the game class
ActionListener actTimer = new ActionListener() ActionListener actTimer = new ActionListener()
{
{
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
if(game == null)
{
}
else
if(game != null)
{ {
game.timerTic(); game.timerTic();
lblTime.setText("Time " + game.getTime()); lblTime.setText("Time " + game.getTime());
} }
} }
}; };
@ -83,7 +77,6 @@ public class SetGame extends javax.swing.JFrame implements ActionListener
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
//System.out.println(e);
//casts the object of e to a setButton then calls the getLoc to find its index location in the cards "setButtons" array //casts the object of e to a setButton then calls the getLoc to find its index location in the cards "setButtons" array
SetButton clicked = (SetButton)e.getSource(); SetButton clicked = (SetButton)e.getSource();
cards[clicked.getLoc()].clicked(); cards[clicked.getLoc()].clicked();
@ -182,19 +175,16 @@ public class SetGame extends javax.swing.JFrame implements ActionListener
lblSetsOnBoard.setText("Sets on board " + game.getSetsLeft()); lblSetsOnBoard.setText("Sets on board " + game.getSetsLeft());
if(game.getSetsLeft() == 0) if(game.getSetsLeft() == 0)
{ {
cmdFindSet.setEnabled(false); cmdFindSet.setEnabled(false);
endGame(); endGame();
} }
else if(game.getHand().length==12 && game.getDeck().cardsLeft() > 2) else if(game.getHand().length==12 && game.getDeck().cardsLeft() > 2)
{ {
cmdOpen3.setEnabled(true);
cmdOpen3.setEnabled(true);
} }
} }
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExitActionPerformed private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExitActionPerformed
System.exit(-1);
System.exit(0);
}//GEN-LAST:event_cmdExitActionPerformed }//GEN-LAST:event_cmdExitActionPerformed
private void endGame() private void endGame()
{ {
@ -206,9 +196,7 @@ public class SetGame extends javax.swing.JFrame implements ActionListener
{ {
game = null; game = null;
cmdOpen3.setEnabled(false); cmdOpen3.setEnabled(false);
JOptionPane.showMessageDialog(null,"There are no more sets left on the board.","End of Game",JOptionPane.WARNING_MESSAGE);
JOptionPane.showMessageDialog(null,"There are no more sets left on the board.","End of Game",JOptionPane.WARNING_MESSAGE);
} }
} }
private void cmdFindSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdFindSetActionPerformed private void cmdFindSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdFindSetActionPerformed

Loading…
Cancel
Save