old file for saving code. Needs refactoring
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Maumataskis/maumataskis/maumataskis_v1.0.8a.py Thu Jun 04 23:28:45 2009 +0300
1.3 @@ -0,0 +1,1576 @@
1.4 +#!/usr/bin/env python
1.5 +# -*- coding: utf-8 -*-
1.6 +
1.7 +####
1.8 +# Maumataskis - strategenis zaidems so taskiokaas e zemiu sopemu
1.9 +# Ce yr bazenis skrepts
1.10 +# zordsdavini@gmail.com, 4193 nu Suoveje
1.11 +# artvras@users.sourceforge.net, 2008 A.D.
1.12 +####
1.13 +
1.14 +def __init__(self):
1.15 + """
1.16 + Maumataske muodelis
1.17 + """
1.18 + version = "1.0.8"
1.19 +
1.20 +import time
1.21 +import pygame, os, sys
1.22 +
1.23 +from pygame.locals import *
1.24 +from math import fabs
1.25 +
1.26 +# Import Psyco if available
1.27 +try:
1.28 + import psyco
1.29 + psyco.full()
1.30 + psyco.log()
1.31 +except ImportError:
1.32 + pass
1.33 +
1.34 +# Reads global parameters
1.35 +HOME = os.path.expanduser("~")
1.36 +HOME = os.path.join(HOME, '.rc_maumataskis')
1.37 +try:
1.38 + f = open(HOME, 'r')
1.39 + HOME = f.readline()
1.40 + f.close()
1.41 + try:
1.42 + HOME = HOME[:-1]
1.43 + os.listdir(HOME)
1.44 + except OSError:
1.45 + HOME = os.path.expanduser("~")
1.46 + HOME = os.path.join(HOME, '.rc_maumataskis')
1.47 + f = open(HOME, 'w')
1.48 + ent = '\n'
1.49 + f.write(os.path.expanduser("~"))
1.50 + f.write(ent)
1.51 + f.close()
1.52 + HOME = os.path.expanduser("~")
1.53 +except IOError:
1.54 + f = open(HOME, 'w')
1.55 + ent = '\n'
1.56 + f.write(os.path.expanduser("~"))
1.57 + f.write(ent)
1.58 + f.close()
1.59 + HOME = os.path.expanduser("~")
1.60 +
1.61 +
1.62 +ZALE = (0, 180, 0)
1.63 +RAUD = (180, 0, 0)
1.64 +MIEL = (0, 0, 255)
1.65 +JOUD = (0, 0, 0)
1.66 +spalvas = [ZALE, RAUD, MIEL, JOUD]
1.67 +
1.68 +db_task = [] # x, y, eejems
1.69 +db_zeme = [] # tlist, eejems
1.70 +gal_zeme = [] # tlist, eejems
1.71 +
1.72 +blacklist = []
1.73 +whitelist = []
1.74 +grandine = []
1.75 +apsopa = 0
1.76 +
1.77 +zh = ["Player 1", "Player 2"]
1.78 +opt = {'kursor_pos' : 0, 't_raidie' : '', 'zaid' : '', 'log' : [], 'log_zhm' : [0.0, 0.0], 'log_zhm_sen' : [0.0, 0.0], 's_dir_cur' : HOME, 's_dir_pos' : 0}
1.79 +flagai = {'SAVE_DIR' : 0, 'new_dir' : 0, 'KNIST_DIR' : 0, 'new_file' : 0, 'new_file_err' : 0, 'load_err' : 0, 'SAUGOM' : 0, 'KRAUNAM' : 0, 'PRINTINAM' : 0, 'KNIST_OK' : 0}
1.80 +global_opt = {'HOME' : HOME}
1.81 +
1.82 +hand_cursor_string = (
1.83 + " XX ",
1.84 + " X..X ",
1.85 + " X..X ",
1.86 + " X..X ",
1.87 + " X..XXXXX ",
1.88 + " X..X..X.XX ",
1.89 + " XX X..X..X.X.X ",
1.90 + "X..XX.........X ",
1.91 + "X...X.........X ",
1.92 + " X.....X.X.X..X ",
1.93 + " X....X.X.X..X ",
1.94 + " X....X.X.X.X ",
1.95 + " X...X.X.X.X ",
1.96 + " X.......X ",
1.97 + " X....X.X ",
1.98 + " XXXXX XX ")
1.99 +
1.100 +kursor_ronka, mask = pygame.cursors.compile(hand_cursor_string, black='X', white='.', xor='o')
1.101 +
1.102 +def veiz((x_m, y_m, eejems), (x_pr, y_pr, eejems2)):
1.103 + global blacklist, whitelist, grandine, apsopa
1.104 + print blacklist
1.105 +
1.106 + YR = 0
1.107 + grandine.append((x_m, y_m, eejems))
1.108 +
1.109 + for i in (-1, 0, 1):
1.110 + for j in (-1, 0, 1): #ieskom kiekvieno tako paskutinio tasko kaimynu
1.111 + if not (i == 0 and j == 0):
1.112 + if (x_m+i, y_m+j, eejems) == (x_pr, y_pr, eejems2) and len(grandine) > 3:
1.113 + YR = 1
1.114 + apsopa = 1
1.115 + break
1.116 + elif (x_m+i, y_m+j, eejems) in db_task and (x_m+i, y_m+j, eejems) not in blacklist \
1.117 + and (x_m+i, y_m+j, eejems) not in whitelist and (x_m+i, y_m+j, eejems) not in grandine:
1.118 + if veiz((x_m+i, y_m+j, eejems), (x_pr, y_pr, eejems2)):
1.119 + print 'buvau'
1.120 + whitelist.append((x_m+i, y_m+j, eejems))
1.121 + YR = 1
1.122 + else:
1.123 + white = 0
1.124 + white2 = 0
1.125 + white3 = 0
1.126 + white4 = 0
1.127 + for k in (-1+i, 0+i, 1+i):
1.128 + print 'i'
1.129 + if (x_m+k, y_m, eejems) in whitelist or (x_m+k, y_m, eejems) in blacklist or (x_m+k, y_m, eejems) in grandine:
1.130 + white2 += 1
1.131 +# if (x_m+k, y_m+2*j, eejems) in whitelist or (x_m+k, y_m, eejems) in blacklist or (x_m+k, y_m, eejems) in grandine:
1.132 +# white3 += 1
1.133 + for k in (-1+j, 0+j, 1+j):
1.134 + print 'j'
1.135 + if (x_m, y_m+k, eejems) in whitelist or (x_m, y_m+k, eejems) in blacklist or (x_m, y_m+k, eejems) in grandine:
1.136 + white += 1
1.137 +# if (x_m+2*i, y_m+k, eejems) in whitelist or (x_m, y_m+k, eejems) in blacklist or (x_m, y_m+k, eejems) in grandine:
1.138 +# white4 += 1
1.139 + if white > 1 or white2 > 1 or white3 > 1 or white4 > 1:
1.140 + whitelist.append((x_m+i, y_m+j, eejems))
1.141 + print 'nebebluogs'
1.142 + else:
1.143 + print 'bluogs'
1.144 + blacklist.append((x_m+i, y_m+j, eejems))
1.145 +
1.146 + if YR:
1.147 + del grandine[-1]
1.148 + return 1
1.149 + else:
1.150 + del grandine[-1]
1.151 + return 0
1.152 +
1.153 +def ekstremumai(Tlistas):
1.154 + xai = []
1.155 + ykai = []
1.156 + for i in Tlistas:
1.157 + xai.append(i[0])
1.158 + ykai.append(i[1])
1.159 + return [min(xai), max(xai), min(ykai), max(ykai)]
1.160 +
1.161 +def belaisvis(ciklas, x, y):
1.162 + count = 0
1.163 + mxx = ekstremumai(ciklas)
1.164 + if (x, y) in ciklas:
1.165 + return 0
1.166 +
1.167 + for xx in range(x, mxx[1] +1):#ieskos susikirtimo tasku horizontalioj linijoj nuo tikrinamo tasko i desine
1.168 + if (xx, y) in ciklas:
1.169 + ind = ciklas.index((xx, y))
1.170 + prieky = ciklas[ind +1]
1.171 + if ind == 0:
1.172 + gale = ciklas[-2]
1.173 + else: gale = ciklas[ind -1]
1.174 + if gale == (xx-1, y-1) or prieky == (xx-1, y-1):#jei nuo tasko eina briauna i virsu, skaitiklis dideja
1.175 + count += 1
1.176 + if gale == (xx, y-1) or prieky == (xx, y-1):
1.177 + count += 1
1.178 + if gale == (xx+1, y-1) or prieky == (xx+1, y-1):
1.179 + count += 1
1.180 + return count%2
1.181 +
1.182 +def plotas(k):
1.183 + s2=0.0
1.184 + for i in range(0, len(k)-1):
1.185 + s2 += (k[i][0] * k[i+1][1] - k[i+1][0] * k[i][1])
1.186 + return fabs(s2/2)
1.187 +
1.188 +def liecias(ciklas, z):
1.189 + liec = 0
1.190 + copyC = ciklas[:]
1.191 + del copyC[0]
1.192 + for t in copyC:
1.193 + if t in z:
1.194 + liec += 1
1.195 + if liec >= 2:
1.196 + return 1
1.197 + return 0
1.198 +
1.199 +def sujungimas(ciklas,zem):
1.200 + temp=[]
1.201 + ciklCopy = ciklas[:]
1.202 + zemCopy = zem[0][:]
1.203 + check=[]
1.204 + del zemCopy[-1]
1.205 + del ciklCopy[-1]
1.206 + ok = 0
1.207 + while not ok:
1.208 + if ciklCopy[0] in zemCopy:
1.209 + tmp = ciklCopy.pop(0)
1.210 + ciklCopy.append(tmp)
1.211 + else: ok = 1
1.212 +
1.213 + for i in range(1,len(ciklCopy)-1):
1.214 + if ciklCopy[i] in zemCopy:
1.215 + zInd = zemCopy.index(ciklCopy[i])
1.216 + if not check: #kol dar nebuvo nei vieno bendro tasko
1.217 + if ciklCopy[i+1] in zemCopy:
1.218 + if ciklCopy[i+1] != zemCopy[zInd-1]:
1.219 + zemCopy.reverse()
1.220 + check = ciklCopy[i]
1.221 + else: return ciklas #jei po pirmo bendro tasko nera antro, lieciasi tik per viena taska. imam kita zeme
1.222 +
1.223 + if ciklCopy[i-1] in zemCopy and ciklCopy[i+1] in zemCopy:
1.224 + temp.append(ciklCopy[i])
1.225 + if check != []:
1.226 + inx = zemCopy.index(check)
1.227 + cIndx = ciklCopy.index(check)
1.228 + zemCopy.extend(zemCopy[0:inx+1])
1.229 + del zemCopy[0:inx+1]
1.230 +
1.231 + for t in zemCopy:
1.232 + if t not in ciklCopy:
1.233 + cIndx+=1
1.234 + ciklCopy.insert(cIndx,t)
1.235 + else:break
1.236 +
1.237 + for t in temp:
1.238 + ciklCopy.remove(t)
1.239 + db_task.remove((t[0],t[1],zem[1]))
1.240 + db_task.append((t[0],t[1],0))
1.241 +
1.242 + ciklCopy.append(ciklCopy[0])
1.243 + db_zeme.remove(zem)
1.244 + return ciklCopy
1.245 + else: return ciklas
1.246 +
1.247 +def uzpildymas(ciklas, ej):
1.248 + extr = ekstremumai(ciklas)
1.249 + istrTask = []
1.250 + for x in range(extr[0], extr[1] +1):
1.251 + for y in range(extr[2], extr[3] +1):
1.252 + if belaisvis(ciklas, x, y):
1.253 + for i in db_task[:]:
1.254 + if i[0] == x and i[1] == y:
1.255 + db_task.remove(i)
1.256 + istrTask.append((i[0], i[1]))
1.257 + db_task.append((x, y, 0))#uzpildoma taskais su 0, kad negaletu ideti
1.258 +
1.259 + for gz in gal_zeme[:]:
1.260 + for t in istrTask:
1.261 + if t in gz[0]:
1.262 + gal_zeme.remove(gz)
1.263 + break
1.264 +
1.265 + for z in db_zeme[:]:
1.266 + for t in istrTask:
1.267 + if t in z[0]:
1.268 + db_zeme.remove(z)
1.269 + break
1.270 + if z[1]==ej:
1.271 + ciklas=sujungimas(ciklas,z)[:]
1.272 +
1.273 + db_zeme.append((ciklas, ej))
1.274 + return 0
1.275 +
1.276 +def atrinkimas(ciklas):
1.277 + extr = ekstremumai(ciklas)
1.278 + for z in db_zeme:
1.279 + if liecias(ciklas, z[0]):
1.280 + for t in db_task:
1.281 + if (t[2] == 0 or t[2] == z[1]) and \
1.282 + t[0] > extr[0] and t[0] < extr[1] and \
1.283 + t[1] > extr[2] and t[1] < extr[3]:
1.284 + if belaisvis(ciklas, t[0], t[1]):
1.285 + if belaisvis(z[0], t[0], t[1]) or (t[0],t[1]) in z[0]:
1.286 + return 0
1.287 + return 1
1.288 +
1.289 +def atmetimas(a, ciklas):
1.290 + t = a[:]
1.291 + t.reverse()
1.292 + for c in ciklas:
1.293 + if a == c or t == c:
1.294 + return 0
1.295 + return 1
1.296 +
1.297 +def zeme(x_m, y_m, eejems):
1.298 +
1.299 + global blacklist, whitelist, grandine, apsopa
1.300 + blacklist = []
1.301 + whitelist = []
1.302 + grandine = []
1.303 + apsopa = 0
1.304 + t0 = time.clock()
1.305 +
1.306 + if not veiz((x_m, y_m, eejems), (x_m, y_m, eejems)): return 0
1.307 + t1 = time.clock()
1.308 + print 'soveizieje: ',t1-t0
1.309 + #t1 = time.clock()
1.310 + takai = [] #visos tasku grandines
1.311 + visiCiklai = [] #grandines, kurios sudaro cikla
1.312 + geriCiklai = []
1.313 + spastai = []
1.314 + tmpPlotai = []
1.315 + takai.append ([(x_m, y_m)]) # pridedam naujausia taska kaip pirma taka
1.316 +
1.317 + for t in takai:
1.318 + for i in (-1, 0, 1):
1.319 + for j in (-1, 0, 1): #ieskom kiekvieno tako paskutinio tasko kaimynu
1.320 + if (t[-1][0] +i, t[-1][1] +j,eejems) in whitelist and \
1.321 + (t[-1][0] +i, t[-1][1] +j) not in t:
1.322 + if i != 0 and j != 0:
1.323 + if (t[-1][0], t[-1][1] +j) in t and \
1.324 + (t[-1][0] +i, t[-1][1]) in t: continue #stengiames isvengti briaunu kirtimo
1.325 + temp = t[:] #jei randam, pridedam ta taska i pabaiga ir padarom nauja taka
1.326 + temp.append((t[-1][0] +i, t[-1][1] +j))
1.327 + takai.append (temp)
1.328 + if len(t) > 3 and (t[-1][0] +i, t[-1][1] +j) == t[0]:
1.329 + if i != 0 and j != 0:
1.330 + if (t[-1][0], t[-1][1] +j) in t and \
1.331 + (t[-1][0] +i, t[-1][1]) in t: continue #stengiames isvengti briaunu kirtimo. kartojasi tas pats patikrinimas :(
1.332 + temp = t[:] #jei takas daro cikla [paskutinis tako taskas pasiekia pirma], nukopijuojam pirma taska i tako pabaiga
1.333 + temp.append(t[0])
1.334 + if atmetimas(temp, visiCiklai):#atmetam vienodus ciklus, kad nesidubliuotu. ir atrenkam teisingus
1.335 + visiCiklai.append(temp)
1.336 + #t2 = time.clock()
1.337 + #print "po visu ciklu:",t2-t1
1.338 +
1.339 + if visiCiklai != []:
1.340 + for c in visiCiklai:
1.341 + tmpPlotai.append((plotas(c), visiCiklai.index(c)))
1.342 + tmpPlotai.sort()
1.343 + tmpPlotai.reverse()#surikiuojam plotu didejimo tvarka
1.344 +
1.345 + for i in tmpPlotai:
1.346 + c = visiCiklai[i[1]]
1.347 + if spastai != []:
1.348 + if liecias(c, spastai[0]): continue
1.349 + elif geriCiklai != []:
1.350 + if liecias(c, geriCiklai[0]): continue
1.351 + if atrinkimas(c):
1.352 + yr = 0
1.353 + for t in db_task:
1.354 + if t[2] != eejems and t[2] != 0:
1.355 + if belaisvis(c, t[0], t[1]):
1.356 + geriCiklai.append(c)
1.357 + yr = 1
1.358 + break
1.359 + if yr == 0:
1.360 + spastai.append(c)
1.361 + if len(spastai) + len(geriCiklai) >= 2: break
1.362 +
1.363 + #t3 = time.clock()
1.364 + #print "po atrinkimo: ",t3-t2
1.365 +
1.366 + if spastai != []:
1.367 + for s in spastai:
1.368 + gal_zeme.append((s,eejems))
1.369 +
1.370 + if geriCiklai != []:
1.371 + for gc in geriCiklai:
1.372 + uzpildymas(gc, eejems)
1.373 +
1.374 + #t4 = time.clock()
1.375 + #print "po uzpildom: ",t4-t3
1.376 + return 0
1.377 +
1.378 +def tasks(x_m, y_m, eejems):
1.379 + # Paisuome taskaa
1.380 + t5=time.clock()
1.381 + tmpPlotai = []
1.382 + yr = 1
1.383 + if eejems == 1:e = 2
1.384 + else: e = 1
1.385 + if gal_zeme != []:
1.386 + for gz in gal_zeme:
1.387 + if gz[1] != eejems:
1.388 + tmpPlotai.append((plotas(gz[0]), gal_zeme.index(gz)))
1.389 + tmpPlotai.sort()
1.390 + tmpPlotai.reverse()
1.391 +
1.392 + for i in tmpPlotai:
1.393 + gz = gal_zeme[i[1]][0]
1.394 + if atrinkimas(gz):
1.395 + if belaisvis(gz, x_m, y_m):
1.396 + uzpildymas(gz, e)
1.397 + yr = 0
1.398 + break
1.399 + t6=time.clock()
1.400 + print "po galzemiu: ",t6-t5
1.401 + if yr:
1.402 + db_task.append((x_m, y_m, eejems))
1.403 +
1.404 + zeme(x_m, y_m, eejems)
1.405 + t7=time.clock()
1.406 + print "po zem: ",t7-t6
1.407 + #print len(db_zeme)
1.408 + return 0
1.409 +
1.410 +def bg(screen, abr1):#, abr2):
1.411 + # Ce paisysam vesa prade
1.412 +
1.413 + bgcolor = pygame.Surface(screen.get_size())
1.414 + bgcolor = bgcolor.convert()
1.415 + bgcolor.fill((235, 235, 155))
1.416 + screen.blit(bgcolor, (0,0))
1.417 +
1.418 + pygame.draw.rect(screen, (250,250,250), (10,10,540,580), 0 )
1.419 +
1.420 + #*****************************
1.421 + pygame.draw.rect(screen, (0,0,0), (570, 210, 225, 320), 1 )
1.422 + pygame.draw.rect(screen, (250,250,250), (571, 211,223,318), 0 )
1.423 +
1.424 + pygame.draw.rect(screen, (0,0,0), (570, 540, 225, 50), 3 )
1.425 + pygame.draw.rect(screen, (250,250,250), (571, 541,223,48), 0 )
1.426 + #***************************
1.427 + pygame.draw.aaline(screen, (0,0,0), (562, 0), (562, 600), 1)
1.428 + screen.blit(abr1, (575,60))
1.429 + #screen.blit(abr2, (563,200))
1.430 + mygt(screen,575,10,215,50,'MENU')
1.431 +
1.432 + for i in range(55):
1.433 + pygame.draw.aaline(screen, (200,200,200), (i*10+10, 10), (i*10+10, 590), 1)
1.434 + for i in range(59):
1.435 + pygame.draw.aaline(screen, (200,200,200), (10, i*10+10), (550, i*10+10), 1)
1.436 +
1.437 + fonts = pygame.font.Font(None,18)
1.438 + txt1 = "v1.1"
1.439 + a = fonts.render(txt1, True, (0,0,0))
1.440 + screen.blit(a, (575, 110))
1.441 +
1.442 + return 0
1.443 +
1.444 +def new():
1.445 + del db_task[:]
1.446 + del db_zeme[:]
1.447 + del gal_zeme[:]
1.448 + clear_log(['Started new game.', (0,0,0)])
1.449 +
1.450 +def clear_log(txt):
1.451 + global opt
1.452 + opt['log'] = []
1.453 + opt['log_zhm'] = [0.0, 0.0]
1.454 + opt['log_zhm_sen'] = [0.0, 0.0]
1.455 + opt['log'].append(txt)
1.456 +
1.457 +def add_log(txt):
1.458 + global opt
1.459 + opt['log'].insert(0,txt)
1.460 +
1.461 +def menu(screen,meniu_flag):
1.462 + # Ce paisuom meniu
1.463 +
1.464 + fonts = pygame.font.Font(None,36)
1.465 + fonts2 = pygame.font.Font(None,24)
1.466 + fonts3 = pygame.font.Font(None,18)
1.467 + txt = 'MENU'
1.468 +
1.469 + if meniu_flag in (1,10,12,13): # Game TAB
1.470 + pygame.draw.rect(screen, (180,200,50), (200,200,410,150), 0 )
1.471 + pygame.draw.rect(screen, (200,50,50), (200,350,410,50), 0 )
1.472 + pygame.draw.rect(screen, (0,0,0), (200,200,410,200), 2 )
1.473 +
1.474 + pygame.draw.aaline(screen, (0,0,0), (200, 259), (610, 259), 0)
1.475 + pygame.draw.aaline(screen, (0,0,0), (200, 260), (610, 260), 0)
1.476 +
1.477 + a = fonts.render(txt, True, (0,0,0))
1.478 + screen.blit(a, (210, 210))
1.479 +
1.480 + tab(screen,300,210,150,50,'Game',1)
1.481 + tab(screen,450,210,150,50,'Options',0)
1.482 +
1.483 + mygt(screen,210,270,185,30,'End Game')
1.484 + mygt(screen,210,310,185,30,'Last point')
1.485 +
1.486 + mygt(screen,210,360,185,30,'OK')
1.487 +
1.488 + mygt(screen,405,270,92,30,'New')
1.489 + mygt(screen,507,270,93,30,'Save')
1.490 + mygt(screen,405,310,92,30,'Load')
1.491 + mygt(screen,507,310,93,30,'Print')
1.492 +
1.493 + mygt(screen,405,360,195,30,'Exit')
1.494 +
1.495 + elif meniu_flag in (2,15): # Options TAB
1.496 + pygame.draw.rect(screen, (180,200,50), (200,200,410,150), 0 )
1.497 + pygame.draw.rect(screen, (200,50,50), (200,350,410,50), 0 )
1.498 + pygame.draw.rect(screen, (0,0,0), (200,200,410,200), 2 )
1.499 +
1.500 + pygame.draw.aaline(screen, (0,0,0), (200, 259), (610, 259), 0)
1.501 + pygame.draw.aaline(screen, (0,0,0), (200, 260), (610, 260), 0)
1.502 +
1.503 + a = fonts.render(txt, True, (0,0,0))
1.504 + screen.blit(a, (210, 210))
1.505 +
1.506 + tab(screen,300,210,150,50,'Game',0)
1.507 + tab(screen,450,210,150,50,'Options',1)
1.508 +
1.509 + mygt(screen,210,360,185,30,'OK')
1.510 +
1.511 + mygt(screen,210,270,185,30,'Players')
1.512 + mygt(screen,210,310,185,30,'Home directory')
1.513 +
1.514 + mygt(screen,405,270,92,30,'Fullscreen')
1.515 + mygt(screen,507,270,93,30,'Settings')
1.516 + mygt(screen,507,310,93,30,'About')
1.517 +
1.518 +
1.519 + if meniu_flag in (10,11): # Exit paklausimas
1.520 + pygame.draw.rect(screen, (200,50,50), (300,250,200,100), 0 )
1.521 + pygame.draw.rect(screen, (0,0,0), (300,250,200,100), 2 )
1.522 +
1.523 + txt1 = "Are You sure?"
1.524 + a = fonts2.render(txt1, True, (0,0,0))
1.525 + screen.blit(a, (310, 260))
1.526 +
1.527 + mygt(screen,310,310,85,30,'Exit')
1.528 + mygt(screen,405,310,85,30,'Cancel')
1.529 +
1.530 + if meniu_flag == 12: # New paklausimas
1.531 + pygame.draw.rect(screen, (200,50,50), (300,250,200,100), 0 )
1.532 + pygame.draw.rect(screen, (0,0,0), (300,250,200,100), 2 )
1.533 +
1.534 + txt1 = "Are You sure?"
1.535 + a = fonts2.render(txt1, True, (0,0,0))
1.536 + screen.blit(a, (310, 260))
1.537 +
1.538 + mygt(screen,310,310,85,30,'New')
1.539 + mygt(screen,405,310,85,30,'Cancel')
1.540 +
1.541 + if meniu_flag == 13: # End Game paklausimas
1.542 + pygame.draw.rect(screen, (200,50,50), (300,250,200,100), 0 )
1.543 + pygame.draw.rect(screen, (0,0,0), (300,250,200,100), 2 )
1.544 +
1.545 + txt1 = "Confirm end of game."
1.546 + a = fonts2.render(txt1, True, (0,0,0))
1.547 + screen.blit(a, (310, 260))
1.548 +
1.549 + mygt(screen,310,310,85,30,'Confirm')
1.550 + mygt(screen,405,310,85,30,'Cancel')
1.551 +
1.552 + if meniu_flag == 14: # Rezultataa
1.553 + pygame.draw.rect(screen, (230,200,50), (100,100,600,400), 0 )
1.554 + pygame.draw.rect(screen, (0,0,0), (100,100,600,400), 2 )
1.555 +
1.556 + txt1 = "The end of the game"
1.557 + a = fonts.render(txt1, True, (0,0,0))
1.558 + screen.blit(a, (110, 110))
1.559 +
1.560 + ## Zaidiejee
1.561 + x = 150
1.562 + y = 150
1.563 + sp = 0
1.564 + k = 0
1.565 + db_zm = []
1.566 + for i in zh:
1.567 + k += 1
1.568 + pygame.draw.rect(screen, spalvas[sp], (x-20,y,10,10) )
1.569 + sp += 1
1.570 + a = fonts3.render(i, True, (0,0,0))
1.571 + screen.blit(a, (x, y))
1.572 + y += 24
1.573 + zm = 0.0 # Atvaizduojam turimas zemes is db_zeme
1.574 + for j in db_zeme:
1.575 + if j[1] == k:
1.576 + zm += plotas(j[0])
1.577 +
1.578 + a = fonts3.render(str(zm), True, (0,0,0))
1.579 + screen.blit(a, (x+100, y-24))
1.580 +
1.581 + db_zm.append(zm)
1.582 +
1.583 + if db_zm[0] > db_zm[1]:
1.584 + txt3 = 'The winer is ' + zh[0] + ' :)'
1.585 + if db_zm[0] < db_zm[1]:
1.586 + txt3 = 'The winer is ' + zh[1] + ' :)'
1.587 + if db_zm[0] == db_zm[1]:
1.588 + txt3 = 'Pat. No one wins this game :-/'
1.589 +
1.590 + a = fonts.render(txt3, True, (0,0,0))
1.591 + screen.blit(a, (110, 220))
1.592 +
1.593 + mygt(screen,510,460,85,30,'Print')
1.594 + mygt(screen,605,460,85,30,'Close')
1.595 +
1.596 + if meniu_flag in (15,16,17): # Players editor
1.597 + pygame.draw.rect(screen, (230,200,50), (200,200,410,200), 0 )
1.598 + pygame.draw.rect(screen, (0,0,0), (200,200,410,200), 2 )
1.599 +
1.600 + txt1 = "Players"
1.601 + a = fonts2.render(txt1, True, (0,0,0))
1.602 + screen.blit(a, (210, 210))
1.603 +
1.604 + ## Zaidiejee
1.605 + x = 210
1.606 + y = 250
1.607 + sp = 0
1.608 + for i in zh:
1.609 + mygt(screen,x,y,390,40,i)
1.610 + pygame.draw.rect(screen, spalvas[sp], (x+360,y+10,20,20) )
1.611 + sp += 1
1.612 + y += 50
1.613 +
1.614 + mygt(screen,515,360,85,30,'Close')
1.615 +
1.616 + if meniu_flag in (16, 17, 18, 19): # Edit one player
1.617 + pygame.draw.rect(screen, (200,50,50), (250,180,300,140), 0 )
1.618 + pygame.draw.rect(screen, (0,0,0), (250,180,300,140), 2 )
1.619 +
1.620 + global opt
1.621 + txt1 = "Edit player's name"
1.622 + a = fonts2.render(txt1, True, (0,0,0))
1.623 + screen.blit(a, (260, 190))
1.624 + if opt['t_raidie'] in ('<','>'):
1.625 + if opt['t_raidie'] == '<':
1.626 + opt['zaid'] = opt['zaid'][:(opt['kursor_pos']-1)] + opt['zaid'][opt['kursor_pos']:]
1.627 + if opt['kursor_pos'] > 0: opt['kursor_pos'] -= 1
1.628 + else:
1.629 + opt['zaid'] = opt['zaid'][:opt['kursor_pos']] + opt['zaid'][(opt['kursor_pos']+1):]
1.630 + opt['t_raidie'] = ''
1.631 + vzaid = opt['zaid'][:opt['kursor_pos']] + opt['t_raidie'] + '|' + opt['zaid'][opt['kursor_pos']:]
1.632 + opt['zaid'] = opt['zaid'][:opt['kursor_pos']] + opt['t_raidie'] + opt['zaid'][opt['kursor_pos']:]
1.633 + if opt['t_raidie']: opt['kursor_pos'] += 1
1.634 + opt['t_raidie'] = ''
1.635 + mygt(screen,260,220,280,40,vzaid)
1.636 +
1.637 + mygt(screen,260,280,135,30,'OK')
1.638 + mygt(screen,405,280,135,30,'Cancel')
1.639 +
1.640 + if meniu_flag == 120: # About
1.641 + pygame.draw.rect(screen, (230,200,50), (100,100,600,400), 0 )
1.642 + pygame.draw.rect(screen, (0,0,0), (100,100,600,400), 2 )
1.643 +
1.644 + abr1 = pygame.image.load("img/maumataskis2.png")
1.645 + screen.blit(abr1, (120,90))
1.646 + abr3 = pygame.image.load("img/maumai_logo.gif")
1.647 + screen.blit(abr3, (170,165))
1.648 +
1.649 + txt1 = "v1.1"
1.650 + a = fonts.render(txt1, True, (0,0,0))
1.651 + screen.blit(a, (320, 113))
1.652 +
1.653 + about_txt = [
1.654 + ['http://maumataskis.sf.net/en/', spalvas[2]],
1.655 + ['', (0, 0, 0)],
1.656 + ['Made by ', (0,0,0)],
1.657 + ['zordsdavini@gmail.com', spalvas[2]],
1.658 + ['artvras@users.sourceforge.net', spalvas[2]]
1.659 + ]
1.660 +
1.661 + text_area(screen, 120, 140, about_txt, 18)
1.662 +
1.663 + txt3 = 'RULES'
1.664 + a = fonts2.render(txt3, True, (0,0,0))
1.665 + screen.blit(a, (120, 250))
1.666 +
1.667 +
1.668 + rules = [
1.669 + ['Game is played by two players alternately placing dots on the vacant intersections of the grid.', (0, 0, 0)],
1.670 + ['Objective is to occupy the larger part of the land by creating territories.', (0, 0, 0)],
1.671 + ['Vertically, horizontally and diagonally adjacent dots form a chain.', (0, 0, 0)],
1.672 + ['The chain only becomes a territory if there is at least one oponents dot inside it.', (0, 0, 0)],
1.673 + ['In other words: the goal is to surround enemy dots or territory and to avoid being captured.', (0, 0, 0)],
1.674 + ['Game ends when there is no vacant intersections or the oponent surrenders.', (0, 0, 0)]
1.675 + ]
1.676 +
1.677 + text_area(screen, 120, 270, rules, 18)
1.678 + mygt(screen,605,460,85,30,'Close')
1.679 +
1.680 +
1.681 +def mygt(screen,x,y,x_sz,y_sz,txt):
1.682 + # Mygtuku paisima f-ja
1.683 +
1.684 + x_m, y_m = pygame.mouse.get_pos()
1.685 + if ( x_m < (x+x_sz) and x_m > x ) and ( y_m < (y+y_sz) and y_m > y ):
1.686 + pygame.draw.rect(screen, (200,160,60), (x,y,x_sz,y_sz), 0 )
1.687 + else:
1.688 + pygame.draw.rect(screen, (255,200,80), (x,y,x_sz,y_sz), 0 )
1.689 +
1.690 + pygame.draw.rect(screen, (0,0,0), (x,y,x_sz,y_sz), 2 )
1.691 +
1.692 + fonts = pygame.font.Font(None,24)
1.693 + a = fonts.render(txt, True, (0,0,0))
1.694 + screen.blit(a, (x+8, y+(y_sz/2)-8))
1.695 +
1.696 +def tab(screen,x,y,x_sz,y_sz,txt,st):
1.697 + # Tabu paisima f-ja
1.698 +
1.699 + x_m, y_m = pygame.mouse.get_pos()
1.700 + if st:
1.701 + pygame.draw.rect(screen, (200,160,60), (x,y,x_sz,y_sz), 0 )
1.702 + else:
1.703 + pygame.draw.rect(screen, (255,200,80), (x,y,x_sz,y_sz), 0 )
1.704 +
1.705 + pygame.draw.rect(screen, (0,0,0), (x,y,x_sz,y_sz), 2 )
1.706 +
1.707 + fonts = pygame.font.Font(None,36)
1.708 + a = fonts.render(txt, True, (0,0,0))
1.709 + screen.blit(a, (x+12, y+(y_sz/2)-12))
1.710 +
1.711 +def save(eejems): #os.path.join(opt['s_dir_cur'], opt['zaid'])
1.712 + f = open(os.path.join(global_opt['HOME'], opt['zaid'] + '.mtg'), 'w')
1.713 + ent = '\n'
1.714 + f.write(str(zh))
1.715 + f.write(ent)
1.716 + f.write(str(db_task))
1.717 + f.write(ent)
1.718 + f.write(str(db_zeme))
1.719 + f.write(ent)
1.720 + f.write(str(eejems))
1.721 + f.write(ent)
1.722 + f.close()
1.723 + add_log(['Saved ' + opt['zaid'] + '.mtg', (0,0,0)])
1.724 +
1.725 +def load():
1.726 + global zh, db_task, db_zeme, opt
1.727 + f = open(os.path.join(global_opt['HOME'], opt['zaid'] + '.mtg'), 'r')
1.728 + zh = eval(f.readline())
1.729 + db_task = eval(f.readline())
1.730 + db_zeme = eval(f.readline())
1.731 + eejems = eval(f.readline())
1.732 + clear_log(['Loaded ' + opt['zaid'] + '.mtg', (0,0,0)])
1.733 + return eejems
1.734 +
1.735 +def last_point(screen,k):
1.736 + if db_task:
1.737 + pygame.draw.circle(screen, (0,0,0), (db_task[-1][0]*10, db_task[-1][1]*10), 40-k, 2)
1.738 +
1.739 +def last_point2(screen,k):
1.740 + if db_task:
1.741 + pygame.draw.circle(screen, (0,0,0), (db_task[-1][0]*10, db_task[-1][1]*10), k+2, 2)
1.742 +
1.743 +def luogs(screen, zhd = None, point = None): # log of the game on the bg
1.744 + global opt
1.745 + add_txt = ''
1.746 + if point:
1.747 + add_txt = zh[zhd - 1] + ': ' + str(point[0]) + ', ' + str(point[1])
1.748 + opt['log'].insert(0,[add_txt, spalvas[zhd - 1]])
1.749 + for i in (0, 1):
1.750 + if (opt['log_zhm'][i] - opt['log_zhm_sen'][i]) != 0:
1.751 + zeme = opt['log_zhm'][i] - opt['log_zhm_sen'][i]
1.752 + opt['log_zhm_sen'][i] = opt['log_zhm'][i]
1.753 + if zeme > 0:
1.754 + add_txt = zh[i] + ': +' + str(zeme)
1.755 + if zeme < 0:
1.756 + add_txt = zh[i] + ': ' + str(zeme)
1.757 + opt['log'].insert(0,[add_txt, spalvas[i]])
1.758 +
1.759 + if len(opt['log']) > 17:
1.760 + del opt['log'][-1]
1.761 +
1.762 + text_area(screen, 580, 510, opt['log'], 18, 1)
1.763 +
1.764 +def text_area(screen, x, y, text, text_size, up = 0):
1.765 + fonts = pygame.font.Font(None, text_size)
1.766 + for txt in text:
1.767 + a = fonts.render(txt[0], True, txt[1])
1.768 + screen.blit(a, (x, y,))
1.769 + if up:
1.770 + y -= text_size
1.771 + else:
1.772 + y += text_size
1.773 +
1.774 +def save_dir(screen):
1.775 + import re
1.776 +
1.777 + global global_opt, opt, flagai
1.778 +
1.779 + pygame.draw.rect(screen, (230,200,50), (100,100,600,400), 0 )
1.780 + pygame.draw.rect(screen, (0,0,0), (100,100,600,400), 2 )
1.781 +
1.782 + fonts = pygame.font.Font(None, 24)
1.783 + if len(global_opt['HOME']) > 40:
1.784 + txt = 'Home directory: ...' + global_opt['HOME'][-40:]
1.785 + else:
1.786 + txt = 'Home directory: ' + global_opt['HOME']
1.787 +
1.788 + a = fonts.render(txt, True, (0,0,0))
1.789 + screen.blit(a, (110, 110,))
1.790 +
1.791 + if len(opt['s_dir_cur']) > 40:
1.792 + txt = 'Curent directory: ...' + opt['s_dir_cur'][-40:]
1.793 + else:
1.794 + txt = 'Curent directory: ' + opt['s_dir_cur']
1.795 +
1.796 + a = fonts.render(txt, True, (0,0,0))
1.797 + screen.blit(a, (110, 134,))
1.798 +
1.799 + listas2 = [f for f in os.listdir(opt['s_dir_cur']) if os.path.isdir(os.path.join(opt['s_dir_cur'], f))]
1.800 + listas = []
1.801 + for i in listas2:
1.802 + if not re.search('^\.', i):
1.803 + listas.append(i)
1.804 +
1.805 + listas[:0] = '.'
1.806 +
1.807 + pygame.draw.rect(screen, (230,200,150), (110,160,580,290), 0 )
1.808 + pygame.draw.rect(screen, (200,200,120), (110,160,580,24), 0 )
1.809 + pygame.draw.rect(screen, (0,0,0), (110,160,580,290), 2 )
1.810 +
1.811 + x = 120
1.812 + y = 165
1.813 + for i in listas[opt['s_dir_pos']:opt['s_dir_pos']+12]:
1.814 + a = fonts.render(i, True, (0,0,0))
1.815 + screen.blit(a, (x, y,))
1.816 + y += 24
1.817 +
1.818 + mygt(screen,110,460,85,30,'New Dir')
1.819 + mygt(screen,510,460,85,30,'Cancel')
1.820 + mygt(screen,605,460,85,30,'Change')
1.821 +
1.822 + events = pygame.event.get()
1.823 + for event in events:
1.824 + if not flagai['new_dir']:
1.825 + if event.type == KEYDOWN and event.key in [K_DOWN] and opt['s_dir_pos'] < len(listas)-1:
1.826 + opt['s_dir_pos'] += 1
1.827 + if event.type == KEYDOWN and event.key in [K_UP] and opt['s_dir_pos'] > 0:
1.828 + opt['s_dir_pos'] -= 1
1.829 + if event.type == KEYDOWN and event.key in [K_ESCAPE]:
1.830 + flagai['SAVE_DIR'] = 0
1.831 + if event.type == KEYDOWN and event.key in [K_RETURN, K_KP_ENTER]:
1.832 + if listas[opt['s_dir_pos']] != '.':
1.833 + opt['s_dir_cur'] = os.path.join(opt['s_dir_cur'], listas[opt['s_dir_pos']])
1.834 + else:
1.835 + tmp = os.path.split(opt['s_dir_cur'])
1.836 + opt['s_dir_cur'] = tmp[0]
1.837 + opt['s_dir_pos'] = 0
1.838 +
1.839 + if flagai['new_dir']:
1.840 + if event.type == KEYDOWN and event.key in [K_LEFT] and opt['kursor_pos'] > 0: opt['kursor_pos'] = opt['kursor_pos'] - 1
1.841 + if event.type == KEYDOWN and event.key in [K_RIGHT] and opt['kursor_pos'] < len(opt['zaid']): opt['kursor_pos'] = opt['kursor_pos'] + 1
1.842 + if event.type == KEYDOWN and event.key in [K_q]: opt['t_raidie'] = 'q'
1.843 + if event.type == KEYDOWN and event.key in [K_w]: opt['t_raidie'] = 'w'
1.844 + if event.type == KEYDOWN and event.key in [K_e]: opt['t_raidie'] = 'e'
1.845 + if event.type == KEYDOWN and event.key in [K_r]: opt['t_raidie'] = 'r'
1.846 + if event.type == KEYDOWN and event.key in [K_t]: opt['t_raidie'] = 't'
1.847 + if event.type == KEYDOWN and event.key in [K_y]: opt['t_raidie'] = 'y'
1.848 + if event.type == KEYDOWN and event.key in [K_u]: opt['t_raidie'] = 'u'
1.849 + if event.type == KEYDOWN and event.key in [K_i]: opt['t_raidie'] = 'i'
1.850 + if event.type == KEYDOWN and event.key in [K_o]: opt['t_raidie'] = 'o'
1.851 + if event.type == KEYDOWN and event.key in [K_p]: opt['t_raidie'] = 'p'
1.852 + if event.type == KEYDOWN and event.key in [K_a]: opt['t_raidie'] = 'a'
1.853 + if event.type == KEYDOWN and event.key in [K_s]: opt['t_raidie'] = 's'
1.854 + if event.type == KEYDOWN and event.key in [K_d]: opt['t_raidie'] = 'd'
1.855 + if event.type == KEYDOWN and event.key in [K_f]: opt['t_raidie'] = 'f'
1.856 + if event.type == KEYDOWN and event.key in [K_g]: opt['t_raidie'] = 'g'
1.857 + if event.type == KEYDOWN and event.key in [K_h]: opt['t_raidie'] = 'h'
1.858 + if event.type == KEYDOWN and event.key in [K_j]: opt['t_raidie'] = 'j'
1.859 + if event.type == KEYDOWN and event.key in [K_k]: opt['t_raidie'] = 'k'
1.860 + if event.type == KEYDOWN and event.key in [K_l]: opt['t_raidie'] = 'l'
1.861 + if event.type == KEYDOWN and event.key in [K_z]: opt['t_raidie'] = 'z'
1.862 + if event.type == KEYDOWN and event.key in [K_x]: opt['t_raidie'] = 'x'
1.863 + if event.type == KEYDOWN and event.key in [K_c]: opt['t_raidie'] = 'c'
1.864 + if event.type == KEYDOWN and event.key in [K_v]: opt['t_raidie'] = 'v'
1.865 + if event.type == KEYDOWN and event.key in [K_b]: opt['t_raidie'] = 'b'
1.866 + if event.type == KEYDOWN and event.key in [K_n]: opt['t_raidie'] = 'n'
1.867 + if event.type == KEYDOWN and event.key in [K_m]: opt['t_raidie'] = 'm'
1.868 + if event.type == KEYDOWN and event.key in [K_0]: opt['t_raidie'] = '0'
1.869 + if event.type == KEYDOWN and event.key in [K_1]: opt['t_raidie'] = '1'
1.870 + if event.type == KEYDOWN and event.key in [K_2]: opt['t_raidie'] = '2'
1.871 + if event.type == KEYDOWN and event.key in [K_3]: opt['t_raidie'] = '3'
1.872 + if event.type == KEYDOWN and event.key in [K_4]: opt['t_raidie'] = '4'
1.873 + if event.type == KEYDOWN and event.key in [K_5]: opt['t_raidie'] = '5'
1.874 + if event.type == KEYDOWN and event.key in [K_6]: opt['t_raidie'] = '6'
1.875 + if event.type == KEYDOWN and event.key in [K_7]: opt['t_raidie'] = '7'
1.876 + if event.type == KEYDOWN and event.key in [K_8]: opt['t_raidie'] = '8'
1.877 + if event.type == KEYDOWN and event.key in [K_9]: opt['t_raidie'] = '9'
1.878 + if event.type == KEYDOWN and event.key in [K_DELETE]: opt['t_raidie'] = '>'
1.879 + if event.type == KEYDOWN and event.key in [K_SPACE]: opt['t_raidie'] = ' '
1.880 + if event.type == KEYDOWN and event.key in [K_BACKSPACE]: opt['t_raidie'] = '<'
1.881 +
1.882 + if event.type == KEYDOWN and event.key in [K_ESCAPE]:
1.883 + flagai['new_dir'] = 0
1.884 + if event.type == KEYDOWN and event.key in [K_RETURN, K_KP_ENTER]:
1.885 + opt['s_dir_cur'] = os.path.join(opt['s_dir_cur'], opt['zaid'])
1.886 + os.mkdir(opt['s_dir_cur'])
1.887 + flagai['new_dir'] = 0
1.888 +
1.889 + if event.type == MOUSEBUTTONUP and event.button == 1:
1.890 + x_m, y_m = event.pos
1.891 + if ( x_m < 595 and x_m > 510 ) and ( y_m < 490 and y_m > 460 ) and not flagai['new_dir']:
1.892 + flagai['SAVE_DIR'] = 0
1.893 + if ( x_m < 690 and x_m > 605 ) and ( y_m < 490 and y_m > 460 ) and not flagai['new_dir']:
1.894 + add_log(["Changed game's dir from", (0,0,0)])
1.895 + add_log(['...' + global_opt['HOME'][-25:] + ' to', (0,0,0)])
1.896 + if listas[opt['s_dir_pos']] == '.':
1.897 + global_opt['HOME'] = opt['s_dir_cur']
1.898 + else:
1.899 + global_opt['HOME'] = os.path.join(opt['s_dir_cur'], listas[opt['s_dir_pos']])
1.900 + add_log(['...' + global_opt['HOME'][-25:], (0,0,0)])
1.901 + HOME = os.path.expanduser("~")
1.902 + HOME = os.path.join(HOME, '.rc_maumataskis')
1.903 + f = open(HOME, 'w')
1.904 + ent = '\n'
1.905 + f.write(global_opt['HOME'])
1.906 + f.write(ent)
1.907 + f.close()
1.908 + flagai['SAVE_DIR'] = 0
1.909 +
1.910 + if ( x_m < 195 and x_m > 110 ) and ( y_m < 490 and y_m > 460 ) and not flagai['new_dir']:
1.911 + flagai['new_dir'] = 1
1.912 + opt['zaid'] = ''
1.913 + opt['kursor_pos'] = 0
1.914 + opt['t_raidie'] = ''
1.915 + if ( x_m < 690 and x_m > 405 ) and ( y_m < 310 and y_m > 280 ) and flagai['new_dir']:
1.916 + flagai['new_dir'] = 0
1.917 + if ( x_m < 395 and x_m > 310 ) and ( y_m < 310 and y_m > 280 ) and flagai['new_dir']:
1.918 + opt['s_dir_cur'] = os.path.join(opt['s_dir_cur'], opt['zaid'])
1.919 + os.mkdir(opt['s_dir_cur'])
1.920 + flagai['new_dir'] = 0
1.921 +
1.922 +
1.923 + if flagai['new_dir']:
1.924 + pygame.draw.rect(screen, (200,50,50), (250,180,300,140), 0 )
1.925 + pygame.draw.rect(screen, (0,0,0), (250,180,300,140), 2 )
1.926 +
1.927 + txt1 = "New Directory"
1.928 + a = fonts.render(txt1, True, (0,0,0))
1.929 + screen.blit(a, (260, 190))
1.930 + if opt['t_raidie'] in ('<','>'):
1.931 + if opt['t_raidie'] == '<':
1.932 + opt['zaid'] = opt['zaid'][:(opt['kursor_pos']-1)] + opt['zaid'][opt['kursor_pos']:]
1.933 + if opt['kursor_pos'] > 0: opt['kursor_pos'] -= 1
1.934 + else:
1.935 + opt['zaid'] = opt['zaid'][:opt['kursor_pos']] + opt['zaid'][(opt['kursor_pos']+1):]
1.936 + opt['t_raidie'] = ''
1.937 + vzaid = opt['zaid'][:opt['kursor_pos']] + opt['t_raidie'] + '|' + opt['zaid'][opt['kursor_pos']:]
1.938 + opt['zaid'] = opt['zaid'][:opt['kursor_pos']] + opt['t_raidie'] + opt['zaid'][opt['kursor_pos']:]
1.939 + if opt['t_raidie']: opt['kursor_pos'] += 1
1.940 + opt['t_raidie'] = ''
1.941 + mygt(screen,260,220,280,40,vzaid)
1.942 +
1.943 + mygt(screen,260,280,135,30,'OK')
1.944 + mygt(screen,405,280,135,30,'Cancel')
1.945 +
1.946 +def knist_dir(screen, ext, ro = 0):
1.947 + import re
1.948 +
1.949 + global global_opt, opt, flagai
1.950 +
1.951 + flagai['KNIST_OK'] = 0
1.952 +
1.953 + pygame.draw.rect(screen, (230,200,50), (100,100,600,400), 0 )
1.954 + pygame.draw.rect(screen, (0,0,0), (100,100,600,400), 2 )
1.955 +
1.956 + fonts = pygame.font.Font(None, 24)
1.957 +
1.958 + if len(global_opt['HOME']) > 40:
1.959 + txt = 'Home directory: ...' + global_opt['HOME'][-40:]
1.960 + else:
1.961 + txt = 'Home directory: ' + global_opt['HOME']
1.962 +
1.963 + a = fonts.render(txt, True, (0,0,0))
1.964 + screen.blit(a, (110, 110,))
1.965 +
1.966 + if not ro: mygt(screen,110,130,85,30,'New')
1.967 +
1.968 + listas2 = [f for f in os.listdir(opt['s_dir_cur']) if os.path.isfile(os.path.join(opt['s_dir_cur'], f))]
1.969 + listas = []
1.970 + for i in listas2:
1.971 + if re.search(ext + '$', i):
1.972 + listas.append(i)
1.973 +
1.974 + pygame.draw.rect(screen, (230,200,150), (110,170,580,280), 0 )
1.975 + pygame.draw.rect(screen, (200,200,120), (110,170,580,24), 0 )
1.976 + pygame.draw.rect(screen, (0,0,0), (110,170,580,280), 2 )
1.977 +
1.978 + x = 120
1.979 + y = 175
1.980 + for i in listas[opt['s_dir_pos']:opt['s_dir_pos']+11]:
1.981 + a = fonts.render(i, True, (0,0,0))
1.982 + screen.blit(a, (x, y,))
1.983 + y += 24
1.984 +
1.985 + mygt(screen,510,460,85,30,'Cancel')
1.986 + mygt(screen,605,460,85,30,'Select')
1.987 +
1.988 + events = pygame.event.get()
1.989 + for event in events:
1.990 + if not flagai['new_file']:
1.991 + if event.type == KEYDOWN and event.key in [K_DOWN] and opt['s_dir_pos'] < len(listas)-1:
1.992 + opt['s_dir_pos'] += 1
1.993 + if event.type == KEYDOWN and event.key in [K_UP] and opt['s_dir_pos'] > 0:
1.994 + opt['s_dir_pos'] -= 1
1.995 + if event.type == KEYDOWN and event.key in [K_ESCAPE]:
1.996 + flagai['KNIST_DIR'] = 0
1.997 + if event.type == KEYDOWN and event.key in [K_RETURN, K_KP_ENTER] and not ro and not flagai['new_file'] and not flagai['new_file_err'] and not flagai['load_err']:
1.998 + opt['zaid'] = listas[opt['s_dir_pos']][:-4]
1.999 + flagai['new_file_err'] = 1
1.1000 + break
1.1001 + if event.type == KEYDOWN and event.key in [K_RETURN, K_KP_ENTER] and ro and not flagai['new_file'] and not flagai['new_file_err'] and not flagai['load_err']:
1.1002 + opt['zaid'] = listas[opt['s_dir_pos']][:-4]
1.1003 + flagai['load_err'] = 1
1.1004 + break
1.1005 +
1.1006 + if flagai['new_file']:
1.1007 + if event.type == KEYDOWN and event.key in [K_LEFT] and opt['kursor_pos'] > 0: opt['kursor_pos'] = opt['kursor_pos'] - 1
1.1008 + if event.type == KEYDOWN and event.key in [K_RIGHT] and opt['kursor_pos'] < len(opt['zaid']): opt['kursor_pos'] = opt['kursor_pos'] + 1
1.1009 + if event.type == KEYDOWN and event.key in [K_q]: opt['t_raidie'] = 'q'
1.1010 + if event.type == KEYDOWN and event.key in [K_w]: opt['t_raidie'] = 'w'
1.1011 + if event.type == KEYDOWN and event.key in [K_e]: opt['t_raidie'] = 'e'
1.1012 + if event.type == KEYDOWN and event.key in [K_r]: opt['t_raidie'] = 'r'
1.1013 + if event.type == KEYDOWN and event.key in [K_t]: opt['t_raidie'] = 't'
1.1014 + if event.type == KEYDOWN and event.key in [K_y]: opt['t_raidie'] = 'y'
1.1015 + if event.type == KEYDOWN and event.key in [K_u]: opt['t_raidie'] = 'u'
1.1016 + if event.type == KEYDOWN and event.key in [K_i]: opt['t_raidie'] = 'i'
1.1017 + if event.type == KEYDOWN and event.key in [K_o]: opt['t_raidie'] = 'o'
1.1018 + if event.type == KEYDOWN and event.key in [K_p]: opt['t_raidie'] = 'p'
1.1019 + if event.type == KEYDOWN and event.key in [K_a]: opt['t_raidie'] = 'a'
1.1020 + if event.type == KEYDOWN and event.key in [K_s]: opt['t_raidie'] = 's'
1.1021 + if event.type == KEYDOWN and event.key in [K_d]: opt['t_raidie'] = 'd'
1.1022 + if event.type == KEYDOWN and event.key in [K_f]: opt['t_raidie'] = 'f'
1.1023 + if event.type == KEYDOWN and event.key in [K_g]: opt['t_raidie'] = 'g'
1.1024 + if event.type == KEYDOWN and event.key in [K_h]: opt['t_raidie'] = 'h'
1.1025 + if event.type == KEYDOWN and event.key in [K_j]: opt['t_raidie'] = 'j'
1.1026 + if event.type == KEYDOWN and event.key in [K_k]: opt['t_raidie'] = 'k'
1.1027 + if event.type == KEYDOWN and event.key in [K_l]: opt['t_raidie'] = 'l'
1.1028 + if event.type == KEYDOWN and event.key in [K_z]: opt['t_raidie'] = 'z'
1.1029 + if event.type == KEYDOWN and event.key in [K_x]: opt['t_raidie'] = 'x'
1.1030 + if event.type == KEYDOWN and event.key in [K_c]: opt['t_raidie'] = 'c'
1.1031 + if event.type == KEYDOWN and event.key in [K_v]: opt['t_raidie'] = 'v'
1.1032 + if event.type == KEYDOWN and event.key in [K_b]: opt['t_raidie'] = 'b'
1.1033 + if event.type == KEYDOWN and event.key in [K_n]: opt['t_raidie'] = 'n'
1.1034 + if event.type == KEYDOWN and event.key in [K_m]: opt['t_raidie'] = 'm'
1.1035 + if event.type == KEYDOWN and event.key in [K_0]: opt['t_raidie'] = '0'
1.1036 + if event.type == KEYDOWN and event.key in [K_1]: opt['t_raidie'] = '1'
1.1037 + if event.type == KEYDOWN and event.key in [K_2]: opt['t_raidie'] = '2'
1.1038 + if event.type == KEYDOWN and event.key in [K_3]: opt['t_raidie'] = '3'
1.1039 + if event.type == KEYDOWN and event.key in [K_4]: opt['t_raidie'] = '4'
1.1040 + if event.type == KEYDOWN and event.key in [K_5]: opt['t_raidie'] = '5'
1.1041 + if event.type == KEYDOWN and event.key in [K_6]: opt['t_raidie'] = '6'
1.1042 + if event.type == KEYDOWN and event.key in [K_7]: opt['t_raidie'] = '7'
1.1043 + if event.type == KEYDOWN and event.key in [K_8]: opt['t_raidie'] = '8'
1.1044 + if event.type == KEYDOWN and event.key in [K_9]: opt['t_raidie'] = '9'
1.1045 + if event.type == KEYDOWN and event.key in [K_DELETE]: opt['t_raidie'] = '>'
1.1046 + if event.type == KEYDOWN and event.key in [K_SPACE]: opt['t_raidie'] = ' '
1.1047 + if event.type == KEYDOWN and event.key in [K_BACKSPACE]: opt['t_raidie'] = '<'
1.1048 +
1.1049 + if event.type == KEYDOWN and event.key in [K_ESCAPE]:
1.1050 + flagai['new_file'] = 0
1.1051 + if event.type == KEYDOWN and event.key in [K_RETURN, K_KP_ENTER]:
1.1052 + flagai['KNIST_DIR'] = 0
1.1053 + flagai['new_file'] = 0
1.1054 + flagai['KNIST_OK'] = 1
1.1055 +
1.1056 + if flagai['new_file_err']:
1.1057 + if event.type == KEYDOWN and event.key in [K_ESCAPE]:
1.1058 + flagai['new_file'] = 1
1.1059 + if event.type == KEYDOWN and event.key in [K_RETURN, K_KP_ENTER]:
1.1060 + flagai['KNIST_DIR'] = 0
1.1061 + flagai['new_file'] = 0
1.1062 + flagai['new_file_err'] = 0
1.1063 + opt['s_dir_pos'] = 0
1.1064 + flagai['KNIST_OK'] = 1
1.1065 +
1.1066 + if flagai['load_err']:
1.1067 + if event.type == KEYDOWN and event.key in [K_ESCAPE]:
1.1068 + flagai['KNIST_DIR'] = 0
1.1069 + flagai['load_err'] = 0
1.1070 + flagai['KNIST_OK'] = 0
1.1071 + opt['s_dir_pos'] = 0
1.1072 + if event.type == KEYDOWN and event.key in [K_RETURN, K_KP_ENTER]:
1.1073 + flagai['KNIST_DIR'] = 0
1.1074 + flagai['load_err'] = 0
1.1075 + flagai['KNIST_OK'] = 1
1.1076 + opt['s_dir_pos'] = 0
1.1077 +
1.1078 + if event.type == MOUSEBUTTONUP and event.button == 1:
1.1079 + x_m, y_m = event.pos
1.1080 + if ( x_m < 595 and x_m > 510 ) and ( y_m < 490 and y_m > 460 ) and not flagai['new_file']:
1.1081 + flagai['KNIST_DIR'] = 0
1.1082 + if ( x_m < 690 and x_m > 605 ) and ( y_m < 490 and y_m > 460 ) and not flagai['new_file'] and not ro:
1.1083 + opt['zaid'] = listas[opt['s_dir_pos']][:-4]
1.1084 + flagai['new_file_err'] = 1
1.1085 + if ( x_m < 690 and x_m > 605 ) and ( y_m < 490 and y_m > 460 ) and not flagai['new_file'] and ro:
1.1086 + opt['zaid'] = listas[opt['s_dir_pos']][:-4]
1.1087 + flagai['load_err'] = 1
1.1088 + if ( x_m < 195 and x_m > 110 ) and ( y_m < 160 and y_m > 130 ) and not flagai['new_file'] and not ro:
1.1089 + flagai['new_file'] = 1
1.1090 + opt['zaid'] = ''
1.1091 + opt['kursor_pos'] = 0
1.1092 + opt['t_raidie'] = ''
1.1093 + if ( x_m < 690 and x_m > 405 ) and ( y_m < 310 and y_m > 280 ) and flagai['new_file'] and not flagai['new_file_err']:
1.1094 + flagai['new_file'] = 0
1.1095 + if ( x_m < 395 and x_m > 310 ) and ( y_m < 310 and y_m > 280 ) and flagai['new_file'] and not flagai['new_file_err']:
1.1096 + if opt['zaid'] + ext in listas:
1.1097 + flagai['new_file_err'] = 1
1.1098 + else:
1.1099 + flagai['new_file'] = 0
1.1100 + flagai['KNIST_DIR'] = 0
1.1101 + flagai['KNIST_OK'] = 1
1.1102 + opt['s_dir_pos'] = 0
1.1103 +
1.1104 + if ( x_m < 395 and x_m > 310 ) and ( y_m < 340 and y_m > 310 ) and flagai['new_file_err']:
1.1105 + flagai['new_file_err'] = 0
1.1106 + flagai['new_file'] = 0
1.1107 + flagai['KNIST_DIR'] = 0
1.1108 + flagai['KNIST_OK'] = 1
1.1109 + opt['s_dir_pos'] = 0
1.1110 +
1.1111 + if ( x_m < 490 and x_m > 405 ) and ( y_m < 340 and y_m > 310 ) and flagai['new_file_err']:
1.1112 + flagai['new_file_err'] = 0
1.1113 + flagai['new_file'] = 1
1.1114 +
1.1115 + if ( x_m < 395 and x_m > 310 ) and ( y_m < 340 and y_m > 310 ) and flagai['load_err']:
1.1116 + flagai['KNIST_DIR'] = 0
1.1117 + flagai['load_err'] = 0
1.1118 + flagai['KNIST_OK'] = 1
1.1119 + opt['s_dir_pos'] = 0
1.1120 +
1.1121 + if ( x_m < 490 and x_m > 405 ) and ( y_m < 340 and y_m > 310 ) and flagai['load_err']:
1.1122 + flagai['KNIST_DIR'] = 0
1.1123 + flagai['load_err'] = 0
1.1124 + flagai['KNIST_OK'] = 0
1.1125 + opt['s_dir_pos'] = 0
1.1126 +
1.1127 + if flagai['new_file']:
1.1128 + pygame.draw.rect(screen, (200,50,50), (250,180,300,140), 0 )
1.1129 + pygame.draw.rect(screen, (0,0,0), (250,180,300,140), 2 )
1.1130 +
1.1131 + txt1 = "New File"
1.1132 + a = fonts.render(txt1, True, (0,0,0))
1.1133 + screen.blit(a, (260, 190))
1.1134 + if opt['t_raidie'] in ('<','>'):
1.1135 + if opt['t_raidie'] == '<':
1.1136 + opt['zaid'] = opt['zaid'][:(opt['kursor_pos']-1)] + opt['zaid'][opt['kursor_pos']:]
1.1137 + if opt['kursor_pos'] > 0: opt['kursor_pos'] -= 1
1.1138 + else:
1.1139 + opt['zaid'] = opt['zaid'][:opt['kursor_pos']] + opt['zaid'][(opt['kursor_pos']+1):]
1.1140 + opt['t_raidie'] = ''
1.1141 + vzaid = opt['zaid'][:opt['kursor_pos']] + opt['t_raidie'] + '|' + opt['zaid'][opt['kursor_pos']:]
1.1142 + opt['zaid'] = opt['zaid'][:opt['kursor_pos']] + opt['t_raidie'] + opt['zaid'][opt['kursor_pos']:]
1.1143 + if opt['t_raidie']: opt['kursor_pos'] += 1
1.1144 + opt['t_raidie'] = ''
1.1145 + mygt(screen,260,220,280,40,vzaid)
1.1146 +
1.1147 + mygt(screen,260,280,135,30,'OK')
1.1148 + mygt(screen,405,280,135,30,'Cancel')
1.1149 +
1.1150 + if flagai['new_file_err']: # Replace paklausimas
1.1151 + pygame.draw.rect(screen, (200,50,50), (300,250,200,100), 0 )
1.1152 + pygame.draw.rect(screen, (0,0,0), (300,250,200,100), 2 )
1.1153 +
1.1154 + txt1 = "File exist. Replace?"
1.1155 + a = fonts.render(txt1, True, (0,0,0))
1.1156 + screen.blit(a, (310, 260))
1.1157 +
1.1158 + mygt(screen,310,310,85,30,'OK')
1.1159 + mygt(screen,405,310,85,30,'Cancel')
1.1160 +
1.1161 + if flagai['load_err']: # Replace paklausimas
1.1162 + pygame.draw.rect(screen, (200,50,50), (300,250,200,100), 0 )
1.1163 + pygame.draw.rect(screen, (0,0,0), (300,250,200,100), 2 )
1.1164 +
1.1165 + txt1 = "It will replace curent"
1.1166 + a = fonts.render(txt1, True, (0,0,0))
1.1167 + screen.blit(a, (310, 260))
1.1168 + txt1 = "game. OK?"
1.1169 + a = fonts.render(txt1, True, (0,0,0))
1.1170 + screen.blit(a, (310, 278))
1.1171 +
1.1172 + mygt(screen,310,310,85,30,'OK')
1.1173 + mygt(screen,405,310,85,30,'Cancel')
1.1174 +
1.1175 +
1.1176 +def main():
1.1177 +
1.1178 + pygame.init()
1.1179 +
1.1180 + # Longs
1.1181 + display_flags = DOUBLEBUF #FULLSCREEN #DOUBLEBUF
1.1182 + width, height = 800, 600
1.1183 +
1.1184 + window = pygame.display.set_mode( (width, height), display_flags )
1.1185 + pygame.display.set_caption('Maumataskis')
1.1186 + screen = pygame.display.get_surface()
1.1187 +
1.1188 + # Kintameeje
1.1189 + een = 1
1.1190 + fullscreen = 0
1.1191 + eejems = 1
1.1192 +
1.1193 + # Laikruodis
1.1194 + tiktak = pygame.time.Clock()
1.1195 +
1.1196 + # Padaruom pagrinda
1.1197 + abr1 = pygame.image.load("img/maumataskis2.png")
1.1198 + #abr2 = pygame.image.load("img/apate.png")
1.1199 + bg(screen, abr1)#, abr2)
1.1200 + pygame.display.flip()
1.1201 +
1.1202 + # Fonts
1.1203 + fonts = pygame.font.Font(None,18)
1.1204 +
1.1205 + MENIU = 0 # Meniu neijungts
1.1206 + meniu_flag = 0
1.1207 + PRINT = 0
1.1208 + LAST_POINT = 0
1.1209 + POINT = 0
1.1210 +
1.1211 + global opt, flagai
1.1212 +
1.1213 + add_log(['Game started.', (0,0,0)])
1.1214 +
1.1215 + while een:
1.1216 + # Pagrinds
1.1217 + bg(screen, abr1)#, abr2)
1.1218 +
1.1219 + luogs(screen)
1.1220 +
1.1221 + # Pripaisymaa
1.1222 +
1.1223 + ## Zaidiejee
1.1224 + x = 595
1.1225 + y = 160
1.1226 + sp = 0
1.1227 + k = 0
1.1228 + for i in zh:
1.1229 + k += 1
1.1230 + pygame.draw.rect(screen, spalvas[sp], (x-20,y,10,10) )
1.1231 + sp += 1
1.1232 + a = fonts.render(i, True, (0,0,0))
1.1233 + screen.blit(a, (x, y))
1.1234 + y += 24
1.1235 + zm = 0.0 # Atvaizduojam turimas zemes is db_zeme
1.1236 + for j in db_zeme:
1.1237 + if j[1] == k:
1.1238 + zm += plotas(j[0])
1.1239 +
1.1240 + opt['log_zhm'][k-1] = zm
1.1241 +
1.1242 + a = fonts.render(str(zm), True, (0,0,0))
1.1243 + screen.blit(a, (x+100, y-24))
1.1244 +
1.1245 +
1.1246 + ## Paisuoms eejems
1.1247 + pygame.draw.rect(screen, (0,0,0), (570,153+((eejems-1)*24),225,24), 2 )
1.1248 +
1.1249 + ## Paisuomi taskaa
1.1250 + for i in db_task:
1.1251 + pygame.draw.circle(screen, spalvas[i[2]-1], (i[0]*10,i[1]*10), 3, 0)
1.1252 +
1.1253 + ## Paisuomas zemes
1.1254 + for i in db_zeme:
1.1255 + a=[]
1.1256 + for j in i[0]:
1.1257 + a.append((j[0]*10,j[1]*10))
1.1258 + pygame.draw.polygon(screen, spalvas[i[1]-1], a, 0)
1.1259 + pygame.draw.lines(screen, (250,250,250),0, a, 1)
1.1260 +
1.1261 + ## Print testavims
1.1262 + if PRINT in (1,2):
1.1263 + pygame.image.save(screen, os.path.join(global_opt['HOME'], opt['zaid'] + '.png'))
1.1264 + add_log(['Printed ' + opt['zaid'] + '.png', (0,0,0)])
1.1265 + PRINT = 0
1.1266 +
1.1267 + if LAST_POINT > 0:
1.1268 + if LAST_POINT < 39:
1.1269 + last_point(screen,LAST_POINT)
1.1270 + LAST_POINT += 1
1.1271 + else: LAST_POINT = 0
1.1272 +
1.1273 + ## Last point animation
1.1274 + if POINT > 0:
1.1275 + if POINT < 29: # Diametr of animation
1.1276 + last_point2(screen,POINT)
1.1277 + POINT += 1 # Spead
1.1278 + else: POINT = 0
1.1279 +
1.1280 +
1.1281 + ## Meniu
1.1282 + if MENIU:
1.1283 + menu(screen,meniu_flag)
1.1284 +
1.1285 + if flagai['SAVE_DIR']:
1.1286 + save_dir(screen)
1.1287 +
1.1288 + if flagai['SAUGOM']:
1.1289 + if flagai['KNIST_DIR']:
1.1290 + knist_dir(screen, '.mtg')
1.1291 + elif flagai['KNIST_OK']:
1.1292 + save(eejems)
1.1293 + flagai['SAUGOM'] = 0
1.1294 + elif not flagai['KNIST_OK']:
1.1295 + flagai['SAUGOM'] = 0
1.1296 +
1.1297 + if flagai['KRAUNAM']:
1.1298 + if flagai['KNIST_DIR']:
1.1299 + knist_dir(screen, '.mtg', 1)
1.1300 + elif flagai['KNIST_OK']:
1.1301 + eejems = load()
1.1302 + flagai['KRAUNAM'] = 0
1.1303 + elif not flagai['KNIST_OK']:
1.1304 + flagai['KRAUNAM'] = 0
1.1305 +
1.1306 + if flagai['PRINTINAM']:
1.1307 + if flagai['KNIST_DIR']:
1.1308 + knist_dir(screen, '.png')
1.1309 + elif flagai['KNIST_OK']:
1.1310 + PRINT = 1
1.1311 + flagai['PRINTINAM'] = 0
1.1312 + elif not flagai['KNIST_OK']:
1.1313 + flagai['PRINTINAM'] = 0
1.1314 +
1.1315 +
1.1316 + # inputaa
1.1317 + events = pygame.event.get()
1.1318 +
1.1319 + EDITOR = [16, 17, 18, 19]
1.1320 +
1.1321 + for event in events:
1.1322 +
1.1323 + if event.type == QUIT or (event.type == KEYDOWN and event.key in [K_q] and meniu_flag not in EDITOR):
1.1324 + meniu_flag = 11
1.1325 + MENIU = 1
1.1326 +
1.1327 + if event.type == KEYDOWN and event.key in [K_f] and meniu_flag not in EDITOR:
1.1328 + if fullscreen:
1.1329 + window = pygame.display.set_mode( (800, 600), DOUBLEBUF )
1.1330 + fullscreen = 0
1.1331 + else:
1.1332 + window = pygame.display.set_mode( (800, 600), FULLSCREEN )
1.1333 + fullscreen = 1
1.1334 +
1.1335 + if event.type == KEYDOWN and event.key in [K_p] and meniu_flag not in EDITOR:
1.1336 + flagai['PRINTINAM'] = 1
1.1337 + flagai['KNIST_DIR'] = 1
1.1338 +
1.1339 + if event.type == KEYDOWN and event.key in [K_s] and meniu_flag not in EDITOR:
1.1340 + flagai['SAUGOM'] = 1
1.1341 + flagai['KNIST_DIR'] = 1
1.1342 +
1.1343 + if event.type == KEYDOWN and event.key in [K_l] and meniu_flag not in EDITOR:
1.1344 + flagai['KRAUNAM'] = 1
1.1345 + flagai['KNIST_DIR'] = 1
1.1346 +
1.1347 + if event.type == KEYDOWN and event.key in [K_a] and meniu_flag not in EDITOR:
1.1348 + LAST_POINT = 1
1.1349 +
1.1350 + if event.type == KEYDOWN and event.key in [K_F1] and meniu_flag not in EDITOR:
1.1351 + meniu_flag = 120
1.1352 + MENIU = 1
1.1353 +
1.1354 + if meniu_flag in EDITOR:
1.1355 + if event.type == KEYDOWN and event.key in [K_LEFT] and opt['kursor_pos'] > 0: opt['kursor_pos'] = opt['kursor_pos'] - 1
1.1356 + if event.type == KEYDOWN and event.key in [K_RIGHT] and opt['kursor_pos'] < len(opt['zaid']): opt['kursor_pos'] = opt['kursor_pos'] + 1
1.1357 + if event.type == KEYDOWN and event.key in [K_q]: opt['t_raidie'] = 'q'
1.1358 + if event.type == KEYDOWN and event.key in [K_w]: opt['t_raidie'] = 'w'
1.1359 + if event.type == KEYDOWN and event.key in [K_e]: opt['t_raidie'] = 'e'
1.1360 + if event.type == KEYDOWN and event.key in [K_r]: opt['t_raidie'] = 'r'
1.1361 + if event.type == KEYDOWN and event.key in [K_t]: opt['t_raidie'] = 't'
1.1362 + if event.type == KEYDOWN and event.key in [K_y]: opt['t_raidie'] = 'y'
1.1363 + if event.type == KEYDOWN and event.key in [K_u]: opt['t_raidie'] = 'u'
1.1364 + if event.type == KEYDOWN and event.key in [K_i]: opt['t_raidie'] = 'i'
1.1365 + if event.type == KEYDOWN and event.key in [K_o]: opt['t_raidie'] = 'o'
1.1366 + if event.type == KEYDOWN and event.key in [K_p]: opt['t_raidie'] = 'p'
1.1367 + if event.type == KEYDOWN and event.key in [K_a]: opt['t_raidie'] = 'a'
1.1368 + if event.type == KEYDOWN and event.key in [K_s]: opt['t_raidie'] = 's'
1.1369 + if event.type == KEYDOWN and event.key in [K_d]: opt['t_raidie'] = 'd'
1.1370 + if event.type == KEYDOWN and event.key in [K_f]: opt['t_raidie'] = 'f'
1.1371 + if event.type == KEYDOWN and event.key in [K_g]: opt['t_raidie'] = 'g'
1.1372 + if event.type == KEYDOWN and event.key in [K_h]: opt['t_raidie'] = 'h'
1.1373 + if event.type == KEYDOWN and event.key in [K_j]: opt['t_raidie'] = 'j'
1.1374 + if event.type == KEYDOWN and event.key in [K_k]: opt['t_raidie'] = 'k'
1.1375 + if event.type == KEYDOWN and event.key in [K_l]: opt['t_raidie'] = 'l'
1.1376 + if event.type == KEYDOWN and event.key in [K_z]: opt['t_raidie'] = 'z'
1.1377 + if event.type == KEYDOWN and event.key in [K_x]: opt['t_raidie'] = 'x'
1.1378 + if event.type == KEYDOWN and event.key in [K_c]: opt['t_raidie'] = 'c'
1.1379 + if event.type == KEYDOWN and event.key in [K_v]: opt['t_raidie'] = 'v'
1.1380 + if event.type == KEYDOWN and event.key in [K_b]: opt['t_raidie'] = 'b'
1.1381 + if event.type == KEYDOWN and event.key in [K_n]: opt['t_raidie'] = 'n'
1.1382 + if event.type == KEYDOWN and event.key in [K_m]: opt['t_raidie'] = 'm'
1.1383 + if event.type == KEYDOWN and event.key in [K_0]: opt['t_raidie'] = '0'
1.1384 + if event.type == KEYDOWN and event.key in [K_1]: opt['t_raidie'] = '1'
1.1385 + if event.type == KEYDOWN and event.key in [K_2]: opt['t_raidie'] = '2'
1.1386 + if event.type == KEYDOWN and event.key in [K_3]: opt['t_raidie'] = '3'
1.1387 + if event.type == KEYDOWN and event.key in [K_4]: opt['t_raidie'] = '4'
1.1388 + if event.type == KEYDOWN and event.key in [K_5]: opt['t_raidie'] = '5'
1.1389 + if event.type == KEYDOWN and event.key in [K_6]: opt['t_raidie'] = '6'
1.1390 + if event.type == KEYDOWN and event.key in [K_7]: opt['t_raidie'] = '7'
1.1391 + if event.type == KEYDOWN and event.key in [K_8]: opt['t_raidie'] = '8'
1.1392 + if event.type == KEYDOWN and event.key in [K_9]: opt['t_raidie'] = '9'
1.1393 + if event.type == KEYDOWN and event.key in [K_DELETE]: opt['t_raidie'] = '>'
1.1394 + if event.type == KEYDOWN and event.key in [K_SPACE]: opt['t_raidie'] = ' '
1.1395 + if event.type == KEYDOWN and event.key in [K_BACKSPACE]: opt['t_raidie'] = '<'
1.1396 +
1.1397 + if event.type == KEYDOWN and event.key in [K_RETURN, K_KP_ENTER]:
1.1398 + if MENIU:
1.1399 + if meniu_flag == 120:
1.1400 + MENIU = 0
1.1401 + meniu_flag = 0
1.1402 + if meniu_flag == 19:
1.1403 + opt['log'].insert(0,[zh[1] + ' -> ' + opt['zaid'], spalvas[1]])
1.1404 + zh[1] = opt['zaid']
1.1405 + MENIU = 0
1.1406 + meniu_flag = 0
1.1407 + if meniu_flag == 18:
1.1408 + opt['log'].insert(0,[zh[0] + ' -> ' + opt['zaid'], spalvas[0]])
1.1409 + zh[0] = opt['zaid']
1.1410 + MENIU = 0
1.1411 + meniu_flag = 0
1.1412 + if meniu_flag in (10, 11):
1.1413 + een = 0
1.1414 +
1.1415 +
1.1416 + if event.type == KEYDOWN and event.key in [K_ESCAPE]:
1.1417 + if MENIU:
1.1418 + if meniu_flag in (16,17):
1.1419 + meniu_flag = 15
1.1420 + if meniu_flag in (18,19):
1.1421 + MENIU = 0
1.1422 + meniu_flag = 0
1.1423 + if meniu_flag in (10, 11):
1.1424 + MENIU = 0
1.1425 +
1.1426 +
1.1427 +
1.1428 +
1.1429 +
1.1430 + if event.type == MOUSEBUTTONUP and event.button == 1:
1.1431 + x_m, y_m = event.pos
1.1432 + if not MENIU:
1.1433 + if ( x_m < 555 and x_m > 5 ) and ( y_m < 595 and y_m > 5 ):
1.1434 + x_m = int(round(x_m, -1))
1.1435 + y_m = int(round(y_m, -1))
1.1436 + tmp = 1
1.1437 + for i in db_task:
1.1438 + if x_m/10 == i[0] and y_m/10 == i[1]:
1.1439 + tmp = 0
1.1440 + break
1.1441 + if tmp:
1.1442 + tasks(x_m/10, y_m/10, eejems)
1.1443 + luogs(screen, eejems, (x_m/10, y_m/10))
1.1444 + POINT = 1
1.1445 + eejems += 1
1.1446 + if eejems > len(zh): eejems = 1
1.1447 +
1.1448 + if ( x_m < 790 and x_m > 575 ) and ( y_m < 60 and y_m > 10 ):
1.1449 + MENIU = 1
1.1450 + meniu_flag = 1
1.1451 + if ( x_m < 690 and x_m > 590 ) and ( y_m < 180 and y_m > 160 ):
1.1452 + MENIU = 1
1.1453 + meniu_flag = 18
1.1454 + opt['zaid'] = zh[0]
1.1455 + opt['kursor_pos'] = len(opt['zaid'])
1.1456 + if ( x_m < 690 and x_m > 590 ) and ( y_m < 204 and y_m > 184 ):
1.1457 + MENIU = 1
1.1458 + meniu_flag = 19
1.1459 + opt['zaid'] = zh[1]
1.1460 + opt['kursor_pos'] = len(opt['zaid'])
1.1461 +
1.1462 + else:
1.1463 + if ( x_m < 395 and x_m > 210 ) and ( y_m < 300 and y_m > 270 ) and meniu_flag == 1:
1.1464 + meniu_flag = 13
1.1465 + if ( x_m < 490 and x_m > 405 ) and ( y_m < 340 and y_m > 310 ) and meniu_flag == 13:
1.1466 + MENIU = 0
1.1467 + if ( x_m < 395 and x_m > 310 ) and ( y_m < 340 and y_m > 310 ) and meniu_flag == 13:
1.1468 + meniu_flag = 14
1.1469 + if ( x_m < 690 and x_m > 605 ) and ( y_m < 490 and y_m > 460 ) and meniu_flag == 14:
1.1470 + new()
1.1471 + MENIU = 0
1.1472 + if ( x_m < 395 and x_m > 210 ) and ( y_m < 390 and y_m > 360 ) and meniu_flag in (1,2):
1.1473 + MENIU = 0
1.1474 + if ( x_m < 600 and x_m > 405 ) and ( y_m < 390 and y_m > 360 ) and meniu_flag == 1:
1.1475 + meniu_flag = 10
1.1476 + if ( x_m < 395 and x_m > 310 ) and ( y_m < 340 and y_m > 310 ) and meniu_flag in (10,11):
1.1477 + een = 0
1.1478 + if ( x_m < 490 and x_m > 405 ) and ( y_m < 340 and y_m > 310 ) and meniu_flag in (10,11):
1.1479 + MENIU = 0
1.1480 + if ( x_m < 450 and x_m > 300 ) and ( y_m < 260 and y_m > 210 ) and meniu_flag == 2:
1.1481 + meniu_flag = 1
1.1482 + if ( x_m < 600 and x_m > 450 ) and ( y_m < 260 and y_m > 210 ) and meniu_flag == 1:
1.1483 + meniu_flag = 2
1.1484 + if ( x_m < 497 and x_m > 405 ) and ( y_m < 300 and y_m > 270 ) and meniu_flag == 1:
1.1485 + meniu_flag = 12
1.1486 + if ( x_m < 490 and x_m > 405 ) and ( y_m < 340 and y_m > 310 ) and meniu_flag == 12:
1.1487 + MENIU = 0
1.1488 + if ( x_m < 395 and x_m > 310 ) and ( y_m < 340 and y_m > 310 ) and meniu_flag == 12:
1.1489 + new()
1.1490 + MENIU = 0
1.1491 + if ( x_m < 497 and x_m > 405 ) and ( y_m < 300 and y_m > 270 ) and meniu_flag == 2:
1.1492 + if fullscreen:
1.1493 + window = pygame.display.set_mode( (800, 600), DOUBLEBUF )
1.1494 + fullscreen = 0
1.1495 + else:
1.1496 + window = pygame.display.set_mode( (800, 600), FULLSCREEN )
1.1497 + fullscreen = 1
1.1498 + if ( x_m < 395 and x_m > 210 ) and ( y_m < 300 and y_m > 270 ) and meniu_flag == 2:
1.1499 + meniu_flag = 15
1.1500 + break
1.1501 + if ( x_m < 590 and x_m > 515 ) and ( y_m < 390 and y_m > 360 ) and meniu_flag == 15:
1.1502 + meniu_flag = 2
1.1503 + if ( x_m < 600 and x_m > 210 ) and ( y_m < 290 and y_m > 250 ) and meniu_flag == 15:
1.1504 + meniu_flag = 16
1.1505 + opt['zaid'] = zh[0]
1.1506 + opt['kursor_pos'] = len(opt['zaid'])
1.1507 + if ( x_m < 600 and x_m > 210 ) and ( y_m < 340 and y_m > 300 ) and meniu_flag == 15:
1.1508 + meniu_flag = 17
1.1509 + opt['zaid'] = zh[1]
1.1510 + opt['kursor_pos'] = len(opt['zaid'])
1.1511 + if ( x_m < 690 and x_m > 405 ) and ( y_m < 310 and y_m > 280 ) and meniu_flag in (16,17):
1.1512 + meniu_flag = 15
1.1513 + if ((( x_m < 395 and x_m > 310 ) and ( y_m < 310 and y_m > 280 )) or (event.type == KEYDOWN and event.key in [K_RETURN])) and meniu_flag == 16:
1.1514 + opt['log'].insert(0,[zh[0] + ' -> ' + opt['zaid'], spalvas[0]])
1.1515 + zh[0] = opt['zaid']
1.1516 + meniu_flag = 15
1.1517 + if ((( x_m < 395 and x_m > 310 ) and ( y_m < 310 and y_m > 280 )) or (event.type == KEYDOWN and event.key in [K_RETURN])) and meniu_flag == 17:
1.1518 + opt['log'].insert(0,[zh[1] + ' -> ' + opt['zaid'], spalvas[1]])
1.1519 + zh[1] = opt['zaid']
1.1520 + meniu_flag = 15
1.1521 + if ( x_m < 690 and x_m > 405 ) and ( y_m < 310 and y_m > 280 ) and meniu_flag in (18,19):
1.1522 + MENIU = 0
1.1523 + meniu_flag = 0
1.1524 + if ( x_m < 395 and x_m > 310 ) and ( y_m < 310 and y_m > 280 ) and meniu_flag == 18:
1.1525 + opt['log'].insert(0,[zh[0] + ' -> ' + opt['zaid'], spalvas[0]])
1.1526 + zh[0] = opt['zaid']
1.1527 + MENIU = 0
1.1528 + meniu_flag = 0
1.1529 + if ( x_m < 395 and x_m > 310 ) and ( y_m < 310 and y_m > 280 ) and meniu_flag == 19:
1.1530 + opt['log'].insert(0,[zh[1] + ' -> ' + opt['zaid'], spalvas[1]])
1.1531 + zh[1] = opt['zaid']
1.1532 + MENIU = 0
1.1533 + meniu_flag = 0
1.1534 + if ( x_m < 690 and x_m > 605 ) and ( y_m < 490 and y_m > 460 ) and meniu_flag == 120:
1.1535 + MENIU = 0
1.1536 + meniu_flag = 0
1.1537 + if ( x_m < 600 and x_m > 507 ) and ( y_m < 340 and y_m > 310 ) and meniu_flag == 2:
1.1538 + meniu_flag = 120
1.1539 + MENIU = 1
1.1540 + if ( x_m < 395 and x_m > 210 ) and ( y_m < 340 and y_m > 310 ) and meniu_flag == 2:
1.1541 + flagai['SAVE_DIR'] = 1
1.1542 + if ( x_m < 600 and x_m > 507 ) and ( y_m < 300 and y_m > 270 ) and meniu_flag == 1:
1.1543 + flagai['SAUGOM'] = 1
1.1544 + flagai['KNIST_DIR'] = 1
1.1545 + if ( x_m < 497 and x_m > 405 ) and ( y_m < 340 and y_m > 310 ) and meniu_flag == 1:
1.1546 + flagai['KRAUNAM'] = 1
1.1547 + flagai['KNIST_DIR'] = 1
1.1548 + MENIU = 0
1.1549 + meniu_flag = 0
1.1550 + if ( x_m < 600 and x_m > 507 ) and ( y_m < 340 and y_m > 310 ) and meniu_flag == 1:
1.1551 + flagai['PRINTINAM'] = 1
1.1552 + flagai['KNIST_DIR'] = 1
1.1553 +
1.1554 +
1.1555 + # Pri pelies prikabinam tikslenema
1.1556 + x_m, y_m = pygame.mouse.get_pos()
1.1557 + if ( x_m < 555 and x_m > 5 ) and ( y_m < 595 and y_m > 5 ) and not MENIU:
1.1558 + x_m = int(round(x_m, -1))
1.1559 + y_m = int(round(y_m, -1))
1.1560 + pygame.draw.circle(screen, (0,0,0), (x_m, y_m), 5, 2)
1.1561 + pos = str(x_m/10) + ", " + str(y_m/10)
1.1562 + a = fonts.render(pos, True, (0,0,0))
1.1563 + screen.blit(a, (x_m+10, y_m-10))
1.1564 +
1.1565 + # Virs meniu pirsts
1.1566 + if not MENIU:
1.1567 + if ( x_m < 790 and x_m > 575 ) and ( y_m < 60 and y_m > 10 ):
1.1568 + pygame.mouse.set_cursor((16,16),(8,1),kursor_ronka,mask)
1.1569 + else:
1.1570 + pygame.mouse.set_cursor(*pygame.cursors.arrow)
1.1571 +
1.1572 + # Zaidema greitis aple 20fps
1.1573 + tiktak.tick(20)
1.1574 + pygame.display.flip()
1.1575 +
1.1576 +
1.1577 +# Paleidema f-je, je nesaukams kap muodelis
1.1578 +if __name__ == "__main__":
1.1579 + main()