// Bryan Blackford - bblackfo@ucsc.edu // Train is a container class for traincars class Train { int x=0; int y=0; int cars=0; // number of cars in train int carlength=30; // length of each car Traincar[] carArr; // car array // initialize train Train(int X,int Y,int Cars) { x=X; y=Y; cars=Cars; // create cars carArr = new Traincar[cars]; for (int c = 0;c < cars;++c) { carArr[c] = new Traincar(x+(carlength*c)+1,y,carlength); } } void update() { // update each car for (int c = 0;c < cars;++c) { carArr[c].update(); } // check if train has moved off screen if (cars > 0) { //print(cars); // debug if (carArr[cars-1].xpos < -carlength) // last car has moved off screen cars = 0; // frees train for reuse } } }