⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 realchessboard.java

📁 一款JAVA款的跳棋
💻 JAVA
字号:
package org.yushang.jumpchess.pkg;

import org.yushang.jumpchess.pub.*;

public class RealChessBoard extends ChessBoard {
	private Chess[][] chessesIndex = new Chess[17][17];
	private Chess[] chesses = null;
	private Position[] chessesPosition = null;
	private static final int CHESSCOUNT = 10; 
	
	public RealChessBoard(PlayerInfo[] playInfos) {
		
		//创建棋子
		chesses = new Chess[CHESSCOUNT * playInfos.length];
		chessesPosition = new Position[CHESSCOUNT * playInfos.length];

		for (int i = 0; i < playInfos.length; i++) {
			Position[] positions = playInfos[i].Area.getAreaPositions();
			for (int j = 0; j < CHESSCOUNT; j++) {
				chesses[i * CHESSCOUNT + j] = 
					new Chess(playInfos[i].color, i * CHESSCOUNT + j);
				chessesPosition[i * CHESSCOUNT + j] = new Position(positions[j]);
			}
		}				
		
		//创建索引
		for (int i = 0; i < chesses.length; i++) {
			Position position =	getPosition(chesses[i]); 
			chessesIndex[position.getx() - 1][position.gety() - 1] = chesses[i];
		}			
		
	}
	
	public Chess getChess(Position position) {
		if (position == null){
			return null;
		}
		return chessesIndex[position.getx() - 1][position.gety() - 1];		
	}
	
	public Chess getChess(int index) {		
		return chesses[index];		
	}

	public int getChessCount() {
		return chesses.length;
	}
	
	public Position getPosition(Chess chess) {		
		return chessesPosition[chess.getindex()];
	}
	
	public Position getPosition(int index) {		
		return chessesPosition[index];
	}

	public void Go(Chess chess, Position chessPosition) {		
		if (chessPosition == null) {
			return;
		}
		Position OldPosition = getPosition(chess);
		//修改索引
		chessesIndex[OldPosition.getx() - 1][OldPosition.gety() - 1] = null;
		chessesIndex[chessPosition.getx() - 1][chessPosition.gety() - 1] = chess;
		
		chessesPosition[chess.getindex()] = new Position(chessPosition);		
	}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -