Python - Juego Memory

 
Vista:

Juego Memory

Publicado por Gonzalo (1 intervención) el 02/11/2015 11:46:24
Buenos días a todos/as mi consulta es la siguiente:

Estoy creando el juego del memory y he conseguido ya, hacer que funcione hasta que se adivinan todas las parejas, pero no se como introducir un segundo jugador o en su defecto que la maquina tire una pareja al azar sin copiar y pegar el mismo código en un if. ¿Alguna solución? Gracias y aquí dejo el código

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
# -*- coding: utf-8 -*-
 
import random, sys
 
seguir = "s" or "S"
while seguir == "s" or "S":
 
    #cartes = [1, 2, 3, 4, 5, 6, 11, 12, 14, 15]
    cartes = [65, 66, 67, 68, 69, 70, 71, 72, 73, 74]
 
    parejas = len(cartes)
 
    tiradas = 0
 
    # Cargamos la lista
    taulell = []
    for i in range(2):
        taulell.append([])
        for j in range(4):
            taulell[i].append([])
            for k in range(5):
                taulell[i][j].append('?')
 
    # Duplicamos las cartas
    cartes = cartes*2
 
    # Barajamos las cartas
    random.shuffle(cartes)
 
    # Cargamos la capa 0 (la capa que no se muestra) con las cartas
    k = 0
    for i in range(4):
        for j in range(5):
            taulell[0][i][j] = chr(cartes[k])
            k = k + 1
 
    # Mostramos la capa 1 y las coordenadas
    def mostrar_tablero(tablero):
        sys.stdout.write(' |')
        for x in range(5):
            sys.stdout.write(' ' + str(x))
        sys.stdout.write('\n')
        print "============"
        lletra = 'A'
        for i in range(4):
            sys.stdout.write(lletra+'|')
            lletra = chr(ord(lletra) + 1)
            for j in range(5):
                sys.stdout.write(' ' + taulell[1][i][j])
            sys.stdout.write('\n')
 
    mostrar_tablero(taulell)
    while taulell[1] != taulell[0]:
        fila = raw_input("Fila?")
        fila = ord(fila) - 65
        columna = int(raw_input("Columna?"))
 
        while columna > 4 or columna < 0 or fila > 4 or fila < 0:
            print "Valor incorrecto"
            fila = raw_input("Fila?")
            fila = ord(fila) - 65
            columna = int(raw_input("Columna?"))
 
        taulell[1][fila][columna] = taulell[0][fila][columna]
        mostrar_tablero(taulell)
 
        resultado_1 = taulell[1][fila][columna]
 
        fila_auxiliar = raw_input("Fila?")
        fila_auxiliar = ord(fila_auxiliar) - 65
        columna_auxiliar = int(raw_input("Columna?"))
 
        while columna_auxiliar > 4 or columna_auxiliar < 0 or fila_auxiliar > 4 or fila_auxiliar < 0:
            print "Valor incorrecto"
            fila_auxiliar = raw_input("Fila?")
            fila_auxiliar = ord(fila_auxiliar) - 65
            columna_auxiliar = int(raw_input("Columna?"))
 
        taulell[1][fila_auxiliar][columna_auxiliar] = taulell[0][fila_auxiliar][columna_auxiliar]
        mostrar_tablero(taulell)
        resultado_2 = taulell[1][fila_auxiliar][columna_auxiliar]
 
        tiradas += 1
 
        if resultado_1 != resultado_2:
            taulell[1][fila][columna] = "?"
            taulell[1][fila_auxiliar][columna_auxiliar] = "?"
        else:
            parejas -= 1
            print "Correcto, te quedan ", parejas, " parejas"
 
    print "Has necesitado ", tiradas, " tiradas"
    seguir = raw_input("Quieres seguir jugando?")
    seguir.lower()
 
 
 
raw_input()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Juego Memory

Publicado por mateo (1 intervención) el 10/10/2019 19:25:18
porque pones raw_input (), no solo al final, en la linea 54, 56 est
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar