重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java象棋移动代码 java象棋棋盘类怎么写

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

Style Type="Text/CSS"

创新互联公司从2013年成立,先为特克斯等服务建站,特克斯等地企业,进行企业商务咨询服务。为特克斯企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

!--

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编写的中国象棋添加一个悔棋的功能

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

java中国际象棋模拟

有一个我们老师编写的贪吃蛇程序 供你参考一下:

GreedSnake.java (也是程序入口):

import java.awt.BorderLayout;

import java.awt.Canvas;

import java.awt.Color;

import java.awt.Container;

import java.awt.Graphics;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import java.util.Iterator;

import java.util.LinkedList;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

public class GreedSnake implements KeyListener {

JFrame mainFrame;

Canvas paintCanvas;

JLabel labelScore;// 计分牌

SnakeModel snakeModel = null;// 蛇

public static final int canvasWidth = 200;

public static final int canvasHeight = 300;

public static final int nodeWidth = 10;

public static final int nodeHeight = 10;

// ----------------------------------------------------------------------

// GreedSnake():初始化游戏界面

// ----------------------------------------------------------------------

public GreedSnake() {

// 设置界面元素

mainFrame = new JFrame("GreedSnake");

Container cp = mainFrame.getContentPane();

labelScore = new JLabel("Score:");

cp.add(labelScore, BorderLayout.NORTH);

paintCanvas = new Canvas();

paintCanvas.setSize(canvasWidth + 1, canvasHeight + 1);

paintCanvas.addKeyListener(this);

cp.add(paintCanvas, BorderLayout.CENTER);

JPanel panelButtom = new JPanel();

panelButtom.setLayout(new BorderLayout());

JLabel labelHelp;// 帮助信息

labelHelp = new JLabel("PageUp, PageDown for speed;", JLabel.CENTER);

panelButtom.add(labelHelp, BorderLayout.NORTH);

labelHelp = new JLabel("ENTER or R or S for start;", JLabel.CENTER);

panelButtom.add(labelHelp, BorderLayout.CENTER);

labelHelp = new JLabel("SPACE or P for pause", JLabel.CENTER);

panelButtom.add(labelHelp, BorderLayout.SOUTH);

cp.add(panelButtom, BorderLayout.SOUTH);

mainFrame.addKeyListener(this);

mainFrame.pack();

mainFrame.setResizable(false);

mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

mainFrame.setVisible(true);

begin();

}

// ----------------------------------------------------------------------

// keyPressed():按键检测

// ----------------------------------------------------------------------

public void keyPressed(KeyEvent e) {

int keyCode = e.getKeyCode();

if (snakeModel.running)

switch (keyCode) {

case KeyEvent.VK_UP:

snakeModel.changeDirection(SnakeModel.UP);

break;

case KeyEvent.VK_DOWN:

snakeModel.changeDirection(SnakeModel.DOWN);

break;

case KeyEvent.VK_LEFT:

snakeModel.changeDirection(SnakeModel.LEFT);

break;

case KeyEvent.VK_RIGHT:

snakeModel.changeDirection(SnakeModel.RIGHT);

break;

case KeyEvent.VK_ADD:

case KeyEvent.VK_PAGE_UP:

snakeModel.speedUp();// 加速

break;

case KeyEvent.VK_SUBTRACT:

case KeyEvent.VK_PAGE_DOWN:

snakeModel.speedDown();// 减速

break;

case KeyEvent.VK_SPACE:

case KeyEvent.VK_P:

snakeModel.changePauseState();// 暂停或继续

break;

default:

}

// 重新开始

if (keyCode == KeyEvent.VK_R || keyCode == KeyEvent.VK_S

|| keyCode == KeyEvent.VK_ENTER) {

snakeModel.running = false;

begin();

}

}

// ----------------------------------------------------------------------

// keyReleased():空函数

// ----------------------------------------------------------------------

public void keyReleased(KeyEvent e) {

}

// ----------------------------------------------------------------------

// keyTyped():空函数

// ----------------------------------------------------------------------

public void keyTyped(KeyEvent e) {

}

// ----------------------------------------------------------------------

// repaint():绘制游戏界面(包括蛇和食物)

// ----------------------------------------------------------------------

void repaint() {

Graphics g = paintCanvas.getGraphics();

// draw background

g.setColor(Color.WHITE);

g.fillRect(0, 0, canvasWidth, canvasHeight);

// draw the snake

g.setColor(Color.BLACK);

LinkedList na = snakeModel.nodeArray;

Iterator it = na.iterator();

while (it.hasNext()) {

Node n = (Node) it.next();

drawNode(g, n);

}

// draw the food

g.setColor(Color.RED);

Node n = snakeModel.food;

drawNode(g, n);

updateScore();

}

// ----------------------------------------------------------------------

// drawNode():绘画某一结点(蛇身或食物)

// ----------------------------------------------------------------------

private void drawNode(Graphics g, Node n) {

g.fillRect(n.x * nodeWidth, n.y * nodeHeight, nodeWidth - 1,

nodeHeight - 1);

}

// ----------------------------------------------------------------------

// updateScore():改变计分牌

// ----------------------------------------------------------------------

public void updateScore() {

String s = "Score: " + snakeModel.score;

labelScore.setText(s);

}

// ----------------------------------------------------------------------

// begin():游戏开始,放置贪吃蛇

你可以参考一下 每次遇到不会的都来求助是很不方便的

如果你想了解和学习更多的JAVA编程,成为一名真正的JAVA高手,你可以来这个裙,前面三个数是四二六 中间是三九六 后面是二八四

把这串数字连起来就可以了,这是一个高手的学习裙,在这里你可以学习到书上学不到的知识,还有大牛相互讨论并指导你解答哦!

// ----------------------------------------------------------------------

void begin() {

if (snakeModel == null || !snakeModel.running) {

snakeModel = new SnakeModel(this, canvasWidth / nodeWidth,

this.canvasHeight / nodeHeight);

(new Thread(snakeModel)).start();

}

}

// ----------------------------------------------------------------------

// main():主函数

// ----------------------------------------------------------------------

public static void main(String[] args) {

GreedSnake gs = new GreedSnake();

}

}

