31.05.2013 Views

2 Taglio della vegetazione - Intro Page - Università degli Studi di ...

2 Taglio della vegetazione - Intro Page - Università degli Studi di ...

2 Taglio della vegetazione - Intro Page - Università degli Studi di ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

'Se è in circolo vizioso esce in modo casuale<br />

If NewDir = Old2Dir And IsOpposit(OldDir, NewDir) Then 'Nel caso la nuova<br />

<strong>di</strong>rezione sia opposta alla vecchia e uguale a quella <strong>di</strong> due step prima (il robot va avanti e in<strong>di</strong>etro in<br />

circolo vizioso)...<br />

NewDir = Casual() 'Sceglie una <strong>di</strong>rezione casuale per uscire dal circolo vizioso<br />

End If<br />

If NewDir OldDir Then Curve += 1 'Se il valore <strong>della</strong> <strong>di</strong>rezione è cambiato<br />

incrementa il contatore delle curve<br />

Old2Dir = OldDir 'Aggiorna il valore <strong>della</strong> <strong>di</strong>rezione <strong>di</strong> due step precedenti<br />

OldDir = NewDir 'Aggiorna il valore <strong>della</strong> <strong>di</strong>rezione precedente<br />

Draw(Me) 'Disegna la form<br />

'Aggiorna la posizione<br />

Select Case NewDir<br />

Case 0 'Il Robot è andato verso Nord<br />

Ratt -= 1 'Decremente l'in<strong>di</strong>ce <strong>di</strong> riga<br />

Case 1 'Il Robot è andato verso Sud<br />

Ratt += 1 'Incrementa l'in<strong>di</strong>ce <strong>di</strong> riga<br />

Case 2 'Il Robot è andato verso Ovest<br />

Catt -= 1 'Decrementa l'in<strong>di</strong>ce <strong>di</strong> colonna<br />

Case 3 'Il Robot è andato verso Est<br />

Catt += 1 'Incrementa l'in<strong>di</strong>ce <strong>di</strong> colonna<br />

End Select<br />

MatriceCampo(Ratt, Catt) = 0 'Segna come controllato il quadrato su cui si trova il robot<br />

Spostamenti += 1 'Incrementa l'in<strong>di</strong>ce <strong>degli</strong> spostamenti<br />

Campo.FillRectangle(Quad_Actual, 8 + 5 * Catt, 32 + 5 * Ratt, 5, 5) 'Disegna il<br />

quadrato su cui si trova il robot al momento<br />

'Blocco "per<strong>di</strong>tempo" che tiene conto dei tempi <strong>di</strong> aggiornamento dell'immagine<br />

If r * c < 1000 Then 'Interviene solo per MatriciCampo piccole (meno <strong>di</strong> 1000 elementi)<br />

For Time = 0 To 10000000<br />

Math.Sqrt(Time) 'Esegue un calcolo ozioso<br />

Next<br />

End If<br />

'Aggiornamento dei dati significativi<br />

Application.DoEvents() 'Porta la Form in primo piano e la attiva in modo da poterne<br />

schiacciare i bottoni<br />

Me.lblMovements.Text = CStr(Spostamenti) 'Aggiorna il valore <strong>della</strong> casella <strong>di</strong> testo<br />

che visualizza gli spostamenti<br />

Me.lblRotations.Text = CStr(Curve) 'Aggiorna il valore <strong>della</strong> casella <strong>di</strong> testo che<br />

visualizza le curve<br />

Me.lblTime.Text = CStr(Math.Round(Curve * TCurva + Spostamenti / Velocità))<br />

'Aggiorna il valore del tempo in base a velocità, spostamenti e curve<br />

150

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!