當前位置:首頁 » 操作系統 » 紅包掃雷源碼

紅包掃雷源碼

發布時間: 2024-01-06 14:49:04

㈠ C語言掃雷游戲源代碼

"掃雷"小游戲C代碼

#include<stdio.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
main( )
{char a[102][102],b[102][102],c[102][102],w;
int i,j; /*循環變數*/
int x,y,z[999]; /*雷的位置*/
int t,s; /*標記*/
int m,n,lei; /*計數*/
int u,v; /*輸入*/
int hang,lie,ge,mo; /*自定義變數*/
srand((int)time(NULL)); /*啟動隨機數發生器*/
leb1: /*選擇模式*/
printf(" 請選擇模式: 1.標准 2.自定義 ");
scanf("%d",&mo);
if(mo==2) /*若選擇自定義模式,要輸入三個參數*/
{do
{t=0; printf("請輸入 行數 列數 雷的個數 ");
scanf("%d%d%d",&hang,&lie,&ge);
if(hang<2){printf("行數太少 "); t=1;}
if(hang>100){printf("行數太多 ");t=1;}
if(lie<2){printf("列數太少 ");t=1;}
if(lie>100){printf("列數太多 ");t=1;}
if(ge<1){printf("至少要有一個雷 ");t=1;}
if(ge>=(hang*lie)){printf("雷太多了 ");t=1;}
}while(t==1);
}
else{hang=10,lie=10,ge=10;} /*否則就是選擇了標准模式(默認參數)*/
for(i=1;i<=ge;i=i+1) /*確定雷的位置*/
{do
{t=0; z[i]=rand( )%(hang*lie);
for(j=1;j<i;j=j+1){if(z[i]==z[j]) t=1;}
}while(t==1);
}
for(i=0;i<=hang+1;i=i+1) /*初始化a,b,c*/
{for(j=0;j<=lie+1;j=j+1) {a[i][j]='1'; b[i][j]='1'; c[i][j]='0';} }
for(i=1;i<=hang;i=i+1)
{for(j=1;j<=lie;j=j+1) {a[i][j]='+';} }
for(i=1;i<=ge;i=i+1) /*把雷放入c*/
{x=z[i]/lie+1; y=z[i]%lie+1; c[x][y]='#';}
for(i=1;i<=hang;i=i+1) /*計算b中數字*/
{for(j=1;j<=lie;j=j+1)
{m=48;
if(c[i-1][j-1]=='#')m=m+1; if(c[i][j-1]=='#')m=m+1;
if(c[i-1][j]=='#')m=m+1; if(c[i+1][j+1]=='#')m=m+1;
if(c[i][j+1]=='#')m=m+1; if(c[i+1][j]=='#')m=m+1;
if(c[i+1][j-1]=='#')m=m+1; if(c[i-1][j+1]=='#')m=m+1;
b[i][j]=m;
}
}
for(i=1;i<=ge;i=i+1) /*把雷放入b中*/
{x=z[i]/lie+1; y=z[i]%lie+1; b[x][y]='#';}

lei=ge; /*以下是游戲設計*/
do
{leb2: /*輸出*/
system("cls");printf(" ");

printf(" ");
for(i=1;i<=lie;i=i+1)
{w=(i-1)/10+48; printf("%c",w);
w=(i-1)%10+48; printf("%c ",w);
}
printf(" |");
for(i=1;i<=lie;i=i+1){printf("---|");}
printf(" ");
for(i=1;i<=hang;i=i+1)
{w=(i-1)/10+48; printf("%c",w);
w=(i-1)%10+48; printf("%c |",w);
for(j=1;j<=lie;j=j+1)
{if(a[i][j]=='0')printf(" |");
else printf(" %c |",a[i][j]);
}
if(i==2)printf(" 剩餘雷個數");
if(i==3)printf(" %d",lei);
printf(" |");
for(j=1;j<=lie;j=j+1){printf("---|");}
printf(" ");
}

scanf("%d%c%d",&u,&w,&v); /*輸入*/
u=u+1,v=v+1;
if(w!='#'&&a[u][v]=='@')
goto leb2;
if(w=='#')
{if(a[u][v]=='+'){a[u][v]='@'; lei=lei-1;}
else if(a[u][v]=='@'){a[u][v]='?'; lei=lei+1;}
else if(a[u][v]=='?'){a[u][v]='+';}
goto leb2;
}
a[u][v]=b[u][v];

leb3: /*打開0區*/
t=0;
if(a[u][v]=='0')
{for(i=1;i<=hang;i=i+1)
{for(j=1;j<=lie;j=j+1)
{s=0;
if(a[i-1][j-1]=='0')s=1; if(a[i-1][j+1]=='0')s=1;
if(a[i-1][j]=='0')s=1; if(a[i+1][j-1]=='0')s=1;
if(a[i+1][j+1]=='0')s=1; if(a[i+1][j]=='0')s=1;
if(a[i][j-1]=='0')s=1; if(a[i][j+1]=='0')s=1;
if(s==1)a[i][j]=b[i][j];
}
}
for(i=1;i<=hang;i=i+1)
{for(j=lie;j>=1;j=j-1)
{s=0;
if(a[i-1][j-1]=='0')s=1; if(a[i-1][j+1]=='0')s=1;
if(a[i-1][j]=='0')s=1; if(a[i+1][j-1]=='0')s=1;
if(a[i+1][j+1]=='0')s=1; if(a[i+1][j]=='0')s=1;
if(a[i][j-1]=='0')s=1; if(a[i][j+1]=='0')s=1;
if(s==1)a[i][j]=b[i][j];
}
}
for(i=hang;i>=1;i=i-1)
{for(j=1;j<=lie;j=j+1)
{s=0;
if(a[i-1][j-1]=='0')s=1; if(a[i-1][j+1]=='0')s=1;
if(a[i-1][j]=='0')s=1; if(a[i+1][j-1]=='0')s=1;
if(a[i+1][j+1]=='0')s=1; if(a[i+1][j]=='0')s=1;
if(a[i][j-1]=='0')s=1; if(a[i][j+1]=='0')s=1;
if(s==1)a[i][j]=b[i][j];
}
}
for(i=hang;i>=1;i=i-1)
{for(j=lie;j>=1;j=j-1)
{s=0;
if(a[i-1][j-1]=='0')s=1; if(a[i-1][j+1]=='0')s=1;
if(a[i-1][j]=='0')s=1; if(a[i+1][j-1]=='0')s=1;
if(a[i+1][j+1]=='0')s=1;if(a[i+1][j]=='0')s=1;
if(a[i][j-1]=='0')s=1; if(a[i][j+1]=='0')s=1;
if(s==1)a[i][j]=b[i][j];
}
}

for(i=1;i<=hang;i=i+1) /*檢測0區*/
{for(j=1;j<=lie;j=j+1)
{if(a[i][j]=='0')
{if(a[i-1][j-1]=='+'||a[i-1][j-1]=='@'||a[i-1][j-1]=='?')t=1;
if(a[i-1][j+1]=='+'||a[i-1][j+1]=='@'||a[i-1][j+1]=='?')t=1;
if(a[i+1][j-1]=='+'||a[i+1][j-1]=='@'||a[i+1][j-1]=='?')t=1;
if(a[i+1][j+1]=='+'||a[i+1][j+1]=='@'||a[i+1][j+1]=='?')t=1;
if(a[i+1][j]=='+'||a[i+1][j]=='@'||a[i+1][j]=='?')t=1;
if(a[i][j+1]=='+'||a[i][j+1]=='@'||a[i][j+1]=='?')t=1;
if(a[i][j-1]=='+'||a[i][j-1]=='@'||a[i][j-1]=='?')t=1;
if(a[i-1][j]=='+'||a[i-1][j]=='@'||a[i-1][j]=='?')t=1;
}
}
}
if(t==1)goto leb3;
}

n=0; /*檢查結束*/
for(i=1;i<=hang;i=i+1)
{for(j=1;j<=lie;j=j+1)
{if(a[i][j]!='+'&&a[i][j]!='@'&&a[i][j]!='?')n=n+1;}
}
}
while(a[u][v]!='#'&&n!=(hang*lie-ge));

for(i=1;i<=ge;i=i+1) /*游戲結束*/
{x=z[i]/lie+1; y=z[i]%lie+1; a[x][y]='#'; }
printf(" ");
for(i=1;i<=lie;i=i+1)
{w=(i-1)/10+48; printf("%c",w);
w=(i-1)%10+48; printf("%c ",w);
}
printf(" |");
for(i=1;i<=lie;i=i+1){printf("---|");}
printf(" ");
for(i=1;i<=hang;i=i+1)
{w=(i-1)/10+48; printf("%c",w);
w=(i-1)%10+48; printf("%c |",w);
for(j=1;j<=lie;j=j+1)
{if(a[i][j]=='0')printf(" |");
else printf(" %c |",a[i][j]);
}
if(i==2)printf(" 剩餘雷個數");
if(i==3)printf(" %d",lei); printf(" |");
for(j=1;j<=lie;j=j+1) {printf("---|");}
printf(" ");
}
if(n==(hang*lie-ge)) printf("你成功了! ");
else printf(" 游戲結束! ");
printf(" 重玩請輸入1 ");
t=0;
scanf("%d",&t);
if(t==1)goto leb1;
}

