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
| import pygame
from random import choice
from Donnees import *
pygame.init()
class Ecran(object):
def __init__(self) :
self.dimension = (largeurScreen,hauteurScreen)
self.scr = pygame.display.set_mode(self.dimension)
self.fond = pygame.image.load("images/backgroundJeu.jpg").convert()
self.imageACache = pygame.image.load('images/violetta1.png').convert_alpha()
pygame.display.set_caption("Jeu du pendu Violetta")
self.scr.blit(self.fond,(0,0))
self.scr.blit(self.imageACache,(394,100))
def afficherRegles (self):
self.police = pygame.font.Font("images/BradBunR.ttf", 35)
self.regles = "Bonjour et Bienvenu sur le jeu du pendu Spécial Violetta.\n" \
"On va voir si tu connais bien ta série préférée.\n" \
"Appuie sur le bouton Nouveau pour commencer."
x = 400
for ligne in self.regles.splitlines():
texteRegle =self.police.render(ligne,1,(146, 36,131))
textRect = texteRegle.get_rect()
textRect.top = x
textRect.centerx = largeurScreen/2
self.scr.blit(texteRegle,textRect)
x = textRect.bottom
#class Ecran
class Clavier(object):
def __init__(self):
self.clavierA = pygame.image.load('images/ClavierUnchecked.png')
self.clavierB = pygame.image.load('images/ClavierChecked.png')
self.position = (100,540)
def initialisation(self):
self.boutons = [Bouton(( 100, 540, 50, 50),'A' ),
Bouton(( 175, 540, 50, 50),'B' ),
Bouton(( 250, 540, 50, 50),'C' ),
Bouton(( 325, 540, 50, 50),'D' ),
Bouton(( 400, 540, 50, 50),'E' ),
Bouton(( 475, 540, 50, 50),'F' ),
Bouton(( 550, 540, 50, 50),'G' ),
Bouton(( 625, 540, 50, 50),'H' ),
Bouton(( 700, 540, 50, 50),'I' ),
Bouton(( 775, 540, 50, 50),'J' ),
Bouton(( 850, 540, 50, 50),'K' ),
Bouton(( 925, 540, 50, 50),'L' ),
Bouton((1000, 540, 50, 50),'M' ),
Bouton(( 100, 615, 50, 50),'N' ),
Bouton(( 175, 615, 50, 50),'O' ),
Bouton(( 250, 615, 50, 50),'P' ),
Bouton(( 325, 615, 50, 50),'Q' ),
Bouton(( 400, 615, 50, 50),'R' ),
Bouton(( 475, 615, 50, 50),'S' ),
Bouton(( 550, 615, 50, 50),'T' ),
Bouton(( 625, 615, 50, 50),'U' ),
Bouton(( 700, 615, 50, 50),'V' ),
Bouton(( 775, 615, 50, 50),'W' ),
Bouton(( 850, 615, 50, 50),'X' ),
Bouton(( 925, 615, 50, 50),'Y' ),
Bouton((1000, 615, 50, 50),'Z' )]
self.scr = pygame.display.get_surface()
pygame.display.update(self.scr.blit(self.clavierA,(100,540)))
def lire_touche(self,ev):
if ev.type == pygame.MOUSEBUTTONUP and ev.button == 1:
index = pygame.Rect(ev.pos,(1,1)).collidelist(self.boutons)
if index > -1:
bouton = self.boutons[index]
r = self.scr.blit(self.clavierB,bouton,bouton.move(-100,-540))
pygame.display.update(r)
del self.boutons[index]
return bouton.lettre
#Classe Clavier
#---------------------------------------------------------------------------------------------------
class Bouton(pygame.Rect,object):
def __init__(self,rect,lettre,flag=0):
pygame.Rect.__init__(self,rect)
self.lettre = lettre
self.flag = flag
#Classe Bouton()
#_____________________________________________________________________________________________________
class BoutonDemarrer(object):
#Classe gérant le bouton démarrer
def __init__(self):
self.boutton = pygame.image.load("images/boutonDemarrer.png")
self.position = (20,20)
self.rect = self.boutton.get_rect(center =(95,45))
def Afficher(self):
BoutonDemarrer.scr = pygame.display.get_surface()
pygame.display.update(self.scr.blit(self.boutton,self.rect))
def clic(self,ev):
if ev.type == pygame.MOUSEBUTTONUP and ev.button == 1:
position = pygame.mouse.get_pos()
if self.rect.collidepoint(position):
return True
#Classe bouton Démarrer()
#--------------------------------------Mots à trouver----------------------------------------------
class motATrouver:
def __init__(self):
self.masque = pygame.display.get_surface()
self.imageMasque = pygame.image.load("images/boutonLettre.png")
self.valeur = self.choixMot()
self.longueur = len(self.valeur)
self.espacement = 20
self.largeur = 75
self.largeurEcran = largeurScreen
self.debut = (self.largeurEcran-self.largeur*self.longueur-(self.longueur-1)*self.espacement)/2
self.police = pygame.font.Font("images/BradBunR.ttf", 85)
def choixMot(self):
"""Cette fonction détermine le mot à trouver"""
return choice(liste_mots).upper()
def afficherMasque (self,fond):
# Efface ancien masque
self.masque.blit(fond,(0,400),(0,400,1150,120))
for i in range (0,self.longueur):
position = (self.debut + i*(self.largeur + self.espacement),400)
self.masque.blit(self.imageMasque,position)
pygame.display.update()
def afficherMot (self,valeurLettre) :
for indice , lettre in enumerate(self.valeur) :
if valeurLettre == lettre :
text = self.police.render(valeurLettre, 1, (255, 255, 255))
textpos = text.get_rect()
textpos.top= 383
textpos.centerx = (self.debut) + indice *(self.largeur +self.espacement) + 37.5
self.masque.blit(text,textpos)
pygame.display.update()
#Classe MotATrouver |
Partager