Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import random
- def affiche_joueur(nom, i):
- longueur = len(nom)
- print "C'est le tour du joueur n°" + str(i)
- print '*' * (longueur+4)
- print '* ' + nom + ' *'
- print '*' * (longueur+4)
- def affiche_main(liste):
- print 'Voici votre main : '
- for i in liste:
- print i,
- print ' '
- def chargerDico(nomFich):
- f = open(nomFich)
- liste = f.read().split()
- dico = {}
- for mot in liste:
- dico[mot] = None
- return dico
- def change_lettres(li, sac):
- x = str(raw_input('Voulez-vous changer des lettres de votre chevalet ? (O/N):'))
- if x == 'O':
- liste_a_changer=[]
- y=1
- while y!='0':
- y= raw_input('Quelle(s) lettre(s) voulez-vous changer ?:')
- liste_a_changer.append(y)
- for i in range(len(liste_a_changer)):
- for j in range(len(li)):
- if li[j]==liste_a_changer[i]:
- echange_listes(li[j],i,li,sac)
- return li
- else:
- return li
- def check_joker(mot):
- for i in range(len(mot)):
- if mot[i] == '&':
- x= raw_input('A quelle lettre correspond votre joker (&)? : ')
- mot= mot[:i] + x + mot[i+1:]
- return mot
- def check_lettres(mot,chevalet):
- mot.upper
- res=True
- for lettre in mot:
- if lettre not in chevalet:
- res=False
- return res
- def check_taille(mot, direction, pos_x, pos_y):
- if direction=='H':
- return len(mot[0])+pos_x<=15
- else:
- return len(mot[0])+pos_y<=15
- def check_total(liste, chevalet):
- x = check_joker(liste[0])
- return isInDico(x, dico) and check_lettres(x, chevalet) and check_taille(x, liste[1], liste[2], liste[3]) and check_position(liste)
- def chevalet(n, sac):
- l = []
- for i in sac[0:n]:
- l.append(i)
- return l
- def choixJoueur():
- """Cette fonction demande au joueur
- quel mot il veut placer sur la grille
- et à quel endroit"""
- dico = chargerDico("french.dic")
- mot=raw_input("Quel mot désirez-vous placer sur la grille?")
- if isInDico(mot,dico)== True:
- direction=raw_input("Quelle est sa direction : horizontale (H) ou verticale (V)?")
- position_x= int(raw_input("Quelle est la position de ce mot en x?"))
- position_y= int(raw_input("Quelle est la position de ce mot en y?"))
- return [mot, direction, position_x,position_y]
- else:
- print'Votre mot est incorrect'
- return choixJoueur()
- def compte_points(mot):
- res = 0
- s= lettres_dico('french.let')
- for i in range(len(mot)):
- for j in range (26):
- if mot[i] == s[j][0]:
- res+= int(s[j][2])
- print 'Votre score est de '+str(res)+'points!'
- return res
- def compte_sac(sac):
- res = 0
- for i in sac:
- res+=1
- return res
- def echange(liste, i1, i2):
- liste[i1], liste[i2] = liste[i2], liste[i1]
- def echange_listes(el1,ind2,liste1,liste2):
- for i in range(len(liste1)):
- if liste1[i]==el1:
- ind1=i
- print ind1
- liste1[ind1]=liste2[ind2]
- liste2[ind2]=el1
- return liste1
- def ecrire_mot(mot, direction, pos_x, pos_y, li):
- mot= mot.upper()
- if direction == 'H':
- for i in range(len(mot)):
- if li[(pos_x+1)][(pos_y+1)+i]== ' *'or li[(pos_x+1)][(pos_y+1)+i]== ' '+ mot[i]:
- li[(pos_x+1)][(pos_y+1)+i]= ' '+mot[i]
- else:
- return False
- return li
- else :
- for i in range(len(mot)):
- if li[(pos_x+1)+i][(pos_y+1)]== ' '+mot[i] or li[(pos_x+1)+i][(pos_y+1)]== ' *':
- li[(pos_x+1)+i][(pos_y+1)]= ' '+mot[i]
- else:
- return False
- return li
- def lettres_dico(nomFichier):
- x=[]
- a = open (nomFichier)
- for i in a.readlines():
- b= i.split()
- x.append(b)
- y = ['&', '2', '0']
- x.append(y)
- return x
- def liste_jeu():
- table=[[' ',' 0',' 1',' 2',' 3',' 4',' 5',' 6',' 7',' 8',' 9','10','11','12','13','14']]
- for i in range(10):
- table.append([str(i)+' ']+15*[' *'])
- for j in range(10,15):
- table.append([str(j)+'']+15*[' *'])
- return table
- def isInDico(mot,dico):
- return mot.upper() in dico
- def melange(listeNombres):
- for i in range(len(listeNombres)-1):
- place = random.randint(i,len(listeNombres)-1)
- echange(listeNombres,i,place)
- def multijoueur():
- l = []
- nbre= int(raw_input('Combien de joueurs participent à la partie ? : '))
- if nbre > 4 or nbre < 1:
- return "Nombre de joueurs incorrect"
- else:
- for i in range(nbre):
- e= raw_input('Quel est le nom du joueur n°'+ str(i+1)+ ':')
- l.append(e)
- return l
- def pioche():
- l= []
- s= lettres_dico('french.let')
- for i in range(len(s)):
- a= s[i][0]
- b= int (s[i][1])
- for i in range (b):
- l.append(a)
- melange(l)
- return l
- def plateau_jeu(liste):
- for ligne in liste:
- for element in ligne:
- print element,
- print ''
- print ''
- def remplir_chevalet(mot, chevalet, sac):
- for i in range(len(mot)):
- for j in chevalet:
- if mot[i]== chevalet[j]:
- chevalet[j]=sac[i]
- return chevalet
- def scrabble():
- m= multijoueur()
- print ''
- lettres_dico('french.let')
- sac=pioche()
- l = liste_jeu()
- plateau_jeu(l)
- li_chevalet_points_sac=[]
- while sac != []:
- a=chevalet(7,sac)
- for i in range(len(m)):
- affiche_joueur(m[i], (i+1))
- n=len(a)
- a= a+chevalet(7-n, sac)
- affiche_main(a)
- sac = sac[7:]
- a=change_lettres(a, sac)
- affiche_main(a)
- b = choixJoueur()
- l=ecrire_mot(b[0],b[1],b[2],b[3],l)
- check_joker(b[0])
- plateau_jeu(l)
- c = compte_sac(sac)
- d= compte_points(b[0])
- f= remplir_chevalet(b[0], a , sac)
- print 'Il reste '+str(c)+'lettres dans la pioche'
- print 'Votre score est de '+str(d)
- e= [f, d, sac]
- li_chevalet_points_sac.append(e)
Add Comment
Please, Sign In to add comment