快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

象棋java小程序代码 java象棋编写

java编程实现中国象棋中马的走位以及输出。

简化一下,假设马不走回头路,一直向右

创新互联公司主营齐齐哈尔网站建设的网络公司,主营网站建设方案,App定制开发,齐齐哈尔h5重庆小程序开发公司搭建,齐齐哈尔网站营销推广欢迎齐齐哈尔等地区企业咨询

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);

}

}

用java编写的中国象棋添加一个悔棋的功能

不急的话后天帮你弄,这两天有事!541617772@qq.com邮箱。建议你换个myEclipse版本7.0太太太旧了,都出到2014了,7.0基本上公司都淘汰了

求用java做个国际象棋的程序

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

Scanner input=new Scanner(System.in);

System.out.println("请输入几*几");

int num=input.nextInt();

String str="";

for (int i = 0; i num; i++) {

System.out.println("请输入第"+(i+1)+"行出现在第几个");

int pos=input.nextInt();

for (int j = 1; j = num; j++) {

if (pos==j) {

str+="Q";

}else {

str+="*";

}

}

str+="\n";

}

System.out.println(str);

}

}

有什么不懂可以HI我

因为看你是初学,我就不用stringBuffer了,如果要用其它方式 HI我

求一个java小程序(要是那种小型游戏程序)

Style Type="Text/CSS"

!--

Input{}

.blokje{

Height:48px;

Width:48px;

Font-Size:16pt;

Font-Weight:900;

Font-Family:Comic Sans MS,Arial,Verdana;

Text-Align:Center;

}

.knopje{

Width:144px;

}

--

/Style

Center

Form

Input Type="Button" Title="Click here to play again" Name="beurten" Width="164px" Class="knopje" Value="Player 1" onClick="wie = 'Player 1'; initieer()"

Table CellPadding="0" CellSpacing="0" Border="0"

Script Language="JavaScript"

!--//

for (i = 1; i 10; i++) {

if (i % 3 == 1) {document.write('Tr');}

document.write('TdInput Type="Button" Name="' + i + '" Value=" " Class="blokje" onClick="wijzig(this.form,this)"/Td');

if (i % 3 == 0) {document.write('/Tr');}

}

//--

/Script

/Table

Input Type="CheckBox" Title="Click here to change from 2 players or computergame" Name="automaat" Value="2 players" Id="autmat" onClick="if (this.value == 'Computer') {this.value = '2 players'; auto = 0} else {this.value = 'Computer'; auto = 1}; wie = 'Player 1'; initieer();"Label For="autmat"与电脑对玩?/Label

Table CellPadding="0" CellSpacing="0" Border="1"

Tr BgColor="Silver"

Td Align="Center" 玩家 1 胜/Td

Td Align="Center" 玩家 2 胜/Td

Td Align="Center" 平局 /Td

/Tr

Tr BgColor="Silver"

Td Align="Center"Input Style="BackGround-Color:Transparent;Border:Solid 0px;Text-Align:Center" Type="Text" Size="3" ReadOnly Title="Player 1" Name="speler1" Value="0"/Td

Td Align="Center"Input Style="BackGround-Color:Transparent;Border:Solid 0px;Text-Align:Center" Type="Text" Size="3" ReadOnly Title="Player 2" Name="speler2" Value="0"/Td

Td Align="Center"Input Style="BackGround-Color:Transparent;Border:Solid 0px;Text-Align:Center" Type="Text" Size="3" ReadOnly Title="Remise" Name="remise" Value="0"/Td

/Tr

/Table

/Form

/Center

Script Language="JavaScript"

!--//

timerID = xtal = ytal = ztal = auto = 0;

wie = 'Player 1';

function initieer(){

clearTimeout(timerID);

cel = new Array(0,0,0,0,0,0,0,0,0,0);

aanv = new Array(); strat = verd = leeg = aanv;

beurt = wissel = 1; wint = keren = 0;

document.forms[0].speler1.value = xtal;

document.forms[0].speler2.value = ytal;

document.forms[0].remise.value = ztal;

if (wie != 'Start') {

for (i in cel) {

cel[i] = 0; if (i 0) {document.forms[0].elements[i].value = ''};

}

}

document.forms[0].beurten.value = wie;

}

