Ejemplo n.º 1
0
 def fill(self,size,colortop,colorbottom,fieldSize):
     self.PM = PylotMap_class(size,colortop,colorbottom)
     self.fieldSize = fieldSize
     self.squareSize = (self.fieldSize - size -1) * 1.0 / size
Ejemplo n.º 2
0
 def fill(self, size, colortop, colorbottom, fieldSize):
     self.PM = PylotMap_class(size, colortop, colorbottom)
     self.fieldSize = fieldSize
     self.squareSize = (self.fieldSize - size - 1) * 1.0 / size
Ejemplo n.º 3
0
class PG(Widget):

    count = NumericProperty(0)
    fieldSize = NumericProperty(0)

    def fill(self,size,colortop,colorbottom,fieldSize):
        self.PM = PylotMap_class(size,colortop,colorbottom)
        self.fieldSize = fieldSize
        self.squareSize = (self.fieldSize - size -1) * 1.0 / size


    def newgame(self):
        self.PM.new()
        self.count = self.PM.count

        self.redraw()


    def redraw(self):
        self.canvas.clear()
        with self.canvas:

            Color(1,1,1)
            Rectangle(pos=(0, 0), size=(self.fieldSize,self.fieldSize))
            for i in self.PM.matr:
                for j in i:
                    Color(*j.color)
                    Rectangle(pos=(1+j.xplace * (self.squareSize + 1), 1+j.yplace * (self.squareSize + 1)), size=(self.squareSize,self.squareSize))

    def findxplace(self, x):
        for i in range(self.PM.size):
            if 1 + self.PM.matr[i][i].xplace * (self.squareSize + 1) < x < 1 + self.PM.matr[i][i].xplace * (self.squareSize + 1) + self.squareSize:
                return self.PM.matr[i][i].xplace
        return -1


    def findyplace(self, y):
        for i in range(self.PM.size):
            if 1 + self.PM.matr[i][i].yplace * (self.squareSize + 1) < y < 1 + self.PM.matr[i][i].yplace * (self.squareSize + 1) + self.squareSize:
                return self.PM.matr[i][i].yplace
        return -1


    def on_touch_up(self, touch):
        xplace = self.findxplace(touch.y)
        yplace = self.findyplace(touch.x)
        if (xplace >= 0) and (yplace >=0):
            self.PM.invert(xplace,yplace)
            self.count = self.PM.count
        self.redraw()
        if self.PM.congratulation():
            self.makesometext()

    def makesometext(self):
        self.lbl.text = "You won! {0}".format(self.count)


    def onbuttonpress(self,lbl,txt):
        self.lbl = lbl

        colortop = (random(), random(), random())
        colorbottom = (random(), random(), random())

        fieldSize = self.parent.width

        self.fill(int(txt.text),colortop,colorbottom,fieldSize)
        self.newgame()
Ejemplo n.º 4
0
class PG(Widget):

    count = NumericProperty(0)
    fieldSize = NumericProperty(0)

    def fill(self, size, colortop, colorbottom, fieldSize):
        self.PM = PylotMap_class(size, colortop, colorbottom)
        self.fieldSize = fieldSize
        self.squareSize = (self.fieldSize - size - 1) * 1.0 / size

    def newgame(self):
        self.PM.new()
        self.count = self.PM.count

        self.redraw()

    def redraw(self):
        self.canvas.clear()
        with self.canvas:

            Color(1, 1, 1)
            Rectangle(pos=(0, 0), size=(self.fieldSize, self.fieldSize))
            for i in self.PM.matr:
                for j in i:
                    Color(*j.color)
                    Rectangle(pos=(1 + j.xplace * (self.squareSize + 1),
                                   1 + j.yplace * (self.squareSize + 1)),
                              size=(self.squareSize, self.squareSize))

    def findxplace(self, x):
        for i in range(self.PM.size):
            if 1 + self.PM.matr[i][i].xplace * (
                    self.squareSize + 1) < x < 1 + self.PM.matr[i][
                        i].xplace * (self.squareSize + 1) + self.squareSize:
                return self.PM.matr[i][i].xplace
        return -1

    def findyplace(self, y):
        for i in range(self.PM.size):
            if 1 + self.PM.matr[i][i].yplace * (
                    self.squareSize + 1) < y < 1 + self.PM.matr[i][
                        i].yplace * (self.squareSize + 1) + self.squareSize:
                return self.PM.matr[i][i].yplace
        return -1

    def on_touch_up(self, touch):
        xplace = self.findxplace(touch.y)
        yplace = self.findyplace(touch.x)
        if (xplace >= 0) and (yplace >= 0):
            self.PM.invert(xplace, yplace)
            self.count = self.PM.count
        self.redraw()
        if self.PM.congratulation():
            self.makesometext()

    def makesometext(self):
        self.lbl.text = "You won! {0}".format(self.count)

    def onbuttonpress(self, lbl, txt):
        self.lbl = lbl

        colortop = (random(), random(), random())
        colorbottom = (random(), random(), random())

        fieldSize = self.parent.width

        self.fill(int(txt.text), colortop, colorbottom, fieldSize)
        self.newgame()