The "Simple Startup Game" is a simplified version of a Battleship-style game where the player must guess the location of a computer’s hidden "Startup," which occupies three consecutive cells in a virtual 7-cell row. In this version, there’s only one Startup, and the program doesn’t use a full 2D grid. Instead, the game uses an array to hold the three consecutive cells where the Startup is located. The player inputs guesses, and the game checks whether each guess is a "hit" or "miss." The goal is to guess all three cells of the Startup’s location, at which point the game ends. The game code is all contained in the main() method of the Game class, and there are no instance variables—just the logic for tracking the guess and checking for hits. The game serves as a precursor to a more complex version with multiple Startups and a larger grid.
In the "Simple Startup Game," the virtual row, where the Startup is hidden, doesn't actually need to be represented as a full array in the program. The row is virtual because the game logic and the user both know that the Startup occupies three consecutive cells out of seven possible positions (ranging from 0 to 6). Instead of building an array to represent the full 7-cell row, you only need an array to hold the actual positions where the Startup is located. This means you only need an array of three integers that represent the specific cells where the Startup resides, without needing to manage the entire grid. The game simply uses these three positions to check if the player’s guesses match the Startup's location. if all the location of "starups" are guessed (numofhits variable becomes equals to 3) then "kill" message will show up.
It uses checkyourself() method which takes in user guess as a parameter and checks whether user guess matches with location of startup cells and setlocationcells() method which is the setter method to set the array location of startup.
Isn't the algo wrong ? For example lets say user guess is 3 and we have an array where startup location is placed at [2,3,4] the first time` the userguess (3) is not equals to 2 and hence the outer else block will be executed which will return miss ? Even though 3 is present in the second element of the array ?
Here is the pdf version of the algorithm for those are not able to understand the problem statement :- .pdf