Algoritmia - Ayuda con matrices

 
Vista:

Ayuda con matrices

Publicado por sheccid65 (1 intervención) el 06/02/2010 20:00:29
Estoy haciendo una matriz que simula el juego del triqui o tres en raya, ya está todo resuelto, pero a la hora de validar que si un jugador marca por ejemplo la casilla 1, el jugador 2 no lo peda hacer... yo lo validé con un si y le mando un mensaje q la casilla está ocupada, pero el mensaje se queda ahi y en las jugadas sgts sigue apareciendo, te mando el codigo donde hago esa parte

For i = 1 To 9
If i Mod 2 <> 0 Then
WriteAt("jugador 1 ", 2, 13)
h = Console.ReadLine
WriteAt(" ", 13, 13)
While m(1, 1) = 2 Or m(1, 2) = 2 Or m(1, 3) = 2 Or m(2, 1) = 2 Or m(2, 2) = 2 Or m(2, 3) = 2 Or m(3, 1) = 2 Or m(3, 2) = 2 Or m(3, 2) = 2
WriteAt("Esta posicion se encuentra ocupada", 4, 15)
WriteAt(" por favor juegue de nuevo ", 5, 15)
' Console.ReadLine()
h = Console.ReadLine
WriteAt(" ", 13, 13)
WriteAt(" ", 4, 15)
WriteAt(" ", 5, 15)
End While

If h = 1 Then
m(1, 1) = 1
a = 3
b = 1
WriteAt("X", a, b)
End If
If h = 2 Then
m(1, 2) = 1
a = 10
b = 1
WriteAt("X", a, b)
End If
If h = 3 Then
m(1, 3) = 1
a = 17
b = 1
WriteAt("X", a, b)
End If
If h = 4 Then
m(2, 1) = 1
a = 3
b = 5
WriteAt("X", a, b)
End If
If h = 5 Then
m(2, 2) = 1
a = 10
b = 5
WriteAt("X", a, b)
End If
If h = 6 Then
m(2, 3) = 1
a = 17
b = 5
WriteAt("X", a, b)
End If
If h = 7 Then
m(3, 1) = 1
a = 3
b = 8
WriteAt("X", a, b)
End If
If h = 8 Then
m(3, 2) = 1
a = 10
b = 8
WriteAt("X", a, b)
End If
If h = 9 Then
m(3, 3) = 1
a = 17
b = 8
WriteAt("X", a, b)
End If

Else
WriteAt("jugador 2 ", 2, 13)
h = Console.ReadLine
WriteAt(" ", 13, 13)
While m(1, 1) = 1 Or m(1, 2) = 1 Or m(1, 3) = 1 Or m(2, 1) = 1 Or m(2, 2) = 1 Or m(2, 3) = 1 Or m(3, 1) = 1 Or m(3, 2) = 1 Or m(3, 2) = 1
WriteAt("Esta posicion se encuentra ocupada", 4, 15)
WriteAt(" por favor juegue de nuevo ", 5, 15)
' Console.ReadLine()
h = Console.ReadLine
WriteAt(" ", 13, 13)
WriteAt(" ", 4, 15)
WriteAt(" ", 5, 15)

End While

If h = 1 Then
m(1, 1) = 2

a = 3
b = 1
WriteAt("O", a, b)
End If
If h = 2 Then
m(1, 2) = 2
a = 10
b = 1
WriteAt("O", a, b)
End If
If h = 3 Then
m(1, 3) = 2
a = 17
b = 1
WriteAt("O", a, b)
End If
If h = 4 Then
m(2, 1) = 2
a = 3
b = 5
WriteAt("O", a, b)
End If
If h = 5 Then
m(2, 2) = 2
a = 10
b = 5
WriteAt("O", a, b)
End If
If h = 6 Then
m(2, 3) = 2
a = 17
b = 5
WriteAt("O", a, b)
End If
If h = 7 Then
m(3, 1) = 2
a = 3
b = 8
WriteAt("O", a, b)
End If
If h = 8 Then
m(3, 2) = 2
a = 10
b = 8
WriteAt("O", a, b)
End If
If h = 9 Then
m(3, 3) = 2
a = 17
b = 8
WriteAt("O", a, b)
End If

End If

Agradezco su ayuda.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder