×

minesweeper

 -2 import java.io.*; import java.util.*; class minesweeper { int board[][],n; minesweeper() { board=new int[0][0]; n=0; } void assign() { int i=0,j=0; for(i=0;i=0) if(board[i+k][j]==9) c++; if(j+k=0) if(board[i][j+k]==9) c++; if(i-k=0) if(board[i-k][j]==9) c++; if(j-k=0) if(board[i][j-k]==9) c++; if(i+k=0&&j+k>=0) if(board[i+k][j+k]==9) c++; if(i-k=0&&j-k>=0) if(board[i-k][j-k]==9) c++; if(i-k=0&&j+k>=0) if(board[i-k][j+k]==9) c++; if(i+k=0&&j-k>=0) if(board[i+k][j-k]==9) c++; } if(c>0) board[i][j]=c; } } } void setfill()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); do { System.out.print("Enter dimension length\t"); n=Integer.parseInt(br.readLine()); if(n<=1) System.out.println("Sorry, minimum side length is 2"); }while(n<=1); board=new int[n][n]; int count=0; for(int i=0;i=n||j>=n||board[i][j]>10&&board[i][j]<=18) System.out.println("Sorry, this position is out of reach"); }while(i>=n||j>=n||board[i][j]>10&&board[i][j]<=18); int k=1; if(board[i][j]==0) { board[i][j]+=10; if(i+k=0) if(board[i+k][j]<9) board[i+k][j]+=10; if(j+k=0) if(board[i][j+k]<9) board[i][j+k]+=10; if(i-k=0) if(board[i-k][j]<9) board[i-k][j]+=10; if(j-k=0) if(board[i][j-k]<9) board[i][j-k]+=10; if(i+k=0&&j+k>=0) if(board[i+k][j+k]<9) board[i+k][j+k]+=10; if(i-k=0&&j-k>=0) if(board[i-k][j-k]<9) board[i-k][j-k]+=10; if(i-k=0&&j+k>=0) if(board[i-k][j+k]<9) board[i-k][j+k]+=10; if(i+k=0&&j-k>=0) if(board[i+k][j-k]<9) board[i+k][j-k]+=10; } else if(board[i][j]>0&&board[i][j]<9) board[i][j]+=10; else { board[i][j]=90; System.out.print("\f"); sad(); System.out.println("Sorry. GAME OVER..."); System.out.println("You have hit a mine"); display(); } }while(board[i][j]!=90); } void display() { for(int i=0;i10) System.out.print((board[i][j]-10)+"\t"); else System.out.print("X"+"\t"); } System.out.println(); } } void nulldisplay() { for(int i=0;i10&&board[i][j]!=90) System.out.print((board[i][j]-10)+"\t"); else System.out.print("X"+"\t"); } System.out.println(); } } boolean wincheck() { boolean f=true; for(int i=0;i
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×633
×244
×117

question asked: 24 Oct '12, 14:42

question was seen: 2,452 times

last updated: 24 Oct '12, 15:59