車的規(guī)則就是 目標(biāo)點(diǎn) 不能超過前面的第一個(gè)人。
創(chuàng)新互聯(lián)專注于滎陽企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站開發(fā),商城建設(shè)。滎陽網(wǎng)站建設(shè)公司,為滎陽等地區(qū)提供建站服務(wù)。全流程按需策劃,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
炮的規(guī)則就是 目標(biāo)點(diǎn) 必須超過前面的第一個(gè) 不超過前面的第二個(gè)人。
你可參考:;word=java%CF%F3%C6%E5%B5%C7%C2%BC%BD%E7%C3%E6%B5%C4%B4%FA%C2%EB
還有這個(gè);
package java1;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.Rectangle;
import java.awt.Font;
public class login extends JFrame
{
public login() {
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args)
{
login frm=new login();
frm.setBounds(300,200,300,260);
frm.setVisible(true);
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jLabel1.setForeground(Color.red);
jLabel1.setText("用戶名");
jLabel1.setBounds(new Rectangle(25, 72, 68, 29));
jButton2.setBounds(new Rectangle(142, 159, 81, 30));
jButton2.setText("取消");
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jButton1.setBounds(new Rectangle(38, 159, 81, 29));
jButton1.setText("確定");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jTextField1.setBounds(new Rectangle(109, 79, 136, 23));
jPasswordField1.setBounds(new Rectangle(109, 115, 136, 23));
this.getContentPane().add(jLabel1);
jLabel3.setFont(new java.awt.Font("隸書", Font.PLAIN, 24));
jLabel3.setText("學(xué) 生 考 試 系 統(tǒng)");
jLabel3.setBounds(new Rectangle(22, 15, 268, 47));
this.getContentPane().add(jTextField1);
this.getContentPane().add(jLabel2);
this.getContentPane().add(jButton2);
this.getContentPane().add(jButton1);
this.getContentPane().add(jLabel3);
this.getContentPane().add(jPasswordField1);
jLabel2.setForeground(Color.red);
jLabel2.setText("密碼");
jLabel2.setBounds(new Rectangle(26, 112, 68, 29));
}
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel3 = new JLabel();
JPasswordField jPasswordField1 = new JPasswordField();
main2 wo=new main2();
int sum;
//判斷權(quán)限的方法
public void success()
{
try{
ResultSet rs1;
String s1="select * from 管理權(quán)限 where name='"+jTextField1.getText()+"' and password='"+jPasswordField1.getText()+"'";
rs1=sqlcx.Rs_jiluji(s1);
rs1.first();
sum=Integer.parseInt((String)(rs1.getString(3)));
System.out.println(sum);
very();
}
catch(Exception c)
}
//根據(jù)權(quán)限設(shè)置窗口
public void very()
{
if (sum==1)
{JOptionPane.showOptionDialog(this, "您現(xiàn)在是以教師權(quán)限登陸", "登陸信息"
, JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, null, null);
}
else
{
JOptionPane.showOptionDialog(this, "你現(xiàn)在是以學(xué)生權(quán)限登陸", "登陸信息"
, JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, null, null);
wo.jButton2.setVisible(false);
wo.jButton3.setVisible(false);
wo.jButton4.setVisible(false);
wo.jButton5.setVisible(false);
wo.jButton6.setVisible(false);
wo.jButton7.setVisible(false);
wo.jButton8.setVisible(false);
wo.jMenu2.setVisible(false);
wo.jMenu3.setVisible(false);
wo.jMenu4.setVisible(false);
}
}
public void jButton1_actionPerformed(ActionEvent e)
{
//判斷用戶名是否為空
if (jTextField1.getText().length() == 0) {
JOptionPane.showOptionDialog(this, "用戶名不能為空", "錯(cuò)誤信息"
, JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, null, null);
}
//判斷密碼是否為空
else if (jPasswordField1.getText().length()==0)
{
JOptionPane.showOptionDialog(this,"密碼不能為空", "錯(cuò)誤信息"
, JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, null, null);
}
else
{
try
{
ResultSet rs;//聲明記錄集
String sql="select * from 管理權(quán)限 where name='"+jTextField1.getText()+"'";
rs = sqlcx.Rs_jiluji(sql);
if (rs.next())
{
if(jPasswordField1.getText().equals(rs.getString(2)))
{
success();
wo.setBounds(60,40,700,600);
wo.setVisible(true);
this.dispose();
}
else
{
JOptionPane.showOptionDialog(this,"密碼錯(cuò)誤", "錯(cuò)誤信息"
, JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, null, null);
}
}
else
{
JOptionPane.showOptionDialog(this,"沒有所要找的用戶名", "錯(cuò)誤信息"
, JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, null, null);
}
}
catch(Exception c){
JOptionPane.showOptionDialog(this,"連接數(shù)據(jù)庫失敗", "錯(cuò)誤信息"
, JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, null, null);
}
}
}
public void jButton2_actionPerformed(ActionEvent e) {
System.exit(0);
}
}
這個(gè)程序?qū)崿F(xiàn)還要一個(gè)關(guān)聯(lián)文件夾“image”象棋棋子圖片 部分代碼如下:(代碼太長 給個(gè)郵箱 我發(fā)給你)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
//主類
public class Chess{
public static void main(String args[]){
new ChessMainFrame("中國象棋:觀棋不語真君子,棋死無悔大丈夫");
}
}
//主框架類
class ChessMainFrame extends JFrame implements ActionListener,MouseListener,Runnable{
//玩家
JLabel play[] = new JLabel[32];
//棋盤
JLabel image;
//窗格
Container con;
//工具欄
JToolBar jmain;
//重新開始
JButton anew;
//悔棋
JButton repent;
//退出
JButton exit;
//當(dāng)前信息
JLabel text;
//保存當(dāng)前操作
Vector Var;
//規(guī)則類對象(使于調(diào)用方法)
ChessRule rule;
/**
** 單擊棋子
** chessManClick = true 閃爍棋子 并給線程響應(yīng)
** chessManClick = false 吃棋子 停止閃爍 并給線程響應(yīng)
*/
boolean chessManClick;
/**
** 控制玩家走棋
** chessPlayClick=1 黑棋走棋
** chessPlayClick=2 紅棋走棋 默認(rèn)紅棋
** chessPlayClick=3 雙方都不能走棋
*/
int chessPlayClick=2;
//控制棋子閃爍的線程
Thread tmain;
//把第一次的單擊棋子給線程響應(yīng)
static int Man,i;
ChessMainFrame(){
new ChessMainFrame("中國象棋");
}
/**
** 構(gòu)造函數(shù)
** 初始化圖形用戶界面
*/
ChessMainFrame(String Title){
//獲行客格引用
con = this.getContentPane();
con.setLayout(null);
//實(shí)例化規(guī)則類
rule = new ChessRule();
Var = new Vector();
//創(chuàng)建工具欄
jmain = new JToolBar();
text = new JLabel("歡迎使用象棋對弈系統(tǒng)");
//當(dāng)鼠標(biāo)放上顯示信息
text.setToolTipText("信息提示");
anew = new JButton(" 新 游 戲 ");
anew.setToolTipText("重新開始新的一局");
exit = new JButton(" 退 出 ");
exit.setToolTipText("退出象棋程序程序");
repent = new JButton(" 悔 棋 ");
repent.setToolTipText("返回到上次走棋的位置");
//把組件添加到工具欄
jmain.setLayout(new GridLayout(0,4));
jmain.add(anew);
jmain.add(repent);
jmain.add(exit);
jmain.add(text);
jmain.setBounds(0,0,558,30);
con.add(jmain);
//添加棋子標(biāo)簽
drawChessMan();
//注冊按扭監(jiān)聽
anew.addActionListener(this);
repent.addActionListener(this);
exit.addActionListener(this);
//注冊棋子移動監(jiān)聽
for (int i=0;i32;i++){
con.add(play[i]);
play[i].addMouseListener(this);
}
//添加棋盤標(biāo)簽
con.add(image = new JLabel(new ImageIcon("image\\Main.GIF")));
image.setBounds(0,30,558,620);
image.addMouseListener(this);
//注冊窗體關(guān)閉監(jiān)聽
this.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent we){
System.exit(0);
}
}
);
//窗體居中
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
if (frameSize.height screenSize.height){
frameSize.height = screenSize.height;
}
if (frameSize.width screenSize.width){
frameSize.width = screenSize.width;
}
this.setLocation((screenSize.width - frameSize.width) / 2 - 280 ,(screenSize.height - frameSize.height ) / 2 - 350);
//設(shè)置
this.setIconImage(new ImageIcon("image\\紅將.GIF").getImage());
this.setResizable(false);
this.setTitle(Title);
this.setSize(558,670);
this.show();
}
/**
** 添加棋子方法
*/
public void drawChessMan(){
//流程控制
int i,k;
//圖標(biāo)
Icon in;
//黑色棋子
//車
in = new ImageIcon("image\\黑車.GIF");
for (i=0,k=24;i2;i++,k+=456){
play[i] = new JLabel(in);
play[i].setBounds(k,56,55,55);
play[i].setName("車1");
}
//馬
in = new ImageIcon("image\\黑馬.GIF");
for (i=4,k=81;i6;i++,k+=342){
play[i] = new JLabel(in);
play[i].setBounds(k,56,55,55);
play[i].setName("馬1");
}
//相
in = new ImageIcon("image\\黑象.GIF");
for (i=8,k=138;i10;i++,k+=228){
play[i] = new JLabel(in);
play[i].setBounds(k,56,55,55);
play[i].setName("象1");
}
//士
in = new ImageIcon("image\\黑士.GIF");
for (i=12,k=195;i14;i++,k+=114){
play[i] = new JLabel(in);
play[i].setBounds(k,56,55,55);
play[i].setName("士1");
}
//卒
in = new ImageIcon("image\\黑卒.GIF");
for (i=16,k=24;i21;i++,k+=114){
play[i] = new JLabel(in);
play[i].setBounds(k,227,55,55);
play[i].setName("卒1" + i);
}
//炮
in = new ImageIcon("image\\黑炮.GIF");
for (i=26,k=81;i28;i++,k+=342){
play[i] = new JLabel(in);
play[i].setBounds(k,170,55,55);
play[i].setName("炮1" + i);
}
//將
in = new ImageIcon("image\\黑將.GIF");
play[30] = new JLabel(in);
play[30].setBounds(252,56,55,55);
play[30].setName("將1");
//紅色棋子
//車
in = new ImageIcon("image\\紅車.GIF");
for (i=2,k=24;i4;i++,k+=456){
play[i] = new JLabel(in);
play[i].setBounds(k,569,55,55);
play[i].setName("車2");
}
//馬
in = new ImageIcon("image\\紅馬.GIF");
for (i=6,k=81;i8;i++,k+=342){
play[i] = new JLabel(in);
play[i].setBounds(k,569,55,55);
play[i].setName("馬2");
}
//相
in = new ImageIcon("image\\紅象.GIF");
for (i=10,k=138;i12;i++,k+=228){
play[i] = new JLabel(in);
play[i].setBounds(k,569,55,55);
play[i].setName("象2");
}
//士
in = new ImageIcon("image\\紅士.GIF");
for (i=14,k=195;i16;i++,k+=114){
play[i] = new JLabel(in);
play[i].setBounds(k,569,55,55);
play[i].setName("士2");
}
//兵
in = new ImageIcon("image\\紅卒.GIF");
for (i=21,k=24;i26;i++,k+=114){
play[i] = new JLabel(in);
play[i].setBounds(k,398,55,55);
play[i].setName("卒2" + i);
}
//炮
in = new ImageIcon("image\\紅炮.GIF");
for (i=28,k=81;i30;i++,k+=342){
play[i] = new JLabel(in);
play[i].setBounds(k,455,55,55);
play[i].setName("炮2" + i);
}
//帥
in = new ImageIcon("image\\紅將.GIF");
play[31] = new JLabel(in);
play[31].setBounds(252,569,55,55);
play[31].setName("帥2");
}
/**
** 線程方法控制棋子閃爍
*/
}
if((i+j)/2==0) 帥哥 這個(gè)是不可能等于0的 你想的效果應(yīng)該是 if((i+j) % 2 == 0) 用這個(gè) 呵呵
簡化一下,假設(shè)馬不走回頭路,一直向右
public class ChessHorse
{
static final int X=8;
static final int Y=4;
public void gossip(int x,int y)
{
while((x=X)(y=Y))
{
System.out.println("("+x+","+y+")");
x+=2;
y++;
}
}
public static void main(String[] args)
{
ChessHorse horse=new ChessHorse();
System.out.println("馬的走位:");
horse.gossip(0,0);
}
}
int[][] loaction=new int[10][9];
左帥:loaction[0][4];
X X X
X X
X X X
-----
[0][3] [1][3] [2][3]
[0][4] [1][4] [2][4]
[0][5] [1][5] [2][5]
即:x=0 x=2 y=3 y=5
------------------------------
右將:loaction[9][4];
X X X
X X
X X X
-----
[7][3] [8][3] [9][3]
[7][4] [8][4] [9][4]
[7][5] [8][5] [9][5]
---------------------------
public int go(int x,int y,int path,int len){
if(loaction[x][y]==1) {//是帥
if(path==1){//向左
if(x=0) return -1;//返回-1代表走發(fā)錯(cuò)誤
else {loaction[x-1][y]=1;loaction[x][y]=-1;}//將左一個(gè)格子標(biāo)記為帥
}
else if(path==2){//向上
...
}
else if(path==3){//向右
...
}
else if(path==4){//向下
...
}//else path
}//if key
else if(loaction[x][x]==2){//2代表將
....
}//if key
}
車就差不多了
新聞標(biāo)題:java象棋代碼的講解 java中國象棋源碼
網(wǎng)站路徑:http://jinyejixie.com/article44/dodphee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、商城網(wǎng)站、外貿(mào)建站、電子商務(wù)、品牌網(wǎng)站設(shè)計(jì)、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)