/*註:在DEV c++上運行通過。行號和列號都從0開始,比如要確定第0行第9列不是「雷」,就在0和9中間加入一個字母,可以輸入【0a9】三個字元再按回車鍵。3行7列不是雷,則輸入【3a7】回車;第8行第5列是雷,就輸入【8#5】回車,9行0列是雷則輸入【9#0】並回車*/

㈡ 急求C語言編譯的小游戲(如掃雷),附帶源代碼和注釋。

小游戲2048:

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

#include<time.h>

#include<windows.h>

int jsk( ); //計算空格數

void rsgm( ); //重置游戲

void inkey( ); //按鍵輸入

void left( ); //向左移動

void right( ); //向右移動

void up( ); //向上移動

void down( ); //向下移動

void show( ); //輸出界面

void adnum( ); //添加隨機數

void yes( ); //游戲是否結束(1是0否)

void gtxy(int x, int y); //控制游標位置的函數

int a[4][4]; //存儲16個格子中的數字

int score = 0; //每局得分

int best = 0; //最高得分

int ifnum; //是否需要添加數字(1是0否)

int over; //游戲結束標志(1是0否)

int i,j,k;

int main( )

{ rsgm( ); //重置游戲

inkey( ); //按鍵輸入

return 0;

}

void setColor(unsigned short ForeColor = 7, unsigned short BackGroundColor = 0)

{ HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleTextAttribute(handle, ForeColor + BackGroundColor * 0x10);

} //用於控制字元顏色的函數

void rsgm( ) //重置游戲

{ score = 0; ifnum = 1; over = 0; srand((unsigned)time(0)); //啟動隨機數發生器

int n = rand( ) % 16; //隨機函數產生0-15的數字

for (i = 0; i < 4; i++)

{for (j = 0; j < 4; j++)

{ if (n == 0) { int k = rand( ) % 3; if (k == 0 || k == 1) { a[i][j] = 2; }

else { a[i][j] = 4; } n--; }

else { a[i][j] = 0; n--; }

}

}

adnum( );

system("cls");

CONSOLE_CURSOR_INFO cursor_info={1,0}; //以下兩行是隱藏游標的設置

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);

setColor(14, 0); //設置字體淡黃色,背景為黑色

printf(" 2048小游戲"); setColor(7, 0); //恢復白字黑底

printf(" ┌──────┬──────┬──────┬──────┐");

printf(" │ │ │ │ │");

printf(" ├──────┼──────┼──────┼──────┤");

printf(" │ │ │ │ │");

printf(" ├──────┼──────┼──────┼──────┤");

printf(" │ │ │ │ │");

printf(" ├──────┼──────┼──────┼──────┤");

printf(" │ │ │ │ │");

printf(" └──────┴──────┴──────┴──────┘");

show( );

}

void show( ) //輸出界面

{ for(i=0;i<4;i++)

for(j=0;j<4;j++)

{ gtxy(7*j+9,2*i+4); //gtxy(7*j+9, 2*i+4)是游標到指定位置輸出數字

if(a[i][j]==0){printf(" "); setColor(7, 0); printf("│");}

else if(a[i][j]<10){ if (a[i][j] == 2) {setColor(14, 0); }

else if (a[i][j] == 4) {setColor(13, 0); }

else if (a[i][j] == 8) {setColor(12, 0); }

printf(" %d ", a[i][j]); setColor(7, 0); printf("│");

}

else if (a[i][j] < 100){if (a[i][j] == 16) {setColor(12, 0); }

else if (a[i][j] == 32) {setColor(10, 0); }

else if (a[i][j] == 64) {setColor(2, 0); }

printf(" %d ", a[i][j]); setColor(7, 0); printf("│");

}

else if (a[i][j] < 1000) {if (a[i][j] == 128) {setColor(9, 0); }

else if (a[i][j] == 256) {setColor(1, 0); }

else if (a[i][j] == 512) {setColor(13, 0); }

printf(" %d ", a[i][j]); setColor(7, 0); printf("│");

}

else if (a[i][j] < 10000) {if (a[i][j] == 1024) {setColor(5, 0); }

else {setColor(15, 0); }

printf(" %d ", a[i][j]); setColor(7, 0); printf("│");

}

}

if (jsk( ) == 0)

{ yes( ); if (over) { gtxy(9,12); setColor(10, 0);

printf(" 游戲結束!是否繼續? [ Y/N ]:"); }

}

}

void inkey( ) //按鍵輸入

{ int key;

while (1)

{ key = getch( );

if (over) { if (key == 89|| key == 121) {rsgm( ); continue; }

else if (key == 78|| key == 110) { return; }

else continue; }

ifnum = 0;

if(key==224)key=getch( );

switch (key)

{ case 75: left( ); break;

case 77: right( ); break;

case 72: up( ); break;

case 80: down( );break;

}

if (score > best) { best = score; }

if (ifnum) { adnum( ); show( ); }

}

}

int jsk( ) //計算空格數

{ int n = 0;

for (i = 0; i < 4; i++)

{ for (j = 0; j < 4; j++) { if ( a[i][j] == 0) {n++;} } }

return n;

}

void left( ) //向左移動

{ for (i = 0; i < 4; i++)

{for (j = 1, k = 0; j < 4; j++)

{ if (a[i][j] > 0)

{ if ( a[i][k] == a[i][j])

{ a[i][k] *= 2; k++;

score = score + 2 * a[i][j];

a[i][j] = 0; ifnum = 1; }

else if ( a[i][k] == 0) { a[i][k] = a[i][j]; a[i][j] = 0; ifnum = 1; }

else { a[i][k + 1] = a[i][j]; if ((k + 1) != j) { a[i][j] = 0; ifnum = 1; }

k++; }

}

}

}

}

void right( ) //向右移動

{for (i = 0; i < 4; i++)

{for (j = 2, k = 3; j >= 0; j--)

{if (a[i][j] > 0)

{ if (a[i][k] == a[i][j])

{a[i][k] *= 2; k--; score = score + 2 * a[i][j]; a[i][j] = 0; ifnum = 1; }

else if ( a[i][k] == 0) {a[i][k] = a[i][j]; a[i][j] = 0; ifnum = 1; }

else { a[i][k - 1] = a[i][j]; if ((k - 1) != j) { a[i][j] = 0; ifnum = 1; } k--; }

}

}

}

}