function zetten() {

clearTimeout(timerID);

if (aanv[0] 0) {

slag = aanv[Math.floor(Math.random() * 10) % aanv.length]

} else if (verd[0] 0) {

slag = verd[Math.floor(Math.random() * 10) % verd.length];

} else if (strat[0] 0) {

slag = strat[Math.floor(Math.random() * 10) % strat.length];

} else {

slag = leeg[Math.floor(Math.random() * 10) % leeg.length];

}

if (beurt == 0 slag 0) {document.forms[0].elements[slag].click()};

}

function win() {

if ( cel[1] + cel[2] + cel[3] == 3 ||

cel[4] + cel[5] + cel[6] == 3 ||

cel[7] + cel[8] + cel[9] == 3 ||

cel[1] + cel[4] + cel[7] == 3 ||

cel[2] + cel[5] + cel[8] == 3 ||

cel[3] + cel[6] + cel[9] == 3 ||

cel[1] + cel[5] + cel[9] == 3 ||

cel[3] + cel[5] + cel[7] == 3

) {

if (confirm("玩家一: 你赢了一局 !!\n还想要继续玩吗?"))

{

wint = 1;

xtal++; wie = 'Player 1'; timerID = setTimeout('initieer()',800)

} else {

xtal++; wie = 'Start'; timerID = setTimeout('initieer()',800)

};

}

if ( cel[1] + cel[2] + cel[3] == 30 ||

cel[4] + cel[5] + cel[6] == 30 ||

cel[7] + cel[8] + cel[9] == 30 ||

cel[1] + cel[4] + cel[7] == 30 ||

cel[2] + cel[5] + cel[8] == 30 ||

cel[3] + cel[6] + cel[9] == 30 ||

cel[1] + cel[5] + cel[9] == 30 ||

cel[3] + cel[5] + cel[7] == 30

) {

if (confirm(((auto == 1) ? ('电脑赢啦!!!') : ('玩家二: 你赢了一局 !!')) + "!\n还想要继续玩吗?")) {

ytal++; wie = 'Player 1'; timerID = setTimeout('initieer()',800)

} else {

ytal++; wie = 'Start'; timerID = setTimeout('initieer()',800)

};

}

}

function wisselen(beurt){

if (wissel == 1) {

if (beurt == 0) {

beurt = 1;

wie = "Player " + 1

}

else {

if (auto == 0) {beurt = 0;

wie = "Player " + 2} else {beurt = 0; wie = "Computer";}

}

if (keren == 9

) {

if (confirm("打平了!!!\n\n还想要继续玩吗?")) {

ztal++; wie = 'Player 1'; timerID = setTimeout('initieer()',800)} else

{ztal++; wie = 'Start'; timerID = setTimeout('initieer()',800)};

}

}

else {

beurt = beurt;

}

wissel = 1;

return(beurt);

}

function wijziging(klik) {

plek = cel[klik]; geklikt = klik;

if (plek == 0){

if (beurt == 0){

xo = "O";

plek = 10;

} else {

xo = "X";

plek = 1;

}

cel[klik] = plek; keren++;

}

else {

if (plek == 10){

xo = "O";}

if (plek == 1){

xo = "X";}

wissel = 0

}

return(xo);

}

function verdedig() {leeg = new Array(); verd = new Array();

for (i = 1; i 10; i++) { oud = cel[i]; cel[i] = 1;

if ( (cel[1] + cel[2] + cel[3] == 3 ||

cel[4] + cel[5] + cel[6] == 3 ||

cel[7] + cel[8] + cel[9] == 3 ||

cel[1] + cel[4] + cel[7] == 3 ||

cel[2] + cel[5] + cel[8] == 3 ||

cel[3] + cel[6] + cel[9] == 3 ||

cel[1] + cel[5] + cel[9] == 3 ||

cel[3] + cel[5] + cel[7] == 3) oud == 0

) { verd[verd.length] = i}

cel[i] = oud;

if (cel[i] == 0) {

if (keren != 1) {leeg[leeg.length] = i} else

if (cel[5] == 0) {leeg[0] = 5; leeg[1] = 10 - geklikt} else

if (i % 2 != 0) {leeg[leeg.length] = i}

};

}

}

