﻿Public Class Trois
  '_______________________________Constantes
  Const cmNbLevel = 5
  '_______________________________Modules
  Dim mobjZones(6, 6) As objMaison
  Dim mobjProchain As objMaison
  Dim mboolInvalidationTemporaire As Boolean
  Dim mgfxDessine As System.Drawing.Graphics
  'Dim mpicSurface(2) As PictureBox
  '_______________________________Démarrage
  Private Sub Trois_Load(ByVal sender As System.Object,
                         ByVal e As System.EventArgs) Handles MyBase.Load
    mpicSurface.Refresh()          'semble effacer le tout
    mgfxDessine = mpicSurface.CreateGraphics()
    'mpicSurface(0) = mpicSurface1
    'mpicSurface(1) = mpicSurface2
    'My.Computer.Audio.Play("C:\Waterfall.wav", AudioPlayMode.Background)
    'My.Computer.Audio.Play(My.Resources.Waterfall, AudioPlayMode.Background)
    peuple()
    mobjProchain = New objMaison(CByte(Rnd() * 5))
    redessine()
  End Sub
  '_______________________________Fonctions_et_subs
  Sub peuple()
    Dim x, y, i, level As Byte
    Randomize()
    For i = 0 To 11
      x = CByte(Rnd() * 6)
      y = CByte(Rnd() * 6)
      level = CByte(Rnd() * 5)
      mobjZones(x, y) = New objMaison(level)
    Next
  End Sub

  Sub redessine()
    For i As Byte = 0 To 5
      mgfxDessine.DrawLine(Pens.PaleGreen, New Point((i * 32) + 32, 0), New Point((i * 32) + 32, 192))
      mgfxDessine.DrawLine(Pens.PaleGreen, New Point(0, (i * 32) + 32), New Point(192, (i * 32) + 32))
      For j As Byte = 0 To 5
        If Not IsNothing(mobjZones(i, j)) Then
          Dim ptPosition As New Point(i * 32, j * 32)
          Dim strLevel As String = String.Format("{0}", (mobjZones(i, j).level))
          mgfxDessine.DrawString(strLevel, New Font("mono", 24), Brushes.Black, ptPosition)
        End If
      Next
    Next
    mgfxDessine.FillRectangle(Brushes.White, 198, 16, 32, 32)
    mgfxDessine.DrawString(String.Format("{0}", (mobjProchain.level)), New Font("mono", 24), Brushes.Black, New Point(198, 16))
  End Sub

  Sub place(ByVal intSourisX As Integer, ByVal intSourisY As Integer)
    If intSourisX < 192 And intSourisY < 192 Then
      Dim i As Byte = CByte(Math.Floor(intSourisX / 32))
      Dim j As Byte = CByte(Math.Floor(intSourisY / 32))
      If IsNothing(mobjZones(i, j)) Then
        mobjZones(i, j) = mobjProchain
        mobjProchain = New objMaison(CByte(Rnd() * 5))
      End If
    End If
    redessine()
  End Sub

  '_______________________________Evenements
  Private Sub tmrSynch_Tick(ByVal sender As System.Object,
                            ByVal e As System.EventArgs) Handles tmrSynch.Tick

  End Sub

  Private Sub picSurface_MouseClick(ByVal sender As System.Object,
                                    ByVal e As System.Windows.Forms.MouseEventArgs) Handles mpicSurface.MouseClick
    place(e.X, e.Y)
  End Sub
  '_______________________________

End Class
'__________________________________________________________________
'_______________________CLASSE____________________________________
'__________________________________________________________________
Class objMaison
  'Dim position As New Point
  Public level As Byte
  Public Sub New(ByVal bytLevel As Byte)
    level = bytLevel
  End Sub
End Class

