×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    1

    [moved] problem with hangman game

    hi everyone i have a problem and i hope you can help me:
    I need to finish a hangman game i only a begineer in python and the problem is that
    i need that ask me for new letter when the keystar is pressed and other problem is with the images make a
    bad refresh i hop you can help me this is my code:

    mport os , random , time, key_codes
    import appuifw, e32, graphics
    from appuifw import *
    from graphics import *
    import audio
    from random import randrange
    from key_codes import *
    import sys
    global canvas, timer

    timer = e32.Ao_timer()
    lock = e32.Ao_lock()


    def quit():
    appuifw.app_lock.signal()



    def vaquero2():
    print "Vaquero avanzado"

    def monito(i):
    if i == 0:
    #crear fondo
    appuifw.app.screen='large'
    appuifw.app.body = canvas = appuifw.Canvas()
    fondo = Image.open(u"e:\\Python\\vaquero_png\\sombra.png")
    fondo.text((5,5), u" * para agregar una letra ", 0xffff00)
    canvas.blit(fondo,target=(0,0))
    if i == 1:
    # CREAR LA SOGA
    appuifw.app.screen='large'
    appuifw.app.body = canvas = appuifw.Canvas()
    fondo = Image.open(u"e:\\Python\\vaquero_png\\pie_der.png")
    fondo.text((5,5), u" * para agregar una letra ", 0xffff00)
    canvas.blit(fondo,target=(0,0))

    if i == 2:
    # CREAR EL PIE IZQUIERDO
    appuifw.app.screen='large'
    appuifw.app.body = canvas = appuifw.Canvas()
    fondo = Image.open(u"e:\\Python\\vaquero_png\\pie_izq.png")
    fondo.text((5,5), u" * para agregar una letra ", 0xffff00)
    canvas.blit(fondo,target=(0,0))

    if i == 3:
    # CREAR EL PIE DERECHO
    appuifw.app.screen='large'
    appuifw.app.body = canvas = appuifw.Canvas()
    fondo = Image.open(u"e:\\Python\\vaquero_png\\pantalon.png")
    fondo.text((5,5), u" * para agregar una letra ", 0xffff00)
    canvas.blit(fondo,target=(0,0))

    if i == 4:
    # CREAR EL PANTALON
    appuifw.app.screen='large'
    appuifw.app.body = canvas = appuifw.Canvas()
    fondo = Image.open(u"e:\\Python\\vaquero_png\\cuerpo.png")
    fondo.text((5,5), u" * para agregar una letra ", 0xffff00)
    canvas.blit(fondo,target=(0,0))

    if i == 5:
    # CREAR EL CUERPO
    appuifw.app.screen='large'
    appuifw.app.body = canvas = appuifw.Canvas()
    fondo = Image.open(u"e:\\Python\\vaquero_png\\brazos.png")
    fondo.text((5,5), u" * para agregar una letra ", 0xffff00)
    canvas.blit(fondo,target=(0,0))

    if i == 6:
    # CREAR LA MANO DERECHA
    appuifw.app.screen='large'
    appuifw.app.body = canvas = appuifw.Canvas()
    fondo = Image.open(u"e:\\Python\\vaquero_png\\cabeza.png")
    fondo.text((5,5), u" * para agregar una letra ", 0xffff00)
    canvas.blit(fondo,target=(0,0))

    if i == 7:
    # CREAR LA MANO DERECHA
    appuifw.app.screen='large'
    appuifw.app.body = canvas = appuifw.Canvas()
    fondo = Image.open(u"e:\\Python\\vaquero_png\\muerto.png")
    fondo.text((5,5), u" * para agregar una letra ", 0xffff00)
    canvas.blit(fondo,target=(0,0))

    def salvado():

    appuifw.app.screen='large'
    appuifw.app.body = canvas = appuifw.Canvas()
    fondo = Image.open(u"e:\\Python\\vaquero_png\\salvado.png")
    fondo.text((5,5), u"AS SALVADO AL VAQUERO ", 0xffff00)
    canvas.blit(fondo,target=(0,0))

    def muerto():
    appuifw.app.screen='large'
    appuifw.app.body = canvas = appuifw.Canvas()
    fondo = Image.open(u"e:\\Python\\vaquero_png\\muerto.png")
    fondo.text((5,5), u" EL VAQUERO A SIDO COLGADO ", 0xffff00)
    canvas.blit(fondo,target=(0,0))

    def al_azar(p): return p[random.randint(0,len(p)-1)]


    def lee_archivo(name):
    d = ''
    try:
    d = open(name,'r').read()
    except:
    appuifw.note(u"NO SE PUDO ABRIR EL ARCHIVO. VERIFIQUE EL PATH O SI EL ARCHIVO EXISTE", "error")
    return d.split()

    def opcion(i):
    if i == 0:
    monito(0)
    if i == 1:
    monito(1)
    if i == 2:
    monito(2)
    if i == 3:
    monito(3)
    if i == 4:
    monito(4)
    if i == 5:
    monito(5)
    if i == 6:
    monito(6)
    if i == 7:
    monito(7)
    if i == 8:
    monito(8)

    def tecla(i,q):
    while True:
    t=appuifw.query(str(i+1)+u") "+q+u"? ","text")
    opcion(i)
    try:
    c = t[0].upper() # Una letra mayuscula
    except IndexError:
    appuifw.note(u"::> Anota una letra (vacio)", "error")
    opcion(i)
    continue
    if len(t) !=1:
    appuifw.note(u"::> Anota solo un caracter", "error")
    opcion(i)
    continue
    if ord(c) in range(ord('A'),ord('Z')+1):# Letra A-Z?
    return c
    appuifw.note(u"::> Anote una letra A-Z (simbolo invalido)", "error")
    opcion(i)

    def aciertos(r,s,c): # Cambia letras correctas, r=actual, s=solucion, c=letra-entrada
    t = ''
    for i,x in enumerate(s): # Ver todas las letras de solucion
    t += x if x==c else r[i] # Agregar acierto o guion
    return t # Regresa nuevo texto actual

    # Main: Algoritmo del Juego
    def ahorcado():
    appuifw.app.screen='large'
    appuifw.app.body = canvas = appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=None)

    palabra = al_azar(lee_archivo("E:\\Python\\Paises2.txt")) # Lee archivo -> lista-palabras -> palabra al azar
    usuario = '-' * len(palabra) # Genera palabra inicial con guiones -> q
    intento, anteriores = 0, [] # No. intento-actual, lista-letras-anteriores
    limite = 7 # No. total de oportunidades
    while intento < limite:

    letra = tecla(intento,usuario) # Leer letra
    if letra in anteriores: # Repetido?

    appuifw.note(u"::> Letra repetida", "error")
    opcion(intento)
    continue # -- Ignorar intento
    anteriores.append(letra) # Agregar tecla a lista
    if not letra in palabra:
    intento += 1 # Fallo?
    opcion(intento)
    continue
    usuario = aciertos(usuario,palabra,letra) # Mostrar aciertos
    if palabra == usuario: # Terminar?
    appuifw.note(u"Felicidades!!! Has Ganado!! la palabra era " + palabra)
    op=appuifw.query(u"Quieres volver a jugar?", "query")
    if op:
    ahorcado()
    else:
    quit()
    break
    else: # Intentos agotados?
    appuifw.note(u"Perdiste, la palabra era: " + palabra) # -- Imprimir solucion
    op=appuifw.query(u"Quieres volver a jugar?", "query")
    if op:
    ahorcado()
    else:
    quit()


    #sound = audio.Sound.open('e:\\Python\Paparazzi.mp3')
    #sound.play()



    def asteris():
    appuifw.app.screen='large'
    appuifw.app.body = canvas = appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=None)
    fondo = Image.open(u"e:\\Python\\vaquero_png\\sombra.png")
    fondo.text((40,40), u" * para agregar una letra ", 0xffff00)
    canvas.blit(fondo2,target=(0,0))
    #canvas2.bind(key_codes.EKeyStar,ahorcado)

    #PANTALLA DE MENUS


    timer = e32.Ao_timer()
    appuifw.app.screen='full'
    appuifw.app.body = canvas1 = appuifw.Canvas()
    fondo1=Image.open('E:\\Python\\MENU.png')
    canvas1.blit(fondo1,target = (0,0))
    timer.after(5.0)
    timer.cancel()

    appuifw.app.menu = [(u"VAQUERO", ( (u"BASICO", ahorcado), (u"AVANZADO", asteris)))]

    appuifw.app.exit_key_handler = quit

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,734

    Re: problem with hangman game

    When you open http://discussion.forum.nokia.com, and see that the first discussion group is called "Forum Nokia Services Feedback", and it starts with "Feedback on FN Renewal", you do not have to post your Python question there immediately, the 8th big title in the list says 'Python', that would have been a better pick.

  3. #3
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: [moved] problem with hangman game

    Please use code tags when posting code. They keep the code indented, which is essential in Python, and easier to read. Click the "Edit Post" button in the bottom right corner of the post and then the "Go Advanced" button. You will then see a button with the # symbol on it. Select your code and click that.

    Also, it would be great if you could tell us a little more about your problems.

Similar Threads

  1. Problem installing a game
    By slaughtermania in forum Mobile Java Games
    Replies: 2
    Last Post: 2008-08-04, 12:53
  2. [Help] my game creation problem
    By leonseah in forum Mobile Java General
    Replies: 6
    Last Post: 2008-07-25, 01:11
  3. [Moved] Arkanoid game
    By amrish20 in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2008-05-28, 12:27
  4. Hangman for 3650
    By nellis10 in forum Mobile Java General
    Replies: 4
    Last Post: 2003-03-26, 12:19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×