jogo_fosforos.py

Created by serenela-moreira

Created on March 28, 2022

1.24 KB

Remova um, dois ou três fósforos. Use a tecla da esquerda para remover um fósforo, a tecla de cima para remover 2 fósforos e a tecla da direita para remover 3 fósforos. O computador joga a seguir. Não deve ficar com o último fósforo.


from math import *
from kandinsky import *
from ion import *
from time import *
from random import randint

def draw(nb, color, top):
  for i in range(nb):
    fill_rect(i*15+10,70,5,50,color)
    fill_rect(i*15+9,60,7,10,top)
brown=color(255,204,153)
red=color(255,0,0)
white=color(255,255,255)
fosforos=0
draw(20,brown,red)
while fosforos<19:
  while keydown(KEY_LEFT) or keydown(KEY_UP) or keydown(KEY_RIGHT):
    continue
  while True :
    draw_string("Retire 1, 2 ou 3 fósforos.",10,140)
    draw_string("O computador joga de seguida.",10,160)
    draw_string("Esquerda=1 ; Cima=2 ; Baixo=3",10,180)
    if keydown(KEY_LEFT):
      fosforos+=1
      break
    else:
      if keydown(KEY_UP):
        fosforos+=2
        break
      else:
        if keydown(KEY_RIGHT):
          fosforos+=3
          break
  draw(fosforos,white,white)
  sleep(0.3)
  if fosforos==19:
    draw_string("Ganhou",100,30)
  else:
    if (20-fosforos)%4==3:
      fosforos+=2
    else:
      if (20-fosforos)%4==0:
        fosforos+=3
      else:
        if (20-fosforos)%4==2:
          fosforos+=1
        else:
          fosforos+=randint(1,3 if fosforos<17 else 20-fosforos-1)
    draw(fosforos,white,white)
    if fosforos==19:
      draw_string("Perdeu",100,30)

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.