Advertisement
wagner-cipriano

Jogo da Forca

Aug 17th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. # -*- coding:UTF-8 -*-
  2. #-------------------------------------------------------------------------------
  3. # Name:        Jogo da Forca
  4. # Purpose:
  5. #
  6. # Author:      Wagner
  7. #
  8. # Created:     17/08/2017
  9. # Copyright:   (c) SSI 2017
  10. # Licence:     <your licence>
  11. #-------------------------------------------------------------------------------
  12.  
  13. Dica = 'Eh um Eletrodomestico' #@TODO: Ler do arquivo texto
  14. PalavraSecreta = 'LAVADORA'    #@TODO: Ler do arquivo texto
  15. QtdeErrosPerm = 3              #@TODO: Ler de algum parametro
  16.  
  17. def PrintPalavra(PalavraSecreta, PalavraForca, LetraEscolhida=None):
  18.     Result = True
  19.     if(LetraEscolhida):
  20.         Result = False
  21.         while (PalavraSecreta.find(LetraEscolhida) != -1):
  22.             PalavraForca[ PalavraSecreta.find(LetraEscolhida) ] = LetraEscolhida
  23.             PalavraSecreta = PalavraSecreta.replace(LetraEscolhida, '-', 1)
  24.             Result = True
  25.     print '\n\n\n', 'Dica: %s\nPalavra secreta:\n\n    '%(Dica), ' '.join(PalavraForca), '\n'*3
  26.     return Result
  27. #
  28.  
  29. CharCoringa = '__'
  30. PalavraForca = [CharCoringa for i in range(len(PalavraSecreta))]  #Regra:
  31. PrintPalavra(PalavraSecreta, PalavraForca)
  32. LetrasTry = ''
  33.  
  34. #Iniciar Jogo
  35. QtdeErros = 0
  36. while(QtdeErros < QtdeErrosPerm):
  37.     #Ler do input do usuario
  38.     LetraEscolhida = raw_input('Informe a letra: ')
  39.     ResLetra = PrintPalavra(PalavraSecreta, PalavraForca, LetraEscolhida)
  40.     if(not ResLetra):
  41.         QtdeErros += 1
  42.         LetrasTry += [', %s' %(LetraEscolhida), LetraEscolhida] [LetrasTry == '']
  43.         print 'Letra "%s" incorreta. Tentativas restantes: %s' %(LetraEscolhida, QtdeErrosPerm-QtdeErros)
  44.  
  45.     elif(PalavraForca.count(CharCoringa) == 0):
  46.         break;
  47.     print 'Letras: %s' %(LetrasTry)
  48.  
  49. if(QtdeErros < QtdeErrosPerm):
  50.     print 'Parabens vc acertou nerd !'
  51. else:
  52.     print '\n'*7, 'Nao foi desta vez, vejo que voce nao e tao inteligente kakakak'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement