package A3;

import java.util.ArrayList;
import java.util.Iterator;

public class DeckIteratorFaceUp implements DeckIterator,Iterator<Card> {
	private StandardDeckImpl cards;
	
	
	public DeckIteratorFaceUp(StandardDeckImpl cards){

		this.cards=cards;
		
	}
	
	@Override
	public boolean hasNext() {
		// TODO Auto-generated method stub
		if(cards.getTop()==null)return false;
		
		for(int i=0; i<cards.getSize();i++){
			
			if(cards.getTop().isFaceUp()){
				cards.cut(i);
				return true;
			}
			cards.rotate();
		}
		return false;

		
	}

	@Override
	public Card next() {
		// TODO Auto-generated method stub
		if(!hasNext()){throw new RuntimeException("No next card.");}
		while (!cards.getTop().isFaceUp()){
			cards.rotate();
		}
		
		return cards.takeTop();
	}

	@Override
	public void remove() {
		// TODO Auto-generated method stub
		throw new RuntimeException("Remove not supported ");
	}

}