void up( ) //向上移動

{for (i = 0; i < 4; i++)

{for (j = 1, k = 0; j < 4; j++)

{if (a[j][i] > 0)

{if ( a[k][i] == a[j][i]) { a[k][i] *= 2; k++;score = score + 2 * a[j][i];

a[j][i] = 0; ifnum = 1; }

else if ( a[k][i] == 0) { a[k][i] = a[j][i]; a[j][i] = 0; ifnum = 1; }

else { a[k + 1][i] = a[j][i]; if ((k + 1) != j) { a[j][i] = 0; ifnum = 1; }

k++; }

}

}

}

}

void down( ) //向下移動

{ for (i = 0; i < 4; i++)

{for (j = 2, k = 3; j >= 0; j--)

{if (a[j][i] > 0)

{if (a[k][i] == a[j][i])

{a[k][i] *= 2; k--;score = score + 2 * a[j][i]; a[j][i] = 0; ifnum = 1; }

else if (a[k][i] == 0) {a[k][i] = a[j][i]; a[j][i] = 0; ifnum = 1; }

else {a[k - 1][i] = a[j][i];

if ((k - 1) != j) {a[j][i] = 0; ifnum = 1; } k--; }

}

}

}

}

void adnum( ) //添加隨機數

{ srand(time(0)); int n = rand( ) % jsk( );

for (int i = 0; i < 4; i++)

{for (int j = 0; j < 4; j++)

{ if (a[i][j] == 0) {if (n != 0) { n--; }

else {int k = rand() % 3;

if (k == 0 || k == 1) {a[i][j] = 2; return; }

else {a[i][j] = 4; return; } }

}

}

}

}

void yes( ) //游戲是否結束

{ for (int i = 0; i < 4; i++)

{for (int j = 0; j < 3; j++)

{if (a[i][j] == a[i][j + 1] || a[j][i] == a[j + 1][i]) {over = 0; return; }}

}

over = 1;

}

void gtxy(int x, int y) //控制游標位置的函數

{ COORD coord;

coord.X = x;

coord.Y = y;

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}

㈢ 懸賞100元錢。注釋一個java掃雷游戲源代碼,就是把每行的意思寫到後面就可以了!在線等。

import java.awt.*;
import javax.swing.*;
import java.util.Random;
import java.awt.event.*;

class Min extends JPanel //雷的類
{
//備註:滑鼠的左鍵 = 1;右鍵 = 3;中鍵 = 2
private int flag = 0,statu = 0; //定義雷的屬性 0:沒有打開 1:打開 2:標示為雷 3:不確定
//flag = 0 不是雷 ; flag = 1是雷
private int but,count = 0; //but:哪一個滑鼠鍵被按下去了 count:這個區域周圍有多少個雷
private int mx = 0,my = 0,mw = 10; //定義雷的坐標和寬度

public Min() //構造函數
{
statu = 0;
}
public Min(int f,int x,int y,int w)
//構造函數
{
flag = f;
mx = x;
my = y;
mw = w;
}
public int getFlag(){return flag;}
public int getStatu(){return statu;}
public int getMx(){return mx;}
public int getMy(){return my;}
public int getMw(){return mw;}
public int getCount(){return count;}
public void setFlag(int f){flag = f;}
public void setCount(int c){count = c;}
public void setData(int f,int x,int y,int w,int s)
//傳遞值
{
flag = f;
mx = (x-1)*w;
my = (y-1)*w;
mw = w-1;
statu = s;
}
//根據你點擊滑鼠的不同來改變雷的屬性
public int sendKey(int key)
{
//返回值,如果游戲結束則返回-1
int rtn = 1;
if(key == 3)
{
switch(statu)
{
case 1:
break;
case 2:
statu = 3;
break;
case 3:
statu = 0;
break;
case 0:
statu = 2;
break;
}
rtn = 1;
}
if(key == 1 && statu == 0)
{
switch(flag)
{
case 0:
statu = 1;
rtn = 2;
break;
case 1:
statu = 1;
rtn = -1;
break;
}
}
return rtn;
}
}

class DrawPanel extends JPanel
{
private int i,j;
private int f = 0; //if f = 1 then game over ,if f =2 then win
private int chx = 0,chy = 0; //專門記錄坐標x,y的值
private int msum = 6,ksum = 0; //msum:雷的個數,ksum:標示雷的個數
private int bx = 10,by = 10,bw = 40; //bx,by:棋盤的大小,bw:棋子的大小
public Min board[][] = {
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
};
// 畫坐標為ax,ay區域的雷的狀態
public void draw(Graphics g,int ax,int ay)
{
int x,y,w; // 坐標x,y;和寬度:w
int s,c,flag; //狀態;雷的個數;
int cx = bw/2 - 4;
int cy = bw/2 + 4;
x = board[ax][ay].getMx();
y = board[ax][ay].getMy();
w = board[ax][ay].getMw();
s = board[ax][ay].getStatu();
c = board[ax][ay].getCount();
flag= board[ax][ay].getFlag();

switch(s)
{
case 0: //沒有打開狀態
{
g.setColor(Color.black);
g.fillRect(x,y,w,w);
break;
}
case 1: //打開狀態
{
g.setColor(Color.blue);
g.fillRect(x,y,w,w);
if(c != 0 && flag == 0) //此處沒有雷
{
g.setColor(Color.red);
g.drawString(String.valueOf(c),x + cx,y + cy);
}
if(flag == 1) //此處有雷
{
g.setColor(Color.red);
g.fillRect(x,y,w,w);
g.setColor(Color.blue);
g.drawString(" 雷",x + cx,y + cy);
}
break;
}
case 2: //標雷狀態
{
g.setColor(Color.green);
g.fillRect(x,y,w,w);
g.setColor(Color.blue);
g.drawString(" 旗",x + cx,y + cy);
break;
}
case 3: //不確定狀態
{
g.setColor(Color.black);
g.fillRect(x,y,w,w);
g.setColor(Color.red);
g.drawString("?",x + cx,y + cy);
break;
}
default:
break;
}
}
// 沒有圖形器的繪圖函數:畫出坐標ax,ay的雷的狀態和圖形
public void draw(int ax,int ay)
{
Graphics g;
g = this.getGraphics();
draw(g,ax,ay);
}

//打開周圍沒有雷的地方,並且繪畫所在區域點擊左鍵觸發
public int openNoMin(int ax,int ay)
{
int i,j;

if(ax<1||ay<1||ax>bx||ay>by) return 0; //滑鼠點擊的區域出界了
if(board[ax][ay].getStatu() != 0) return 0; //如果此區域打開了,返回
board[ax][ay].sendKey(1); //如果返回值等於-1,就說明游戲結束
draw(ax,ay);
if(board[ax][ay].getFlag() == 1)
//如果游戲結束,把所有的雷都顯示出來
{
for(i = 1;i<=bx;i++)
{
for(j = 1;j <= by;j++)
{
if(board[i][j].getFlag() == 1)
{
board[i][j].sendKey(1);
draw(i,j);
}
}
}
return -1;
}
//如果游戲沒有結束
if(board[ax][ay].getCount() > 0)
{
ksum ++;
return 1; //周圍有雷,就不用打開周圍地區
}
if(board[ax][ay].getCount() == 0 && board[ax][ay].getFlag() == 0)
//周圍沒有雷,打開周圍地區,直到有雷的地區
{
openNoMin(ax-1,ay-1);openNoMin(ax,ay-1);openNoMin(ax+1,ay-1);
openNoMin(ax-1,ay ); openNoMin(ax+1,ay );
openNoMin(ax-1,ay+1);openNoMin(ax,ay+1);openNoMin(ax+1,ay+1);
}
ksum ++;
return 1;
}

//計算坐標x,y的周圍雷的個數
public int getCount(int ai,int aj)
{
int sum = 0;
if(board[ai][aj].getFlag() == 1)
{
return sum;
}

if(ai>1&&aj>1&&ai<bx&&aj<by)
{
sum = board[ai-1][aj-1].getFlag()+ board[ai][aj-1].getFlag()+ board[ai+1][aj-1].getFlag()+
board[ai-1][aj ].getFlag()+ board[ai+1][aj ].getFlag()+
board[ai-1][aj+1].getFlag()+ board[ai][aj+1].getFlag()+ board[ai+1][aj+1].getFlag();
}
if(ai==1&&aj==1)
{
sum = board[ai+1][aj ].getFlag()+
board[ai][aj+1].getFlag()+ board[ai+1][aj+1].getFlag();
}
if(ai==1&&aj==by)
{
sum = board[ai][aj-1].getFlag()+ board[ai+1][aj-1].getFlag()+
board[ai+1][aj ].getFlag();
}
if(ai==bx&&aj==1)
{
sum = board[ai-1][aj ].getFlag()+
board[ai-1][aj+1].getFlag()+ board[ai][aj+1].getFlag();
}
if(ai==bx&&aj==by)
{
sum = board[ai-1][aj-1].getFlag()+ board[ai][aj-1].getFlag()+
board[ai-1][aj ].getFlag();
}
if(ai==1&&aj>1&&aj<by)
{
sum = board[ai][aj-1].getFlag()+ board[ai+1][aj-1].getFlag()+
board[ai+1][aj ].getFlag()+
board[ai][aj+1].getFlag()+ board[ai+1][aj+1].getFlag();
}
if(ai==bx&&aj>1&&aj<by)
{
sum = board[ai-1][aj-1].getFlag()+ board[ai][aj-1].getFlag()+
board[ai-1][aj ].getFlag()+
board[ai-1][aj+1].getFlag()+ board[ai][aj+1].getFlag();
}
if(ai>1&&ai<bx&&aj==1)
{
sum = board[ai-1][aj ].getFlag()+ board[ai+1][aj ].getFlag()+
board[ai-1][aj+1].getFlag()+ board[ai][aj+1].getFlag()+ board[ai+1][aj+1].getFlag();
}
if(ai>1&&ai<bx&&aj==by)
{
sum = board[ai-1][aj-1].getFlag()+ board[ai][aj-1].getFlag()+ board[ai+1][aj-1].getFlag()+
board[ai-1][aj ].getFlag()+ board[ai+1][aj ].getFlag();
}
return sum;
}

// 傳入參數:幾列,幾行,寬度,雷數
public void initMin(int ax,int ay,int aw,int as)
{
int k = 1; //表明產生的第幾個雷
Random r; //隨機數

f = 0; //f=0表示游戲還沒有結束
ksum = 0;
bx = ax;
by = ay;
bw = aw;
msum = as;
r = new Random();
//初始化底盤的值
for(i = 1;i <= bx;i++)
{
for(j=1;j<=by;j++)
{
board[i][j].setData(0,i,j,bw,0);
}
}
// 隨機產生雷
while(k <= msum)
{
i = r.nextInt(bx)+1;
j = r.nextInt(by)+1;
if(board[i][j].getFlag() != 1)
{
board[i][j].setFlag(1);
k++;
}
}
// 非雷區的周圍有幾個雷,初始化其值
for(i = 1;i <= bx;i++)
{
for(j=1;j<=by;j++)
{
board[i][j].setCount(getCount(i,j));
}
}

setBackground(Color.white);
repaint();
}
// 構造函數
public DrawPanel(int ax,int ay,int aw,int as)
{
initMin(ax,ay,aw,as);
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent me)
{
int r;
if(f != 0) return; //如果游戲結束,返回
chx = me.getX();
chy = me.getY();
if(me.getButton() != 1)
{
board[chx/bw+1][chy/bw+1].sendKey(me.getButton());
draw(chx/bw+1,chy/bw+1);
}
else if(me.getButton() == 1)
{
if(openNoMin(chx/bw+1,chy/bw+1) == -1)
{
f = 1;
repaint();
}
else if ( ksum + msum == bx*by )
{
f = 2;
repaint();
}
}
}
}
);
}
// 重畫所有的圖形,包括一些修飾的圖形
public void paint(Graphics g)
{
int x,y,w;
int s;
int cx = bw/2 - 4;
int cy = bw/2 + 4;

g.clearRect(0,0,600,600);
for(i=1;i<=bx;i++)
{
for(j=1;j<=by;j++)
{
draw(g,i,j);
}
}
if(f == 1)
{
Font f = new Font("11",1,70);
Font fo = g.getFont();
g.setColor(Color.white);
g.setFont(f);
//g.setSize();
g.drawString("Game Over",0,200);
g.setFont(fo);
}
if( f == 2 )
{
Font f = new Font("11",1,70);
Font fo = g.getFont();
g.setColor(Color.white);
g.setFont(f);
//g.setSize();
g.drawString("You win!",0,200);
g.setFont(fo);
}
}

};
// 主類和程序的入口
public class Mine extends JFrame implements ActionListener
{
Container cp = getContentPane();
JButton bt = new JButton("開局");
Label l1 = new Label("列:");
Label l2 = new Label("行:");
Label l3 = new Label("寬度:");
Label l4 = new Label("雷的個數:");
TextField tf1 = new TextField("10",2); //列
TextField tf2 = new TextField("10",2); //行
TextField tf3 = new TextField("40",2); //寬度
TextField tf4 = new TextField("15",2); //雷的個數
int x=10,y=10,w=40,sum=15;
DrawPanel dp = new DrawPanel(x,y,w,sum);

public Mine()
{
setBackground(Color.white);
cp.setLayout(null);
cp.add(dp);
cp.add(bt);
cp.add(tf1);
cp.add(tf2);
cp.add(tf3);
cp.add(tf4);
cp.add(l1);
cp.add(l2);
cp.add(l3);
cp.add(l4);

l1.setBounds(20 ,10,20,20);
tf1.setBounds(40,10,20,20);
l2.setBounds(70,10,20,20);
tf2.setBounds(90,10,20,20);
l3.setBounds(120,10,40,20);
tf3.setBounds(160,10,20,20);
l4.setBounds(190,10,60,20);
tf4.setBounds(250,10,20,20);
bt.setBounds(300,10,80,20);
dp.setBounds(20,40,x*w,y*w);
setResizable(false);
setSize(x*w+40,y*w+80);
setTitle(" 掃雷");
show();
bt.addActionListener(this);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{System.exit(0);}
}
);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == bt)
{
//x = Integer.parseInt(tf1.getText());
//y = Integer.parseInt(tf2.getText());
//w = Integer.parseInt(tf3.getText());
sum = Integer.parseInt(tf4.getText());
setSize(x*w+40,y*w+80);
dp.setBounds(20,40,x*w,y*w);
show();
dp.initMin(x,y,w,sum);
}
}
public static void main(String args[])
{
new Mine();
}
};

㈣ 紅包掃雷玩法介紹

合理適度的游戲允許人類在模擬環境下挑戰和克服障礙,可以幫助人類開發智力、鍛煉思維和反應能力、訓練技能、培養規則意識等,大型網路游戲還可以培養戰略戰術意識和團隊精神。以下是我為大家收集的紅包掃雷玩法介紹,僅供參考,歡迎大家閱讀。

