コード例 #1
0
 def printshadow(self):
     shadowpos = coord(self.pos.x, self.pos.y)
     while 1:
         shadowpos.y += 1
         if self.collision(shadowpos):
             shadowpos.y -= 1
             break
     for i, line in enumerate(self.peice):
         for j, ch in enumerate(line):
             if ch != '.':
                 real = coord((shadowpos.x + j) * self.scl,
                              (shadowpos.y + i) * self.scl + self.offset.y)
                 color = self.selectcolor(ch)
                 color = color // pygame.Color(3, 3, 3)
                 self.printblock(coord(real.x, real.y), color, None, True)
コード例 #2
0
 def printpeice(self):
     for i, line in enumerate(self.peice):
         for j, ch in enumerate(line):
             if ch != '.':
                 real = self.realpos(j, i)
                 color = self.selectcolor(ch)
                 self.printblock(coord(real.x, real.y), color)
コード例 #3
0
 def __init__(self, parent, x, y, mult) :
     case.case.__init__(self, parent)
     self.coord = coord.coord(x,y)
     self.mult = mult
     self.col_fond = self.app.settings['col_grille'][self.mult]
     self.Bind(wx.EVT_LEFT_DOWN, self.OnClickCase)
     self.Bind(wx.EVT_LEFT_DCLICK, self.OnClickCase)
コード例 #4
0
 def printStats(self):
     statScale = 10
     pygame.draw.line(self.screen, (255, 255, 255), (450, self.offset.y),
                      (450, 600 + self.offset.y), 3)
     txt = pygame.font.SysFont("Arial", 20).render("Statistics", True,
                                                   (255, 255, 255))
     self.screen.blit(txt, (470, 10))
     txt = pygame.font.SysFont("Arial", 20).render(
         "Lines: " + str(self.linesCleared), True, (255, 255, 255))
     self.screen.blit(txt, (460, 50))
     txt = pygame.font.SysFont("Arial", 20).render("Tetris Rate:", True,
                                                   (255, 255, 255))
     self.screen.blit(txt, (460, 100))
     if self.linesCleared != 0:
         txt = pygame.font.SysFont("Arial", 20).render(
             str(int(self.numOfTetris * 100 / self.numOfClears)) + "%",
             True, (255, 255, 255))
     else:
         txt = pygame.font.SysFont("Arial",
                                   20).render("100%", True, (255, 255, 255))
     self.screen.blit(txt, (470, 130))
     for n, item in enumerate(self.peices):
         txt = pygame.font.SysFont("Arial",
                                   20).render(str(self.record[n]), True,
                                              (255, 255, 255))
         self.screen.blit(txt, (480, 193 + 70 * n))
         for i, line in enumerate(item):
             for j, ch in enumerate(line):
                 if ch != '.':
                     lengthOffset = statScale * (3 - len(item)) / 2
                     point = coord(
                         lengthOffset + 480 + j * statScale, 120 + 70 * n +
                         i * statScale + self.offset.y + lengthOffset)
                     color = self.selectcolor(ch)
                     self.printblock(point, color, statScale)
コード例 #5
0
 def printgrid(self):
     for i, line in enumerate(self.grid):
         for j, ch in enumerate(line):
             if ch != '.':
                 color = self.selectcolor(ch)
                 self.printblock(
                     coord(j * self.scl, i * self.scl + self.offset.y),
                     color)
コード例 #6
0
 def kbin(self, event):
     if self.paused:
         if event.unicode.lower() == 'p' or event.unicode.lower() == '\x1b':
             self.pause()
         elif event.unicode.lower() == 'q':
             self.running = False
         elif event.unicode.lower() == 'r':
             self.__init__()
         elif event.unicode.lower() == 'g':
             self.grabBag = not self.grabBag
             self.WriteSettingsToFile()
             self.render()
             self.drawPause()
         elif event.unicode.lower() == 's':
             self.shadowOn = not self.shadowOn
             self.WriteSettingsToFile()
             self.render()
             self.drawPause()
         elif event.unicode.lower() == 'l':
             self.instant_lock = not self.instant_lock
             self.WriteSettingsToFile()
             self.render()
             self.drawPause()
     elif self.gameover:
         if event.unicode.lower() == '\x1b' or event.unicode.lower() == 'q':
             self.running = False
         elif event.unicode.lower() == 'r':
             self.__init__()
     else:
         if event.unicode.lower() == 'p' or event.unicode.lower() == '\x1b':
             self.pause()
         if event.unicode.lower() == 'w':
             self.instadrop()
         elif event.unicode.lower() == 'a':
             self.move(coord(-1, 0))
         elif event.unicode.lower() == 's':
             self.move(coord(0, 1))
             self.score += 1
         elif event.unicode.lower() == 'd':
             self.move(coord(1, 0))
         elif event.unicode.lower() == 'q':
             self.rotate('l')
         elif event.unicode.lower() == 'e':
             self.rotate('r')
         elif event.unicode.lower() == ' ':
             self.swaphold()
コード例 #7
0
 def reinit_saisie(self) :
     "Enleve la fleche et les jetons temporaires de la grille (remis dans le tirage)"
     for c in self :
         if c.is_fleche() :
             c.efface_fleche()
         if c.get_jeton_status() == jeton.TEMP :
             self.app.frame.tirage.move_to(c)
     self.entry = False
     self.app.frame.set_status_coo("")
     self.coord_ini = coord.coord()
コード例 #8
0
 def reinit_saisie(self) :
     "Enleve la fleche et les jetons temporaires de la grille (remis dans le tirage)"
     for c in self :
         if c.is_fleche() :
             c.efface_fleche()
         if c.get_jeton_status() == jeton.TEMP :
             self.app.frame.tirage.move_to(c)
     self.entry = False
     self.app.frame.set_status_coo("")
     self.coord_ini = coord.coord()
コード例 #9
0
 def pose_mot(self, coo_str, mot, status) :
     """ Pose un mot sur la grille
     La coordonnée est en texte
     Appelé pour le mot du Top pour permettre de le repérer (status = PREPOSE)
     Appelé depuis la box des propositions (status = TEMP)
     """
     coo = coord.coord(coo_str=coo_str)
     t = self.app.frame.tirage
     for l in mot :
         t.move_from(self.case_coord(coo), status, l)
         coo = coo.next()
コード例 #10
0
 def pose_mot(self, coo_str, mot, status) :
     """ Pose un mot sur la grille 
     La coordonnée est en texte
     Appelé pour le mot du Top pour permettre de le repérer (status = PREPOSE)
     Appelé depuis la box des propositions (status = TEMP)
     """
     coo = coord.coord(coo_str=coo_str)
     t = self.app.frame.tirage
     for l in mot :
         t.move_from(self.case_coord(coo), status, l)
         coo = coo.next()
コード例 #11
0
 def read_grille(self, txt_grille) :
     """ Initialise la grille à partir du texte renvoyé par le serveur
     """
     self.vide_grille()
     # prend les jetons dans le reliquat
     # et les pose sur la grille
     r = self.app.reliquat
     for y, ligne in enumerate(txt_grille.split("\n")) :
         for x, lettre in enumerate(ligne) :
             if lettre != "." :
                 c = coord.coord(x, y)
                 r.move_from(self.case_coord(c), jeton.POSE, lettre)
コード例 #12
0
 def read_grille(self, txt_grille) :
     """ Initialise la grille à partir du texte renvoyé par le serveur
     """
     self.vide_grille()
     # prend les jetons dans le reliquat
     # et les pose sur la grille
     r = self.app.reliquat
     for y, ligne in enumerate(txt_grille.split("\n")) :
         for x, lettre in enumerate(ligne) :
             if lettre != "." :
                 c = coord.coord(x, y)
                 r.move_from(self.case_coord(c), jeton.POSE, lettre)
コード例 #13
0
 def lock(self):
     self.holdready = True
     for i, line in enumerate(self.peice):
         for j, ch in enumerate(line):
             if ch != '.':
                 self.grid[i + self.pos.y][j + self.pos.x] = ch
     self.clearlines()
     self.getnextpeice()
     self.updateRecord()
     self.pos = coord(4, 0)
     if self.collision():
         self.endgame()
コード例 #14
0
 def rotate(self, ch, recur=True):
     if self.peiceLength == 2:
         return
     valid_directions = [
         coord(1, 1),
         coord(-1, 1),
         coord(1, 0),
         coord(-1, 0),
         coord(0, 1),
         coord(0, -1),
     ]
     temp = self.matrix(self.peiceLength)
     if ch == 'r':
         for i in range(self.peiceLength):
             for j in range(self.peiceLength):
                 temp[i][j] = self.peice[self.peiceLength - 1 - j][i]
         self.peice = temp
         if self.collision() and recur:
             for direction in valid_directions:
                 if self.move(direction, False, True):
                     return
             self.rotate('l', False)
     elif ch == 'l':
         for i in range(self.peiceLength):
             for j in range(self.peiceLength):
                 temp[i][j] = self.peice[j][self.peiceLength - 1 - i]
         self.peice = temp
         if self.collision() and recur:
             for direction in valid_directions:
                 if self.move(direction, False, True):
                     return
             self.rotate('r', False)
コード例 #15
0
 def swaphold(self):
     if self.holdready:
         self.peice, self.hold = self.hold, self.peice
         self.pos = coord(4, 0)
         self.holdready = False
         empty = True
         for line in self.peice:
             for ch in line:
                 if ch != '.':
                     empty = False
         if empty:
             self.getnextpeice()
         self.peiceLength = len(self.peice)
コード例 #16
0
 def __init__(self, parent, app) :
     wx.Panel.__init__(self, parent, -1)
     self.app = app
     self.coord_ini = coord.coord()   # coord_ini est récupéré depuis case (OnClickCase)
     self.coord_cur = coord.coord()   # coordonnée courante 
     self.entry = False          # flag saisie en cours
     fill = self.app.settings["size_fill"]
     sizer = wx.GridBagSizer(hgap=0, vgap=0)
     sizer.Add( (2*fill,2*fill), pos=(0,0))
     sizer.Add( (fill,fill), pos=(16,16))
     for i in xrange(15) :
         t = str(i+1)
         sizer.Add(wx.StaticText(self, -1, t), pos=(0,i+1), flag=wx.ALIGN_CENTER)
         t = chr(65+i)
         sizer.Add(wx.StaticText(self, -1, t), pos=(i+1,0), flag=wx.ALIGN_CENTER)
     self.cases = {}
     for y in range(15) :
         for x in range(15) :
             self.cases[(x,y)] = case_grille.case_grille(self, x, y, mult[x][y])
             sizer.Add(self.cases[(x,y)], pos=(y+1, x+1))
     self.SetSizer(sizer)
     self.Fit()
コード例 #17
0
 def __init__(self, parent, app) :
     wx.Panel.__init__(self, parent, -1)
     self.app = app
     self.coord_ini = coord.coord()   # coord_ini est récupéré depuis case (OnClickCase)
     self.coord_cur = coord.coord()   # coordonnée courante
     self.entry = False          # flag saisie en cours
     fill = self.app.settings["size_fill"]
     sizer = wx.GridBagSizer(hgap=0, vgap=0)
     sizer.Add( (2*fill,2*fill), pos=(0,0))
     sizer.Add( (fill,fill), pos=(16,16))
     for i in range(15) :
         t = str(i+1)
         sizer.Add(wx.StaticText(self, -1, t), pos=(0,i+1), flag=wx.ALIGN_CENTER)
         t = chr(65+i)
         sizer.Add(wx.StaticText(self, -1, t), pos=(i+1,0), flag=wx.ALIGN_CENTER)
     self.cases = {}
     for y in range(15) :
         for x in range(15) :
             self.cases[(x,y)] = case_grille.case_grille(self, x, y, mult[x][y])
             sizer.Add(self.cases[(x,y)], pos=(y+1, x+1))
     self.SetSizer(sizer)
     self.Fit()
コード例 #18
0
 def printhold(self):
     pygame.draw.line(self.screen, (255, 255, 255),
                      (300, 135 + self.offset.y),
                      (450, 135 + self.offset.y), 3)
     for i, line in enumerate(self.hold):
         for j, ch in enumerate(line):
             if ch != '.':
                 lengthOffset = self.scl * (4 - len(line)) / 2
                 point = coord(
                     lengthOffset + 315 + j * self.scl,
                     14 + i * self.scl + self.offset.y + lengthOffset)
                 color = self.selectcolor(ch)
                 self.printblock(point, color)
コード例 #19
0
 def __init__(self):
     pygame.display.init()
     pygame.font.init()
     pygame.display.set_caption('PyTetris')
     self.tiks = 1
     self.sz = 550, 640
     self.screen = pygame.display.set_mode(size=self.sz)
     self.running = True
     self.scl = 30
     self.pos = coord(4, 0)
     self.holdready = True
     self.lockrate = 0
     self.level = 0
     self.speed = self.get_speed()
     self.offset = coord(150, 40)
     self.score = 0
     self.locktries = 0
     self.paused = False
     self.chain = 0
     self.grabBag = True
     self.record = [0] * 7
     self.remainingPeices = self.peices.copy()
     self.peice = self.getrandpeice()
     self.updateRecord()
     self.peiceLength = len(self.peice)
     self.gameover = False
     self.hold = self.matrix(4)
     self.grid = self.matrix(10, 20)
     self.queue = [self.matrix(4) for i in range(0, 5)]
     pygame.key.set_repeat(80)
     self.fillqueue()
     self.linesCleared = 0
     self.numOfTetris = 0
     self.numOfClears = 0
     self.shadowOn = True
     self.level_up_goal = 10
     self.instant_lock = False
     self.readSettingsFromFile()
コード例 #20
0
 def printqueue(self):
     queuescl = 20
     pygame.draw.line(self.screen, (255, 255, 255), (300, self.offset.y),
                      (300, 600 + self.offset.y), 3)
     for n, item in enumerate(self.queue):
         for i, line in enumerate(item):
             for j, ch in enumerate(line):
                 if ch != '.':
                     lengthOffset = queuescl * (3 - len(item)) / 2
                     point = coord(
                         lengthOffset + 345 + j * queuescl,
                         queuescl + 150 + 90 * n + i * queuescl +
                         self.offset.y + lengthOffset)
                     color = self.selectcolor(ch)
                     self.printblock(point, color, queuescl)
コード例 #21
0
ファイル: utils.py プロジェクト: kharyuk/astro
def parse_coord(coo, type, div = ':'):
    tmp1 = coo.split(div)
    tmp = [float(t) for t in tmp1]
    if len(tmp) == 1:
        tmp.append(0)
        tmp.append(0)
    if len(tmp) == 2:
        tmp.append(0)

    c = coo[0]
    if c == '-':
        sgn = -1
    else:
        sgn = 1
    return coord(abs(tmp[0]), tmp[1], tmp[2], sgn, type)
コード例 #22
0
 def play(self):
     #game loop
     while self.running:
         if not self.paused and not self.gameover:
             if self.tiks % self.speed == 0:
                 self.move(coord(0, 1), True)
             if not self.gameover:
                 self.render()
         pygame.display.update()
         self.tik()
         for event in pygame.event.get():
             if event.type == pygame.QUIT:
                 self.running = False
             elif event.type == pygame.KEYDOWN:
                 self.kbin(event)
     pygame.display.quit()
コード例 #23
0
 def move(self, change, auto=False, nolock=False):
     down = False
     if change == coord(0, 1):
         down = True
     self.pos.x += change.x
     self.pos.y += change.y
     if self.collision():
         self.pos.x -= change.x
         self.pos.y -= change.y
         if nolock:
             return False
         if down:
             if not auto:
                 self.lock()
             elif self.locktries >= self.lockrate or self.instant_lock:
                 self.lock()
                 self.locktries = 0
             else:
                 self.locktries += 1
         return False
     return True
コード例 #24
0
 def __init__(self, options) :
     self.options = options
     while True :
         tree = self.gen_part()
         tot = int(tree.find("resume/total").text)
         nbtour = int(tree.find("resume/nbtour").text)
         if tot >= options.minpoint and options.mintour <= nbtour <= options.maxtour :
             break
     self.liste = []
     tour = 0
     for e in tree.findall("tour"):
         n = e.find("tirage")
         ttt = tirage.tirage(n.text)
         n = e.find("coord")
         ccc = coord.coord(coo_str=n.text)
         n = e.find("mot")
         mmm = str(n.text)
         n = e.find("points")
         pts = int(n.text)
         tour += 1
         self.liste.append( (ttt, ccc, mmm, pts, tour) )
コード例 #25
0
        # plus la prime de scrabble éventuele de 50 points
        if scrab :
            point += 50

        return point, mot_nonex

