forked from mbairi/MineSweeperAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.py
More file actions
67 lines (52 loc) · 2.01 KB
/
renderer.py
File metadata and controls
67 lines (52 loc) · 2.01 KB
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
import pygame
import numpy as np
import sys
import random
class Render():
def __init__(self,state):
self.GRAY_SHADES= [
(39, 43, 48),
(34, 40, 49),
(238, 238, 238),
]
self.BLUE = [
(0, 172, 181),
(0,165,181),
(0,160,181),
(0,155,181),
(0,150,181)
]
h,w = state.shape
self.blockSize = 30
self.WINDOW_HEIGHT = h*self.blockSize
self.WINDOW_WIDTH = w*self.blockSize
self.state = state
self.init()
def init(self):
pygame.init()
self.font = pygame.font.SysFont('Courier', 18,bold=True)
self.SCREEN = pygame.display.set_mode((self.WINDOW_HEIGHT, self.WINDOW_WIDTH))
self.CLOCK = pygame.time.Clock()
self.SCREEN.fill(self.GRAY_SHADES[1])
def draw(self):
self.drawGrid()
pygame.display.update()
def bugfix(self):
return pygame.event.get()
def addText(self,no,x,y,color):
self.SCREEN.blit(self.font.render(str(no), True, color), (x, y))
pygame.display.update()
def drawGrid(self):
j=0
for column in range(0, self.WINDOW_WIDTH, self.blockSize):
i=0
for row in range(0, self.WINDOW_HEIGHT, self.blockSize):
if(self.state[i][j]==-1):
pygame.draw.rect(self.SCREEN, self.GRAY_SHADES[0], [column,row,self.blockSize,self.blockSize])
if(self.state[i][j]==0):
pygame.draw.rect(self.SCREEN, self.GRAY_SHADES[2], [column,row,self.blockSize,self.blockSize])
elif(self.state[i][j]>0):
pygame.draw.rect(self.SCREEN, self.BLUE[0], [column,row,self.blockSize,self.blockSize])
self.addText(self.state[i][j],column+10,row+7,self.GRAY_SHADES[2])
i+=1
j+=1