java五子棋代码可悔棋 java五子棋源码( 四 )


grids[x][y].setValue(-1);
WinCheck();
turn=true;
}
/* 璸衡?ê?よ?Τ?隔 */
private void setMark2(int x, int y)
{
int space=0, temp_x=x, temp_y=y;
do
{
space=space+1;
temp_x=temp_x+displace_x;
temp_y=temp_y+displace_y;
}while(temp_x=0temp_xlengthtemp_y=0temp_ylengthgrid[temp_x][temp_y]==0space4);
if(space+step=5)
setMark(x, y);
else
setMark(x-(step+1)*displace_x, y-(step+1)*displace_y); /* э?癸翴 */
}
public void run()
{
try
{
switch(game_state)
{
case Start: Thread.sleep(2000);
dialog.show();
game_state=Playing;
repaint();
break;
case End: repaint();
Thread.sleep(1500);
ReStart();
repaint();
break;
}
}
catch(InterruptedException ex)
{
}
}
public void paint(Graphics g)
{
super.paint(g);
switch(game_state)
{
case Start: g.drawString("2005.7 by Yu Lin Tao", 91, 240);
g.setFont(font);
g.setColor(Color.BLUE);
g.drawString("Gobang", 112, 120);
g.drawImage(title, 134, 135, this);
break;
case Playing:
case End:
g.drawString("?产: 筿福:", 105, 40);
g.drawImage(black, 132, 30, this);
g.drawImage(white, 182, 30, this);
if(winner!=0)
{
g.setFont(font);
g.setColor(Color.RED);
message = winner==1? "?墓?":"?块?";
g.drawString(message, 120, 185);
}
break;
}
}
public void undo()
{
if(steps.size()0)
{
for(int i=0; i2; i++)
{
((Grid)steps.get(steps.size()-1)).Initial();
steps.remove(steps.size()-1);
}
}
}
private void Save()
{
String str;
try
{
File file = new File("innings.men");
file.createNewFile();
BufferedWriter write = new BufferedWriter(new FileWriter(file));
for(int i=0; isteps.size(); i++)
{
str=(((Grid)steps.get(i)).getLocX())+","+(((Grid)steps.get(i)).getLocY())+","+(((Grid)steps.get(i)).getValue());
write.write(str);
write.newLine();
}
write.close();
}
catch(Exception ex)
{
}
}
private void Load()
{
try
{
String[] step_array;
String str;
File file = new File("innings.men");
if(!file.exists())
{
JOptionPane.showMessageDialog(null, "⊿Τ?郎");
return;
}
BufferedReader read = new BufferedReader(new FileReader(file));
ReStart();
while(read.ready())
{
str=read.readLine();
step_array=str.split(",");
grids[Integer.parseInt(step_array[0])][Integer.parseInt(step_array[1])].setValue(Integer.parseInt(step_array[2]));
steps.add(grids[Integer.parseInt(step_array[0])][Integer.parseInt(step_array[1])]);
}
}
catch(Exception ex)
{
}
}
private class Grid extends JPanel implements MouseListener
{
int x, y, value;
boolean selected;
public Grid(int x, int y)
{
this.x=x;
this.y=y;
addMouseListener(this);
}
public void mousePressed(MouseEvent event)
{
if(game_state==Playing)
{
int button=event.getButton();
if(button==MouseEvent.BUTTON1)
{
if(value=https://www.04ip.com/post/=0)
{
steps.add(this);
setValue(1);
WinCheck();
turn=false;
if(game_state==Playing)
gobangAI();
}
}
else
control_menu.show(this, event.getX(), event.getY());
}
}
public void mouseEntered(MouseEvent event)
{
if(game_state==Playing)
setSelected(true);
}
public void mouseExited(MouseEvent event)
{
if(game_state==Playing)
setSelected(false);
}

推荐阅读