Java Weiqi Game Source code

Source: Internet
Author: User

//Li Yuze source code, can not be arbitrarily modified.
//Time: September 22, 2017.
//Location: Beijing Weekend Technology Co., Ltd.
//package Com.bao;
/ * Weiqi * /
/*import java.awt.*; import java.awt.event.*;
@SuppressWarnings ("Serial")
class Chesspad extends Panel implements Mouselistener,actionlistener {int x=-1,y=-1, pawn color =-1; Button Button=new button ("Start Again");
TextField text_1=new TextField ("Please Black Chess"), Text_2=new TextField ();
Chesspad () {setSize (440,440);
setlayout (null); SetBackground (color.orange);
Addmouselistener (this); Add (button); Button.setbounds (10,5,60,26) ;
Button.addactionlistener (this);
Add (text_1); Text_1.setbounds (90,5,90,24);
Add (text_2); Text_2.setbounds (290,5,90,24);
text_1.seteditable (f ...
//This code and guaranteed to run
}
}
//package Com.bao;

/* Li Yuze java Weiqi game development */

Import java.awt.*;
Import java.awt.event.*;

//@SuppressWarnings ("Serial")
class Chesspad extends Panel implements Mouselistener,actionlistener
{
int x=-1,y=-1, chess piece color =-1;
button Button=new button ("Start Again");
TextField text_1=new TextField ("Please Black Chess"), Text_2=new TextField ();
Chesspad ()
{
setSize (440,440);
setlayout (null); SetBackground (color.orange);
Addmouselistener (this); Add (button); Button.setbounds (10,5,60,26) ;
Button.addactionlistener (this);
Add (text_1); Text_1.setbounds (90,5,90,24);
Add (text_2); Text_2.setbounds (290,5,90,24);
text_1.seteditable (false); Text_2.seteditable (false) ;
}
Public void Paint (Graphics g)
{
for (int i=40;i<=380;i=i+20) {g.drawline (40,i,400,i);}
G.drawline (40,400,400,400);
for (int j=40;j<=390;j=j+20) {g.drawline (j,40,j,400);}
G.drawline (400,40,400,400);
G.filloval (97,97,6,6); G.filloval (377,97,6,6);
G.filloval (97,97,6,6); G.filloval (337,337,6,6);
G.filloval (217,217,6,6);
}
Public void mousepressed (MouseEvent e)
{
if (e.getmodifiers () ==inputevent.button1_mask)
{
x= (int) e.getx (); y= (int) e.gety ();
chesspoint_black chesspoint_black=new Chesspoint_black (this);
chesspoint_white chesspoint_white=new Chesspoint_white (this);
int a= (x+10)/20,b= (y+10)/20;
if (x/20<2| | y/20<2| | x/20>19| | y/20>19) {}
Else
{
if (chess piece color ==1)
{
This.add (chesspoint_black);
chesspoint_black.setbounds (a*20-10,b*20-10,20,20);
Pawn color = Pawn Color * ( -1);
text_2.settext ("Please white Chess");
Text_1.settext ("");
}
else if (chess piece color ==-1)
{
This.add (chesspoint_white);
chesspoint_white.setbounds (a*20-10,b*20-10,20,20);
Pawn color = Pawn Color * ( -1);
Text_1.settext ("Please black Chess");
Text_2.settext ("");
}
}
}
}
Public void mousereleased (MouseEvent e) {}
Public void mouseentered (MouseEvent e) {}
Public void mouseexited (MouseEvent e) {}
Public void mouseclicked (MouseEvent e) {}
Public void actionperformed (ActionEvent e)
{
This.removeall (); The color of a piece is =-1;
Add (button); Button.setbounds (10,5,60,26);
Add (text_1); Text_1.setbounds (90,5,90,24);
Text_2.settext (""); Text_1.settext ("Please play chess");
Add (text_2); Text_2.setbounds (290,5,90,24);
}
}
//@SuppressWarnings ("Serial")
class Chesspoint_black extends Canvas implements MouseListener
{
Chesspad chesspad=null;
chesspoint_black (Chesspad p)
{
setSize (20,20); Chesspad=p;addmouselistener (this);
}
Public void Paint (Graphics g) {G.setcolor (color.black); G.filloval (0,0,20,20);}
Public void mousepressed (MouseEvent e)
{
if (e.getmodifiers () ==inputevent.button3_mask)
{
Chesspad.remove (this);
chesspad. Pieces color =1;
Chesspad.text_2.setText (""); Chesspad.text_1.setText ("Please black Chess");
}
}
Public void mousereleased (MouseEvent e)
{

}
Public void mouseentered (MouseEvent e)
{

}
Public void mouseexited (MouseEvent e)
{

}
Public void mouseclicked (MouseEvent e)
{
if (E.getclickcount () >2)
Chesspad.remove (this);
}

}

//@SuppressWarnings ("Serial")
class Chesspoint_white extends Canvas implements MouseListener
{
Chesspad chesspad=null;
chesspoint_white (Chesspad p)
{
setSize (20,20); Addmouselistener (this);
chesspad=p;
}
Public void Paint (Graphics g) {G.setcolor (color.white); G.filloval (0,0,20,20);}
Public void mousepressed (MouseEvent e)
{
if (e.getmodifiers () ==inputevent.button3_mask)
{
Chesspad.remove (this); chesspad. Pawn color =-1;
chesspad.text_2.setText ("please white"); Chesspad.text_1.setText ("");
}
}
Public void mousereleased (MouseEvent e) {}
Public void mouseentered (MouseEvent e) {}
Public void mouseexited (MouseEvent e) {}
Public void mouseclicked (MouseEvent e)
{
if (E.getclickcount () >2)
Chesspad.remove (this);
}
}

//@SuppressWarnings ("Serial")
Public class Demo extends Frame
{
chesspad chesspad=new Chesspad ();
Demo ()
{
setvisible (true);
setlayout (null);
label Label=new label ("Game developer: Li Yuze Help: Left-click the pawn, double-click to eat pieces, right-undo", Label.center);
Add (label); Label.setbounds (70,55,440,26);
Label.setbackground (color.orange);
Add (Chesspad); Chesspad.setbounds (70,90,440,440);
Addwindowlistener (New Windowadapter ()
{public void windowclosing (WindowEvent e) {system.exit (0);}});
pack (); setSize (600,550);
}
Public static void Main (String args[])
{
//@SuppressWarnings ("unused")
Demo Chess=new demo ();
}
}

Java Weiqi Game Source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.