Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Language! The assignment is to create a text-based, turn-based Space Invade

ID: 3867848 • Letter: J

Question

Java Language!

The assignment is to create a text-based, turn-based Space Invaders style game.

The game board is 6 wide by 10 high, though really it could be wider but that would make the game harder.

You type 'f' into the console to fire. This destroys all enemy ships in the column that the player is currently in.

To move you type 'm' followed by the number of the column to move to that column. For example if you want to move to the second column you type in "m 2".

Each round the space invaders move down toward the ground. For each one that hits the ground you lose a life.

Explanation / Answer

commons.java

Alien.java

This is the Alien sprite. Each alien has an inner Bomb class.

The act() method is called from the Board class. It is used to position an alien in horizontal direction.

The getBomb() method is called when the alien is about to drop a bomb.

Player.java

This is the Player sprite. We control the cannon with the cursor keys.

These are the initial coordinates of the player sprite.

If we press the left cursor key, the dx variable is set to -2. Next time the act() method is called, the player moves to the left.

If we release the left or the right cursor, the dx variable is set to zero. The player sprite stops moving.

Shot.java

This is the Shot sprite. The shot is triggered with the Space key. The H_SPACE and the V_SPACEconstants are used to position the missile appropriately.

Sprite.java

This is the basic Sprite class. Other sprites inherit from it. It has some common functionality.

Board.java

The main logic of the game is located in the Board class.

In the gameInit() method we create 24 aliens. The alien image size is 12x12 px. We put 6 px space among the aliens. We also create the player and the shot objects.

The drawBombing() method draws bombs launched by the aliens.

Inside the paintComponent() method, we draw the ground, the aliens, the player, the shot, and the bombs.

Next we will examine the animationCycle() method.

If we destroy all aliens, we win the game.

If the shot triggered by the player collides with an alien, the alien ship is destroyed. More precisely, the dying flag is set. We use it to display an explosion. The deaths variable increases and the shot sprite is destroyed.

If the aliens reach the right end of the Board, they move down and change their direction to the left.

This code moves aliens. If they reach the bottom, the invasion begins.

This is the code that determines whether the alien will drop a bomb. The alien must not be destroyed; i.e. he must be visible. The bomb's destroyed flag must be set. In other words, it is alien's first bomb dropping or previous dropped bomb already hit the ground. If these two conditions are fulfilled, the bombing is left to the chance.

If the bomb is not destroyed, it goes 1 px to the ground. If it hits the bottom, the destroyed flag is set. The alien is now ready to drop another bomb.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote