Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- instructions = \
- """
- \nISTRUZIONI:
- Questo gioco è un semplice tris
- Per ogni turno il giocatore deve inserire un numero
- di slot che sarà quello in cui sarà inserita la lettera
- corrispondente al giocatore(X per il player 1 e O per il player 2)
- Gli slot sono strutturati secondo una numerazione crescente.
- Questa è una tabella con ogni slot nel suo posto:
- 1|2|3
- 4|5|6
- 7|8|9
- Il gioco finisce quando un giocatore riesce ad allineare tre lettere uguali
- Spero che ti piaccia! ;)\n
- """ \
- [1:-1]
- table = [["-","-","-"],
- ["-","-","-"],
- ["-","-","-"]]
- playerSymbols = {1:"X" , 2:"O"}
- def printTable(table) :
- string = []
- for line in table :
- strLine = "|".join(line)
- string.append(strLine)
- string = "\n".join(string)
- print(string)
- while True :
- inst = input("Hai mai giocato a questo gioco?(y/n): ").lower()
- if inst == "n" :
- print(instructions)
- break
- elif inst == "y" :
- break
- else :
- continue
- input("Premi ENTER per iniziare!")
- player = 1
- while True :
- printTable(table)
- symbol = playerSymbols[player]
- print("Player %s(%s)" % (str(player), symbol))
- while True :
- slot = input("Inserisci slot: ")
- if slot == "" :
- continue
- if not slot.isdecimal() :
- print("Lo slot deve essere un numero")
- continue
- slot = int(slot)
- if not 1 <= slot <= 9 :
- print("Slot non valido")
- continue
- else :
- break
- if 1 <= slot <= 3 :
- if table[0][slot - 1] != "-" :
- table[0][slot - 1] = symbol
- elif 4 <= slot <= 6 :
- table[1][(slot - 6) - 1] = symbol
- elif 7 <= slot <= 9 :
- table[2][(slot - 6) - 1] = symbol
- userXWin = ((table[0] == ["X","X","X"]) or \
- (table[1] == ["X","X","X"]) or \
- (table[2] == ["X","X","X"]) or \
- ((table[0][0] == "X") and (table[1][1] == "X") and (table[2][2] == "X")) or \
- ((table[0][2] == "X") and (table[1][1] == "X") and (table[2][0] == "X")) or \
- ((table[0][1] == "X") and (table[1][1] == "X") and (table[2][1] == "X")) or \
- ((table[0][0] == "X") and (table[1][0] == "X") and (table[2][0] == "X")) or \
- ((table[0][2] == "X") and (table[1][2] == "X") and (table[2][2] == "X")))
- userOWin = ((table[0] == ["O","O","O"]) or \
- (table[1] == ["O","O","O"]) or \
- (table[2] == ["O","O","O"]) or \
- ((table[0][0] == "O") and (table[1][1] == "O") and (table[2][2] == "O")) or \
- ((table[0][2] == "O") and (table[1][1] == "O") and (table[2][0] == "O")) or \
- ((table[0][1] == "O") and (table[1][1] == "O") and (table[2][1] == "O")) or \
- ((table[0][0] == "O") and (table[1][0] == "O") and (table[2][0] == "O")) or \
- ((table[0][2] == "O") and (table[1][2] == "O") and (table[2][2] == "O")))
- if userOWin == True :
- printTable(table)
- input("Il player 2 ha vinto!")
- break
- elif userXWin == True :
- printTable(table)
- input("Il Player 1 ha vinto!")
- break
- if player == 1 :
- player = 2
- elif player == 2 :
- player = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement