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.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? how do we represent squares we have checked?.how do we distinguish between each player's ships?.You would need to think about questions such as: If you created this game as a computer program you need to think about how the actual game played on paper would be converted into code. ![]() Two players plot their ships on a grid in secret and then take it in turns to guess where their opponent has plotted their ships. Each point on the grid represents a space on a map of the ocean where a ship might be. The following example will show how a two-dimensional array can be used to represent the classic game of Battleship by Hasbro.īattleship is a game which is played on a two-dimensional grid. Arrays are used frequently by games developers to structure data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |