java回合制游戏源代码 java游戏源码合集( 二 )


急需基于eclipse的JAVA小游戏源代码?。。?/h2>单人版五子棋,不用导入,直接新建一个mywindow类就行 , 然后把一下代码粘贴就Ok了 。或者,直接用dos就可以了 。。
---------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class mypanel extends Panel implements MouseListener
{
int chess[][] = new int[11][11];
boolean Is_Black_True;
mypanel()
{
Is_Black_True = true;
for(int i = 0;i11;i++)
{
for(int j = 0;j11;j++)
{
chess[i][j] = 0;
}
}
addMouseListener(this);
setBackground(Color.BLUE);
setBounds(0, 0, 360, 360);
setVisible(true);
}
public void mousePressed(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
if(x25 || x330 + 25 ||y25 || y330+25)
{
return;
}
if(chess[x/30-1][y/30-1] != 0)
{
return;
}
if(Is_Black_True == true)
{
chess[x/30-1][y/30-1] = 1;
Is_Black_True = false;
repaint();
Justisewiner();
return;
}
if(Is_Black_True == false)
{
chess[x/30-1][y/30-1] = 2;
Is_Black_True = true;
repaint();
Justisewiner();
return;
}
}
void Drawline(Graphics g)
{
for(int i = 30;i = 330;i += 30)
{
for(int j = 30;j = 330; j+= 30)
{
g.setColor(Color.WHITE);
g.drawLine(i, j, i, 330);
}
}
for(int j = 30;j = 330;j += 30)
{
g.setColor(Color.WHITE);
g.drawLine(30, j, 330, j);
}
}
void Drawchess(Graphics g)
{
for(int i = 0;i11;i++)
{
for(int j = 0;j11;j++)
{
if(chess[i][j] == 1)
{
g.setColor(Color.BLACK);
g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16);
}
if(chess[i][j] == 2)
{
g.setColor(Color.WHITE);
g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16);
}
}
}
}
void Justisewiner()
{
int black_count = 0;
int white_count = 0;
int i = 0;
for(i = 0;i11;i++)//横向判断
{
for(int j = 0;j11;j++)
{
if(chess[i][j] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[i][j] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
for(i = 0;i11;i++)//竖向判断
{
for(int j = 0;j11;j++)
{
if(chess[j][i] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[j][i] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
for(i = 0;i7;i++)//左向右斜判断
{
for(int j = 0;j7;j++)
{
for(int k = 0;k5;k++)
{
if(chess[i + k][j + k] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[i + k][j + k] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");

推荐阅读