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

📄 autorobot.java

📁 小游戏一个 蜘蛛纸牌
💻 JAVA
字号:
package dujid.araneid;

import java.util.Iterator;
import java.util.Stack;

public class AutoRobot {
	private Araneid main;
	public AutoRobot() {
	}
	public AutoRobot(Araneid main) {
		this.main = main;
	}
	public boolean isAddAble(Card previous, Card next) {
		if (previous.getCurrent()==previous.getRear() ||
		next.getCurrent()==next.getRear()) return false;

		int p = Integer.parseInt((String)previous.getCode());
		int n = Integer.parseInt((String)next.getCode());
		if (n==p-1 || n==p-21 || n==p-41 || n==p-61
		|| n==p+19 || n==p+39 || n==p+59)
			return true;
		else
			return false;
	}
	public boolean isSelectAble(Card cardtarget, Stack cards) {
		if (cardtarget.getCurrent()==cardtarget.getRear() || cards.size()<=0 ) return false;

		int pos = cards.search(cardtarget);
		if (pos<=0) return false;
		Card cardlast = (Card)cards.lastElement();
		if (cardlast.getCurrent()==cardlast.getRear()) return false;

		int last = Integer.parseInt((String)(cardlast.getCode()));
		int count = cards.size();
		for (int i=count-pos;i<count;i++) {
			int target = Integer.parseInt((String)((Card)cards.elementAt(i)).getCode());
			if (target - last != count-i-1) return false;
		}
		return true;
	}
	public Card[] searchCardMoveAble(Pools[] pools) {
		for (int i=0;i<pools.length;i++) {
			pools[i].removeNoteCard();
			Pools poolSelect = (Pools)pools[i];
			Stack cardsSelect = (Stack)poolSelect.getCards();
			if (cardsSelect.size()<=0) continue;
			Iterator cardlistSelect = (Iterator)cardsSelect.iterator();
			while(cardlistSelect.hasNext()) {
				Card cardSelect = (Card)cardlistSelect.next();
				int sel = cardsSelect.search(cardSelect);
				Card cardPrevious = null;
				if (sel<cardsSelect.size()) {
					cardPrevious = (Card)cardsSelect.elementAt(cardsSelect.size()-sel-1);
				}
				if (isSelectAble(cardSelect,cardsSelect)) {
					for (int k=0;k<pools.length;k++) {
						if (k==i) continue;
						Pools poolTarget = (Pools)pools[k];
						Stack cardsTarget = (Stack)poolTarget.getCards();
						if (cardsTarget.size()<=0) continue;
						Card cardTarget = (Card)cardsTarget.lastElement();
						if (isAddAble(cardTarget,cardSelect)) {
							cardSelect.setPool(poolSelect);
							cardTarget.setPool(poolTarget);
							if (cardPrevious==null) {
								return new Card[] {cardSelect,cardTarget};
							} else {
								if ( !(cardPrevious.getCode().equals(cardTarget.getCode())
								&& cardPrevious.getCurrent() != cardPrevious.getRear())) {
									return new Card[] {cardSelect,cardTarget};
								}
							}
						}
					}
				}
			}
		}
		return null;
	}
	public boolean isMoveListAble(Stack cardlist) {
		if (cardlist.size() < 13) return false;
		Card cardlast = (Card)cardlist.lastElement();
		int last = Integer.parseInt((String)cardlast.getCode());
		if (last != 1) return false;
		//int card13 = Integer.parseInt(((Card)cardlist.elementAt(cardlist.size()-13)).getCode());
		for(int i=1;i<=13;i++) {
			Card card = (Card)cardlist.elementAt(cardlist.size()-i);
			if (card.getCurrent()==card.getRear()) return false;
			int step = Integer.parseInt(card.getCode());
			if (step!=i) return false;
		}
		return true;
	}
	public void autoTurnLast(Pools pool) {
		if (!pool.getCards().isEmpty()) {
			Card card = (Card)pool.getCards().lastElement();
			card.turn2front();
		}
	}
	public void moveCompletedList(Stack cards) {
		//Iterator cardlist = (Iterator)cards.iterator();
		for (int i=0;i<12;i++) {
			cards.pop();
		}
		main.completedpool.putCompleted((Card)cards.pop());
		main.player.addScore(100);

		if (this.isVictoried(main.pool)) {
			showVictoriedPanel();
		}
	}
	public boolean isVictoried(Pools[] pool) {
		for (int i=0;i<pool.length;i++) {
			if (pool[i].getCards().size() > 0) return false;
		}
		return true;
	}
	public void showVictoriedPanel() {
		main.getContentPane().removeAll();
		main.getContentPane().add(main.victorypanel);
		main.validate();
		main.getContentPane().repaint();
	}
	public int getCardIndexOnMouse(int y,Pools pool) {
		Stack cards = (Stack)pool.getCards();
		if (cards.size()<=0) return -1;
		Iterator cardlist = cards.iterator();

		int space=0;
		int yy=0;
		//Card cardlast = (Card)cards.lastElement();
		main.poolmousemotion.removeCardIndexSelect();
		//AutoRobot robot = new AutoRobot();
		int count=0;
		while(cardlist.hasNext()) {
			Card card = (Card)cardlist.next();
			if (card.getCurrent() == card.getRear())
				space=5;
			else
				space=5+pool.getCardSpaceCoeff();
			int yend = yy+space;
			count++;
			if ( ((y>yy && y<yend) || (y>yy && count==cards.size())) && isSelectAble(card,cards)) {
				return cards.size()-count+1;
			}
			yy+=space;
		}
		return -1;
	}
}

⌨️ 快捷键说明

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