- توردا
- 9 سائەت
- جۇغلانما
- 163
- ئاقچا
- 1
- ئاخىرقى قېتىم
- 2012-5-8
- تىزىملاتقان
- 2011-12-23
- تېما
- 7
- نادىر
- 0
- ھوقۇقى
- 50
- يازما
- 12

- جۇغلانما
- 163
- ئاقچا
- 1
- توردا
- 9 سائەت
- تىزىملاتقان
- 2011-12-23
- نادىر
- 0
- تېما
- 7
|
ئەسسالامۇ-ئەلەيكۇم!!!قىرىنداشلار بىز ھەق ياسساپ بەرگەن ئويۇننى ئويناۋەمەي ئۆزىمىزمۇ ئويۇن ياسساپ ئويناپ كۆرەيلى!!! مەن مەردانجان ماڭسۇر (Handiyar) بولىمەن.Www.Handiyar.cn Www.Handiyar.netسا مەن بىلەن ئالاقىلىشىنىڭ ....چچ:736969230
كۆد ........................‹باشلندى›..................................
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import javax.swing.JButton;
import javax.swing.JOptionPane;
public class ExitActionListener implements ActionListener{
private JButton[][]Button_Game;
private int Bomb_I,Bomb_J;
private String Level;
public ExitActionListener(){
}
public ExitActionListener(JButton[][]Button_Game,String Level,int Bomb_I,int Bomb_J){
this.Button_Game=Button_Game;
this.Level=Level;
this.Bomb_I=Bomb_I;
this.Bomb_J=Bomb_J;
}
public void actionPerformed(ActionEvent e){
int OptionPane_Exit=JOptionPane.showConfirmDialog(null,"是否保存当前游戏?","提示",JOptionPane.YES_NO_CANCEL_OPTION);
if(OptionPane_Exit==JOptionPane.OK_OPTION){
//Code Of Save Game
if(SuperClass.SaveGame_File.exists()){
int OptionPane_OverWrite=JOptionPane.showConfirmDialog(null,"是否覆盖先前的文档?","提示",JOptionPane.YES_NO_OPTION);
if(OptionPane_OverWrite==JOptionPane.OK_OPTION){
try {
SuperClass.SaveGame_File.delete();
SuperClass.SaveGame_File.createNewFile();
FileOutputStream fos=new FileOutputStream(SuperClass.SaveGame_File);
OutputStreamWriter osw=new OutputStreamWriter(fos);
BufferedWriter Game_Writer=new BufferedWriter(osw);
Game_Writer.write(Level);
Game_Writer.newLine();
for(int i=0;i
for(int j=0;j
for(int k=0;k<13;k++){
if(Button_Game[j].getIcon()==SuperClass.Icon_Used[k]){
Game_Writer.write(String.valueOf(k));
Game_Writer.newLine();
}
}
}
}
Game_Writer.close();
} catch (IOException e1) {
e1.printStackTrace();
}
System.exit(0);
}
else if(OptionPane_OverWrite==JOptionPane.NO_OPTION){
}
}
else if(SuperClass.SaveGame_File.exists()==false){
try {
SuperClass.SaveGame_File.createNewFile();
FileOutputStream fos=new FileOutputStream(SuperClass.SaveGame_File);
OutputStreamWriter osw=new OutputStreamWriter(fos);
BufferedWriter Game_Writer=new BufferedWriter(osw);
Game_Writer.write(Level);
Game_Writer.newLine();
for(int i=0;i
for(int j=0;j
for(int k=0;k<13;k++){
if(Button_Game[j].getIcon()==SuperClass.Icon_Used[k]){
Game_Writer.write(String.valueOf(k));
Game_Writer.newLine();
}
}
}
}
Game_Writer.close();
} catch (IOException e1) {
e1.printStackTrace();
}
System.exit(0);
}
}
else if(OptionPane_Exit==JOptionPane.NO_OPTION){
System.exit(0);
}
else if(OptionPane_Exit==JOptionPane.CANCEL_OPTION){
}
}
}
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class HardFrame extends MineFrame{
private static final int Bomb_I=16;
private static final int Bomb_J=30;
private JButton[][]Game_Buttons=new JButton[Bomb_I][Bomb_J];
private int[][]Map_Bomb=new int[Bomb_I][Bomb_J];
private MouseLeftListener MouseLeft=new MouseLeftListener(Game_Buttons,Map_Bomb,Bomb_I,Bomb_J);
private MouseRightListener MouseRight=new MouseRightListener(Game_Buttons,Map_Bomb,Bomb_I,Bomb_J);
private ExitActionListener ExitListener=new ExitActionListener(Game_Buttons,"Hard",Bomb_I,Bomb_J);
private LoadingActionListener LoadingListener=new LoadingActionListener(Game_Buttons,Bomb_I,Bomb_J);
public HardFrame(){
Frame_Super.setSize(820,520);
Frame_Super.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width-Frame_Super.getSize().width)/2,
(Toolkit.getDefaultToolkit().getScreenSize().height-Frame_Super.getSize().height)/2);
Exit.addActionListener(ExitListener);
Loading_Game.addActionListener(LoadingListener);
New_Game.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SuperClass.Tag_Num=0;
Frame_Super.setVisible(false);
String levelString=Methods.GetProperties("LEVEL");
if(levelString.equals("Middle")){
new MiddleFrame();
}
else if(levelString.equals("Hard")){
new HardFrame();
}
else{
new SimpleFrame();
}
}
});
TextField_MineRemain.setText(String.valueOf(SuperClass.MineNum_Hard));
super.Panel_Center.setLayout(new GridLayout(Bomb_I,Bomb_J));
for(int i=0;i
for(int j=0;j
Game_Buttons[j]=new JButton();
Game_Buttons[j].setIcon(SuperClass.Icon_Used[12]);
Game_Buttons[j].addActionListener(MouseLeft);
Game_Buttons[j].addMouseListener(MouseRight);
super.Panel_Center.add(Game_Buttons[j]);
Map_Bomb[j]=SuperClass.ICON[0];
}
}
Map_Bomb=Methods.randomBombSite(Map_Bomb,SuperClass.MineNum_Hard,Bomb_I,Bomb_J);
Methods.GetBombNum(Map_Bomb,Bomb_I,Bomb_J);
Frame_Super.validate();
Frame_Super.setVisible(true);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JButton;
import javax.swing.JOptionPane;
public class LoadingActionListener implements ActionListener{
private int Bomb_I,Bomb_J;
private JButton[][]Game_Buttons;
public LoadingActionListener(){
}
public LoadingActionListener(JButton[][]Game_Buttons,int Bomb_I,int Bomb_J){
this.Game_Buttons=Game_Buttons;
this.Bomb_I=Bomb_I;
this.Bomb_J=Bomb_J;
}
public void actionPerformed(ActionEvent e){
FileInputStream fis;
try {
if(SuperClass.SaveGame_File.exists()==false){
try {
SuperClass.SaveGame_File.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
}
}
fis = new FileInputStream(SuperClass.SaveGame_File);
InputStreamReader isr=new InputStreamReader(fis);
BufferedReader Game_Reader=new BufferedReader(isr);
String String_Read;
try {
String_Read=Game_Reader.readLine();
if(String_Read.equals("Simple")){
if((Bomb_I==9)&&(Bomb_J==9)){
for(int i=0;i
for(int j=0;j
String_Read=Game_Reader.readLine();
if((Integer.valueOf(String_Read)>=0)&&(Integer.valueOf(String_Read)<=12)){
Game_Buttons[j].setIcon(SuperClass.Icon_Used[Integer.valueOf(String_Read)]);
}
else{
SuperClass.SaveGame_File.delete();
SuperClass.SaveGame_File.createNewFile();
JOptionPane.showMessageDialog(null,"存档无法打开,已被删除");
break;
}
}
}
}
else{
JOptionPane.showMessageDialog(null,"将游戏设置为简单,先建简单游戏再载入档案...");
}
}
else if(String_Read.equals("Middle")){
if((Bomb_I==16)&&(Bomb_J==16)){
for(int i=0;i
for(int j=0;j
String_Read=Game_Reader.readLine();
if((Integer.valueOf(String_Read)>=0)&&(Integer.valueOf(String_Read)<=12)){
Game_Buttons[j].setIcon(SuperClass.Icon_Used[Integer.valueOf(String_Read)]);
}
else{
SuperClass.SaveGame_File.delete();
SuperClass.SaveGame_File.createNewFile();
JOptionPane.showMessageDialog(null,"存档无法打开,已被删除");
break;
}
}
}
}
else{
JOptionPane.showMessageDialog(null,"将游戏设置为中等,先建中等游戏再载入档案...");
}
}
else if(String_Read.equals("Hard")){
if((Bomb_I==16)&&(Bomb_J==30)){
for(int i=0;i
for(int j=0;j
String_Read=Game_Reader.readLine();
if((Integer.valueOf(String_Read)>=0)&&(Integer.valueOf(String_Read)<=12)){
Game_Buttons[j].setIcon(SuperClass.Icon_Used[Integer.valueOf(String_Read)]);
}
else{
SuperClass.SaveGame_File.delete();
SuperClass.SaveGame_File.createNewFile();
JOptionPane.showMessageDialog(null,"存档无法打开,已被删除");
break;
}
}
}
}
else{
JOptionPane.showMessageDialog(null,"将游戏设置为困难,新建困难游戏再载入档案...");
}
}
else{
SuperClass.SaveGame_File.delete();
JOptionPane.showMessageDialog(null,"存档无法打开,已被删除");
}
} catch (IOException e1){
e1.printStackTrace();
}
} catch (FileNotFoundException e1){
e1.printStackTrace();
}
}
}
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.JButton;
public class Methods {
public static final int CLICK_WRONG=0;
public static final int LESS=1;
public static final int MORE=2;
public static final int RIGHT=3;
public static int[][] randomBombSite(int[][]Map_Bomb,int BombNum,int BombLimit_I,int BombLimit_J){
int X,Y;
for(int i=0;i
double Site_I=Math.random()*BombLimit_I;
double Site_J=Math.random()*BombLimit_J;
if(Site_I>=(BombLimit_I-0.5)){
X=0;
}
else{
X=Math.round((float)Site_I);
}
if(Site_J>=(BombLimit_J-0.5)){
Y=0;
}
else{
Y=Math.round((float)Site_J);
}
if(Map_Bomb[X][Y]!=SuperClass.BOMB){
Map_Bomb[X][Y]=SuperClass.BOMB;
}
else if(Map_Bomb[X][Y]==SuperClass.BOMB){
BombNum++;
}
}
return Map_Bomb;
}
public static boolean ExistInArray(ArrayListArray,int[]Element_In){
boolean Flag_Exist=false;
int[]GetFromArray=new int[2];
for(int i=0;i
GetFromArray=(int[])Array.get(i);
if((GetFromArray[0]==Element_In[0])&&(GetFromArray[1]==Element_In[1])){
Flag_Exist=true;
break;
}
}
return Flag_Exist;
}
public static void GetBombNum(int[][]Map_Bomb,int Bomb_I,int Bomb_J){
for(int i=0;i
for(int j=0;j
int cnt=0;
if(Map_Bomb[j]!=SuperClass.BOMB){
if(((i+1)
cnt++;
}
if(((j+1)[j+1]==SuperClass.BOMB)){
cnt++;
}
if(((i+1)
cnt++;
}
if(((i-1)>=0)&&((j+1)
cnt++;
}
if(((i+1)=0)&&(Map_Bomb[i+1][j-1]==SuperClass.BOMB)){
cnt++;
}
if(((j-1)>=0)&&(Map_Bomb[j-1]==SuperClass.BOMB)){
cnt++;
}
if(((i-1)>=0)&&(Map_Bomb[i-1][j]==SuperClass.BOMB)){
cnt++;
}
if(((i-1)>=0)&&((j-1)>=0)&&(Map_Bomb[i-1][j-1]==SuperClass.BOMB)){
cnt++;
}
Map_Bomb[j]=cnt;
}
}
}
}
public static boolean CheckWin(JButton[][]Game_Buttons,int[][]Map_Bomb,int Bomb_I,int Bomb_J){
boolean flag=true;
for(int i=0;i
for(int j=0;j
if((Game_Buttons[j].getIcon()==SuperClass.Icon_Used[10])&&Map_Bomb[j]!=SuperClass.BOMB){
flag=false;
break;
}
}
}
return flag;
}
public static int GetTagNum(JButton[][]Game_Buttons,int[]Location,int Bomb_I,int Bomb_J){
int cnt=0;
if((Location[0]+1)
if((Game_Buttons[Location[0]+1][Location[1]].getIcon()==SuperClass.Icon_Used[10])){
cnt++;
}
}
if((Location[0]-1)>=0){
if((Game_Buttons[Location[0]-1][Location[1]].getIcon()==SuperClass.Icon_Used[10])){
cnt++;
}
}
if((Location[1]+1)
if((Game_Buttons[Location[0]][Location[1]+1].getIcon()==SuperClass.Icon_Used[10])){
cnt++;
}
}
if((Location[1]-1)>=0){
if((Game_Buttons[Location[0]][Location[1]-1].getIcon()==SuperClass.Icon_Used[10])){
cnt++;
}
}
if(((Location[0]+1)
if((Game_Buttons[Location[0]+1][Location[1]+1].getIcon()==SuperClass.Icon_Used[10])){
cnt++;
}
}
if(((Location[0]+1)=0)){
if((Game_Buttons[Location[0]+1][Location[1]-1].getIcon()==SuperClass.Icon_Used[10])){
cnt++;
}
}
if(((Location[0]-1)>=0)&&((Location[1]+1)
if((Game_Buttons[Location[0]-1][Location[1]+1].getIcon()==SuperClass.Icon_Used[10])){
cnt++;
}
}
if(((Location[0]-1)>=0)&&((Location[1]-1)>=0)){
if((Game_Buttons[Location[0]-1][Location[1]-1].getIcon()==SuperClass.Icon_Used[10])){
cnt++;
}
}
return cnt;
}
public static int TwoClickRight(JButton[][]Game_Buttons,int[][]Map_Bomb,int Bomb_I,int Bomb_J,int[]Location){
int flag=RIGHT;
int TagNum=Methods.GetTagNum(Game_Buttons,Location,Bomb_I,Bomb_J);
if(TagNum==Map_Bomb[Location[0]][Location[1]]){
if((Location[0]+1)
if((Game_Buttons[Location[0]+1][Location[1]].getIcon()==SuperClass.Icon_Used[10])&&(Map_Bomb[Location[0]+1][Location[1]]!=SuperClass.BOMB)){
flag=CLICK_WRONG;
}
}
if((Location[0]-1)>=0){
if((Game_Buttons[Location[0]-1][Location[1]].getIcon()==SuperClass.Icon_Used[10])&&(Map_Bomb[Location[0]-1][Location[1]]!=SuperClass.BOMB)){
flag=CLICK_WRONG;
}
}
if((Location[1]+1)
if((Game_Buttons[Location[0]][Location[1]+1].getIcon()==SuperClass.Icon_Used[10])&&(Map_Bomb[Location[0]][Location[1]+1]!=SuperClass.BOMB)){
flag=CLICK_WRONG;
}
}
if((Location[1]-1)>=0){
if((Game_Buttons[Location[0]][Location[1]-1].getIcon()==SuperClass.Icon_Used[10])&&(Map_Bomb[Location[0]][Location[1]-1]!=SuperClass.BOMB)){
flag=CLICK_WRONG;
}
}
if(((Location[0]+1)
if((Game_Buttons[Location[0]+1][Location[1]+1].getIcon()==SuperClass.Icon_Used[10])&&(Map_Bomb[Location[0]+1][Location[1]+1]!=SuperClass.BOMB)){
flag=CLICK_WRONG;
}
}
if(((Location[0]+1)=0)){
if((Game_Buttons[Location[0]+1][Location[1]-1].getIcon()==SuperClass.Icon_Used[10])&&(Map_Bomb[Location[0]+1][Location[1]-1]!=SuperClass.BOMB)){
flag=CLICK_WRONG;
}
}
if(((Location[0]-1)>=0)&&((Location[1]+1)
if((Game_Buttons[Location[0]-1][Location[1]+1].getIcon()==SuperClass.Icon_Used[10])&&(Map_Bomb[Location[0]-1][Location[1]+1]!=SuperClass.BOMB)){
flag=CLICK_WRONG;
}
}
if(((Location[0]-1)>=0)&&((Location[1]-1)>=0)){
if((Game_Buttons[Location[0]-1][Location[1]-1].getIcon()==SuperClass.Icon_Used[10])&&(Map_Bomb[Location[0]-1][Location[1]-1]!=SuperClass.BOMB)){
flag=CLICK_WRONG;
}
}
}
else if(TagNum
flag=LESS;
}
else if(TagNum>Map_Bomb[Location[0]][Location[1]]){
flag=MORE;
}
return flag;
}
public static void ShowAllNull(JButton[][]Game_Buttons,int[][]Map_Bomb,int Bomb_I,int Bomb_J,int i,int j){
ArrayListZeroList=new ArrayList();
int[]Location=new int[2];
Location[0]=i;
Location[1]=j;
ZeroList.add(Location);
int TestNum=0;
do{
Location=ZeroList.get(TestNum);
if((Location[0]+1)
int[]Temp=new int[2];
Temp[0]=Location[0]+1;
Temp[1]=Location[1];
Game_Buttons[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if((Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0])&&(Methods.ExistInArray(ZeroList,Temp)==false)){
ZeroList.add(Temp);
}
}
if((Location[0]-1)>=0){
int[]Temp=new int[2];
Temp[0]=Location[0]-1;
Temp[1]=Location[1];
Game_Buttons[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if((Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0])&&(Methods.ExistInArray(ZeroList,Temp)==false)){
ZeroList.add(Temp);
}
}
if((Location[1]+1)
int[]Temp=new int[2];
Temp[0]=Location[0];
Temp[1]=Location[1]+1;
Game_Buttons[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if((Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0])&&(Methods.ExistInArray(ZeroList,Temp)==false)){
ZeroList.add(Temp);
}
}
if((Location[1]-1)>=0){
int[]Temp=new int[2];
Temp[0]=Location[0];
Temp[1]=Location[1]-1;
Game_Buttons[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if((Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0])&&(Methods.ExistInArray(ZeroList,Temp)==false)){
ZeroList.add(Temp);
}
}
if(((Location[0]+1)
int[]Temp=new int[2];
Temp[0]=Location[0]+1;
Temp[1]=Location[1]+1;
Game_Buttons[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if((Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0])&&(Methods.ExistInArray(ZeroList,Temp)==false)){
ZeroList.add(Temp);
}
}
if(((Location[0]+1)=0)){
int[]Temp=new int[2];
Temp[0]=Location[0]+1;
Temp[1]=Location[1]-1;
Game_Buttons[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if((Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0])&&(Methods.ExistInArray(ZeroList,Temp)==false)){
ZeroList.add(Temp);
}
}
if(((Location[0]-1)>=0)&&((Location[1]+1)
int[]Temp=new int[2];
Temp[0]=Location[0]-1;
Temp[1]=Location[1]+1;
Game_Buttons[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if((Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0])&&(Methods.ExistInArray(ZeroList,Temp)==false)){
ZeroList.add(Temp);
}
}
if(((Location[0]-1)>=0)&&((Location[1]-1)>=0)){
int[]Temp=new int[2];
Temp[0]=Location[0]-1;
Temp[1]=Location[1]-1;
Game_Buttons[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if((Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0])&&(Methods.ExistInArray(ZeroList,Temp)==false)){
ZeroList.add(Temp);
}
}
TestNum++;
}while(TestNum
}
public static void CreatPropertiesFile(){
try {
SuperClass.Properties_Game.load(new FileInputStream(SuperClass.Properties_File));
SuperClass.Properties_Game.setProperty("PLAYED_TIMES_SIMPLE","0");
SuperClass.Properties_Game.setProperty("PLAYED_TIMES_MIDDLE","0");
SuperClass.Properties_Game.setProperty("PLAYED_TIMES_HARD","0");
SuperClass.Properties_Game.setProperty("PLAYED_TIMES_SIMPLE","0");
SuperClass.Properties_Game.setProperty("PLAYED_TIMES_MIDDLE","0");
SuperClass.Properties_Game.setProperty("PLAYED_TIMES_HARD","0");
SuperClass.Properties_Game.setProperty("WIN_TIMES_SIMPLE","0");
SuperClass.Properties_Game.setProperty("WIN_TIMES_MIDDLE","0");
SuperClass.Properties_Game.setProperty("WIN_TIMES_HARD","0");
SuperClass.Properties_Game.setProperty("LEAST_TIME_SIMPLE","0");
SuperClass.Properties_Game.setProperty("LEAST_TIME_MIDDLE","0");
SuperClass.Properties_Game.setProperty("LEAST_TIME_HARD","0");
SuperClass.Properties_Game.setProperty("LEVEL","Simple");
SuperClass.Properties_Game.store(new FileOutputStream(SuperClass.Properties_File),"");
} catch (IOException e) {
e.printStackTrace();
}
}
public static String GetProperties(String KeyString){
String GettedString="";
if(SuperClass.Properties_File.exists()==false){
Methods.CreatPropertiesFile();
}
try {
SuperClass.Properties_Game.load(new FileInputStream(SuperClass.Properties_File));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
GettedString=SuperClass.Properties_Game.getProperty(KeyString);
return GettedString;
}
public static void SetProperties(String KeyString,String Value){
if(SuperClass.Properties_File.exists()==false){
Methods.CreatPropertiesFile();
}
try {
SuperClass.Properties_Game.setProperty(KeyString,Value);
SuperClass.Properties_Game.store(new FileOutputStream(SuperClass.Properties_File),"");
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
public static void WriteWinData(int Bomb_I,int Bomb_J){
if(Bomb_I==9&&Bomb_J==9){
Methods.SetProperties("PLAYED_TIMES_SIMPLE",String.valueOf(Integer.valueOf(SuperClass.Properties_Game.getProperty("PLAYED_TIMES_SIMPLE"))+1));
Methods.SetProperties("WIN_TIMES_SIMPLE",String.valueOf(Integer.valueOf(SuperClass.Properties_Game.getProperty("WIN_TIMES_SIMPLE"))+1));
Methods.SetProperties("LEAST_TIME_SIMPLE",String.valueOf(Math.min(SuperClass.CountTime,Integer.valueOf(SuperClass.Properties_Game.getProperty("LEAST_TIME_SIMPLE")))));
}
else if(Bomb_I==16&&Bomb_J==16){
Methods.SetProperties("PLAYED_TIMES_MIDDLE",String.valueOf(Integer.valueOf(SuperClass.Properties_Game.getProperty("PLAYED_TIMES_MIDDLE"))+1));
Methods.SetProperties("WIN_TIMES_MIDDLE",String.valueOf(Integer.valueOf(SuperClass.Properties_Game.getProperty("WIN_TIMES_MIDDLE"))+1));
Methods.SetProperties("LEAST_TIME_MIDDLE",String.valueOf(Math.min(SuperClass.CountTime,Integer.valueOf(SuperClass.Properties_Game.getProperty("LEAST_TIME_MIDDLE")))));
}
else if(Bomb_I==16&&Bomb_J==30){
Methods.SetProperties("PLAYED_TIMES_HARD",String.valueOf(Integer.valueOf(SuperClass.Properties_Game.getProperty("PLAYED_TIMES_HARD"))+1));
Methods.SetProperties("WIN_TIMES_HARD",String.valueOf(Integer.valueOf(SuperClass.Properties_Game.getProperty("WIN_TIMES_HARD"))+1));
Methods.SetProperties("LEAST_TIME_HARD",String.valueOf(Math.min(SuperClass.CountTime,Integer.valueOf(SuperClass.Properties_Game.getProperty("LEAST_TIME_HARD")))));
}
}
public static void WriteLoseData(int Bomb_I,int Bomb_J){
if(Bomb_I==9&&Bomb_J==9){
Methods.SetProperties("PLAYED_TIMES_SIMPLE",String.valueOf(Integer.valueOf(SuperClass.Properties_Game.getProperty("PLAYED_TIMES_SIMPLE"))+1));
}
else if(Bomb_I==16&&Bomb_J==16){
Methods.SetProperties("PLAYED_TIMES_MIDDLE",String.valueOf(Integer.valueOf(SuperClass.Properties_Game.getProperty("PLAYED_TIMES_MIDDLE"))+1));
}
else if(Bomb_I==16&&Bomb_J==30){
Methods.SetProperties("PLAYED_TIMES_HARD",String.valueOf(Integer.valueOf(SuperClass.Properties_Game.getProperty("PLAYED_TIMES_HARD"))+1));
}
}
}
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class MiddleFrame extends MineFrame{
private static final int Bomb_I=16;
private static final int Bomb_J=16;
private JButton[][]Game_Buttons=new JButton[Bomb_I][Bomb_J];
private int[][]Map_Bomb=new int[Bomb_I][Bomb_J];
private MouseLeftListener MouseLeft=new MouseLeftListener(Game_Buttons,Map_Bomb,Bomb_I,Bomb_J);
private MouseRightListener MouseRight=new MouseRightListener(Game_Buttons,Map_Bomb,Bomb_I,Bomb_J);
private ExitActionListener ExitListener=new ExitActionListener(Game_Buttons,"Middle",Bomb_I,Bomb_J);
private LoadingActionListener LoadingListener=new LoadingActionListener(Game_Buttons,Bomb_I,Bomb_J);
public MiddleFrame(){
Frame_Super.setSize(450,510);
Frame_Super.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width-Frame_Super.getSize().width)/2,
(Toolkit.getDefaultToolkit().getScreenSize().height-Frame_Super.getSize().height)/2);
Exit.addActionListener(ExitListener);
Loading_Game.addActionListener(LoadingListener);
New_Game.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SuperClass.Tag_Num=0;
Frame_Super.setVisible(false);
String levelString=Methods.GetProperties("LEVEL");
if(levelString.equals("Middle")){
new MiddleFrame();
}
else if(levelString.equals("Hard")){
new HardFrame();
}
else{
new SimpleFrame();
}
}
});
TextField_MineRemain.setText(String.valueOf(SuperClass.MineNum_Middle));
super.Panel_Center.setLayout(new GridLayout(Bomb_I,Bomb_J));
for(int i=0;i
for(int j=0;j
Game_Buttons[j]=new JButton();
Game_Buttons[j].setIcon(SuperClass.Icon_Used[12]);
Game_Buttons[j].addActionListener(MouseLeft);
Game_Buttons[j].addMouseListener(MouseRight);
super.Panel_Center.add(Game_Buttons[j]);
Map_Bomb[j]=SuperClass.ICON[0];
}
}
Map_Bomb=Methods.randomBombSite(Map_Bomb,SuperClass.MineNum_Middle,Bomb_I,Bomb_J);
Methods.GetBombNum(Map_Bomb,Bomb_I,Bomb_J);
Frame_Super.validate();
Frame_Super.setVisible(true);
}
}
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
public class MineFrame extends SuperClass{
protected JFrame Frame_Super;
private JMenuBar MineFrameMenuBar;
private JMenu Game,Help;
private JMenuItem Statistics,Setting,Change_Skin,Lookup_Help,About_Game,Get_More;
protected JMenuItem Loading_Game,Exit,New_Game;
protected static JTextField TextField_MineRemain;
protected JTextField TextField_Time;
private Font Font_TextField;
private JPanel Panel_East,Panel_West,Panel_South,Panel_North;
protected JPanel Panel_Center;
protected static TimerTask TimeCountTask;
public MineFrame(){
Frame_Super=new JFrame("Game Of MineSweep");
Frame_Super.setResizable(false);
MineFrameMenuBar=new JMenuBar();
Game=new JMenu("游戏(G)");
Game.setMnemonic('G');
Help=new JMenu("帮助(H)");
Help.setMnemonic('H');
New_Game=new JMenuItem("新游戏(N)");
New_Game.setMnemonic('N');
Loading_Game=new JMenuItem("载入游戏(L)");
Loading_Game.setMnemonic('L');
Statistics=new JMenuItem("统计信息(S)");
Statistics.setMnemonic('S');
Setting=new JMenuItem("选项(O)");
Setting.setMnemonic('O');
Change_Skin=new JMenuItem("更改外观(A)");
Change_Skin.setMnemonic('A');
Exit=new JMenuItem("退出(X)");
Exit.setMnemonic('X');
Lookup_Help=new JMenuItem("查看帮助(V)");
Lookup_Help.setMnemonic('V');
About_Game=new JMenuItem("关于(A)");
About_Game.setMnemonic('A');
Get_More=new JMenuItem("建议与意见(M)");
Get_More.setMnemonic('M');
New_Game.setAccelerator(KeyStroke.getKeyStroke("F2"));
Loading_Game.setAccelerator(KeyStroke.getKeyStroke("F3"));
Statistics.setAccelerator(KeyStroke.getKeyStroke("F4"));
Setting.setAccelerator(KeyStroke.getKeyStroke("F5"));
Change_Skin.setAccelerator(KeyStroke.getKeyStroke("F6"));
Exit.setAccelerator(KeyStroke.getKeyStroke("F7"));
Lookup_Help.setAccelerator(KeyStroke.getKeyStroke("F1"));
Game.add(New_Game);
Game.add(Loading_Game);
Game.addSeparator();
Game.add(Statistics);
Game.add(Setting);
Game.add(Change_Skin);
Game.addSeparator();
Game.add(Exit);
Help.add(Lookup_Help);
Help.addSeparator();
Help.add(About_Game);
Help.addSeparator();
Help.add(Get_More);
MineFrameMenuBar.add(Game);
MineFrameMenuBar.add(Help);
Frame_Super.setJMenuBar(MineFrameMenuBar);
Font_TextField=new Font(null,Font.ITALIC,20);
TextField_Time=new JTextField("0",6);
TextField_Time.setFont(Font_TextField);
TextField_Time.setEditable(false);
TextField_MineRemain=new JTextField(6);
TextField_MineRemain.setFont(Font_TextField);
TextField_MineRemain.setEditable(false);
Panel_East=new JPanel();
Panel_West=new JPanel();
Panel_South=new JPanel();
Panel_North=new JPanel();
Panel_Center=new JPanel();
Panel_South.setLayout(new GridLayout(1,2));
Panel_South.add(TextField_Time);
Panel_South.add(TextField_MineRemain);
Frame_Super.setLayout(new BorderLayout());
Frame_Super.add(Panel_East,BorderLayout.EAST);
Frame_Super.add(Panel_West,BorderLayout.WEST);
Frame_Super.add(Panel_South,BorderLayout.SOUTH);
Frame_Super.add(Panel_North,BorderLayout.NORTH);
Frame_Super.add(Panel_Center,BorderLayout.CENTER);
TimeCountTask=new TimerTask(){
public void run() {
TextField_Time.setText(String.valueOf((Integer.valueOf(TextField_Time.getText())+1)));
SuperClass.CountTime=Integer.valueOf(TextField_Time.getText());
}
};
SuperClass.FirstClickFlag=true;
SuperClass.TimeCount=new Timer();
Statistics.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
new StatisticsFrame();
}
});
Setting.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
new SettingFrame();
}
});
Change_Skin.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,"Not Applicable");
}
});
Lookup_Help.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,"SB Needs Help");
}
});
About_Game.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,"Made By wzw");
}
});
Get_More.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try {
Runtime.getRuntime().exec("cmd.exe /c start http://222.20.68.203/Suggestions/");
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
Frame_Super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import javax.swing.UIManager;
public class MineSweeper{
public MineSweeper(){
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch(Exception e) {
}
String LevelString=Methods.GetProperties("LEVEL");
if(LevelString.equals("Middle")){
new MiddleFrame();
}
else if(LevelString.equals("Hard")){
new HardFrame();
}
else{
new SimpleFrame();
}
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JOptionPane;
public class MouseLeftListener implements ActionListener{
private JButton [][]Button_Game;
private int[][]Map_Bomb;
private int Bomb_I,Bomb_J;
public MouseLeftListener() {
}
public MouseLeftListener(JButton[][]Button_Game,int[][]Map_Bomb,int Bomb_I,int Bomb_J){
this.Button_Game=Button_Game;
this.Map_Bomb=Map_Bomb;
this.Bomb_I=Bomb_I;
this.Bomb_J=Bomb_J;
}
public void actionPerformed(ActionEvent e) {
Object Button_Select=e.getSource();
if(SuperClass.FirstClickFlag){
SuperClass.TimeCount.scheduleAtFixedRate(MineFrame.TimeCountTask,0,1000);
SuperClass.FirstClickFlag=false;
}
for(int i=0;i
for(int j=0;j
if((Button_Select==Button_Game[j])){
if(Map_Bomb[j]==SuperClass.BOMB){
for(int x=0;x
for(int y=0;y
Button_Game[x][y].setIcon(SuperClass.Icon_Used[Map_Bomb[x][y]]);
}
}
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
Methods.WriteLoseData(Bomb_I,Bomb_J);
SuperClass.Tag_Num=0;
JOptionPane.showMessageDialog(null,"你输了...");
}
else if((Button_Game[j].getIcon()==SuperClass.Icon_Used[12])&&(Map_Bomb[j]!=SuperClass.BOMB)){
Button_Game[j].setIcon(SuperClass.Icon_Used[Map_Bomb[j]]);
if(Map_Bomb[j]==SuperClass.ICON[0]){
Methods.ShowAllNull(Button_Game,Map_Bomb,Bomb_I,Bomb_J,i,j);
}
}
}
}
}
}
}
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JOptionPane;
public class MouseLeftTwoClickListener extends MouseAdapter{
private JButton [][]Button_Game;
private int[][]Map_Bomb;
private int Bomb_I,Bomb_J;
private int ClickNum;
public MouseLeftTwoClickListener() {
}
public MouseLeftTwoClickListener(JButton[][]Button_Game,int[][]Map_Bomb,int Bomb_I,int Bomb_J){
this.Button_Game=Button_Game;
this.Map_Bomb=Map_Bomb;
this.Bomb_I=Bomb_I;
this.Bomb_J=Bomb_J;
}
public void mouseClicked(MouseEvent e){
ClickNum=e.getClickCount();
Object ClickButton=e.getSource();
for(int i=0;i
for(int j=0;j
if((Button_Game[j]==ClickButton)&&ClickNum==2){
int[]Location=new int[2];
Location[0]=i;
Location[1]=j;
if(((Button_Game[j].getIcon())!=SuperClass.Icon_Used[0])&&
((Button_Game[j].getIcon())!=SuperClass.Icon_Used[9])&&
((Button_Game[j].getIcon())!=SuperClass.Icon_Used[10])&&
((Button_Game[j].getIcon())!=SuperClass.Icon_Used[11])&&
((Button_Game[j].getIcon())!=SuperClass.Icon_Used[12])){
int TwoClickFlag=Methods.TwoClickRight(Button_Game,Map_Bomb,Bomb_I,Bomb_J,Location);
if(TwoClickFlag==Methods.RIGHT){
if((Location[0]+1)
int[]Temp=new int[2];
Temp[0]=Location[0]+1;
Temp[1]=Location[1];
if(Map_Bomb[Temp[0]][Temp[1]]!=SuperClass.BOMB){
Button_Game[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if(Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0]){
Methods.ShowAllNull(Button_Game,Map_Bomb,Bomb_I,Bomb_J,Temp[0],Temp[1]);
}
}
}
if((Location[0]-1)>=0){
int[]Temp=new int[2];
Temp[0]=Location[0]-1;
Temp[1]=Location[1];
if(Map_Bomb[Temp[0]][Temp[1]]!=SuperClass.BOMB){
Button_Game[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if(Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0]){
Methods.ShowAllNull(Button_Game,Map_Bomb,Bomb_I,Bomb_J,Temp[0],Temp[1]);
}
}
}
if((Location[1]+1)
int[]Temp=new int[2];
Temp[0]=Location[0];
Temp[1]=Location[1]+1;
if(Map_Bomb[Temp[0]][Temp[1]]!=SuperClass.BOMB){
Button_Game[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if(Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0]){
Methods.ShowAllNull(Button_Game,Map_Bomb,Bomb_I,Bomb_J,Temp[0],Temp[1]);
}
}
}
if((Location[1]-1)>=0){
int[]Temp=new int[2];
Temp[0]=Location[0];
Temp[1]=Location[1]-1;
if(Map_Bomb[Temp[0]][Temp[1]]!=SuperClass.BOMB){
Button_Game[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if(Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0]){
Methods.ShowAllNull(Button_Game,Map_Bomb,Bomb_I,Bomb_J,Temp[0],Temp[1]);
}
}
}
if(((Location[0]+1)
int[]Temp=new int[2];
Temp[0]=Location[0]+1;
Temp[1]=Location[1]+1;
if(Map_Bomb[Temp[0]][Temp[1]]!=SuperClass.BOMB){
Button_Game[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if(Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0]){
Methods.ShowAllNull(Button_Game,Map_Bomb,Bomb_I,Bomb_J,Temp[0],Temp[1]);
}
}
}
if(((Location[0]+1)=0)){
int[]Temp=new int[2];
Temp[0]=Location[0]+1;
Temp[1]=Location[1]-1;
if(Map_Bomb[Temp[0]][Temp[1]]!=SuperClass.BOMB){
Button_Game[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if(Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0]){
Methods.ShowAllNull(Button_Game,Map_Bomb,Bomb_I,Bomb_J,Temp[0],Temp[1]);
}
}
}
if(((Location[0]-1)>=0)&&((Location[1]+1)
int[]Temp=new int[2];
Temp[0]=Location[0]-1;
Temp[1]=Location[1]+1;
if(Map_Bomb[Temp[0]][Temp[1]]!=SuperClass.BOMB){
Button_Game[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if(Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0]){
Methods.ShowAllNull(Button_Game,Map_Bomb,Bomb_I,Bomb_J,Temp[0],Temp[1]);
}
}
}
if(((Location[0]-1)>=0)&&((Location[1]-1)>=0)){
int[]Temp=new int[2];
Temp[0]=Location[0]-1;
Temp[1]=Location[1]-1;
if(Map_Bomb[Temp[0]][Temp[1]]!=SuperClass.BOMB){
Button_Game[Temp[0]][Temp[1]].setIcon(SuperClass.Icon_Used[Map_Bomb[Temp[0]][Temp[1]]]);
if(Map_Bomb[Temp[0]][Temp[1]]==SuperClass.ICON[0]){
Methods.ShowAllNull(Button_Game,Map_Bomb,Bomb_I,Bomb_J,Temp[0],Temp[1]);
}
}
}
}
else if(TwoClickFlag==Methods.LESS){
new ThreadOfTwoClick(Button_Game,Location[0],Location[1],Button_Game[Location[0]][Location[1]].getIcon()).start();
}
else{
Methods.WriteLoseData(Bomb_I,Bomb_J);
JOptionPane.showMessageDialog(null,"你输了...");
}
}
}
}
}
}
}
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JOptionPane;
public class MouseRightListener extends MouseAdapter{
private JButton [][]Button_Game;
private int[][]Map_Bomb;
private int Bomb_I,Bomb_J;
public MouseRightListener() {
}
public MouseRightListener(JButton[][]Button_Game,int[][]Map_Bomb,int Bomb_I,int Bomb_J){
this.Button_Game=Button_Game;
this.Map_Bomb=Map_Bomb;
this.Bomb_I=Bomb_I;
this.Bomb_J=Bomb_J;
}
public void mouseClicked(MouseEvent e) {
Object Button_Select=e.getSource();
if(SuperClass.FirstClickFlag){
SuperClass.TimeCount.scheduleAtFixedRate(MineFrame.TimeCountTask,0,1000);
SuperClass.FirstClickFlag=false;
}
for(int i=0;i
for(int j=0;j
if(e.getButton()==MouseEvent.BUTTON3){
if(Button_Select==Button_Game[j]){
if(Button_Game[j].getIcon()==SuperClass.Icon_Used[12]){
Button_Game[j].setIcon(SuperClass.Icon_Used[10]);
SuperClass.Tag_Num++;
if((Bomb_I==9)&&(Bomb_J==9)){
MineFrame.TextField_MineRemain.setText(String.valueOf(SuperClass.MineNum_Simple-SuperClass.Tag_Num));
if(SuperClass.Tag_Num==SuperClass.MineNum_Simple){
if(Methods.CheckWin(Button_Game,Map_Bomb,Bomb_I,Bomb_J)==true){
Methods.WriteWinData(Bomb_I,Bomb_J);
JOptionPane.showMessageDialog(null,"你赢了...");
}
}
}
else if((Bomb_I==16)&&(Bomb_J==16)){
MineFrame.TextField_MineRemain.setText(String.valueOf(SuperClass.MineNum_Middle-SuperClass.Tag_Num));
if(SuperClass.Tag_Num==SuperClass.MineNum_Middle){
if(Methods.CheckWin(Button_Game,Map_Bomb,Bomb_I,Bomb_J)==true){
Methods.WriteWinData(Bomb_I,Bomb_J);
JOptionPane.showMessageDialog(null,"你赢了...");
}
}
}
else if((Bomb_I==16&&Bomb_J==30)){
MineFrame.TextField_MineRemain.setText(String.valueOf(SuperClass.MineNum_Hard-SuperClass.Tag_Num));
if(SuperClass.Tag_Num==SuperClass.MineNum_Hard){
if(Methods.CheckWin(Button_Game,Map_Bomb,Bomb_I,Bomb_J)==true){
Methods.WriteWinData(Bomb_I,Bomb_J);
JOptionPane.showMessageDialog(null,"你赢了...");
}
}
}
}
else if(Button_Game[j].getIcon()==SuperClass.Icon_Used[10]){
Button_Game[j].setIcon(SuperClass.Icon_Used[11]);
SuperClass.Tag_Num--;
if((Bomb_I==9)&&(Bomb_J==9)){
MineFrame.TextField_MineRemain.setText(String.valueOf(SuperClass.MineNum_Simple-SuperClass.Tag_Num));
}
else if((Bomb_I==16)&&(Bomb_J==16)){
MineFrame.TextField_MineRemain.setText(String.valueOf(SuperClass.MineNum_Middle-SuperClass.Tag_Num));
}
else if((Bomb_I==16&&Bomb_J==30)){
MineFrame.TextField_MineRemain.setText(String.valueOf(SuperClass.MineNum_Hard-SuperClass.Tag_Num));
}
}
else if(Button_Game[j].getIcon()==SuperClass.Icon_Used[11]){
Button_Game[j].setIcon(SuperClass.Icon_Used[12]);
}
}
}
}
}
}
}
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class SettingFrame implements ActionListener{
private JFrame SetFrame;
private JPanel panel1,panel2;
private JButton Confirm;
private JLabel Label_Simple,Label_Middle,Label_Hard;
private JRadioButton RadioButton_Simple,RadioButton_Middle,RadioButton_Hard;
private Font font=new Font(null,Font.ITALIC,13);
private String Game_Level;
public SettingFrame(){
Game_Level=Methods.GetProperties("LEVEL");
SetFrame=new JFrame("设置选项");
SetFrame.setSize(350,100);
SetFrame.setLocation(300,200);
SetFrame.setResizable(false);
panel1=new JPanel();
panel2=new JPanel();
Confirm=new JButton("确定");
Confirm.setFont(font);
Label_Simple=new JLabel("9*9方格10个雷");
Label_Middle=new JLabel("16*16方格40个雷");
Label_Hard=new JLabel("16*30方格99个雷");
Label_Simple.setFont(font);
Label_Middle.setFont(font);
Label_Hard.setFont(font);
RadioButton_Simple=new JRadioButton("简单");
RadioButton_Middle=new JRadioButton("中等");
RadioButton_Hard=new JRadioButton("困难");
if(Game_Level.equals("Middle")){
RadioButton_Middle.setSelected(true);
}
else if(Game_Level.equals("Hard")){
RadioButton_Hard.setSelected(true);
}
else{
RadioButton_Simple.setSelected(true);
}
RadioButton_Simple.setFont(font);
RadioButton_Middle.setFont(font);
RadioButton_Hard.setFont(font);
panel1.setLayout(new GridLayout(2,3));
panel1.add(RadioButton_Simple);
panel1.add(RadioButton_Middle);
panel1.add(RadioButton_Hard);
panel1.add(Label_Simple);
panel1.add(Label_Middle);
panel1.add(Label_Hard);
panel2.add(Confirm);
SetFrame.add(panel1,BorderLayout.CENTER);
SetFrame.add(panel2,BorderLayout.SOUTH);
RadioButton_Simple.addActionListener(this);
RadioButton_Middle.addActionListener(this);
RadioButton_Hard.addActionListener(this);
Confirm.addActionListener(this);
SetFrame.validate();
SetFrame.setVisible(true);
}
public void actionPerformed(ActionEvent e){
Object Select_Object=e.getSource();
if(Select_Object==Confirm){
if(RadioButton_Simple.isSelected()){
Methods.SetProperties("LEVEL","Simple");
}
else if(RadioButton_Middle.isSelected()){
Methods.SetProperties("LEVEL","Middle");
}
else if(RadioButton_Hard.isSelected()){
Methods.SetProperties("LEVEL","Hard");
}
SetFrame.setVisible(false);
}
else if(Select_Object==RadioButton_Simple){
RadioButton_Simple.setSelected(true);
RadioButton_Middle.setSelected(false);
RadioButton_Hard.setSelected(false);
}
else if(Select_Object==RadioButton_Middle){
RadioButton_Simple.setSelected(false);
RadioButton_Middle.setSelected(true);
RadioButton_Hard.setSelected(false);
}
else if(Select_Object==RadioButton_Hard){
RadioButton_Simple.setSelected(false);
RadioButton_Middle.setSelected(false);
RadioButton_Hard.setSelected(true);
}
}
}
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class SimpleFrame extends MineFrame{
private static final long serialVersionUID = 1L;
private static final int Bomb_I=9;
private static final int Bomb_J=9;
protected JButton[][]Game_Buttons=new JButton[Bomb_I][Bomb_J];
private int[][]Map_Bomb=new int[Bomb_I][Bomb_J];
private MouseLeftListener MouseLeft=new MouseLeftListener(Game_Buttons,Map_Bomb,Bomb_I,Bomb_J);
private MouseRightListener MouseRight=new MouseRightListener(Game_Buttons,Map_Bomb,Bomb_I,Bomb_J);
private ExitActionListener ExitListener=new ExitActionListener(Game_Buttons,"Simple",Bomb_I,Bomb_J);
private LoadingActionListener LoadingListener=new LoadingActionListener(Game_Buttons,Bomb_I,Bomb_J);
private MouseLeftTwoClickListener DoubleClickListener=new MouseLeftTwoClickListener(Game_Buttons,Map_Bomb,Bomb_I,Bomb_J);
public SimpleFrame(){
Frame_Super.setSize(260,330);
Frame_Super.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width-Frame_Super.getSize().width)/2,
(Toolkit.getDefaultToolkit().getScreenSize().height-Frame_Super.getSize().height)/2);
TextField_MineRemain.setText(String.valueOf(SuperClass.MineNum_Simple));
Exit.addActionListener(ExitListener);
Loading_Game.addActionListener(LoadingListener);
New_Game.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SuperClass.Tag_Num=0;
Frame_Super.setVisible(false);
String levelString=Methods.GetProperties("LEVEL");
if(levelString.equals("Middle")){
new MiddleFrame();
}
else if(levelString.equals("Hard")){
new HardFrame();
}
else{
new SimpleFrame();
}
}
});
super.Panel_Center.setLayout(new GridLayout(Bomb_I,Bomb_J));
for(int i=0;i
for(int j=0;j
Game_Buttons[j]=new JButton();
Game_Buttons[j].setIcon(SuperClass.Icon_Used[12]);
Game_Buttons[j].addActionListener(MouseLeft);
Game_Buttons[j].addMouseListener(MouseRight);
Game_Buttons[j].addMouseListener(DoubleClickListener);
super.Panel_Center.add(Game_Buttons[j]);
Map_Bomb[j]=SuperClass.ICON[0];
}
}
Map_Bomb=Methods.randomBombSite(Map_Bomb,SuperClass.MineNum_Simple,Bomb_I,Bomb_J);
Methods.GetBombNum(Map_Bomb,Bomb_I,Bomb_J);
Frame_Super.validate();
Frame_Super.setVisible(true);
}
}
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class StatisticsFrame{
private JFrame DataFrame;
private JButton Clear_Data;
private JComboBox ComboBox;
private String[]BoxList=new String[3];
private JLabel LeastTime1,PlayedTimes1,WinTimes1,WinRate1;
private JLabel LeastTime2,PlayedTimes2,WinTimes2,WinRate2;
private Font font=new Font(null,Font.ITALIC,13);
private String LeastTimeString,PlayedTimesString,WinTimesString,WinRateString;
public StatisticsFrame(){
LeastTimeString=Methods.GetProperties("LEAST_TIME_SIMPLE");
PlayedTimesString=Methods.GetProperties("PLAYED_TIMES_SIMPLE");
WinTimesString=Methods.GetProperties("WIN_TIMES_SIMPLE");
WinRateString=String.valueOf(Float.valueOf(WinTimesString)/Float.valueOf(PlayedTimesString));
DataFrame=new JFrame("数据统计");
DataFrame.setSize(400,100);
DataFrame.setLocation(300,200);
DataFrame.setResizable(false);
Clear_Data=new JButton("清零");
Clear_Data.setFont(font);
BoxList[0]=new String("简单游戏");
BoxList[1]=new String("中等游戏");
BoxList[2]=new String("困难游戏");
ComboBox=new JComboBox(BoxList);
ComboBox.setFont(font);
ComboBox.setEnabled(true);
ComboBox.setSelectedIndex(0);
LeastTime1=new JLabel("最少时间");
PlayedTimes1=new JLabel("所玩局数");
WinTimes1=new JLabel("获胜局数");
WinRate1=new JLabel("获胜率");
LeastTime1.setFont(font);
PlayedTimes1.setFont(font);
WinTimes1.setFont(font);
WinRate1.setFont(font);
LeastTime2=new JLabel();
PlayedTimes2=new JLabel();
WinTimes2=new JLabel();
WinRate2=new JLabel();
LeastTime2.setFont(font);
PlayedTimes2.setFont(font);
WinTimes2.setFont(font);
WinRate2.setFont(font);
LeastTime2.setText(LeastTimeString);
PlayedTimes2.setText(PlayedTimesString);
WinTimes2.setText(WinTimesString);
WinRate2.setText(WinRateString);
DataFrame.setLayout(new GridLayout(2,5));
DataFrame.add(ComboBox);
DataFrame.add(LeastTime1);
DataFrame.add(PlayedTimes1);
DataFrame.add(WinTimes1);
DataFrame.add(WinRate1);
DataFrame.add(Clear_Data);
DataFrame.add(LeastTime2);
DataFrame.add(PlayedTimes2);
DataFrame.add(WinTimes2);
DataFrame.add(WinRate2);
Clear_Data.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int Confirm=JOptionPane.showConfirmDialog(null,"确定将数据清零","清零提示",JOptionPane.OK_CANCEL_OPTION);
if(Confirm==JOptionPane.OK_OPTION){
Methods.SetProperties("PLAYED_TIMES_SIMPLE","0");
Methods.SetProperties("PLAYED_TIMES_MIDDLE","0");
Methods.SetProperties("PLAYED_TIMES_HARD","0");
Methods.SetProperties("LEAST_TIME_SIMPLE",String.valueOf(Integer.MAX_VALUE));
Methods.SetProperties("LEAST_TIME_MIDDLE",String.valueOf(Integer.MAX_VALUE));
Methods.SetProperties("LEAST_TIME_HARD",String.valueOf(Integer.MAX_VALUE));
Methods.SetProperties("WIN_TIMES_SIMPLE","0");
Methods.SetProperties("WIN_TIMES_MIDDLE","0");
Methods.SetProperties("WIN_TIMES_HARD","0");
LeastTime2.setText("无");
PlayedTimes2.setText("0");
WinTimes2.setText("0");
WinRate2.setText("NaN");
}
else{
}
}
});
ComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(ComboBox.getSelectedIndex()==0){
LeastTimeString=Methods.GetProperties("LEAST_TIME_SIMPLE");
PlayedTimesString=Methods.GetProperties("PLAYED_TIMES_SIMPLE");
WinTimesString=Methods.GetProperties("WIN_TIMES_SIMPLE");
WinRateString=String.valueOf(Float.valueOf(WinTimesString)/Float.valueOf(PlayedTimesString));
LeastTime2.setText(LeastTimeString);
PlayedTimes2.setText(PlayedTimesString);
WinTimes2.setText(WinTimesString);
WinRate2.setText(WinRateString);
}
else if(ComboBox.getSelectedIndex()==1){
LeastTimeString=Methods.GetProperties("LEAST_TIME_MIDDLE");
PlayedTimesString=Methods.GetProperties("PLAYED_TIMES_MIDDLE");
WinTimesString=Methods.GetProperties("WIN_TIMES_MIDDLE");
WinRateString=String.valueOf(Float.valueOf(WinTimesString)/Float.valueOf(PlayedTimesString));
LeastTime2.setText(LeastTimeString);
PlayedTimes2.setText(PlayedTimesString);
WinTimes2.setText(WinTimesString);
WinRate2.setText(WinRateString);
}
else if(ComboBox.getSelectedIndex()==2){
LeastTimeString=Methods.GetProperties("LEAST_TIME_HARD");
PlayedTimesString=Methods.GetProperties("PLAYED_TIMES_HARD");
WinTimesString=Methods.GetProperties("WIN_TIMES_HARD");
WinRateString=String.valueOf(Float.valueOf(WinTimesString)/Float.valueOf(PlayedTimesString));
LeastTime2.setText(LeastTimeString);
PlayedTimes2.setText(PlayedTimesString);
WinTimes2.setText(WinTimesString);
WinRate2.setText(WinRateString);
}
}
});
DataFrame.validate();
DataFrame.setVisible(true);
}
}
import java.io.File;
import java.util.Properties;
import java.util.Timer;
import javax.swing.Icon;
import javax.swing.ImageIcon;
public class SuperClass {
protected static final int[]ICON={0,1,2,3,4,5,6,7,8};
protected static final int BOMB=9;
protected static Icon[]Icon_Used=new ImageIcon[14];
public static final int MineNum_Simple=10;
public static final int MineNum_Middle=40;
public static final int MineNum_Hard=99;
protected static File SaveGame_File=new File("SaveGame.txt");
protected static File Properties_File=new File("Properties.txt");
protected static Properties Properties_Game=new Properties();
protected static int Tag_Num=0;
protected static int CountTime=0;
protected static boolean FirstClickFlag=true;
protected static Timer TimeCount=new Timer();
public SuperClass(){
for(int i=0;i
Icon_Used=new ImageIcon(("Icon"+File.separator+String.valueOf(i)+".jpg"));
}
}
}
import javax.swing.Icon;
import javax.swing.JButton;
public class ThreadOfTwoClick extends Thread{
private Icon Icon_Sourse;
private JButton[][]Button_Game;
private int Location_I;
private int Location_J;
public ThreadOfTwoClick(){
}
public ThreadOfTwoClick(JButton[][]Button_Game,int Location_I,int Location_J,Icon Icon_Sourse){
this.Button_Game=Button_Game;
this.Location_I=Location_I;
this.Location_J=Location_J;
this.Icon_Sourse=Icon_Sourse;
}
public void run(){
try {
Button_Game[Location_I][Location_J].setIcon(SuperClass.Icon_Used[13]);
Thread.sleep(150);
Button_Game[Location_I][Location_J].setIcon(Icon_Sourse);
Thread.sleep(150);
Button_Game[Location_I][Location_J].setIcon(SuperClass.Icon_Used[13]);
Thread.sleep(150);
Button_Game[Location_I][Location_J].setIcon(Icon_Sourse);
Thread.sleep(150);
Button_Game[Location_I][Location_J].setIcon(SuperClass.Icon_Used[13]);
Thread.sleep(150);
Button_Game[Location_I][Location_J].setIcon(Icon_Sourse);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
بۇ يازمىنى ئاخىرىدا ways_love تەھرىرلىگەن. ۋاقتى 2012-3-22 21:27
|
|