screen 1,640,256,2,2
window 2,"ESTRAZIONI",(0,11)-(300,242),16,1
window 3,"CONTROLLO",(310,11)-(631,242),16,1
palette 0,0,0,0
palette 1,0,1,0
palette 2,1,0,0
palette 3,0,1,1

cap&=100000
dim ate%(50)
dim amb%(100,2)
dim est%(10,5)
dim atap(50)
dim ambp(100)
dim atar(50)
dim ambr(100)
dim tfl(100)
gg=9
mm=2
aa=91
te=1
ta=1
j=1
citta$(1)="BARI"
citta$(2)="CAGLIARI"
citta$(3)="FIRENZE"
citta$(4)="GENOVA"
citta$(5)="MILANO"
citta$(6)="NAPOLI"
citta$(7)="PALERMO"
citta$(8)="ROMA"
citta$(9)="TORINO"
citta$(10)="VENEZIA"
fl=0
sx=103
sy=51
for n=1 to 10
cey(n)=sy
sy=sy+16
next n
for n=1 to 5
cex(n)=sx
sx=sx+24
next n


main:

gosub ESTRAZIONE
gosub SHOWESTR
if fl=1 then gosub CheckWIN
gosub CONTROLLO
gosub calcSPESA

color 1,0
loop31:
print
input "VUOI VEDERE I NUMERI GIOCATI (s/n)";r$
if r$="n" then goto loop30
if r$="s" then goto ShowNUM
goto loop31
loop30:
print
input "RETURN per eseguire l'ESTRAZIONE";qq
gg=gg+7
if gg>31 then 
	gg=gg-31
	mm=mm+1
	end if
if mm=13 then 
	mm=1
	aa=aa+1
	end if

goto main

end

ESTRAZIONE:

for n=1 to 10
randomize timer
for i=1 to 5
loop1:
est%(n,i)=rnd*90
if est%(n,i)=0 goto loop1
if i>1 then
	for z=1 to i-1
	if est%(n,z)=est%(n,i) goto loop1
	next z
	end if
next i
next n
return

SHOWESTR:

window output 2
cls
y=7
color 3,0
locate 3,4
print "ESTRAZIONE DEL"gg"/"mm"/"aa
for n=1 to 10
color 2,0
locate y,4
print citta$(n)
color 1,0
locate y,12
print est%(n,1)
locate y,15
print est%(n,2)
locate y,18
print est%(n,3)
locate y,21
print est%(n,4)
locate y,24
print est%(n,5)
y=y+2
next n
return

CONTROLLO:

window output 3
color 1,0
print "IL TUO CAPITALE E' DI LIRE"
color 3,0
print cap&
print
if fl=1 then goto stessiNUM
fl=1
loop2:
tut=0
color 1,0
print
input "QUALE RUOTA GIOCHI (o TUTTE) ";ru$
if ru$="" goto loop2
if ru$="tu" or ru$="tut" or ru$="tutt" or ru$="tutte" then 
	tut=1
	goto loop3
	end if
for n=1 to 10
if ucase$(ru$)=mid$(citta$(n),1,len(ru$)) then
	chi=n
	goto loop3
	end if
next n
beep
goto loop2
loop3:
print
input "1)AMBATA  2)AMBO  3)TERNO";k
if k<1 or k>3 goto loop3
print
if k=1 and tut=1 then
	beep
	color 2,0
	print "NON PUOI GIOCARE UNA AMBATA"
        print "SU TUTTE LE RUOTE !"
	goto loop2
	tut=0
	end if

loopPUN:

input "QUANTO PUNTI ";pun
if pun<500 then
	beep
	goto loopPUN
	end if
on k gosub iata,iamb,iter
print
loop6:
color 1,0
input "VUOI GIOCARE ALTRI NUMERI (s/n) ";r$
if r$="s" goto loop2
if r$="n" then return
goto loop6

calcSPESA:

color 3,0
print
for n=1 to te-1
spesa=spesa+atap(n)
next n
for n=1 to ta-1
spesa=spesa+ambp(n)
next n

print "HAI SPESO";spesa;"LIRE"
cap&=cap&-spesa
print "TI RESTANO";cap&;"LIRE"
return

iata:

print
print "QUALI NUMERI (0 per uscire)"
loop4:
color 2,0
print "-"te"-"
color 1,0
input ate%(te)
if ate%(te)>90 then
	beep
	goto loop4
	end if
atap(te)=pun
atar(te)=chi
if ate%(te)=0 goto loop5
te=te+1
goto loop4
loop5:
return

iamb:

print
print "QUALI NUMERI (0 per uscire)"
loop7:
color 2,0
print "-"ta"-"
color 1,0
input amb%(ta,1)
input amb%(ta,2)
if amb%(ta,1)>90 or amb%(ta,2)>90 then
	beep
	goto loop7
	end if
ambp(ta)=pun
if tut=0 then ambr(ta)=chi
if tut=1 then tfl(ta)=1 else tfl(ta)=0
if amb%(ta,1)=0 goto loop8
ta=ta+1
goto loop7
loop8:
return

iter:

beep
print
print "SORRY, NOT YET AVAILABLE !"
return

checkWIN:

window output 3

if te>1 then
	for n=1 to te-1
		for z=1 to 5
		if ate%(n)=est%(atar(n),z) then
			window output 2
			color 3,0
			circle (cex(z),cey(atar(n))),12
			atf=atf+1
			win=win+(atap(n)*11)
			window output 3
			end if
		next z
	next n
end if

if ta>1 then
	for n=1 to ta-1
	if tfl(n)=1 goto loop15
	next n
	goto loop16
	end if

