Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package minesweeper
- import kotlin.random.Random
- const val fieldSize = 9
- val field = MutableList(fieldSize) {
- MutableList(fieldSize) { "." }
- }
- fun main() {
- var mines = readln().toInt()
- while (mines > 0) {
- val row = Random.nextInt(0, fieldSize - 1)
- val cell = Random.nextInt(0, fieldSize - 1)
- if (field[row][cell] == "X") {
- continue
- } else {
- field[row][cell] = "X"
- helpInTheGame(row, cell)
- mines--
- }
- }
- for (raw in field) {
- println(raw.joinToString(""))
- }
- }
- fun helpInTheGame(row: Int, cell: Int) {
- if(row == 0 && cell == 0) {
- topLeft()
- } else if (row == 0 && cell == fieldSize - 1) {
- topRight()
- } else if (row == fieldSize - 1 && cell == 0) {
- bottomLeft()
- } else if (row == fieldSize - 1 && cell == fieldSize - 1) {
- bottomRight()
- } else if (row == 0) {
- firstRow(cell)
- } else if (row == fieldSize - 1) {
- lastRow(cell)
- } else if (cell == 0) {
- leftRow(row)
- } else if (cell == fieldSize - 1) {
- rightRow(row)
- } else placedAnywhere(row, cell)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement