summaryrefslogtreecommitdiff
path: root/comp/work/21/minesweeper.py
diff options
context:
space:
mode:
Diffstat (limited to 'comp/work/21/minesweeper.py')
-rw-r--r--comp/work/21/minesweeper.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/comp/work/21/minesweeper.py b/comp/work/21/minesweeper.py
new file mode 100644
index 0000000..2a6be22
--- /dev/null
+++ b/comp/work/21/minesweeper.py
@@ -0,0 +1,66 @@
+import random
+grid = [
+ [0,0,0,0,0,0],
+ [0,0,0,0,0,0],
+ [0,0,0,0,0,0],
+ [0,0,0,0,0,0],
+ [0,0,0,0,0,0],
+ [0,0,0,0,0,0],
+ ]
+
+def getValidPos(text):
+ inp = -1
+ while inp < 1 or inp > 6:
+ inp = int(input(text))
+ return inp
+
+def printGrid():
+ for i in grid:
+ for j in i:
+ if j == "B":
+ print("0", end = " ")
+ else:
+ print(j, end = " ")
+ print()
+
+def placeBombs(amount):
+ for i in range(amount):
+ grid[random.randint(0,5)][random.randint(0,5)] = "B"
+
+def isMineNear(row, collumn):
+ row = row - 1
+ collumn = collumn - 1
+ try:
+ if grid[row][collumn+1] == "B":
+ print("a bomb is near")
+ elif grid[row][collumn-1] == "B":
+ print("a bomb is near")
+ elif grid[row+1][collumn] == "B":
+ print("a bomb is near")
+ elif grid[row-1][collumn] == "B":
+ print("a bomb is near")
+ elif grid[row+1][collumn+1] == "B":
+ print("a bomb is near")
+ elif grid[row-1][collumn-1] == "B":
+ print("a bomb is near")
+ elif grid[row-1][collumn+1] == "B":
+ print("a bomb is near")
+ elif grid[row+1][collumn-1] == "B":
+ print("a bomb is near")
+ except:
+ pass
+
+
+placeBombs(10)
+
+score = 0
+while True:
+ printGrid()
+ row = getValidPos("row: ")
+ collumn = getValidPos("collumn: ")
+ if grid[row-1][collumn-1] == "B":
+ print("you blew up, your score was", score)
+ break
+ grid[row-1][collumn-1] = "G"
+ score = score + 1
+ isMineNear(row, collumn)