loop15:

for n=1 to ta-1
if tfl(n)=1 then gosub ESISTE
next n
goto loop16

ESISTE:

for i=1 to 10
for z=1 to 5
if amb%(n,1)=est%(i,z) then 
	tx=z
	ty=i
	gosub HuTuAMBO
	end if
next z
next i
return

loop16:

if ta>1 then
	for n=1 to ta-1
		for z=1 to 5
		if tfl(n)=0 then
			if amb%(n,1)=est%(ambr(n),z) then 
			tx=z
			ty=ambr(n)
			gosub HuntAMBO
			end if
		end if
		next z
	next n
end if

if atf=0 and amf=0 then
	color 2,0
	print
	print "NON E' USCITO NESSUN NUMERO"
	print
	gosub ReSTART
	return
	end if
color 2,0
	print
	print "SONO USCITI:"

if atf>0 then
	color 3,0
	print atf "NUMERO/I"
	end if
if amf>0 then 
	color 3,0
	print amf "AMBO/I"
	end if
print
print "HAI VINTO" win "LIRE"
print
cap&=cap&+win
gosub ReSTART
return

return

HuntAMBO:

for i=1 to 5
if amb%(n,2)=est%(ambr(n),i) then
	window output 2
	color 3,0
	circle (cex(tx),cey(ty)),12
	circle (cex(i),cey(ambr(n))),12
	amf=amf+1
	win=win+(ambp(n)*250)
	window output 3
	end if
next i
return

HuTuAMBO:

for m=1 to 5
if amb%(n,2)=est%(i,m) then
	window output 2
	color 3,0
	circle (cex(tx),cey(ty)),12
	circle (cex(m),cey(i)),12
	amf=amf+1
	win=win+(ambp(n)*25)
	window output 3
	end if
next m
return

stessiNUM:
print
input "RIGIOCHI GLI STESSI NUMERI (s/n)";r$
if r$="n" then
	te=1
	ta=1
        tut=0
	goto loop2
	end if
if r$="s" then goto qPUNTATA
goto stessiNUM
		

ReSTART:
atf=0
amf=0
win=0
spesa=0
return

qPUNTATA:
print
input "CON LE STESSE PUNTATE (s/n)";r$
print
if r$="s" goto loop6
if r$="n" goto ModPUNT
goto qPUNTATA

ModPUNT:
color 2,0
print "1> RADDOPPIA TUTTE"
print
print "2> AUMENTA TUTTE DI n LIRE"
print
print "3> SELEZIONA GLI AUMENTI"
print
color 3,0
loop10:
input "QUALE (1..3)";nx
print
if nx<1 or nx>3 goto loop10

on nx gosub RADDOPPIA,AUMENTA,SELEZIONA
goto loop6

RADDOPPIA:
if te>1 then
 for n=1 to te-1
 atap(n)=atap(n)*2
 next n
end if

if ta>1 then
 for n=1 to ta-1
 ambp(n)=ambp(n)*2
 next n
end if
return

AUMENTA:

print
input "DI QUANTO ";xq
print
if te>1 then
 for n=1 to te-1
 atap(n)=atap(n)+xq
 next n
end if

if ta>1 then
 for n=1 to ta-1
 ambp(n)=ambp(n)+xq
 next n
end if
return

SELEZIONA:

color 2,0
print
print "1> RADDOPPIA LE AMBATE"
print
print "2> RADDOPPIA GLI AMBI"
print
print "3> AUMENTA DI n LE AMBATE"
print
print "4> AUMENTA DI n GLI AMBI"
print
print "5> SELEZIONE SINGOLA AMBATE"
print
print "6> SELEZIONE SINGOLA AMBI"
print
print "7> QUIT
print
color 3,0
loop20:
input "QUALE (1..7)";nx
print
if nx<1 or nx>7 goto loop20
if nx=7 goto loop6
on nx gosub RaddAMBATE,RaddAMBI,AumAMBATE,AumAMBI,SelAMBATE,SelAMBI
goto SELEZIONA

RaddAMBATE:

if te>1 then
 for n=1 to te-1
 atap(n)=atap(n)*2
 next n
end if
return

RaddAMBI:

if ta>1 then
 for n=1 to ta-1
 ambp(n)=ambp(n)*2
 next n
end if
return

AumAMBATE:

print
input "DI QUANTO ";xq
print
if te>1 then
 for n=1 to te-1
 atap(n)=atap(n)+xq
 next n
end if
return

AumAMBI:

print
input "DI QUANTO ";xq
print
if ta>1 then
 for n=1 to ta-1
 ambp(n)=ambp(n)+xq
 next n
end if
return

ShowNUM:

color 2,0
print
print "1> SOLO LE AMBATE"
print
print "2> SOLO GLI AMBI"
print
print "3> TUTTI I NUMERI"
print
color 1,0
input "QUALE (1..3)";qv
if qv<1 or qv>3 goto shownum

if qv=1 or qv=3 then
	color 3,0
	print
	for n=1 to te-1
	print mid$(citta$(atar(n)),1,2);" ";ate%(n);" ";atap(n)
	next n
	print
	color 1,0
	end if

if qv=2 or qv=3 then
	color 3,0
	print
	for n=1 to ta-1
	if tfl(n)=0 then print mid$(citta$(ambr(n)),1,2);" ";amb%(n,1);amb%(n,2);" ";ambp(n)
	if tfl(n)=1 then print "TUT";amb%(n,1);amb%(n,2);" ";ambp(n)
	next n
	print
	color 1,0
	end if

goto loop30
