Skip to content

Commit

Permalink
Game can now read from an excel file of database values so that only …
Browse files Browse the repository at this point in the history
…values that we want appear instead of random numbers appearing
  • Loading branch information
himat committed Aug 10, 2013
1 parent 7616817 commit 60f64f7
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 61 deletions.
7 changes: 3 additions & 4 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="mysql-connector-java-5.1.23-bin.jar"/>
<classpathentry kind="lib" path="servlet-api.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="dom4j-2.0.0-ALPHA-2.jar"/>
<classpathentry kind="lib" path="poi-ooxml-schemas-3.9-20121203.jar"/>
<classpathentry kind="lib" path="poi-ooxml-3.9-20121203.jar"/>
<classpathentry kind="lib" path="poi-3.9-20121203.jar"/>
<classpathentry kind="lib" path="poi-ooxml-3.9-20121203.jar"/>
<classpathentry kind="lib" path="poi-ooxml-schemas-3.9-20121203.jar"/>
<classpathentry kind="lib" path="mysql-connector-java-5.1.23-bin.jar"/>
<classpathentry kind="lib" path="xbean.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
8 changes: 6 additions & 2 deletions src/com/mathgame/cards/OperationCard.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.mathgame.cards;

import java.awt.Dimension;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import com.mathgame.math.MathGame;

/**
*
* Card class for holding operations
Expand Down Expand Up @@ -43,7 +46,7 @@ public void setOperation(String operation) {
this.operation = operation;
}

public OperationCard(String operation){
public OperationCard(MathGame mathGame, String operation){
String imageFile=null;
if(operation.equals("add"))
imageFile = "add.png";
Expand All @@ -58,7 +61,8 @@ else if(operation.equals("divide"))

this.operation = operation;

ImageIcon icon = new ImageIcon("images/"+imageFile);
Image background = mathGame.getImage(mathGame.getDocumentBase(), "images/"+imageFile);
ImageIcon icon = new ImageIcon(background);
this.setIcon(icon);

this.setPreferredSize(new Dimension(width,height));
Expand Down
26 changes: 17 additions & 9 deletions src/com/mathgame/math/CardPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.mathgame.math;

import java.awt.Dimension;
import java.awt.Image;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
Expand All @@ -24,6 +25,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;

public class CardPanel extends JPanel{
Expand All @@ -34,6 +36,8 @@ public class CardPanel extends JPanel{
*
*/
private static final long serialVersionUID = 1L;
MathGame mathGame;

