Package pr.battlebots

Source Code of pr.battlebots.VecIterator

package pr.battlebots;

import java.util.Iterator;
import pr.lib.Vec;

public class VecIterator implements Iterator<Vec> {

        public VecIterator(int rowA, int rowB, int colA, int colB) {
            this.startCol = Math.min(colA, colB);
            this.startRow = Math.min(rowA, rowB);
            this.endCol = Math.max(colA, colB);
            this.endRow = Math.max(rowA, rowB);
            this.row = rowA;
            this.col = colA;
        }
        public final int startRow, startCol, endRow, endCol;
        int row, col;

        @Override
        public boolean hasNext() {
            return col <= endCol && row <= endRow;
        }

        @Override
        public Vec next() {

            Vec v = new Vec(col, row);
            //Debug.log(v.toString());
            col++;
            if (col > endCol) {
                col = startCol;
                row++;
            }

            return v;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("I'm sorry Dave, I'm afraid I can't do that.");
        }
    }
TOP

Related Classes of pr.battlebots.VecIterator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.