summaryrefslogtreecommitdiff
path: root/comp/work/21/minesweeper.py
blob: 2a6be2254e3c053686ab151f1b87b70cff693cea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)