nutolz.blogg.se

Java code for minesweeper game
Java code for minesweeper game










Height ) īomb_Count : Positive := Width * Height * 20 / 100 Procedure Set_Bombs (Item : in out Grid Max_X, Max_Y, Count : Positive ) is Opened andĬlear_Neighbours (The_X + 1, The_Y - 1 ) Opened andĬlear_Neighbours (The_X - 1, The_Y - 1 ) If Mines_Nearby (Item, The_X, The_Y ) = 0 then only proceed if neighbours don't have mines Procedure Clear_Neighbours (The_X, The_Y : Positive ) is clears the neighbours, if they don't have mines clears a field and it's neighbours, if they don't have mines Procedure Mark (Item : in out Grid X, Y : in Positive ) is

java code for minesweeper game

counts how many mines are in the surrounding fieldsįunction Mines_Nearby (Item : Grid X, Y : Positive ) return Natural is Type Grid is array (Positive range, Positive range ) of Field Note: Changes may be made to the method of clearing mines to more closely follow a particular implementation of the game so long as such differences and the implementation that they more accurately follow are described.Īda with Ada. You may also omit all GUI parts of the task and work using text input and output. The Task is to create a program that allows you to play minesweeper on a 6 by 4 grid, and that assumes all user input is formatted correctly and so checking inputs for correct form may be omitted. You win when you have correctly identified all mines.Of course you lose if you try to clear space that has a hidden mine.

java code for minesweeper game

Other free points show as an integer count of the number of adjacent true mines in its immediate neighborhood, or as a single space ' ' if the free point is not adjacent to any true mines.If the point is free space then it is cleared, as are any adjacent points that are also free space- this is repeated recursively for subsequent adjacent free points unless that point is marked as a mine or is a mine.You can mark what you think is free space by entering its coordinates.You may mark what you think is the position of a mine which will show as a '?'.You are initially shown all grids as obscured, by a single dot '.'.The grid is shown as a rectangle of characters between moves.Each mine occupies a single grid point, and its position is initially unknown to the player.The total number of mines to be found is shown at the beginning of the game.The top left of the grid is position 1,1 the bottom right is at n,m.

java code for minesweeper game

Positions in the grid are modified by entering their coordinates where the first coordinate is horizontal in the grid and the second vertical. There is an n by m grid that has a random number (between 10% to 20% of the total number of tiles, though older implementations may use 20%.60% instead) of randomly placed mines that need to be found. You are encouraged to solve this task according to the task description, using any language you may know.












Java code for minesweeper game