NumberCard card1;
NumberCard card2;
NumberCard card3;
Expand All @@ -42,22 +46,26 @@ public class CardPanel extends JPanel{
NumberCard card6;
NumberCard ans;
final String imageFile = "images/Card Bar.png";
BufferedImage background;
Image background;

JLayeredPane masterLayer;

Calculate calc;
ArrayList<String> values;
ArrayList<Boolean> cardExists;

FileInputStream cardValueInput;
InputStream cardValueInput;
XSSFWorkbook cardValueWorkbook;
final String cardValueFile = "values.xlsx";
XSSFSheet currentSheet;
int rowCount;
int currentRowNumber;
XSSFRow currentRow;

public CardPanel(MathGame mathGame){
this.mathGame = mathGame;
}

/**
* Initializes a card panel
* @param masterLayer
Expand Down Expand Up @@ -108,14 +116,13 @@ public void init(JLayeredPane masterLayer) {
this.add(card6);
this.add(ans);

try {
background = ImageIO.read(new File(imageFile));
} catch (IOException e) {
e.printStackTrace();
}
background = mathGame.getImage(mathGame.getDocumentBase(), imageFile);


try {
cardValueInput = new FileInputStream(cardValueFile);
//File excelFile = new File(cardValueFile);
cardValueInput = getClass().getClassLoader().getResourceAsStream("images/values.xlsx");
System.out.println("file size: " + cardValueInput.available());
cardValueWorkbook = new XSSFWorkbook(cardValueInput);

currentSheet = cardValueWorkbook.getSheetAt(0);
Expand All @@ -126,7 +133,8 @@ public void init(JLayeredPane masterLayer) {
rowIter.next();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("excel file not found");
System.out.println(new File(cardValueFile));
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
Expand Down
11 changes: 4 additions & 7 deletions src/com/mathgame/math/HoldPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
Expand All @@ -26,9 +27,9 @@ public class HoldPanel extends JPanel {
*/
private static final long serialVersionUID = -2013522168342802483L;
final String imageFile = "images/card holder.png";
BufferedImage background;
Image background;

public void init() {
public void init(MathGame mathGame) {

this.setLayout(new FlowLayout());
Border empty = BorderFactory.createEmptyBorder(10,10,10,10);
Expand All @@ -40,11 +41,7 @@ public void init() {
size.height = 150;
setPreferredSize(size);

try {
background = ImageIO.read(new File(imageFile));
} catch (IOException e) {
e.printStackTrace();
}
background = mathGame.getImage(mathGame.getDocumentBase(), imageFile);
}

@Override
Expand Down
12 changes: 5 additions & 7 deletions src/com/mathgame/math/MathGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
public class MathGame extends JApplet implements ActionListener
{

/**
*
*/
private static final long serialVersionUID = 412526093812019078L;
int appWidth=900;//1300 or 900
int appHeight=620;
Expand Down Expand Up @@ -84,7 +81,7 @@ public class MathGame extends JApplet implements ActionListener

@Override
public void init(){
System.out.println("initing");
setSize(appWidth, appHeight);
setLayout(null);
//((JComponent) getContentPane()).setBorder(new LineBorder(Color.yellow));
Expand All @@ -99,22 +96,22 @@ public void init(){
sidePanel.setBounds(750, 0, 150, 620);//x, y, width, height
sidePanel.init(this);

cardPanel = new CardPanel();//top card panel
cardPanel = new CardPanel(this);//top card panel
cardPanel.setBounds(0, 0, 750, 150);
cardPanel.init(layer);
cardPanel.randomize( cardPanel.randomValues() );

opPanel = new OperationPanel();//operation panel
opPanel.setBounds(0, 150, 750, 60);
opPanel.init(layer, mover);
opPanel.init(this, mover);

workPanel = new WorkspacePanel();
workPanel.setBounds(0, 210, 750, 260);
workPanel.init(this);

holdPanel = new HoldPanel();
holdPanel.setBounds(0, 470, 750, 150);
holdPanel.init();
holdPanel.init(this);

//adding panels to the game
add(layer);
Expand Down Expand Up @@ -237,6 +234,7 @@ public void init(){
setCursor(lightPenCursor);
layer.setCursor(imageCursor);
*/
System.out.println("init done");
}


Expand Down
25 changes: 11 additions & 14 deletions src/com/mathgame/math/OperationPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
Expand All @@ -27,21 +28,21 @@ public class OperationPanel extends JPanel
OperationCard multiply;
OperationCard divide;

final String imageFile = "images/Operation Bar.png";
BufferedImage background;
final String imageFile = "images/Operation bar.png";
Image background;

JLayeredPane masterLayer;

public void init(JLayeredPane layer, CompMover mover)//pass layeredpane layer so to regen operations
public void init(MathGame mathGame, CompMover mover)//pass layeredpane layer so to regen operations
{
setLayout(null);
//TitledBorder opBorder = BorderFactory.createTitledBorder("Operation Panel");
//this.setBorder(new LineBorder(Color.black));

add = new OperationCard("add");
subtract = new OperationCard("subtract");
multiply = new OperationCard("multiply");
divide = new OperationCard("divide");
add = new OperationCard(mathGame, "add");
subtract = new OperationCard(mathGame, "subtract");
multiply = new OperationCard(mathGame, "multiply");
divide = new OperationCard(mathGame, "divide");

add.setBounds(20, 160, 40, 40);
subtract.setBounds(80, 160, 40, 40);
Expand All @@ -55,13 +56,9 @@ public void init(JLayeredPane layer, CompMover mover)//pass layeredpane layer so
this.add(multiply);
this.add(divide);

masterLayer = layer;//layered pane passed over
masterLayer = mathGame.layer;//layered pane passed over

try {
background = ImageIO.read(new File(imageFile));
} catch (IOException e) {
e.printStackTrace();
}
background = mathGame.getImage(mathGame.getDocumentBase(), imageFile);
}

public void addOperator(String op) {//primarily to regen operator after use
Expand All @@ -85,7 +82,7 @@ else if(op.contentEquals("divide")) {

@Override
public void paintComponent(Graphics g){
super.paintComponents(g);
super.paintComponent(g);
g.drawImage(background, 0, 0, null);


Expand Down
8 changes: 2 additions & 6 deletions src/com/mathgame/math/SidePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class SidePanel extends JPanel implements ActionListener{
Font sansSerif36 = new Font("SansSerif", Font.PLAIN, 36);

final String imageFile = "images/control bar.png";
BufferedImage background;
Image background;

//JTextArea error;

Expand Down Expand Up @@ -93,11 +93,7 @@ public void init(MathGame mathgame)
setDiff = new JTextField("");
updateDiff = new JButton("Update Difficulty");

try {
background = ImageIO.read(new File(imageFile));
} catch (IOException e) {
e.printStackTrace();
}
background = mathgame.getImage(mathgame.getDocumentBase(), imageFile);

add(clock);
add(toggle);
Expand Down
21 changes: 9 additions & 12 deletions src/com/mathgame/math/WorkspacePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
Expand All @@ -29,14 +30,14 @@ public class WorkspacePanel extends JPanel{
*
*/
private static final long serialVersionUID = 7408931441173570326L;
MathGame game;//holds the game so it can reference all the other panels (hehehe...)
MathGame mathGame;//holds the game so it can reference all the other panels
final String imageFile = "images/Workspace.png";
BufferedImage background;
Image background;

Calculate calc;
CompMover mover;

public void init(MathGame game) {
public void init(MathGame mathGame) {
this.setLayout(new FlowLayout());

Border empty = BorderFactory.createEmptyBorder(70,70,70,70);
Expand All @@ -48,15 +49,11 @@ public void init(MathGame game) {
size.height = 260;
setPreferredSize(size);

try {
background = ImageIO.read(new File(imageFile));
} catch (IOException e) {
e.printStackTrace();
}
background = mathGame.getImage(mathGame.getDocumentBase(), imageFile);

calc = new Calculate();
mover = new CompMover();
this.game = game;
this.mathGame = mathGame;
}

public void calcCheck(){
Expand All @@ -65,7 +62,7 @@ public void calcCheck(){
Double answer= null;
if(count == 3)
{
answer = calc.calculate(this.getComponent(0), this.getComponent(1), this.getComponent(2), game);
answer = calc.calculate(this.getComponent(0), this.getComponent(1), this.getComponent(2), mathGame);
System.out.println("NUM1:"+this.getComponentCount());
}

Expand All @@ -87,13 +84,13 @@ public void calcCheck(){
NumberCard card2 = (NumberCard) this.getComponent(2);
OperationCard op = (OperationCard) this.getComponent(1);
System.out.println("Registering new Move");
game.sidePanel.undo.registerNewMove(card1, op, card2, answerCard);
mathGame.sidePanel.undo.registerNewMove(card1, op, card2, answerCard);
//when cards collide... it becomes a new move!
}
}

String restoreOperator = new String(currentOperation());
game.opPanel.addOperator(restoreOperator);
mathGame.opPanel.addOperator(restoreOperator);

System.out.println("NUM:"+this.getComponentCount());
this.remove(0);
Expand Down
File renamed without changes.
Binary file added values.xlsx
Binary file not shown.

0 comments on commit 60f64f7

Please sign in to comment.