Microsoft Small Basic

Program Listing: LMV134
Nb_Joueur = 2 ' Nombre de joueurs

Nb_Cartes_Distribuees = 1 ' Nombre de cartes distribuées par joueur

EV3.SetLEDColor("OFF","NORMAL")
LCD.Clear()

'*************************************************************
'* Choix du mode de fonctionnement *
'*************************************************************
LCD.Text(1,0,0,2,"Choix mode")
LCD.Text(1,0,30,2,"1.Melange")
LCD.Text(1,0,60,2,"2.Melange +")
LCD.Text(1,0,78,2," Distribue")
bouton_presse=""
Mode=1
While bouton_presse<>"E"
If bouton_presse="U" then
Mode=Mode+1
If Mode>2 Then
Mode=2
EndIf
EndIf
If bouton_presse="D" then
Mode=Mode-1
If Mode<1 Then
Mode=1
EndIf
EndIf
LCD.Text(1,81,108,2," ")
LCD.Text(1,81,108,2,Mode)
Buttons.Flush()
Buttons.Wait()
bouton_presse=buttons.GetClicks()
EndWhile

If Mode=1 then ' Mode mélange seul choisit
Melange_cartes()
Goto fin
EndIf

LCD.Clear()

'*************************************************************
'* Choix du nombre de joueurs *
'*************************************************************
LCD.Text(1,0,18,2,"Joueurs ")
bouton_presse=""
While bouton_presse<>"E"
If bouton_presse="U" then
Nb_Joueur=Nb_Joueur+1
If Nb_Joueur>20 Then
Nb_Joueur=20
EndIf
EndIf
If bouton_presse="D" then
Nb_Joueur=Nb_Joueur-1
If Nb_Joueur<2 Then
Nb_Joueur=2
EndIf
EndIf
LCD.Text(1,128,18,2," ")
LCD.Text(1,128,18,2,Nb_Joueur)
Buttons.Flush()
Buttons.Wait()
bouton_presse=buttons.GetClicks()
EndWhile

'*************************************************************
'* Choix du nombre de cartes par joueur *
'*************************************************************
LCD.Text(1,0,40,2,"Cartes ")
bouton_presse=""
While bouton_presse<>"E"
If bouton_presse="U" then
Nb_Cartes_Distribuees=Nb_Cartes_Distribuees+1
If Nb_Cartes_Distribuees>54 Then
Nb_Cartes_Distribuees=54
EndIf
EndIf
If bouton_presse="D" then
Nb_Cartes_Distribuees=Nb_Cartes_Distribuees-1
If Nb_Cartes_Distribuees<1 Then
Nb_Cartes_Distribuees=1
EndIf
EndIf
LCD.Text(1,128,40,2," ")
LCD.Text(1,128,40,2,Nb_Cartes_Distribuees)
Buttons.Flush()
Buttons.Wait()
bouton_presse=buttons.GetClicks()
EndWhile

'*************************************************************
'* Choix de l'amplitude de rotation *
'*************************************************************
Amplitude_Rotation = 360 ' Valeur angulaire de l'amplitude totale de distribution
LCD.Text(1,0,62,2,"Amplitu ")
bouton_presse=""
While bouton_presse<>"E"
If bouton_presse="U" then
Amplitude_Rotation=Amplitude_Rotation+30
If Amplitude_Rotation>360 Then
Amplitude_Rotation=360
EndIf
EndIf
If bouton_presse="D" then
Amplitude_Rotation=Amplitude_Rotation-30
If Amplitude_Rotation<90 Then
Amplitude_Rotation=90
EndIf
EndIf
LCD.Text(1,128,62,2," ")
LCD.Text(1,128,62,2,Amplitude_Rotation)
Buttons.Flush()
Buttons.Wait()
bouton_presse=buttons.GetClicks()
EndWhile
Amplitude_Rotation=Amplitude_Rotation*7.5
If Amplitude_Rotation=2700 Then
sens_distri=-1
Pas_Rotation=Amplitude_Rotation/(Nb_Joueur)
Amplitude_Rotation=Pas_Rotation
else
sens_distri=1
Pas_Rotation=Amplitude_Rotation/(Nb_Joueur-1)
endif

boucle_principale:

LCD.Clear()
LCD.Text(1,33,20,2,"Attente")
LCD.Text(1,9,45,2,"Depart !!!")
while Sensor.ReadPercent(2)=0
EndWhile

Melange_cartes()

LCD.Clear()
LCD.Text(1,33,20,2,"Attente")
LCD.Text(1,9,45,2,"Presseur !")
while Sensor.ReadPercent(2)=0
EndWhile

Index_Distri_cartes=1
Index_Distri_Joueurs=1

boucle_distribution:

Distribue_Cartes()

verification_donne:

Index_Distri_Joueurs=Index_Distri_Joueurs+1
If Index_Distri_Joueurs<=Nb_Joueur Then
Motor.Move("C",50,Pas_Rotation,"True")
Goto boucle_distribution
Else
Index_Distri_cartes=Index_Distri_cartes+1
Motor.Move("C",-50*sens_distri,Amplitude_Rotation,"True")
Index_Distri_Joueurs=1
If Index_Distri_cartes<=Nb_Cartes_Distribuees Then
Goto boucle_distribution
Else
Goto boucle_principale
EndIf
EndIf

fin:

'*************************************************************
'* Routine Melange_Cartes *
'*************************************************************
Sub Melange_cartes
sens = -100
stop = "False"
chrono=EV3.Time
While ("True")
i = 0
Motor.Start("B",sens)
mix_avant:
If EV3.Time-chrono < 2500 then
Ctrl_presence_cartes()
If stop = "True" then
Goto fin_melange
EndIf
Goto mix_avant
EndIf
sens = sens * (-1)
chrono=EV3.Time
Motor.Start("B",sens)
mix_arriere:
If EV3.Time-chrono < 750 then
Ctrl_presence_cartes()
If stop = "True" then
Goto fin_melange
EndIf
Goto mix_arriere
EndIf
sens = sens * (-1)
EndWhile
fin_melange:
EndSub

'*************************************************************
'* Routine qui contrôle la présence de cartes dans les casiers *
'*************************************************************
Sub Ctrl_presence_cartes
if Sensor.ReadPercent(4) > 10 then
Program.Delay(500)
Motor.Stop("B","False")
stop = "True"
EndIf
EndSub

'*************************************************************
'* Routine qui distribue les cartes *
'*************************************************************
Sub Distribue_Cartes
depart:
Temps_0=EV3.Time
Motor.Start("A",50)
etape1:
If Sensor.ReadPercent(3)<5 Then
Motor.Stop("A","True")
Motor.start("A",-50)
Else
If EV3.Time-Temps_0 > 1500 Then
Motor.Stop("A","True")
Motor.start("A",-50)
Temps_0=EV3.Time
etape3:
If Sensor.ReadPercent(3)<5 Then
Goto etape2
Else
If Sensor.ReadPercent(1)=0 Then
etape4:
Motor.Stop("A","False")
Goto depart
Else
If EV3.Time-Temps_0 > 500 Then
Goto etape4
Else
Goto etape3
EndIf
Endif
EndIf
Else
Goto etape1
EndIf
EndIf
etape2:
If Sensor.ReadPercent(1)=0 Then
Program.Delay(250)
Motor.Stop("A","False")
Else
Goto etape2
EndIf
EndSub