ocean represents the grid where the opponent ships are.That suggests that our initialisation might want to include two arrays: In the normal game you have a grid for your ships where you mark enemy attacks and you have another grid for marking where you've hit the opponent. When we've hit all the squares which contain parts of boats, the game is over. You tell your opponent which square you're targeting by giving them a coordinate like 'A2', 'J3' and so on. How do we distinguish between each player's ships?Īs the game goes on, we need to mark which grid squares we have aimed at. The array can be initialised so that the ocean is empty with the following: ocean =. Empty spaces could be represented by using full stops. The next decision is what goes in each blank space on the map. We determine that the grid size should be eight by eight. The paper version of the game uses grid references like A2, H5, C3 but the array uses two numbers to indicate the position of a data element such as, and. retrieve the value of data at individual locations.set the value of data elements at individual locations. Coordinate grid games battleship online update#It would be best to use a data structure that allows the game to store and update data in a grid. We will work through some of these questions here, one step at a time: How is the game grid represented?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |