1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
# import
from p5 import *
from random import choice
def setup():
# initialisation de l'interface
createCanvas(400, 400)
background(200)
noStroke()
def draw():
joueur() # affichage formes
ordinateur()
anim_bouton_pierre()
nouveau_bouton_pierre()
anim_bouton_papier()
nouveau_bouton_papier()
anim_bouton_ciseaux()
nouveau_bouton_ciseaux()
affichage_choix_ordinateur()
def bouton_pierre(x, y) :
if x>75 and x<175 and y>100 and y<130 : # souris dans Pierre ?
return True
def anim_bouton_pierre() :
if bouton_pierre(mouseX, mouseY) :
fill("gray")
rect(75, 100, 100, 30)
fill("black")
text("Pierre", 98, 122)
def bouton_pierre_appuye() :
if bouton_pierre(mouseX, mouseY) and mouseIsPressed :
return True
def nouveau_bouton_pierre() :
if bouton_pierre_appuye() :
fill("red")
rect(75, 100, 100, 30)
fill("black")
text("Pierre", 98, 122)
def bouton_papier(x, y) :
if x>75 and x<175 and y>150 and y<180 : # souris dans Papier ?
return True
def anim_bouton_papier() :
if bouton_papier(mouseX, mouseY) :
fill("gray")
rect(75, 150, 100, 30)
fill("black")
text("Papier", 95, 172)
def bouton_papier_appuye() : # bouton Papier appuyé ?
if bouton_papier(mouseX, mouseY) and mouseIsPressed :
return True
def nouveau_bouton_papier() :
if bouton_papier_appuye() :
fill("red")
rect(75, 150, 100, 30)
fill("black")
text("Papier", 95, 172)
def bouton_ciseaux(x, y) :
if x>75 and x<175 and y>200 and y<230 : # souris dans Ciseaux ?
return True
def anim_bouton_ciseaux() :
if bouton_ciseaux(mouseX, mouseY) :
fill("gray")
rect(75, 200, 100, 30)
fill("black")
text("Ciseaux", 90, 222)
def bouton_ciseaux_appuye() : # bouton Ciseaux appuyé ?
if bouton_ciseaux(mouseX, mouseY) and mouseIsPressed :
return True
def nouveau_bouton_ciseaux() :
if bouton_ciseaux_appuye() :
fill("red")
rect(75, 200, 100, 30)
fill("black")
text("Ciseaux", 90, 222)
def choix_ordinateur() : # réponse aléatoire
r =""
liste = ["Pierre", "Papier", "Ciseaux"]
r = choice(liste)
return r
def affichage_choix_ordinateur() :
if bouton_pierre_appuye() or bouton_papier_appuye() or bouton_ciseaux_appuye() :
a = choix_ordinateur()
if a == "Pierre" :
fill("black")
textSize(18)
text("Pierre", 222, 172)
elif a == "Papier" :
fill("black")
textSize(18)
text("Papier", 222, 172)
elif a == "Ciseaux" :
fill("black")
textSize(18)
text("Ciseaux", 222, 172)
def joueur() :
fill("black") # affiche "Joueur"
textSize(20)
text("Joueur", 90, 50, 100, 50)
fill("white") # affiche les rectangles des options
rect(75, 100, 100, 30)
rect(75, 150, 100, 30)
rect(75, 200, 100, 30)
fill("black") # affiche le nom des options dans les rectangles
text("Pierre", 98, 122)
text("Papier", 95, 172)
text("Ciseaux", 90, 222)
def ordinateur() :
fill("black") # affiche "Adversaire"
textSize(18)
text("Adversaire", 220, 66)
fill("white") # affiche le rectangle de la réponse adverse
rect(220, 150, 100, 30)
run() |