资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java写的中国象棋代码 java写的中国象棋代码怎么写

求要中国象棋将,帅的走法的JAVA代码

int[][] loaction=new int[10][9];

创新互联专注于企业全网整合营销推广、网站重做改版、朝阳网站定制设计、自适应品牌网站建设、html5商城建设、集团公司官网建设、外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为朝阳等各大城市提供网站开发制作服务。

左帅: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代表走发错误

else {loaction[x-1][y]=1;loaction[x][y]=-1;}//将左一个格子标记为帅

}

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

}

车就差不多了

java象棋登录界面的代码

你可参考:;word=java%CF%F3%C6%E5%B5%C7%C2%BC%BD%E7%C3%E6%B5%C4%B4%FA%C2%EB

还有这个;

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("学 生 考 试 系 统");

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;

//判断权限的方法

public void success()

{

try{

ResultSet rs1;

String s1="select * from 管理权限 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)

}

//根据权限设置窗口

public void very()

{

if (sum==1)

{JOptionPane.showOptionDialog(this, "您现在是以教师权限登陆", "登陆信息"

, JOptionPane.DEFAULT_OPTION,

JOptionPane.ERROR_MESSAGE,

null, null, null);

}

else

{

JOptionPane.showOptionDialog(this, "你现在是以学生权限登陆", "登陆信息"

, 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, "用户名不能为空", "错误信息"

, JOptionPane.DEFAULT_OPTION,

JOptionPane.ERROR_MESSAGE,

null, null, null);

}

//判断密码是否为空

else if (jPasswordField1.getText().length()==0)

{

JOptionPane.showOptionDialog(this,"密码不能为空", "错误信息"

, JOptionPane.DEFAULT_OPTION,

JOptionPane.ERROR_MESSAGE,

null, null, null);

}

else

{

try

{

ResultSet rs;//声明记录集

String sql="select * from 管理权限 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,"密码错误", "错误信息"

, JOptionPane.DEFAULT_OPTION,

JOptionPane.ERROR_MESSAGE,

null, null, null);

}

}

else

{

JOptionPane.showOptionDialog(this,"没有所要找的用户名", "错误信息"

, JOptionPane.DEFAULT_OPTION,

JOptionPane.ERROR_MESSAGE,

null, null, null);

}

}

catch(Exception c){

JOptionPane.showOptionDialog(this,"连接数据库失败", "错误信息"

, JOptionPane.DEFAULT_OPTION,

JOptionPane.ERROR_MESSAGE,

null, null, null);

}

}

}

public void jButton2_actionPerformed(ActionEvent e) {

System.exit(0);

}

}

用JAVA写象棋代码,炮的规则和车的规则怎么写 这题没有钱的 我发错了

车的规则就是 目标点 不能超过前面的第一个人。

炮的规则就是 目标点 必须超过前面的第一个 不超过前面的第二个人。


分享题目:java写的中国象棋代码 java写的中国象棋代码怎么写
网站URL:http://cdkjz.cn/article/ddicded.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220