Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois Farquet committed Oct 11, 2013
0 parents commit e76ef9d
Show file tree
Hide file tree
Showing 15 changed files with 767 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Minesweeper.app/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>CFBundleName</key>
<string>Minesweeper</string>
<key>CFBundleIdentifier</key>
<string>org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleAllowMixedLocalizations</key>
<string>true</string>
<key>CFBundleExecutable</key>
<string>JavaApplicationStub</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleGetInfoString</key>
<string>Developed by Francois Farquet ([email protected])</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleIconFile</key>
<string>icon_small.icns</string>
<key>Java</key>
<dict>
<key>MainClass</key>
<string>org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader</string>
<key>JVMVersion</key>
<string>1.5+</string>
<key>ClassPath</key>
<string>$JAVAROOT/Minesweeper.jar</string>
<key>Properties</key>
<dict>
<key>apple.laf.useScreenMenuBar</key>
<string>true</string>
</dict>
</dict>
</dict>
</plist>
Binary file not shown.
1 change: 1 addition & 0 deletions Minesweeper.app/Contents/PkgInfo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APPLnull
Binary file not shown.
Binary file not shown.
Binary file added Minesweeper.jar
Binary file not shown.
60 changes: 60 additions & 0 deletions Minesweeper/src/minesweeper/ButtonAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Author: Francois Farquet
* Date: 3 avr. 2011
*/


package minesweeper;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class ButtonAction implements MouseListener
{
private Cell aCell;
private Grid grid;

public ButtonAction(Cell aCase, Grid grid)
{
this.aCell = aCase;
this.grid = grid;
}

public void mouseClicked(MouseEvent e)
{
if(!grid.finished())
{
Settings.hasStarted = true;

if(!aCell.isVisible())
{
if(e.getModifiers() == 16) // if it's a regular clic
{
aCell.setVisible();
}
else // if it's alt+clic, cmd+clic, maj+clic, ...
{
aCell.toggleFlag();
}

if(grid.check())
{
grid.setFinished();
grid.congratulations();
}
}
}
}

public void mouseEntered(MouseEvent e) {
}

public void mouseExited(MouseEvent e) {
}

public void mousePressed(MouseEvent e) {
}

public void mouseReleased(MouseEvent e) {
}
}
169 changes: 169 additions & 0 deletions Minesweeper/src/minesweeper/Cell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
* Author: Francois Farquet
* Date: 3 avr. 2011
*/

package minesweeper;

import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class Cell
{
private boolean bomb=false;
private boolean flagged=false;
private boolean visible=false;
private int bombNumberAround=0;
private JButton aCase;
private JLabel bombsLeft;
private int row;
private int col;
private Grid grid;

public Cell(Grid grid, int row, int col, JLabel bombsLeft)
{
aCase = new JButton("");
aCase.setBackground(Color.GRAY);
this.row = row;
this.col = col;
this.grid = grid;
this.bombsLeft = bombsLeft;
}

public void setBomb()
{
bomb=true;
}

public boolean getBomb()
{
return bomb;
}

public void setVisible()
{
if(!visible)
{
if(bomb)
{
aCase.setText("X");
Settings.flagCount++;
bombsLeft.setText(""+(Settings.nbBombs - Settings.flagCount));
grid.setFinished();
JOptionPane.showMessageDialog(null,"Boooom !!!");
}
else
{
if(flagged)
{
Settings.flagCount--;
bombsLeft.setText(""+(Settings.nbBombs - Settings.flagCount));
}

Color caseColor;
switch(bombNumberAround)
{
case 8 :
caseColor = Color.WHITE;
break;
case 7 :
caseColor = Color.CYAN;
break;
case 6 :
caseColor = Color.MAGENTA;
break;
case 5 :
caseColor = Color.ORANGE;
break;
case 4 :
caseColor = Color.PINK;
break;
case 3 :
caseColor = Color.RED;
break;
case 2 :
caseColor = Color.BLUE;
break;
case 1 :
caseColor = Color.DARK_GRAY;
break;
case 0 :
default :
disableCase();
caseColor = Color.DARK_GRAY;
}
if(bombNumberAround != 0)
{
aCase.setText(bombNumberAround+"");
aCase.setForeground(caseColor);
}
}
visible = true;

if(!this.getBomb() && this.getNbBomb() == 0)
grid.checkAround(this);
}
}

public void disableCase()
{
aCase.setText("");
aCase.setEnabled(false);
}

public boolean isVisible()
{
return visible;
}

public void toggleFlag()
{
if(!flagged)
{
flagged = true;
aCase.setText("F");
Settings.flagCount++;
bombsLeft.setText(""+(Settings.nbBombs - Settings.flagCount));
}
else
{
flagged = false;
aCase.setText("");
Settings.flagCount--;
bombsLeft.setText(""+(Settings.nbBombs - Settings.flagCount));
}
}

public boolean getFlaged()
{
return flagged;
}

public void setNbBomb(int nb)
{
bombNumberAround = nb;
}

public int getNbBomb()
{
return bombNumberAround;
}

public JButton getCase()
{
return aCase;
}

public int getRow()
{
return row;
}

public int getCol()
{
return col;
}
}
27 changes: 27 additions & 0 deletions Minesweeper/src/minesweeper/Counter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Author: Francois Farquet
* Date: 3 avr. 2011
*/


package minesweeper;

import java.util.TimerTask;

import javax.swing.JLabel;

public class Counter extends TimerTask
{
private JLabel time;

public Counter(JLabel time)
{
this.time = time;
}
public void run()
{
if(Settings.hasStarted)
time.setText(""+(Integer.valueOf(time.getText())+1));
}

}
Loading

0 comments on commit e76ef9d

Please sign in to comment.