Node.java:

public class Node {

int x;

int y;

Node(int x, int y) {

this.x = x;

this.y = y;

}

}

SnakeModel.java:

import java.util.Arrays;

import java.util.LinkedList;

import java.util.Random;

import javax.swing.JOptionPane;

public class SnakeModel implements Runnable {

GreedSnake gs;

boolean[][] matrix;// 界面数据保存在数组里

LinkedList nodeArray = new LinkedList();

Node food;

int maxX;// 最大宽度

int maxY;// 最大长度

int direction = 2;// 方向

boolean running = false;

int timeInterval = 200;// 间隔时间(速度)

double speedChangeRate = 0.75;// 速度改变程度

boolean paused = false;// 游戏状态

int score = 0;

int countMove = 0;

// UP和DOWN是偶数,RIGHT和LEFT是奇数

public static final int UP = 2;

public static final int DOWN = 4;

public static final int LEFT = 1;

public static final int RIGHT = 3;

// ----------------------------------------------------------------------

// GreedModel():初始化界面

// ----------------------------------------------------------------------

public SnakeModel(GreedSnake gs, int maxX, int maxY) {

this.gs = gs;

this.maxX = maxX;

this.maxY = maxY;

matrix = new boolean[maxX][];

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

matrix[i] = new boolean[maxY];

Arrays.fill(matrix[i], false);// 没有蛇和食物的地区置false

}

// 初始化贪吃蛇

int initArrayLength = maxX 20 ? 10 : maxX / 2;

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

int x = maxX / 2 + i;

int y = maxY / 2;

nodeArray.addLast(new Node(x, y));

matrix[x][y] = true;// 蛇身处置true

}

food = createFood();

matrix[food.x][food.y] = true;// 食物处置true

}

// ----------------------------------------------------------------------

// changeDirection():改变运动方向

// ----------------------------------------------------------------------

public void changeDirection(int newDirection) {

if (direction % 2 != newDirection % 2)// 避免冲突

{

direction = newDirection;

}

}

