RowOfAlien

RowOfAlien - row[topIndex = alien public void draw(Graphics...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.awt.Graphics; // You do not have to throw an exception if an index is out // of bounds. // This skeleton shows the member functions and data members // that are required. You may add more as you wish. public class RowOfAlien { // CONSTANTS public final int EMPTY = -1; // VARIABLES private Alien[] row; private int topIndex; public RowOfAlien(int numberOfAliens) { row = new Alien[numberOfAliens]; topIndex = -1; } public void add(Alien alien) { if (topIndex < row.length - 1) { topIndex = topIndex + 1;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: row[topIndex] = alien; } } public void draw(Graphics g) { for (int index = 0; index <= topIndex; index++) { row[index].draw(g); } } public void move() { for (int index = 0; index <= topIndex; index++) { row[index].move(); } } public void remove(int index) { for (int update = index; update < topIndex; update++) { row[update] = row[update + 1]; } topIndex--; } public int topIndexReturn() { return topIndex; } public Alien returnAlien(int index){ return row[index]; } }...
View Full Document

This note was uploaded on 06/10/2011 for the course COMP 110 taught by Professor Stotts during the Spring '08 term at UNC.

Ask a homework question - tutors are online