Thursday, February 17, 2011

Brown Hair With Purple Highlights

[Python3.1] Find the nugget!


A little game in python3.1, just to get the hang of the function call, the doctype and to build on an idea born in the bus to provide material to ' Academy :)




    #! / Usr / bin / env python3.1   
# -*- coding: utf-8 -*-
import sys import
random

final stampaCantiere ( field, nugget = None): #
step if the nugget is then checked cell by cell
# which is the right where to put
if nugget! = None :
for r in range ( field ):
for c in range ( campo ):
if r == pepita [ 0 ] and c == pepita [ 1 ]:
print ( " '' ) print
() # altrimenti fai una stampa veloce
# separo i due casi per evitare di eseguire sempre del codice molto pesante else : for
i in range
( campo ):
print
( "
trovaPepita ( tent, field ): "" "\\ nCreate an array of size field * field where it poses a 'nugget' so random through the randomInt function () that we must try to find
to win. If the distance between the 'quarry' and added that the nugget is one, will warn us of the neighborhood.



Can 'be invoked without arguments, in case the default values \u200b\u200b saranno 6 tentativi e una matrice 6x6, altrimenti accetta due numeri dove il numero dei tentativi deve essere inferiore al numero delle cave."""
if
tent >= campo *
campo :
exit (
" Così non si puo' giocare! " )
print (
" \ n Benvenuto nella miniera di TuxErrante !
\ n Sarò lieto di \ condividere con te il mio oro
,
as long as you manage to find ! \\ N \\ You {0}
explosive charges and {1} caves to explore. \\ n
\\ Are you ready? \\ n is the outline of yard \\ n ".
format ( tent,
field field *)) # get the coordinates Nugget randomly between 0 and the size of the field-1 nugget = [ random. randInt
(0 , field - 1) random. randInt (0 , field -
1)]
stampaCantiere ( field ) # print the blank while tent > 0 : bangx = input ( " \ n Inserisci le coordinate in
cui vuoi piazzare la mina \ comprese tra [ 0 ..{}] \ n x =
"
. format ( campo - 1
)) bangy = input ( " y = " )
if not bangx . isnumeric () or not bangy .
isnumeric (): print (
" Inserisci delle coordinate numeriche per favore! \n" ) continue else : bangx , bangy = int ( bangx ), int
( bangy ) if bangx <
0 or
bangx > = \u200b\u200b field or
bangy \u0026lt;0 or bangy > = \u200b\u200b field : print ( " Please enter the correct coordinates !
\\ n \\ Remember those you have in hand are explosive ! \\ n ") continuous else : # Coordinates entered eligible
if ( nugget [ 0] ==
bangx ) and ( nugget
[ 1]
== bangy ): reveals where # is the nugget!
print ( "coordinate secret {},{}" . format ( nugget [0 ] nugget [ 1])) stampaCantiere
( field, nugget )
exit ( "Congratulations! You found it! We ricchiiiii !! " ) else : # says if you are away or less from the nugget tent -= 1 if
abs ( nugget [0
] - bangx ) ==
1 or abs (
pepita [ 1
] - bangy ) == 1 : print ( " Ci sei vicino !!" ) else : print ( " No, no, non ci siamo. \n" ) if tent >= 1 :
print ( " Dai ritenta !!" )
else :
print ( " Peccato che abbia finito l'esplosivo !! \n Ecco dov'era :" )
stampaCantiere ( campo , pepita )
# chiamata della funzione principale # se viene chiamata senza argomenti gli verranno passati di default 6 e 6
# chiamare lo script con '-h' per vedere la documentazione
if len ( sys
. argv ) == 3 :

trovaPepita
(
int ( sys
. argv [ 1
]), int ( sys . argv [ 2 ])) elif
len ( sys . argv ) == 2 and sys . argv [ 1 ] == '-h' :
print ( trovaPepita . __doc__ ) else : trovaPepita ( 6 , 6 )







Go to last version!

0 comments:

Post a Comment