From eb1a5582181bf3188f30d665a295321d36bdc795 Mon Sep 17 00:00:00 2001 From: standenboy Date: Thu, 25 Jan 2024 10:57:10 +0000 Subject: did the cover work --- comp/work/21/minesweeper.py | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 comp/work/21/minesweeper.py (limited to 'comp/work/21/minesweeper.py') 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) -- cgit v1.2.3