How to realize simple Chinese Chess with java
This article mainly explains "how to achieve simple Chinese chess with java". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to achieve simple Chinese chess with java".
Running effect
Code
Import java.awt.Canvas;import java.awt.Color;import java.awt.Font;import java.awt.Graphics;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.image.BufferedImage;import java.util.Random;import java.util.Stack;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JOptionPane Public class Chinesechese extends Canvas implements MouseListener {class Record {int fromx,fromy,tox,toy,fromindex,toindex; Record (int fromx,int fromy,int tox,int toy,int fromindex,int toindex) {this.fromx=fromx; this.fromy=fromy; this.tox=tox; this.toy=toy; this.fromindex=fromindex; this.toindex=toindex } int take_x=-1,take_y=-1,player=0; boolean isRuning=true; int table [] [] = new int [10] [11]; String name [] = {"," general "," official "," elephant "," soldier "," gun "," pawn "," handsome "," scholar "," phase "," horse "," chariot "," gun "," soldier "} Int value [] = {0pet1000, 3pyrrh, 3pje, 3pyrr5, BufferedImage map = new BufferedImage (500,600, BufferedImage.TYPE_INT_RGB); BufferedImage offScreenImage = new BufferedImage (500,600, BufferedImage.TYPE_INT_RGB); BufferedImage runImage = new BufferedImage (500,600, BufferedImage.TYPE_INT_RGB); Stack recordstk=new Stack () Chinesechese () {this.addMouseListener (this); this.setBounds (150,0550,600); this.setBackground (Color.BLACK); Graphics g=map.getGraphics (); g.setColor (Color.WHITE); g.fillRect (0,0Magne500,570); g.setColor (Color.black); g.setFont (new Font ("Dialog", 0jing35)) G.drawString ("Chu he Han Jie", 130,285); for (int item0)