紅包掃雷玩法介紹1

微信紅包掃雷怎麼玩的?

1、下載微信紅包掃雷這款軟體,打開。

2、在「設置——輔助功能——微信紅包掃雷軟體」里,點擊「開啟」。

3、打開微信,在「設置——新消息提醒」里,前兩個選項「接受新消息通知」和「通知顯示消息詳情」均勾選「開啟」。(好多人就是這一步忘記做了)

4、打開某一個微信群組,點擊右上角,往下拉,「消息免打擾」選項,勾選「關閉」。(也就是要把「群消息的提示保持在開啟」的狀態,這樣才能觸系統發底層介面。)

5、在微信紅包掃雷軟體,勾選「開啟自動搶紅包」「牛牛金額調改」「接龍金額調改」「三公金額調改」等等。

6、如果你還沒有成功,首先確認你是智能手機(包括蘋果需越獄安卓直接可用),其次需要你的微信升級到最新版本。

微信紅包掃雷技巧規則

1、首先隨便調改紅包兩位尾數數字,也可調成隨機號碼,比如1,1,2,3,4,5……

2、開啟微信紅包掃雷軟體可以在第一時間幫你搶到別人的紅包。

3、同時微信紅包掃雷這款軟體可以幫你搶到數額較大的紅包。

4、微信紅包掃雷軟體可以隨意調整微信紅包裡面的`金額。

紅包掃雷玩法介紹2

1在「開始」——「游戲」中找到「掃雷」並打開游戲。

2「掃雷」中有「初級」,「中級」和「高級」三種難度,玩家可根據自身情況進行選擇以進行游戲。

3單擊方塊查看該方塊周圍有多少地雷。三個1中間夾的格子肯定是雷但並不是所有的被1包圍的個子都是雷。

4翻開所有的方塊而沒有顯示地雷即為獲勝。祝大家玩得開心,玩得愉快!

㈤ 求助Java掃雷源碼注釋

import java.awt.*;
import java.util.*;
import java.io.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
import javax.swing.border.*;
/**
* <p>Title:掃雷</p>
*
* <p>Description:學JAVA以來做的第一個游戲,程序中可能還有些BUG,希望大家提出來供一起探討,
* 如果要測試記錄文件,可以把雷的數量改的少一點,
* arithmetic中的while(landmintTally<99), button_mouseClicked中的
* if((landmineNum-1)==0),有3處,表示還剩的雷數.completeGame中的
* for (int i=0; i<99; i++)</p>
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: private </p>
*
* @author cqp
* @version demo
*/
public class shaolei extends JFrame {

/**類的屬性和控制項實例化*/
ImageIcon ButtonIcon; //按鈕的圖片;
HashMap map = new HashMap(); //雷和數字的狀態,鍵為位置(0-479),值為狀態,0-6為數字,7為雷;
HashMap flag_landmine = new HashMap(); //按鈕上打的標記,如問號,對勾和取消,8為標記雷,9為問號,10為默認值空;
JMenuBar file = new JMenuBar(); //菜單欄;
JMenu game = new JMenu(); //菜單按鈕;
JMenuItem start = new JMenuItem(); //菜單項;
JMenuItem record = new JMenuItem(); //菜單項;
JMenuItem quit = new JMenuItem(); //菜單項;
JMenuItem clearReocrd = new JMenuItem();//菜單項;
JMenu help = new JMenu(); //菜單按鈕;
JButton[] cardsBtn = new JButton[480]; //480個按鈕;
JButton beginBtn = new JButton(); //開始按鈕;
JPanel pane = new JPanel(); //雷區面板;
JPanel paneTime = new JPanel(); //記數器所在的面板;
JOptionPane saveRecord = new JOptionPane(); //保存記錄對話框;
JTextField landmineTally = new JTextField("99");//所剩雷的計數器;
JTextField timeTally = new JTextField("0"); //時間計數器;
GridLayout gridLayout1 = new GridLayout(); //網格布局;
Timer timer; //線程設施;
String[] landmine = new String[99]; //存放雷的位置,用來判斷雷的位置是否重復;
slFrame_button_actionAdatper[] buttonClick =new slFrame_button_actionAdatper[480];//雷區按鈕的事件類;
int mouseKey=0; //得到滑鼠先按下的哪個鍵,用來判斷滑鼠是否同時按下了左右鍵;
int timeCount = 0; //時間計數器;

/**構造方法*/
public shaolei() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}

/**界面設置*/
private void jbInit() throws Exception {
getContentPane().setLayout(null);
this.setJMenuBar(file);
game.setText("游戲");
start.setText("開局");
start.addActionListener(new slFrame_start_actionAdapter(this));
record.setText("排行榜");
record.addActionListener(new slFrame_record_actionAdapter(this));
quit.setText("退出");
quit.addActionListener(new slFrame_quit_actionAdapter(this));
help.setText("幫助");
clearReocrd.setText("清除記錄");
clearReocrd.addActionListener(new slFrame_clearReocrd_actionAdapter(this));
landmineTally.setBounds(new Rectangle(5, 5, 40, 25));
landmineTally.setBackground(new Color(0,0,0));
landmineTally.setForeground(new Color(255,0,0));
landmineTally.setFont(new java.awt.Font("Times New Roman", Font.BOLD, 20));
landmineTally.setBorder(BorderFactory.createBevelBorder(1));
landmineTally.setEditable(false);
timeTally.setBounds(new Rectangle(520, 5, 50, 25));
timeTally.setBackground(new Color(0,0,0));
timeTally.setForeground(new Color(255,0,0));
timeTally.setHorizontalAlignment(4);
timeTally.setFont(new java.awt.Font("Times New Roman", Font.BOLD, 20));
timeTally.setBorder(BorderFactory.createBevelBorder(0));
timeTally.setEditable(false);
beginBtn.setBounds(new Rectangle(250, 5, 25, 25));
beginBtn.setBorder(BorderFactory.createBevelBorder(0));
beginBtn.addActionListener(new slFrame_beginBtn_actionAdatper(this));
beginBtn.setIcon(createImageIcon("images/laugh.jpg"));
paneTime.setBounds(new Rectangle(0, 0, 585, 35));
paneTime.setBorder(BorderFactory.createEtchedBorder());
paneTime.setLayout(null);
paneTime.add(landmineTally);
paneTime.add(timeTally);
paneTime.add(beginBtn);
pane.setBounds(new Rectangle(0, 35, 590, 320));
pane.setLayout(gridLayout1);
gridLayout1.setColumns(30);
gridLayout1.setRows(16);
file.add(game);
file.add(help);
game.add(start);
game.add(record);
game.add(quit);
help.add(clearReocrd);
this.getContentPane().add(pane);
this.getContentPane().add(paneTime);

ActionListener listener = new ActionListener(){ //自定義線程
public void actionPerformed(ActionEvent e){
timeCount++;
timeTally.setText(Integer.toString(timeCount));
}
};
timer = new Timer(1000, listener); //增加線程,並每1秒執行一次;

for (int i=0;i<480;i++) //實例化480個小按鈕加到面板pane中
{
cardsBtn[i] = new JButton();
cardsBtn[i].setText(""); //按鈕上的文字去掉;
cardsBtn[i].setBorder(null); //按鈕的邊框去掉;
pane.add(cardsBtn[i]);
}
}

/**主方法*/
public static void main(String[] args) {
shaolei frame = new shaolei();
frame.setSize(580,410);
frame.setTitle("掃雷");
frame.show();
frame.setResizable(false); //不能修改窗體大小
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //點關閉按鈕時直
}

/**自定義方法,用來給按鈕增加圖片*/
protected static ImageIcon createImageIcon(String path){
java.net.URL imgURL = shaolei.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}

/**菜單按鈕的事件,開始游戲*/
public void start_actionPerformed(ActionEvent e) {
start(); //初始化;
arithmetic(); //計算雷的位置;
calculate(); //計算雷的分布情況;
timer.start(); //時間線程開始;
}

/**開始游戲按鈕的事件*/
public void beginBtn_mouseClicked(ActionEvent e){
start_actionPerformed(e); //直接調用菜單的事件;
}

/**自定義方法,游戲從這里開始,方法里對按鈕的屬性和狀態進行初始化;*/
void start(){
timeCount=0; //時間從0開始;
landmineTally.setText("99");//所剩雷數為99;
for (int i = 0; i<480; i++){
cardsBtn[i].setIcon(null); //清除按鈕上的圖片;
map.put( Integer.toString(i),Integer.toString(10)); //分布狀態全為10,表示為空;
flag_landmine.put( Integer.toString(i),Integer.toString(10)); //標記狀態全為10;
cardsBtn[i].removeMouseListener(buttonClick[i]); //去除雷區所有按鈕的滑鼠事件;
}
}

/**自定義方法,用來計算雷的分布位置*/
void arithmetic(){
Calendar time = Calendar.getInstance(); //日歷類,得到當前時間;
int leed = time.get(Calendar.SECOND); //得到當前時間的秒;
Random rand = new Random(leed); //把秒數當個隨機數的種子;
int tempRand; //臨時隨機數;
int landmintTally=0; //得到多少雷的計數器;
boolean flag=false; //標記是否重復;
int tempNum;
while(landmintTally < 99){ //最多隻能有99顆雷;
tempRand = (int)(rand.nextFloat()*480); //得隨機數;
tempNum = Integer.parseInt(map.get(Integer.toString(tempRand)).toString());
if (tempNum == 7) continue; //如果重復執行一個數字;
landmine[landmintTally] = Integer.toString(tempRand); //把得到的位置放進字元串;
map.put(Integer.toString(tempRand),Integer.toString(7)); //把得到的位置放到map集合里,值為7,表示有雷;
landmintTally++; //計數器加1;
}
}

/**計算雷的分部情況,指一個按鈕周圍有多少雷;*/
void calculate()
{
int num; //按鈕的狀態;
int sum=0; //計數器,計算周圍有幾顆雷;
int leftUp, up, rightUp, left, right, leftDown, down, rightDown; //定義了8個位置
for (int i = 0; i<480; i++)
{
leftUp = i-31;
up = i-30;
rightUp = i-29;
left = i-1;
right = i+1;
leftDown = i+29;
down = i+30;
rightDown= i+31;
cardsBtn[i].setBorder(BorderFactory.createBevelBorder(0)); //設置按鈕的邊框樣式;
buttonClick[i] = new slFrame_button_actionAdatper(this,i); //實例化事件類;
cardsBtn[i].addMouseListener(buttonClick[i]); //給當前按鈕添加滑鼠事件;
num = Integer.parseInt(map.get(Integer.toString(i)).toString());//得到當前按鈕的狀態;
if (num == 7){
continue; //如果這個按鈕的狀態為雷,跳到下個按鈕;
}

if (i == 0) { //左上角第一顆雷;
num = Integer.parseInt(map.get(Integer.toString(i)).toString());
if ( Integer.parseInt(map.get(Integer.toString(right)).toString()) == 7 ) sum++; //如果是雷計數器加1;
if ( Integer.parseInt(map.get(Integer.toString(down)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightDown)).toString()) == 7 ) sum++;
map.put(Integer.toString(0),Integer.toString(sum)); //把得到的數字放到當前的位置;
sum=0; //計數器清零;
continue; //下個按鈕;
}else if (i == 29) { //右上角第一顆雷;
if ( Integer.parseInt(map.get(Integer.toString(left)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(leftDown)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(down)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
continue;
}else if (i == 450) { //左下角第一顆雷;
if ( Integer.parseInt(map.get(Integer.toString(right)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(up)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightUp)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
continue;
}else if (i == 479) { //右下角第一顆雷;
if ( Integer.parseInt(map.get(Integer.toString(left)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(leftUp)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(up)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
return;
}else if (i<29){ //第一行;
if ( Integer.parseInt(map.get(Integer.toString(left)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(leftDown)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(down)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(right)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightDown)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
continue;
}else if (i>450){ //最後一行;
if ( Integer.parseInt(map.get(Integer.toString(leftUp)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(up)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightUp)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(left)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(right)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
continue;
}else if ( (i%30) == 0 ){ //第一列;
if ( Integer.parseInt(map.get(Integer.toString(up)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightUp)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(right)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(down)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightDown)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
continue;
}else if ( ((i+1)%30) == 0 ){ //最後一列;
if ( Integer.parseInt(map.get(Integer.toString(leftUp)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(up)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(left)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(leftDown)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(down)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
continue;
}else{ //除去四周剩下的;
if ( Integer.parseInt(map.get(Integer.toString(leftUp)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(up)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightUp)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(left)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(right)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(leftDown)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(down)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightDown)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
continue;
}
}
}

/**滑鼠點擊事件,參數i為點擊按鈕的位置 */
public void button_mouseClicked(MouseEvent e,int i){
int mKey = e.getButton(); //點擊的哪個鍵;
int landmineNum = Integer.parseInt(landmineTally.getText().toString()); //所剩的雷數;
int num = Integer.parseInt(map.get(Integer.toString(i)).toString()); //當前按鈕的狀態;
int flag = Integer.parseInt(flag_landmine.get(Integer.toString(i)).toString());//當前按鈕的標記狀態;

if ( (mKey == 3) && ( cardsBtn[i].getBorder()!= null)){ //點擊為滑鼠右鍵,並且邊框不為空(空的表示已按亮開的);
if (flag == 10){ //如果沒有標記,則改為標記狀態;
flag_landmine.put(Integer.toString(i),Integer.toString(8));
ButtonIcon = createImageIcon("images/8.jpg");
cardsBtn[i].setIcon(ButtonIcon);
landmineTally.setText( Integer.toString(landmineNum - 1) );
if ( (landmineNum-1) == 0) //如果標記的雷數為99;
completeGame(); //完成游戲;
}else if (flag == 8){ //如果為標記狀態,則改為問號;
flag_landmine.put(Integer.toString(i),Integer.toString(9));
ButtonIcon = createImageIcon("images/9.jpg");
cardsBtn[i].setIcon(ButtonIcon);
landmineTally.setText( Integer.toString(landmineNum + 1) );
if ( (landmineNum+1) == 0) //如果標記的雷數為99;
completeGame(); //完成游戲;
}else if (flag == 9){ //如果為問號,則取消標記;
flag_landmine.put(Integer.toString(i),Integer.toString(10));
cardsBtn[i].setIcon(null);
}
}else if (mKey == 1){ //如果點擊為滑鼠左鍵;
flag_landmine.put(Integer.toString(i),Integer.toString(10)); //先清除所點擊按鈕的標記狀態;
if ( (landmineNum+1) == 0) //如果標記的雷數為99;
completeGame(); //完成游戲;
if (num == 7){ //如果銨鈕的狀態為雷,則結束游戲;
overGame(i);
}else if (num == 0){ //如果雷數為空
if ( flag == 8 ){ //如果已經標記為雷,計數器加1;
landmineTally.setText( Integer.toString(landmineNum + 1) );
}
ButtonIcon = createImageIcon("images/0.jpg");
cardsBtn[i].setIcon(ButtonIcon);
cardsBtn[i].setBorder(null);
display(i); //亮開周圍的按鈕;
}else { //數字為1-6之間,亮開按鈕,並顯示數字所對應的圖片;
if ( flag == 8 ){ //如果已經標記為雷,計數器加1;
landmineTally.setText( Integer.toString(landmineNum + 1) );
}
ButtonIcon = createImageIcon("images/"+num+".jpg");
cardsBtn[i].setIcon(ButtonIcon);
cardsBtn[i].setBorder(null);
}
}
if ( (mouseKey==1 && mKey == 3) || (mouseKey==3 && mKey == 1) ){ //滑鼠左右鍵同時點按下;
open(i); //亮開周圍的按鈕(先判斷);

}
mouseKey = 0;
}

/**自定義方法,用來判斷是否要亮開周圍的按鈕*/
void open(int i){
int landmineAmount = 0; //實際的雷數;
int flagAmount=0; //標記的雷數;
int landmine_leftUp=0, landmine_up=0, landmine_rightUp=0, landmine_left=0, landmine_right=0,
landmine_leftDown=0, landmine_down=0, landmine_rightDown=0; //定義了實際雷的8個位置
int flag_leftUp=0, flag_up=0, flag_rightUp=0, flag_left=0, flag_right=0,
flag_leftDown=0, flag_down=0, flag_rightDown=0; //定義了標記雷的8個位置

//實際雷所在的8個位置和標記雷的8個位置,如果不加判斷則hashMap集合會越界;
if (i > 31) landmine_leftUp = Integer.parseInt(map.get(Integer.toString(i-31)).toString());
if (i > 30) landmine_up = Integer.parseInt(map.get(Integer.toString(i-30)).toString());
if (i > 29) landmine_rightUp = Integer.parseInt(map.get(Integer.toString(i-29)).toString());
if (i > 1) landmine_left = Integer.parseInt(map.get(Integer.toString(i-1)).toString());
if (i < 479) landmine_right = Integer.parseInt(map.get(Integer.toString(i+1)).toString());
if (i < 450) landmine_leftDown = Integer.parseInt(map.get(Integer.toString(i+29)).toString());
if (i < 449) landmine_down = Integer.parseInt(map.get(Integer.toString(i+30)).toString());
if (i < 448) landmine_rightDown = Integer.parseInt(map.get(Integer.toString(i+31)).toString());

if (i > 31) flag_leftUp = Integer.parseInt(flag_landmine.get(Integer.toString(i-31)).toString());
if (i > 30) flag_up = Integer.parseInt(flag_landmine.get(Integer.toString(i-30)).toString());
if (i > 29) flag_rightUp = Integer.parseInt(flag_landmine.get(Integer.toString(i-29)).toString());
if (i > 1) flag_left = Integer.parseInt(flag_landmine.get(Integer.toString(i-1)).toString());
if (i < 479) flag_right = Integer.parseInt(flag_landmine.get
太長了寫不完,我把壓縮包發給你吧,49905518注意查收

㈥ C++掃雷源代碼

這是字元界面的掃雷:

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <windows.h>
#include <conio.h>

// defines
#define KEY_UP 0xE048
#define KEY_DOWN 0xE050
#define KEY_LEFT 0xE04B
#define KEY_RIGHT 0xE04D
#define KEY_ESC 0x001B
#define KEY_1 '1'
#define KEY_2 '2'
#define KEY_3 '3'
#define GAME_MAX_WIDTH 100
#define GAME_MAX_HEIGHT 100

// Strings Resource
#define STR_GAMETITLE "ArrowKey:MoveCursor Key1:Open \
Key2:Mark Key3:OpenNeighbors"
#define STR_GAMEWIN "Congratulations! You Win! Thank you for playing!\n"
#define STR_GAMEOVER "Game Over, thank you for playing!\n"
#define STR_GAMEEND "Presented by yzfy . Press ESC to exit\n"

//-------------------------------------------------------------
// Base class
class CConsoleWnd
{
public:
static int TextOut(const char*);
static int GotoXY(int, int);
static int CharOut(int, int, const int);
static int TextOut(int, int, const char*);
static int GetKey();
public:
};

//{{// class CConsoleWnd
//
// int CConsoleWnd::GetKey()
// Wait for standard input and return the KeyCode
//
int CConsoleWnd::GetKey()
{
int nkey=getch(),nk=0;
if(nkey>=128||nkey==0)nk=getch();
return nk>0?nkey*256+nk:nkey;
}

//
// int CConsoleWnd::GotoXY(int x, int y)
// Move cursor to (x,y)
// Only Console Application
//
int CConsoleWnd::GotoXY(int x, int y)
{
COORD cd;
cd.X = x;cd.Y = y;
return SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),cd);
}

//
// int CConsoleWnd::TextOut(const char* pstr)
// Output a string at current position
//
int CConsoleWnd::TextOut(const char* pstr)
{
for(;*pstr;++pstr)putchar(*pstr);
return 0;
}

//
// int CConsoleWnd::CharOut(int x, int y, const int pstr)
// Output a char at (x,y)
//
int CConsoleWnd::CharOut(int x, int y, const int pstr)
{
GotoXY(x, y);
return putchar(pstr);
}

//
// int CConsoleWnd::TextOut(const char* pstr)
// Output a string at (x,y)
//
int CConsoleWnd::TextOut(int x, int y, const char* pstr)
{
GotoXY(x, y);
return TextOut(pstr);
}
//}}

//-------------------------------------------------------------
//Application class
class CSLGame:public CConsoleWnd
{
private:
private:
int curX,curY;
int poolWidth,poolHeight;
int bm_gamepool[GAME_MAX_HEIGHT+2][GAME_MAX_WIDTH+2];
public:
CSLGame():curX(0),curY(0){poolWidth=poolHeight=0;}
int InitPool(int, int, int);
int MoveCursor(){return CConsoleWnd::GotoXY(curX, curY);}
int DrawPool(int);
int WaitMessage();
int GetShowNum(int, int);
int TryOpen(int, int);
private:
int DFSShowNum(int, int);
private:
const static int GMARK_BOOM;
const static int GMARK_EMPTY;
const static int GMARK_MARK;
};
const int CSLGame::GMARK_BOOM = 0x10;
const int CSLGame::GMARK_EMPTY= 0x100;
const int CSLGame::GMARK_MARK = 0x200;

//{{// class CSLGame:public CConsoleWnd
//
// int CSLGame::InitPool(int Width, int Height, int nBoom)
// Initialize the game pool.
// If Width*Height <= nBoom, or nBoom<=0,
// or Width and Height exceed limit , then return 1
// otherwise return 0
//
int CSLGame::InitPool(int Width, int Height, int nBoom)
{
poolWidth = Width; poolHeight = Height;
if(nBoom<=0 || nBoom>=Width*Height
|| Width <=0 || Width >GAME_MAX_WIDTH
|| Height<=0 || Height>GAME_MAX_HEIGHT
){
return 1;
}
// zero memory
for(int y=0; y<=Height+1; ++y)
{
for(int x=0; x<=Width+1; ++x)
{
bm_gamepool[y][x]=0;
}
}
// init seed
srand(time(NULL));
// init Booms
while(nBoom)
{
int x = rand()%Width + 1, y = rand()%Height + 1;
if(bm_gamepool[y][x]==0)
{
bm_gamepool[y][x] = GMARK_BOOM;
--nBoom;
}
}
// init cursor position
curX = curY = 1;
MoveCursor();
return 0;
}

//
// int CSLGame::DrawPool(int bDrawBoom = 0)
// Draw game pool to Console window
//
int CSLGame::DrawPool(int bDrawBoom = 0)
{
for(int y=1;y<=poolHeight;++y)
{
CConsoleWnd::GotoXY(1, y);
for(int x=1;x<=poolWidth;++x)
{
if(bm_gamepool[y][x]==0)
{
putchar('.');
}
else if(bm_gamepool[y][x]==GMARK_EMPTY)
{
putchar(' ');
}
else if(bm_gamepool[y][x]>0 && bm_gamepool[y][x]<=8)
{
putchar('0'+bm_gamepool[y][x]);
}
else if(bDrawBoom==0 && (bm_gamepool[y][x] & GMARK_MARK))
{
putchar('#');
}
else if(bm_gamepool[y][x] & GMARK_BOOM)
{
if(bDrawBoom)
putchar('*');
else
putchar('.');
}
}
}
return 0;
}

//
// int CSLGame::GetShowNum(int x, int y)
// return ShowNum at (x, y)
//
int CSLGame::GetShowNum(int x, int y)
{
int nCount = 0;
for(int Y=-1;Y<=1;++Y)
for(int X=-1;X<=1;++X)
{
if(bm_gamepool[y+Y][x+X] & GMARK_BOOM)++nCount;
}
return nCount;
}

//
// int CSLGame::TryOpen(int x, int y)
// Try open (x, y) and show the number
// If there is a boom, then return EOF
//
int CSLGame::TryOpen(int x, int y)
{
int nRT = 0;
if(bm_gamepool[y][x] & GMARK_BOOM)
{
nRT = EOF;
}
else
{
int nCount = GetShowNum(x,y);
if(nCount==0)
{
DFSShowNum(x, y);
}
else bm_gamepool[y][x] = nCount;
}
return nRT;
}

//
// int CSLGame::DFSShowNum(int x, int y)
// Private function, no comment
//
int CSLGame::DFSShowNum(int x, int y)
{
if((0<x && x<=poolWidth) &&
(0<y && y<=poolHeight) &&
(bm_gamepool[y][x]==0))
{
int nCount = GetShowNum(x, y);
if(nCount==0)
{
bm_gamepool[y][x] = GMARK_EMPTY;
for(int Y=-1;Y<=1;++Y)
for(int X=-1;X<=1;++X)
{
DFSShowNum(x+X,y+Y);
}
}
else bm_gamepool[y][x] = nCount;
}
return 0;
}

//
// int CSLGame::WaitMessage()
// Game loop, wait and process an input message
// return: 0: not end; 1: Win; otherwise: Lose
//
int CSLGame::WaitMessage()
{
int nKey = CConsoleWnd::GetKey();
int nRT = 0, nArrow = 0;
switch (nKey)
{
case KEY_UP:
{
if(curY>1)--curY;
nArrow=1;
}break;
case KEY_DOWN:
{
if(curY<poolHeight)++curY;
nArrow=1;
}break;
case KEY_LEFT:
{
if(curX>1)--curX;
nArrow=1;
}break;
case KEY_RIGHT:
{
if(curX<poolWidth)++curX;
nArrow=1;
}break;
case KEY_1:
{
nRT = TryOpen(curX, curY);
}break;
case KEY_2:
{
if((bm_gamepool[curY][curX]
& ~(GMARK_MARK|GMARK_BOOM))==0)
{
bm_gamepool[curY][curX] ^= GMARK_MARK;
}
}break;
case KEY_3:
{
if(bm_gamepool[curY][curX] & 0xF)
{
int nb = bm_gamepool[curY][curX] & 0xF;
for(int y=-1;y<=1;++y)
for(int x=-1;x<=1;++x)
{
if(bm_gamepool[curY+y][curX+x] & GMARK_MARK)
--nb;
}
if(nb==0)
{
for(int y=-1;y<=1;++y)
for(int x=-1;x<=1;++x)
{
if((bm_gamepool[curY+y][curX+x]
& (0xF|GMARK_MARK)) == 0)
{
nRT |= TryOpen(curX+x, curY+y);
}
}
}
}
}break;
case KEY_ESC:
{
nRT = EOF;
}break;
}
if(nKey == KEY_1 || nKey == KEY_3)
{
int y=1;
for(;y<=poolHeight;++y)
{
int x=1;
for(;x<=poolWidth; ++x)
{
if(bm_gamepool[y][x]==0)break;
}
if(x<=poolWidth) break;
}
if(! (y<=poolHeight))
{
nRT = 1;
}
}
if(nArrow==0)
{
DrawPool();
}
MoveCursor();
return nRT;
}
//}}

//-------------------------------------------------------------
//{{
//
// main function
//
int main(void)
{
int x=50, y=20, b=100,n; // define width & height & n_booms
CSLGame slGame;
// Init Game
{
CConsoleWnd::GotoXY(0,0);
CConsoleWnd::TextOut(STR_GAMETITLE);
slGame.InitPool(x,y,b);
slGame.DrawPool();
slGame.MoveCursor();
}
while((n=slGame.WaitMessage())==0) // Game Message Loop
;
// End of the Game
{
slGame.DrawPool(1);
CConsoleWnd::TextOut("\n");
if(n==1)
{
CConsoleWnd::TextOut(STR_GAMEWIN);
}
else
{
CConsoleWnd::TextOut(STR_GAMEOVER);
}
CConsoleWnd::TextOut(STR_GAMEEND);
}
while(CConsoleWnd::GetKey()!=KEY_ESC)
;
return 0;
}
//}}

㈦ 怎麼玩微信紅包掃雷

以下是我將要分享給大家的關於怎麼玩微信紅包掃雷的一些攻略技巧,希望大家喜歡!更多的好玩有趣游戲攻略盡在經驗網游戲欄目!大家一起來關注吧。

微信紅包掃雷怎麼玩的?

1、下載微信紅包掃雷這款軟體,打開。

2、在「設置——輔助功能——微信紅包掃雷軟體」里,點擊「開啟」。

3、打開微信,在「設置——新消息提醒」里,前兩個選項「接受新消息通知」和「通知顯示消息詳情」均勾選「開啟」。(好多人就是這一步忘記做了)

4、打開某一個微信群組,點擊右上角,往下拉,「消息免打擾」選項,勾選「關閉」。(也就是要把「群消息的提示保持在開啟」的狀態,這樣才能觸系統發底層介面。)

5、在微信紅包掃雷軟體,勾選「開啟自動搶紅包」「牛牛金額調改」「接龍金額調改」「三公金額調改」等等。

6、如果你還沒有成功,首先確認你是智能手機(包括蘋果需越獄安卓直接可用),其次需要你的微信升級到最新版本。

微信紅包掃雷技巧規則

1、首先隨便調改紅包兩位尾數數字,也可調成隨機號碼,比如1,1,2,3,4,5......

2、開啟微信紅包掃雷軟體可以在第一時間幫你搶到別人的'紅包。

3、同時微信紅包掃雷這款軟體可以幫你搶到數額較大的紅包。

4、微信紅包掃雷軟體可以隨意調整微信紅包裡面的金額。

熱點內容
c語言演算法結構 發布:2024-11-29 07:23:08 瀏覽:222
空氣壓縮呼吸 發布:2024-11-29 07:23:00 瀏覽:56
百望雲伺服器設備編號必填 發布:2024-11-29 07:13:50 瀏覽:33
安卓手機想不起來密碼怎麼格式化 發布:2024-11-29 07:13:08 瀏覽:552
防止sql注入net 發布:2024-11-29 07:12:18 瀏覽:206
三菱可編程式控制制器手冊 發布:2024-11-29 07:09:28 瀏覽:245
帶鋼演算法 發布:2024-11-29 06:57:49 瀏覽:52
python外包 發布:2024-11-29 06:49:11 瀏覽:425
怎麼用安卓手機查蘋果的序列號 發布:2024-11-29 06:21:08 瀏覽:508
r11s原始密碼是多少 發布:2024-11-29 05:52:20 瀏覽:79