CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Start learning now
  • All questions
Satya Vath
Level 31
Vijayawada
  • 07.10.2019
  • 645views
  • 2comments

Help Me

Question about the task Space Invaders (Part 28/34)
Games,  Level 0,  Lesson 6
Under discussion

At this stage, we'll add a checkHit(List<Bullet> bullets) method for checking whether the player's projectile has hit an enemy ship.
After a hit, we need to "kill" the corresponding projectile and enemy ship. Additionally, we'll add a deleteHiddenShips() method that will remove "hidden" ships from the list.
To remove the ships, you can either use an iterator, or create a copy of the ships list and run through it in a loop. If we determine that a ship needs to be removed, we'll call ships.remove(ship).
The checkHit(List<Bullet> bullets) and deleteHiddenShips() methods must be called in the SpaceInvadersGame class's check() method.

Requirements:
  • The EnemyFleet class must have a public void checkHit(List<Bullet> bullets) method.
  • In the checkHit(List<Bullet> bullets) method, you need to use the isCollision(GameObject) method to check whether each enemy ship in the ships list has collided with any of the projectiles in the bullets list.
  • If a ship and projectile have collided (the isCollision(GameObject) method returns true) and the ship is "alive" and the projectile is "alive", you need to call the kill() on them.
  • The EnemyFleet class must have a public void deleteHiddenShips() method.
  • The deleteHiddenShips() method must remove from the ships list all ships that are not visible on the playing field (ship.isVisible() == false).
  • In the SpaceInvadersGame class's check() method, you need to call the checkHit(List<Bullet>) method with playerBullets as the argument on the enemyFleet object before the call to the removeDeadBullets() method.
  • In the SpaceInvadersGame class's check() method, you need to call the deleteHiddenShips() method on the enemyFleet object after the checkHit(List<Bullet>) method.
package com.codegym.games.spaceinvaders; public enum Direction { RIGHT, LEFT, UP, DOWN }
0
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Guadalupe Gagnon
Level 37 , Tampa, United States
7 October 2019, 17:21
In the checkHit() method your code checks if the bullet at bullets index i collides with the ship at ships index i, however what the code should do is check if bullet at index i collides with any of the ships in the ships list.
0
Satya Vath
Level 31 , Vijayawada, India
8 October 2019, 05:05
Thank You Solved It :D
0
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.