package gamecontrollers.rules.tileplacementrules;

import gamecontrollers.Message;

/**
 * Created by williammacfarlane on 4/14/14.
 */
public class TiltedTilePlacement extends TilePlacementRule {

	@Override
	public void update() {

	}

	@Override
	public Message getErrorMessage() {
		return null;
	}
}

@@ -80,226 +80,2869 @@
 ge;%0A
-%0A/**%0A * Created by williammacfarlane on 4/14/14.%0A */%0Apublic class TiltedTilePlacement extends TilePlacementRule %7B%0A%0A%09@Override%0A%09public void update() %7B%0A%0A%09%7D%0A%0A%09@Override%0A%09public Message getErrorMessage() %7B%0A%09%09return null;%0A%09
+import gamecontrollers.commandcreator.TileCommandCreator;%0Aimport models.board.Direction;%0Aimport models.board.Space;%0Aimport models.board.TileComponent;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Iterator;%0Aimport java.util.List;%0A%0A%0A/**%0A * Created by williammacfarlane on 4/14/14.%0A */%0Apublic class TiltedTilePlacement extends TilePlacementRule %7B%0A    private Message message;%0A    private TileCommandCreator creator;%0A    private Space targetSpace;%0A    private TileComponent targetTile;%0A    private List%3CSpace%3E spacesToBeTouched;%0A    private List%3CTileComponent%3E visitedTiles;%0A%0A    public TiltedTilePlacement(TileCommandCreator creator)%7B%0A        this.creator = creator;%0A        spacesToBeTouched = new ArrayList%3CSpace%3E();%0A        visitedTiles = new ArrayList%3CTileComponent%3E();%0A    %7D%0A%0A%09@Override%0A%09public void update() %7B%0A        //clear last update%0A        spacesToBeTouched.clear();%0A        visitedTiles.clear();%0A%0A        targetSpace = creator.getCurrentSpace();%0A        targetTile = creator.getCurrentTile();%0A%0A        populateList(targetTile, targetSpace);%0A%0A        //this is the height of the space underneath the target tile%0A        //use this height to check the height of all other spaces%0A        int referenceHeight = targetSpace.getHeight();%0A%0A        //boolean to know if tilting was detected%0A        boolean isTilted = false;%0A        for(Space space : spacesToBeTouched)%7B%0A            if(referenceHeight != space.getHeight())%7B%0A                isTilted = true;%0A                break;%0A            %7D%0A        %7D%0A%0A        if(isTilted)%7B%0A            message = new Message(%22TILTED TILE%22, true);%0A            setValidity(false);%0A        %7D%0A        else%7B%0A            message = new Message(%22tile is level%22, false);%0A            setValidity(true);%0A        %7D%0A%0A%0A%09%7D%0A%0A%09@Override%0A%09public Message getErrorMessage() %7B%0A%09%09return null;%0A%09%7D%0A%0A    //populate the list of affected spaces%0A    private void populateList(TileComponent tile, Space space)%7B%0A        //get the directions iterator from the target tile%0A        spacesToBeTouched.add(space);%0A        Iterator%3CDirection%3E iterator = tile.getDirection().iterator();%0A%0A        //check the spaces under the target tile for the same height%0A        while(iterator.hasNext())%7B%0A            Direction direction = iterator.next();%0A            if(tile.siblingExists(direction))%7B%0A                //tile is joined in this direction so the space in this direction will be touched%0A                //add it if it hasnt already been added%0A                if(!spacesToBeTouched.contains(space))%0A                    spacesToBeTouched.add(space.getAdjacentSpace(direction));%0A%0A%0A                //if that tile hasnt been visited then visit it%0A                if(!visitedTiles.contains(tile))%0A                    populateList(tile.getConjoinedTile(direction), space.getAdjacentSpace(direction));%0A            %7D%0A%0A        %7D%0A        visitedTiles.add(tile);%0A%0A%0A    
 %7D%0A%7D%0A

Implement TiltedTilePlacement