function aanval() {aanv = new Array();

for (i = 1; i 10; i++) { oud = cel[i]; cel[i] = 10;

if ( (cel[1] + cel[2] + cel[3] == 30 ||

cel[4] + cel[5] + cel[6] == 30 ||

cel[7] + cel[8] + cel[9] == 30 ||

cel[1] + cel[4] + cel[7] == 30 ||

cel[2] + cel[5] + cel[8] == 30 ||

cel[3] + cel[6] + cel[9] == 30 ||

cel[1] + cel[5] + cel[9] == 30 ||

cel[3] + cel[5] + cel[7] == 30) oud == 0

) { aanv[aanv.length] = i}

cel[i] = oud;

}

}

function strategie() {strat = new Array();

for (i = 1; i 10; i++) { oud = cel[i]; cel[i] = 10;

if ( (cel[1] + cel[2] + cel[3] == 20 ||

cel[4] + cel[5] + cel[6] == 20 ||

cel[7] + cel[8] + cel[9] == 20 ||

cel[1] + cel[4] + cel[7] == 20 ||

cel[2] + cel[5] + cel[8] == 20 ||

cel[3] + cel[6] + cel[9] == 20 ||

cel[1] + cel[5] + cel[9] == 20 ||

cel[3] + cel[5] + cel[7] == 20) oud == 0

) {

if (keren != 3) {strat[strat.length] = i} else if (i % 2 != 0) {strat[strat.length] = i}

}

cel[i] = oud;

}

}

function wijzig(form,element){

wijziging(element.name);

element.value = xo;

beurt = wisselen(beurt);

form.beurten.value = wie;

verdedig(); aanval(); strategie(); win();

if (auto == 0 || wint == 1) {return} else {

timerID = setTimeout('zetten()',600)

}

}

initieer();

//--

/Script

这是一个3子棋的游戏,不太大,把上面这段代码加入body/body中。

你好,请问你有具体的将棋子图片放到棋盘上的Java代码吗?或者是你自己编写的Java国际象棋程序?很急!!!

有,但是我不能直接给你。我可以告诉你步骤。

首先是加载图片文件为 Image:比如你有个类叫 ResourceLoader 那么就添加下面的类成员:

public static final URL url = ResourceLoader.class.getResource("/xxx/.../文件名.png");

public static final Image img = Toolkit.getDefaultToolkit().createImage(url);

然后就加载好了。下一步是继承一个 JPanel(例如),添加鼠标/键盘事件,并重写 paint 方法(或 paintComponent 方法)。例如——

public class ChessPanel extends JPanel {

private Point[] chessPoints = new Point[共多少个棋子];

private boolean[] shown = new boolean[共多少个棋子];

@Override public void paintComponent (Graphics g) {

super.paintComponent(g);

for (int i=0; i共多少个棋子; i++) {

if (shown[i]) {

g.drawImage(ResourceLoader.img, chessPoints[i].x, chessPoints[i].y, 棋子宽度, 棋子高度);

}

}

}

class MouseControler extends MouseAdapter {

@Override public void mousePressed (MouseEvent me) {

//自己写吧

repaint();

}

}

}

最后说明一下,图片资源文件可以打包到 jar 里。我把关键的部分都已经告诉你了。具体逻辑实现你自己写吧。当然数据结构你也可以自己写,我的例子只是告诉你相应的在 paint 或者 paintComponent 方法里全部画出来就行了。

希望能采纳。

显示一个国际象棋棋盘的java源代码

import java.awt.Color;

import javax.swing.*;

public class Chess extends JPanel

{// 继承面板类

public Chess(int grids,int gridsize)

{//grids:行数和列数, gridsize:单元格的高和宽

super(null);

for(int i=0; igrids; i++)

{

for(int j=0; jgrids; j++)

{

JLabel l = new JLabel();//生成标签实例

l.setSize(gridsize,gridsize);

l.setLocation(i*gridsize,j*gridsize);

if((i+j)%2==0)

{ //当小方格的坐标和刚好是偶数时,

l.setBackground(Color.black); //设置为方格为黑色

l.setOpaque(true); //设置为不透明

}

l.setBorder(BorderFactory.createLineBorder(Color.black)); //设置边界为黑色

add(l);//将l标签添加到面板

}

}

}

public static void main(String[] args)

{

JFrame f = new JFrame();

f.setSize(658,677); //边框的长和宽

f.setLocationRelativeTo(null); //设置窗口相对于指定组件的位置

f.add(new Chess(8,80));

f.setVisible(true);

}

}


当前文章:象棋java小程序代码 java象棋编写
转载来源:http://6mz.cn/article/docgdsc.html

其他资讯