power_old2.py

Created by elnix91

Created on September 28, 2025

4.55 KB

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):
      if case==1:
        rect(3+x*24,3+y*24,23,23,(255,100,255))
        rect(5+x*24,5+y*24,19,19,COLORS[int(FIELD[y*9+x])])
      else:rect(x*24+3,y*24+3,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])

#soldat,tank,avion,bateau
#regiment,char,chasseur,cuirasse
#gagner,argent,invoquer,deplacer,fusionner

# 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],["Avion",3,3],["tank",2,4],["bateau",2,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)]
MONEY=[0 for i in range(nbPlayers)]
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)

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)
        if int(FIELD[y*9+x])>2 and int(FIELD[y*9+x])!=tour+3 and earn==0:
          MONEY[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("MONEY:"+str(MONEY[tour]),225,40,TXT,(255,255,0))
    first,brek,earn=1,0,1
    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)
        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):
        units=-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)
        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
            ds("UNITS:",15,35,(255,0,0))
            ds((str(FIELDS[Y][X][tour].count(i))+" "+UNITS[i][0]),15,55+units*19,TXT,SKY)
        if units==-1:ds("NONE OF YOURS UNITS",65,102,(255,0,0),SKY)
        while 1:
          if k(17):
            brak=1
            break
        if brak:break
    if brek:break

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.