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

📄 cardfoundation.java

📁 一个J2ME编写的牌类游戏
💻 JAVA
字号:
package de.tsr.jsol.logic;

import java.util.*;
import java.util.NoSuchElementException;
import javax.microedition.lcdui.*;

import de.tsr.jsol.gui.IGraphicsWrapper;
import de.tsr.jsol.util.CStack;

public class CardFoundation extends CardContainer implements ICardSelection{
	CStack _foundation = new CStack();
	Card _selection;
	ScoreCounter _scoreCounter;
	
	public CardFoundation(int x, int y, ScoreCounter scoreCounter) {
		super(x, y);
		_scoreCounter = scoreCounter;
	}
	
	protected void Draw(IGraphicsWrapper g) {
		if( !_foundation.empty() && _selection == null ) {
			((Card)_foundation.peek()).Paint(g);
		}
		else if( _selection != null ) {
			g.setStrokeStyle( Graphics.DOTTED );
			_selection.Paint( g );
			g.setStrokeStyle( Graphics.SOLID);			
		}
		else {
			DrawEmptyContainer(g);
		}		
	}
	
	public void SingleClicked() {
		return ;
	}
	
	public ICardSelection Clicked(ICardSelection selection) {
		if( selection == null ) 
			return VisitClicked();
		else
			return VisitCardGroup(selection);
		}
	
	
	private ICardSelection VisitCardGroup(ICardSelection selection) {		
		if( selection.SelectionSize() != 1 ) return selection;
		
		if(_foundation.empty() ) {
			if( selection.SelectedCardAt(0).Rank() == Card.ACE ) {
				_foundation.push(selection.SelectedCardAt(0) );
				_scoreCounter.AddScore(10);
				selection.RemoveSelection();
				return null;
			}
			else 
				return selection;
		}
		else if( selection.SelectedCardAt(0).Suit() == _foundation.peek().Suit() 
				&& selection.SelectedCardAt(0).Rank() == _foundation.peek().Rank() + 1 ) {
			_foundation.push(selection.SelectedCardAt(0) );
			_scoreCounter.AddScore(10);
			selection.RemoveSelection();
			return null;
		}
		return selection;
	}

	private ICardSelection VisitClicked() {
		if( ! _foundation.empty() ) {
			_selection  = _foundation.pop();
			_scoreCounter.SubtractScore(10);
			return this;
		}
		return null;
	}
	
	public Card SelectedBottomCard() {
		return _selection;
	}
	public Card SelectedCardAt(int position) {
		if( position != 0 ) {
			throw new NoSuchElementException("Index out of range. Waste has only one"
					+ " selected Card.");
		}
		return _selection;
	}
	public Card SelectedTopCard() {
		return _selection;
	}
	
	public int SelectionSize() {
		if( _selection == null ) 
			return 0;
		else 
			return 1;		
	}
	public void RemoveSelection() {
		_selection = null;
	}
	public Enumeration SelectedElements() {
		Vector v = new Vector();
		v.addElement(_selection);
		return v.elements();
	}
	
	public Card CardOnTop() {
		if( _foundation.empty() ) 
			return null;
		else 
			return _foundation.peek();
	}
}

⌨️ 快捷键说明

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