Skip to content

v06 solitaire moves ResetDeckMove.scs

George Heineman edited this page Feb 8, 2018 · 1 revision
	ResetDeckMove : {
		λname.   {letbox NameParameter     = {name} in {

		box ["=======" NameParameter "\ResetDeckMove.java=======
package " NameParameter ";

import ks.common.games.*;
import ks.common.model.*;

/**
 * Represents the reset of the deck given an array of (or just a single) Stack objects
 * into which cards were dealt.
 */
public class ResetDeckMove extends ks.common.model.Move {
	/** The deck. */
    protected Deck deck;

	/** Stacks containing cards. */
	protected Stack[] stacks;

	public ResetDeckMove(Deck from, Stack[] stacks) {
		super();

		this.deck = from;
		this.stacks = stacks;
	}

	public ResetDeckMove(Deck from, Stack singleStack) {
		super();

		this.deck = from;
		this.stacks = new Stack[] { singleStack };
	}

	/**
	 * Each move should knows how to execute itself.
	 */
	public boolean doMove (Solitaire theGame) {

		// VALIDATE:
		if (valid (theGame) == false)
			return false;

		// EXECUTE:
		int numAdded = 0;
		for (int i = stacks.length-1; i >= 0; i--) {
			while (!stacks[i].empty()) {
				deck.add(stacks[i].get());
				numAdded++;
			}
		}

		// finally update the total number.
		theGame.updateNumberCardsLeft(numAdded);
		return true;
	}
	/**
	 * This move cannot be undone.
	 */
	public boolean undo(ks.common.games.Solitaire game) {
		return false;
	}

	/**
	 * Validate ResetDeck Move.
	 * @param game edu.wpi.cs.soltaire.games.Solitaire
	 */
	public boolean valid (ks.common.games.Solitaire game) {
		// VALIDATION:
		boolean validation = false;

		if (deck.empty())
			validation = true;

		return validation;
	}
}
		"]

		}}
	}