if __name__ == '__main__' :
    import coord
    import dico
    import tirage

    d = dico.dico("../dic/ods5.dawg")
    g = grille()
    t = tirage.tirage("TETESAU")
    c = coord.coord()

    c.fromstr("H8")
    m = "TATES"
    controle = g.controle(c, m, t)
    print controle
    if controle <= 0 :
        print g.point(c, m, controle, d)
    g.pose(c, m)
    print g

    t = tirage.tirage("AEPESTU")
    c.fromstr("7H")
    m = "EPATES"
    controle = g.controle(c, m, t)
    print controle
コード例 #26
0
import sys
sys.path.append('../common')

import wx
import case
import coord
import jeton


class case_grille(case.case):
    """ Représente une case de la grille
    """
    def __init__(self, parent, x, y, mult):
        case.case.__init__(self, parent)
        self.coord = coord.coord(x, y)
        self.mult = mult
        self.col_fond = self.app.settings['col_grille'][self.mult]
        self.Bind(wx.EVT_LEFT_DOWN, self.OnClickCase)
        self.Bind(wx.EVT_LEFT_DCLICK, self.OnClickCase)

    def OnClickCase(self, evt):
        """ Si on clique sur une case, on amorce une saisie
        ou on passe d'horizontal à vertical si on reclique
        """
        # si pas de tour en cours, on sort
        if self.app.tour_on == False:
            return
        g = self.app.frame.grille
        # si la case est vide , on met une fleche horizontale
        if not self.is_fleche():
コード例 #27
0
 def instadrop(self):
     while self.move(coord(0, 1)):
         self.score += 1
コード例 #28
0
 def realpos(self, x=0, y=0):
     return coord((self.pos.x + x) * self.scl,
                  (self.pos.y + y) * self.scl + self.offset.y)
コード例 #29
0
ファイル: vdb.py プロジェクト: kharyuk/astro
def process_vdb(vdbname, gfields, sun, ind, ra_interest, dec_interest, print_coord = True, print_head = True):
    
    lcol = 12
    fields = [] + gfields
    fields.append('RAJ2000')
    fields.append('DEJ2000')
    v = Vizier(columns = fields, catalog = vdbname)
    v.ROW_LIMIT = -1
    result = v.query_constraints(catalog = vdbname, RAJ2000 = ra_interest, DEJ2000 = dec_interest)
    #result[result.keys()[0]].pprint()

    numobjs = len(result[0])
    twelveoc = 12*60*60
    tms = twelveoc*np.array([1., 3., 4.])

    prline = '==========' + '=' + '============'
    prhead = 'Date      ' + ' ' + ' Time       '
    
    l = len(fields)
    if not print_coord:
        l -= 2
        
    for i in xrange(l):
        prline = prline + '=' + '='*lcol
        tmp = fields[i]
        if len(tmp) < lcol:
            tmp = tmp + ' '*(lcol - len(tmp))
        prhead = prhead + ' ' + tmp
    prhead = prhead + ' ' + 'Dec distance'
    prline = prline + '=' + '============'
     
    if print_head:   
        print prline
        print prhead
        print prline
    
    for i in xrange(numobjs):
        ri = result[0][i].as_void()
        ri= list(ri)
        ri=ri[:-2]
        [ra, dec] = [ri[-2], ri[-1]]
        ra = parse_coord( ra, 'ra', ' ')
        dec = parse_coord( dec, 'deg', ' ')
        t, num = comp_time(sun[ind-1][1], sun[ind][1], sun[ind+1][1], ra)
        t = t.f2s()

        if num > 0:
            t += 2*twelveoc
        tmp = tms - t
        sz = tmp[tmp > 0].size
        if sz == 1:
            idx = ind+1
        elif sz == 2:
            idx = ind
        elif sz == 3:
            idx = ind-1
        t = coord(0, 0, t + twelveoc, 1, 'ra')
        if idx == ind:
            curdate = sun[idx][0]
            tmp = str(curdate[0])
            if len(tmp) <  2:
                tmp = ' ' + tmp
            date = '' + tmp + '/'
            tmp = str(curdate[1])
            if len(tmp) < 2:
                tmp = ' ' + tmp
            date = date + tmp + '/' + str(curdate[2])
            dist = comp_dist(curdate[0], curdate[1], t, dec)

            printer = '' + date + ' ' + str(t)
            
            stri = [str(x) for x in ri[:-2]]
            if print_coord:
                stri = stri + [str(ra), str(dec)]
            
            for x in stri:
                if len(x) < lcol:
                    x = ' '*(lcol - len(x)) + x
                printer = printer + ' ' + x
            printer = printer + ' ' + str(dist)
            print printer