// ----------------------------------------------------------------------

// moveOn():贪吃蛇运动函数

// ----------------------------------------------------------------------

public boolean moveOn() {

Node n = (Node) nodeArray.getFirst();

int x = n.x;

int y = n.y;

switch (direction) {

case UP:

y--;

break;

case DOWN:

y++;

break;

case LEFT:

x--;

break;

case RIGHT:

x++;

break;

}

if ((0 = x x maxX) (0 = y y maxY)) {

if (matrix[x][y])// 吃到食物或者撞到身体

{

if (x == food.x y == food.y)// 吃到食物

{

nodeArray.addFirst(food);// 在头部加上一结点

// 计分规则与移动长度和速度有关

int scoreGet = (10000 - 200 * countMove) / timeInterval;

score += scoreGet 0 ? scoreGet : 10;

countMove = 0;

food = createFood();

matrix[food.x][food.y] = true;

return true;

} else

return false;// 撞到身体

} else// 什么都没有碰到

{

nodeArray.addFirst(new Node(x, y));// 加上头部

matrix[x][y] = true;

n = (Node) nodeArray.removeLast();// 去掉尾部

matrix[n.x][n.y] = false;

countMove++;

return true;

}

}

return false;// 越界(撞到墙壁)

}

// ----------------------------------------------------------------------

// run():贪吃蛇运动线程

// ----------------------------------------------------------------------

public void run() {

running = true;

while (running) {

try {

Thread.sleep(timeInterval);

} catch (Exception e) {

break;

}

if (!paused) {

if (moveOn())// 未结束

{

gs.repaint();

} else// 游戏结束

{

JOptionPane.showMessageDialog(null, "GAME OVER",

"Game Over", JOptionPane.INFORMATION_MESSAGE);

break;

}

}

}

running = false;

}

// ----------------------------------------------------------------------

// createFood():生成食物及放置地点

// ----------------------------------------------------------------------

private Node createFood() {

int x = 0;

int y = 0;

do {

Random r = new Random();

x = r.nextInt(maxX);

y = r.nextInt(maxY);

} while (matrix[x][y]);

return new Node(x, y);

}

// ----------------------------------------------------------------------

// speedUp():加快蛇运动速度

// ----------------------------------------------------------------------

public void speedUp() {

timeInterval *= speedChangeRate;

}

// ----------------------------------------------------------------------

// speedDown():放慢蛇运动速度

// ----------------------------------------------------------------------

public void speedDown() {

timeInterval /= speedChangeRate;

}

// ----------------------------------------------------------------------

// changePauseState(): 改变游戏状态(暂停或继续)

// ----------------------------------------------------------------------

public void changePauseState() {

paused = !paused;

}

}

满意请采纳

JAVA中国象棋打谱软件怎么用

中国象棋是双方在有着9 条竖线和10 条横线的棋盘上对弈的,竖线与横线的交叉点称做棋点,每个棋子都是在棋点上行走,而不是在方格中行走,河界将棋盘分成两个等份,每一边都有一块由9个点组成的"九宫", 棋子"将"、"帅"、"士" 只能在"九宫"内移动。并且 "将"、"帅" 每一步只可以水平或垂直移动一个棋点。 "士" 它只能在"九宫"内移动,并且它每一步只可以沿对角线方向移动一个棋点。 "象" 它必须一步沿对角线方向走两个棋点,但它既不能过河,也不能跳过或穿越障碍,即象在走的过程中不能被"别眼"。 "马" 每一步只可以水平或垂直移动一个棋点,但必须按对角线方向,向左或右移动,中国象棋的马不能跳过障碍,即在走的过程中不能被"别腿"。 "车" 可以水平或垂直方向移动任意个无阻碍的点。 "炮" 移动起来和车很类似,但它必须跳过一个棋子来吃掉对方的一个棋子,被跳过的那个棋子称为桥或者屏风。 "兵' 每步只能向前移动一个棋点,过河以后,它便增加了向左右移动的能力,兵不允许向后移动。


当前名称:java象棋移动代码 java象棋棋盘类怎么写
本文路径:http://cqcxhl.com/article/dogscjj.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP