f2

来源:互联网 发布:linux 7ssh22号端口 编辑:程序博客网 时间:2024/04/29 16:36

def init_crosspos(CROSSPOS):
     for i in range(NUMLINESHORIZONTAL):
        center_x = BOARDLEFT + BOXSIZE + i*BOXSIZE
        cols = []
        for j in range(NUMLINESVERTICAL):
            center_y = BOARDTOP + BOXSIZE + j*BOXSIZE
            new_rect =  pygame.Rect(center_x -SENSITIVESIZE/2,center_y-SENSITIVESIZE/2,SENSITIVESIZE,SENSITIVESIZE)
            cols.append(new_rect)
            #print new_rect
        CROSSPOS.append(cols)


init_crosspos(CROSSPOS)
def init_cross(cross):
    for i in range(NUMLINESHORIZONTAL):
        cols = []
        for j in range(NUMLINESVERTICAL):
            cols.append(0)
        cross.append(cols)

 

def draw_board():
    #pygame.draw.line(Surface, color, start_pos, end_pos, width=1): return Rect
    for x in range(1,NUMLINESHORIZONTAL):
        pygame.draw.line(DISPLAYSURF,WHITE,(BOARDLEFT + x*BOXSIZE,BOARDTOP),(BOARDLEFT + x*BOXSIZE,BOARDTOP + BOARDHEIGHT-1),1)
    for y in range(1,NUMLINESVERTICAL):
        pygame.draw.line(DISPLAYSURF,WHITE,(BOARDLEFT,BOARDTOP + y*BOXSIZE),(BOARDLEFT+BOARDWIDTH-1,BOARDTOP +y*BOXSIZE),1)

def get_position_clicked(CROSSPOS,mousex,mousey):
    for i in range(NUMLINESHORIZONTAL):  
        for j in range(NUMLINESVERTICAL):
            if CROSSPOS[i][j].collidepoint(mousex,mousey) == True:
                return i,j,CROSSPOS[i][j].centerx,CROSSPOS[i][j].centery
    return None,None,None,None