コード例 #30
0
ファイル: vdb.py プロジェクト: kharyuk/astro
def handle_date(date, records, catalogue, vphi = 15):
    mdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    
    sun = []
    for i in xrange(len(records[0])):
        sun.append([parse_date(records[0][i]), parse_coord(records[1][i], 'ra'), parse_coord(records[2][i], 'deg')])
    ay = sun[ 0][0][-1]
    by = sun[-1][0][-1]
    
    if len(date) == 3:
        im = 1 # index of month
        iy = 2 # index of year (in date list)
       
    elif len(date) == 2:
        im = 0
        iy = 1
    
    assert (date[im] >   0) and (date[im] <= 12), "Inccorect month value"
    assert (date[iy] >= ay) and (date[iy] <= by), "Selected year is not presented in current sun ephemeris"
    
    if catalogue == 'V/50':
        fields = ['Name', 'HD', 'Vmag']
        entry_phrase = "Catalogue V50: stars with m <= 6.5"
    elif catalogue == 'VII/239A/icpos':
        entry_phrase = "\nCatalogue VII/239A/icpos: mean position of NGC/IC objects"
        fields = ['NGC/IC', 'Cat']
    else:
        print "Unknown catalogue"
        return None
    
    if date[iy] % 4 == 0:
        mdays[1] += 1
    
    if len(date) == 3:
        days = [date[0]]
    elif len(date) == 2:
        days = range(1, mdays[date[im]-1] + 1)
        
    for ind0, row in enumerate(sun):
        if [days[0], date[im], date[iy]] in row:
            break
            
    print entry_phrase

    for ind in xrange(ind0, ind0 + len(days)):

        ra_interest = str(sun[ind-1][1]) + '..' + str(sun[ind+1][1])
        a = sun[ind-1][2]
        b = sun[ind+1][2]
        if a.f2s() < b.f2s():
            c = a
            d = b
        else:
            c = b
            d = a

        phi = coord(vphi,0,0,1,'deg')

        dec_interest = str(c - phi) + '..' + str(d + phi)

        print ra_interest, dec_interest

        ra_interest = ra_interest.replace(' ', '')
        dec_interest = dec_interest.replace(' ', '')

        if ind != ind0:
            prhead = False
        else:
            prhead= True
        process_vdb(catalogue, fields, sun, ind, ra_interest, dec_interest, print_head = prhead)
        print
コード例 #31
0
                channel.envoi(msg.msg("info", txt))
        elif ret == 0 :
            m = msg.msg("connect",(0,"Erreur : nom existant", proto_serv))
            self.info("Tentative de %s" % mm.nick)
        elif ret == 2 :
            m = msg.msg("connect",(2,"Reconnexion", proto_serv))
            self.info("Reconnexion de %s" % mm.nick)
        return channel, m

    def traite_propo(self, (channel, mm)) :
        # une proposition active le 'tick'
        self.jo.set_tick(mm.nick, channel)
        coo_str = mm.param[0]
        mot = mm.param[1]
        tir = self.tirage
        coo = coord.coord(coo_str=coo_str)
        controle = self.gr.controle(coo, mot, tir)
        return channel, mm, controle, coo

    def traite_propo_controle(self, (channel, mm, controle, coo)) :
        mot = mm.param[1]
        if controle <= 0 :
            point, mot_nonex  = self.gr.point(coo, mot, controle == -1, self.dic)
            self.jo.set_msg_fin_tour(mm.nick, mot_nonex)
            score = point
            m = msg.msg("valid",(str(coo), mot, point))
            if len(mot_nonex) > 0 :
                # met le score a 0 si non existant
                score = 0
            self.jo.set_points_tour(mm.nick, score)
            if self.options.log :
コード例 #32
0
ファイル: case.py プロジェクト: philippechataignon/wxscrab
 def __init__(self, x, y, mult) :
     self.coord = coord.coord(x,y)
     self.mult = mult
     self.jeton = None