1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| Sub nbcell_autour(ByVal x As Long, ByVal y As Long, ByVal Size As Long)
Dim X1 As Long, Y1 As Long, NB As Long
For X1 = x - 1 To x + 1
For Y1 = y - 1 To y + 1
If Y1 > 0 And X1 > 0 And X1 <= Size And Y1 <= Size Then
If Cells(X1, Y1).Interior.ColorIndex = xlNone Then
'Coopérateur
NB = NB + 1
End If
Else
'Hors plateau de jeu
End If
Next Y1
Next X1
If Cells(x, y).Interior.ColorIndex <> xlNone Then
'Case de défectionnaire
Cells(x, y).Value = CStr(NB) & "T"
Else
'case de coopérateur
Cells(x, y).Value = NB
End If
End Sub
Sub iteration()
Dim x, y As Long
Dim T As Double
T = InputBox("Donnez le montant de la prime ")
If Cells(x, y).Value = CStr(NB) & "T" > Cells(x, y).Value = NB Then
Cells(x, y).Value = CStr(NB) & "T"
End Sub |
Partager