power_old.py

Created by elnix91

Created on September 28, 2025

3.53 KB

debug version of power, the last version is available here


from kandinsky import fill_rect as rect,draw_string as ds
from ion import keydown as k
from time import sleep
#from power_units import *
COLORS=[(0,0,0),(0,0,255),(255,255,100),(255,0,0),(0,255,0),(0,255,255),(255,255,0)]
FIELD="211121112133314441133314441133314441211121112155516661155516661155516661211121112"
FIELDS=[[[[],[],[],[]]for X in range(9)]for Y in range(9)]
TYPES=["Sea","Island","P1","P2","P3","P4"]
# [units]
def menu():
  nbPlayers=0
  first=1
  rect(0,0,320,222,(255,255,255))
  ds("POWER !",125,20,(255,0,0))
  ds("Nombre de joueurs:",70,50,(0,0,255))
  ds("+",155,90)
  ds("-",155,150)
  while k(4):1
  while not (k(4) or k(52)):
    if k(1) or k(2) or first:
      first=0
      if k(1):nbPlayers=(nbPlayers+1)%3
      if k(2):nbPlayers=(nbPlayers-1)%3
      ds(str(nbPlayers+2),155,120)
      while k(1) or k(2):1
  return nbPlayers+2

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(4):
        if len(FIELDS[y][x][i])>0:
          rect(x*24+8,y*24+8,13,13,(0,0,0))
          rect(x*24+10,y*24+10,9,9,COLORS[i+3])

# soldat,tank,avion,bateau
# regiment,char,chasseur,cuirasse

# gagner argent,invoquer,deplacer,fusionner
class actions:
  def __init__(self):1
  def move(self,x,y,x_,y_):
    if (max(self.x,x_)-min(self.x,x_)<=self.speed) and max(self.y,y_)-min(self.y,y_)<=self.speed:return x_,y_
    else:return 0


class soldat:
  def __init__(self,x,y):
    self.power=1
    self.speed=1
    self.heigh=[1,1]
    self.x=x
    self.y=y
  def move(self,x_,y_):
    if (max(self.x,x_)-min(self.x,x_)<=self.speed) and max(self.y,y_)-min(self.y,y_)<=self.speed:return x_,y_
    else:return 0

nbPlayers=menu()
X,Y=4,4
tour=0

FIELDS[3][3][0].append([0,1])

# MAIN GAME LOOP
while 1:
  tour=(tour+1)%nbPlayers
# NEW ROUND LOOP
  while 1:
    rect(0,0,320,222,(255,255,255))
    rect(0,0,222,222,COLORS[0])
    for y in range(9):
      for x in range(9):
        draw_cell(x,y)
    ds("Round: ",230,0)
    ds("P"+str(tour+1),300,0,(0,0,0),COLORS[tour+3])
    first=1
    brek=0
    while k(0) or k(1) or k(2) or k(3) or k(4) or k(5):1
#   ROUND LOOP
    while 1:
#   Validation bloc
      if k(52):
        choice=0
        second=1
        rect(100,61,120,100,(0,0,0))
        rect(103,64,112,92,(255,255,255))
        ds("Valider?",120,71)
        ds("Oui",115,101,(0,255,0))
        ds("Non",175,101,(255,0,0))
        while not k(4):
          if k(0) or k(3) or second:
            second=0
            ds(" ",105+choice*60,101)
            ds(" ",145+choice*60,101)
            choice=(choice+k(3)-k(0))%2
            ds("[",105+choice*60,101)
            ds("]",145+choice*60,101)
            while k(0) or k(3):1
        if choice==0:
          brek=1
          break
        else:break
# Selection bloc
      if k(0) or k(1) or k(2) or k(3) or first:
        draw_cell(X,Y)
        X=(X+(k(3)-k(0)))%9
        Y=(Y+(k(2)-k(1)))%9
        draw_cell(X,Y,1)
        rect(222,182,100,18,(255,255,255))
        ds(""+TYPES[int(FIELD[Y*9+X])-1],222,182)
        ds("["+str(X)+";"+str(Y)+"]",246,202,(255,0,0),(255,255,255))
        while k(0) or k(1) or k(2) or k(3):1
      first=0
# Action bloc
      if k(4):
        rect(10,10,300,202,(0,0,0))
        rect(13,13,294,196,(255,255,255))
        ds("CELL:",15,15)
        ds("["+str(X)+" "+str(Y)+"]",70,15,(255,0,0))
        while 1:
          if k(17):
            brek=1
            break
        if brek: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.