Advertisement
LiMIllusion

Battaglia Navale Python

Jul 22nd, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1. #Battaglia Navale A Linea di Comando
  2. #Cesta Luca
  3.  
  4. import sys
  5. import os
  6. import locale
  7. import time
  8.  
  9.  
  10. def clearscreen():
  11.     if sys.platform[0:3]=='win':
  12.         clear='cls'
  13.     else:
  14.         clear='clear'
  15.     os.system(clear)
  16.  
  17. def lingua():
  18.     if locale.getdefaultlocale()[0]=='it_IT':
  19.         file=open('lingua','w')
  20.         file.write('ita')
  21.     elif locale.getdefaultlocale()[0]=='en_GB' or 'en_US':
  22.         file=open('lingua','w')
  23.         file.write('eng')
  24.     else:
  25.         linguamanuale(lang)
  26.  
  27. def linguamanuale():
  28.     while (1):
  29.         lingua= input(' Choose your language: \n Scegli la tua lingua: \n ENG/ITA \n ')
  30.         if lingua.lower()=='ita':
  31.             file=open('lingua','w')
  32.             file.write('ita')
  33.             break
  34.         elif lingua.lower()=='eng':
  35.             file=open('lingua','w')
  36.             file.write('eng')
  37.             break
  38.         else:
  39.             clearscreen()
  40.             print(' Scelta non valida. \n Invalid choice.')
  41.  
  42. def animling():
  43.     for i in range(100):
  44.         if i==50:
  45.             lingua()
  46.         print(" Getting your language: ", i+1,"% / Ottenendo la tua lingua: ", i+1,"%", end="\r")
  47.         time.sleep(0.05)
  48.     clearscreen()
  49.     file=open('lingua')
  50.     if file.read()=='ita':
  51.         print("\n Successo!\n ")
  52.         time.sleep(0.05)
  53.         input(" Premi invio per continuare...")
  54.     else:
  55.         input("\n Done!\n")
  56.         time.sleep(0.05)
  57.         input(" Press enter to continue...")
  58.  
  59. def letturanomegiocatore():
  60.     file=open('lingua')
  61.     file2=open('giocatore','w')
  62.     if file.read()=='ita':
  63.         nome=input(" Ciao! sembra che ancora non ci siamo presentati, io sono Alfred, il computer, giochero' con te nei momenti di noia! \n Tu, invece, chi sei? \n ")
  64.     else:
  65.         nome=input(" Hi! It seems that we have not yet submitted, I am Alfred, the computer, I will play with you in moments of boredom \n You, however, who are You? \n ")
  66.     file2.write(nome)
  67. def esci():
  68.     exit()
  69.  
  70.  
  71.  
  72.  
  73.    
  74. def main():
  75.     clearscreen()
  76.     try:
  77.         file=open('lingua')
  78.         if file.read()=='':
  79.             animling()
  80.     except FileNotFoundError:
  81.         animling()
  82.     clearscreen()
  83.     try:
  84.         file2=open('giocatore')
  85.         if file2.read()=='':
  86.             letturanomegiocatore()
  87.     except FileNotFoundError:
  88.         letturanomegiocatore()
  89.     clearscreen()
  90.     file2=open('giocatore')
  91.     nome=file2.read()
  92.     while(1):
  93.         print(" Ciao ",nome, " sei pronto per giocare?\n")
  94.         sceltamenu=input(" Scegli cosa vuoi fare:\n 1. Nuova partita.\n 2. Opzioni.\n 3. Esci.\n")
  95.         if sceltamenu==1:
  96.             partita()
  97.             break
  98.         elif sceltamenu==2:
  99.             opzioni()
  100.             break
  101.         elif sceltamenu==3:
  102.             esci()
  103.             break
  104.         else:
  105.             input(" Scelta non valida, premi invio per continuare.")
  106.             clearscreen()
  107.  
  108.  
  109.  
  110. if __name__ == '__main__':
  111.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement