debug version of power, the last version is available here
# Modules from kandinsky import fill_rect as rect,set_pixel as set,draw_string as ds from ion import keydown as k from time import sleep # Choose number of players def menu(nbPlayers=0,first=1): rect(0,0,320,222,SKY) ds("POWER !",125,20,(255,0,0),SKY) ds("Nombre de joueurs:",70,50,(0,0,255),SKY) ds("+",155,90,(0,0,0),SKY) ds("-",155,150,(0,0,0),SKY) while k(4):1 while not k(4): if k(1) or k(2) or first: nbPlayers,first=(nbPlayers+(k(1)-k(2)))%3,0 ds(str(nbPlayers+2),155,120,TXT,SKY) while k(1) or k(2):1 return nbPlayers+2 # Dram the cell in x,y def draw_cell(x,y,case=0,first=0): if first: rect(3+x*24,3+y*24,23,23,COLORS[int(FIELD[y*9+x])]) for i in range(nbPlayers): for l in range(8): if l in FIELDS[y][x][i]: rect(x*24+8,y*24+8,13,13,TXT) rect(x*24+10,y*24+10,9,9,COLORS[i+3]) break if 8 in FIELDS[y][x][i]: for j in range(15): for k in range(15): if FLAG[j*15+k]=="1":set(8+x*24+k,9+y*24+j,TXT) elif FLAG[j*15+k]=="2":set(8+x*24+k,9+y*24+j,COLORS[i+3]) if case>0: if case==1:c=(255,100,255) elif case==2:c=(COLORS[int(FIELD[y*9+x])]) rect(3+x*24,3+y*24,23,2,c) rect(3+x*24,3+y*24,2,23,c) rect(26+x*24,26+y*24,-23,-2,c) rect(26+x*24,26+y*24,-2,-23,c) # Variables SKY,TXT=(255,255,255),(0,0,0) COLORS=[(0,0,0),(0,0,255),(255,255,100),(255,0,0),(0,255,0),(0,255,255),(255,255,0)] FIELD="211121112133315551133315551133315551211121112166614441166614441166614441211121112" FLAG="001110000000000001122100000000001122221100000001122222211000001122222222100001122222211000001122221100000001122110000000001111000000000001100000000000001100000000000001100000000000111111000000000111111000000000000000000000000" TYPES=["Sea","Island","P1","P2","P3","P4"] UNITS=[["Soldat",1,1,2],["Avion",3,3,3],["tank",2,4,5],["bateau",2,10,10],["regiment",2,10],["chasseur",5,30],["char",4,40],["cuirasse",3,50],["drapeau",0,0]] nbPlayers=menu() FIELDS=[[[[]for i in range(nbPlayers)]for X in range(9)]for Y in range(9)] POWER=[0 for i in range(nbPlayers)] ACTIONS=["MOVE","GENERATE","FUSE"] BASES=[[0,0],[8,8],[0,8],[8,0]] X,Y=4,4 tour=nbPlayers-1 # Configure flags FIELDS[0][0][0].append(8) FIELDS[8][8][1].append(8) if nbPlayers>2:FIELDS[0][8][2].append(8) if nbPlayers>3:FIELDS[8][0][3].append(8) # Tests FIELDS[7][8][0].append(0) FIELDS[3][5][1].append(5) FIELDS[3][5][1].append(5) FIELDS[3][5][1].append(5) for i in range(8): FIELDS[0][0][0].append(i) # MAIN GAME LOOP while 1: tour=(tour+1)%nbPlayers earn=0 earned=0 # NEW ROUND LOOP while 1: rect(0,0,320,222,SKY) rect(0,0,222,222,TXT) for y in range(9): for x in range(9): draw_cell(x,y,0,1) if int(FIELD[y*9+x])>2 and int(FIELD[y*9+x])!=tour+3 and earn==0: POWER[tour]+=len(FIELDS[y][x][tour]) earned+=1 ds("Round: ",230,0,TXT,SKY) ds("P"+str(tour+1),300,0,TXT,COLORS[tour+3]) ds("POWER: "+str(POWER[tour]),240,40,TXT,(255,255,0)) first,earn,brek,brak=1,1,0,0 while k(4):1 # ROUND LOOP while 1: # Validation bloc if k(52): choice,second=0,1 rect(100,71,120,70,TXT) rect(103,74,114,64,SKY) ds("Valider?",120,81,TXT,SKY) ds("Oui",115,111,(0,255,0),SKY) ds("Non",175,111,(255,0,0),SKY) while not k(4): if k(0) or k(3) or second: second=0 rect(105+choice*60,111,10,18,SKY) rect(145+choice*60,111,10,18,SKY) choice=(choice+k(3)-k(0))%2 ds("[",105+choice*60,111,TXT,SKY) ds("]",145+choice*60,111,TXT,SKY) while k(0) or k(3):1 if choice==0:brek=1 break # Selection bloc if k(0) or k(1) or k(2) or k(3) or first: first=0 draw_cell(X,Y,2) X=(X+(k(3)-k(0)))%9 Y=(Y+(k(2)-k(1)))%9 draw_cell(X,Y,1) ds("→ "+TYPES[int(FIELD[Y*9+X])-1]+" ",222,182,TXT,SKY) ds("["+str(X)+";"+str(Y)+"]",246,202,(255,0,0),SKY) while k(0) or k(1) or k(2) or k(3):1 # Action bloc if k(4) and len(FIELDS[Y][X][tour])>0: units,action,second,actions=-1,0,1,[] rect(10,10,300,202,TXT) rect(13,13,294,196,SKY) ds("CELL:",15,15,TXT,SKY) ds("["+str(X)+" "+str(Y)+"]",70,15,(255,0,0),SKY) ds("ACTIONS:",180,50,(255,0,0),SKY) if 8 in FIELDS[Y][X][tour]:ds("YOUR FLAG",210,15,TXT,COLORS[3+tour]) for i in range(8): if i in FIELDS[Y][X][tour]: units+=1 if units==0:ds("UNITS:",15,35,(255,0,0)) ds((str(FIELDS[Y][X][tour].count(i))+" "+UNITS[i][0]),15,55+units*19,TXT,SKY) for i in range(len(FIELDS)): if i in FIELDS[Y][X][tour]: actions.append(0) break if BASES[tour][0]==Y and BASES[tour][1]==X:actions.append(1) for i in range(len(FIELDS[Y][X][tour])): if FIELDS[Y][X][tour].count(FIELDS[Y][X][tour][i])>2: actions.append(2) break for i in range(len(actions)):ds(ACTIONS[actions[i]],220-len(ACTIONS[actions[i]])*5,80+i*30,TXT,SKY) while k(4) or k(17):1 while 1: if k(1) or k(2) or second: second=0 rect(210-len(ACTIONS[actions[action]])*5,80+action*30,10,18,SKY) rect(220+len(ACTIONS[actions[action]])*5,80+action*30,10,18,SKY) action=(action+(k(2)-k(1)))%len(actions) ds("[",210-len(ACTIONS[actions[action]])*5,80+action*30,(255,0,0),SKY) ds("]",220+len(ACTIONS[actions[action]])*5,80+action*30,(255,0,0),SKY) while k(1) or k(2):1 elif k(4) or k(17): if k(4) and actions[action]==0: print("move") move=1 if k(4) and actions[action]==1:generate=1 if k(4) and actions[action]==2:fuse=1 brak=1 break if brak:break if brek:break #soldat,tank,avion,bateau #regiment,char,chasseur,cuirasse