package com.lilijun.game.bingo.util; publicclass TestWin ...{ protectedstaticboolean test(int table[][],int N,int M)...{ //scan by rows int i,j,c,pre,s; for(i =0;i < N;i ++)...{ c =1;pre =0; for(j =0;j < M;j ++)...{ if(j ==0) pre =0; else pre = table[i][j -1]; if(table[i][j] ==0) continue; else...{ if(table[i][j] != pre) c =1; else c ++; if(c ==4) returntrue; } } } //scan by colum for(j =0;j < M;j ++)...{ c =1;pre =0; for(i =0;i < N;i ++)...{ if(i ==0) pre =0; else pre = table[i-1][j]; if(table[i][j] ==0) continue; else...{ if(table[i][j] != pre) c =1; else c ++; if(c ==4) returntrue; } } } //scan by "/" for(i =3;i < N;i ++)...{ c =1;pre =0; for(s = i,j =0;s >=0;s --,j ++)...{ if(s == i) pre =0; else pre = table[s+1][j-1]; if(table[s][j] ==0) continue; else...{ if(table[s][j] != pre) c =1; else c ++; if(c ==4) returntrue; } } } for(j =1;j < M -3;j ++)...{ c =1;pre =0; for(i = N-1,s = j;s < M;s ++,i--)...{ if(i == N-1) pre =0; else pre = table[i+1][s-1]; if(table[i][s] ==0) continue; else...{ if(table[i][s] != pre) c =1; else c ++; if(c ==4) returntrue; } } } //scan by "" for(i =0;i < N-3;i ++)...{ c =1;pre =0; for(s = i,j =0;s < N;s ++,j ++)...{ if(s == i) pre =0; else pre = table[s-1][j-1]; if(table[s][j] ==0) continue; else...{ if(table[s][j] != pre) c =1; else c ++; if(c ==4) returntrue; } } } for(j =1;j < M -3;j ++)...{ c =1;pre =0; for(i =0,s = j;s < M&&i < N;s ++,i++)...{ if(i ==0) pre =0; else pre = table[i-1][s-1]; if(table[i][s] ==0) continue; else...{ if(table[i][s] != pre) c =1; else c ++; if(c ==4) returntrue; } } } returnfalse; } publicstaticvoid main(String args[])...{ int a[][] =newint[][]...{ ...{0,0,0,1,0,0,0}, ...{0,1,1,2,1,2,1}, ...{0,1,1,1,2,2,1}, ...{1,2,2,1,1,1,2}, ...{2,1,1,2,2,2,1}, ...{1,1,2,1,2,1,1} }; if(TestWin.test(a, 6, 7)) System.out.println("You win!"); else System.out.println("Game Over!"); } }
/** *//** * */ package com.lilijun.game.bingo.util; /** *//** * @author lilijun * */ publicinterface GameController ...{ /**//* * initialize data used in game and begin the game */ publicvoid beginGame(); /**//* * end the game and quit from the game */ publicvoid endGame(); /** *//** * @param position the x position of game table * put a chess on the game table */ publicvoid putChess(int position); }
ChessBoardPanel.java:/** *//** * By 2006-10-5,I have finished how to draw chess board */package com.lilijun.game.bingo.ui;import javax.swing.JPanel;import java.awt.Color;import java.awt.Graphic