Computer Science / Game Programming
import java.util.Random; import comp1022p.ColorImage; import comp1022p.assignment.ModelLogic; import comp1022p.assignment.Target; public class StudentModel implements ModelLogic { /** * Initializes a 2D target array with m rows and n columns of Target objects according to the game level. You can assume that the 2D array itself (but not the Target objects inside) is already initialized. * * Game level 1: * All targets are stationary. * * Game level 2: * For even numbered rows, targets at even numbered columns are stationary, targets at odd numbered columns are movable. * For odd numbered rows, targets at odd numbered columns are stationary, targets at even numbered columns are movable. * * Game level 3: * All targets are movable. * * @param targets The m x n 2D target array. * @param gameLevel The game level of the game. */ public void initializeTargetArray(Target[][] targets, int gameLevel) { //*** Finish this method. ***// } /** * Generates an intermediate bullet ColorImage for the shooting animation according to the current step of the animation. * * As the current step approaches the final step, the intermediate bullet image should appear farther away and smaller in size. * This method selects a bullet image of the correct depth from an array of pre-generated depth images (ordered from closer to farther away) and set it to the correct scale according to the current step of the animation. * In order to select the correct depth image from the array and to set its scale to a correct value, the technique of linear interpolation should be used. * * As an example, given the following: * s0 - initial scale * s1 - final scale * t0 - initial step * t1 - final step * t - current step * * then s, the current scale, can be calculated by the following formula: * * s = s0 + (s1 - s0) * (t - t0) / (t1 - t0) * * Reference: http://en.wikipedia.org/wiki/Linear_interpolation * * @param depthImages An array of bullet images of different depths, ordered from closer to farther away. * @param initialStep The initial step of the shooting animation. * @param currentStep The current step of the shooting animation. * @param finalStep The final step of the shooting animation. * @param initialScale The initial scale of the intermediate bullet image. * @param finalScale The final scale of the intermediate bullet image. * * @return The intermediate bullet image for the shooting animation. */ public ColorImage generateIntermediateBulletImage(ColorImage[] depthImages, int initialStep, int currentStep, int finalStep, double initialScale, double finalScale) { //*** Finish this method. ***// return null; //You need to change this statement to something else in your implementation. } /** * Moves the bullet image for the shooting animation according to the current step of the animation. * * As the current step approaches the final step, the intermediate bullet image should move closer to the final x, y positions. * This method set the x, y position of the bullet image to the correct values according to the current step of the animation. * In order to calculate the correct values of x, y positions, the technique of linear interpolation should be used. * * As an example, given the following: * y0 - initial y position * y1 - final y position * t0 - initial step * t1 - final step * t - current step * * then y, the current y position, can be calculated by the following formula: * * y = y0 + (y1 - y0) * (t - t0) / (t1 - t0) * * Reference: http://en.wikipedia.org/wiki/Linear_interpolation * * @param bulletImage The bullet image to be moved. * @param initialStep The initial step of the shooting animation. * @param currentStep The current step of the shooting animation. * @param finalStep The final step of the shooting animation. * @param initialX The initial x position of the intermediate bullet image. * @param finalX The final x position of the intermediate bullet image. * @param initialY The initial y position of the intermediate bullet image. * @param finalY The final y position of the intermediate bullet image. */ public void moveBulletImage(ColorImage bulletImage, int initialStep, int currentStep, int finalStep, int initialX, int finalX, int initialY, int finalY) { //*** Finish this method. ***// } /** * Updates the position of movable targets. * * This method checks each of the targets in the 2D array and update its position by the following rules: * * 1. Targets that are stationary should not be moved. * 2. Targets that are movable should be moved to an adjacent position (horizontally, vertically and diagonally) by some chance, GIVEN THAT the target in the adjacent position is already being hit. * 3. If there are multiple adjacent positions available, moving to either one is acceptable. * 4. If there are multiple targets that could be moved to the same position, moving either one is acceptable. * 5. Each target should be moved ONCE only for each call of this method. * * @param targets The 2D array containing all the targets. */ public void updateTargetPositions(Target[][] targets) { //*** Finish this method. ***// } }