elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a Git (Primera Parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  tres en raya sencillito en vb
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] 2 3 Ir Abajo Respuesta Imprimir
Autor Tema: tres en raya sencillito en vb  (Leído 19,872 veces)
Daklon

Desconectado Desconectado

Mensajes: 57



Ver Perfil
tres en raya sencillito en vb
« en: 29 Octubre 2010, 18:50 pm »

pues siguiendo consejos he echo este 3 en raya rapidito xD

la interfaz he de reconocer que me quedo muy chapuzas xD

en el rar esta el form el proyecto y el exe ya compilado pero si no se fían compilenlo ustedes xD

el código creo que se podría optimizar un poco, ya que repito muchas veces el mismo código a ver si pueden decirme como

el enlace:
Citar

el codigo:
Código
  1. Option Explicit
  2. Function cambio()
  3. If Label11.Caption = "1" Then
  4. Label11.Caption = "2"
  5. Command2.Caption = "O"
  6. Command3.Caption = "O"
  7. Command4.Caption = "O"
  8. Command5.Caption = "O"
  9. Command6.Caption = "O"
  10. Command7.Caption = "O"
  11. Command8.Caption = "O"
  12. Command9.Caption = "O"
  13. Command10.Caption = "O"
  14. Else: Label11.Caption = "1"
  15. Command2.Caption = "X"
  16. Command3.Caption = "X"
  17. Command4.Caption = "X"
  18. Command5.Caption = "X"
  19. Command6.Caption = "X"
  20. Command7.Caption = "X"
  21. Command8.Caption = "X"
  22. Command9.Caption = "X"
  23. Command10.Caption = "X"
  24. End If
  25.  
  26. End Function
  27. Function ganador()
  28. If Label1.Caption & Label2.Caption & Label3.Caption = "XXX" Then
  29. Command2.Enabled = False
  30. Command3.Enabled = False
  31. Command4.Enabled = False
  32. Command5.Enabled = False
  33. Command6.Enabled = False
  34. Command7.Enabled = False
  35. Command8.Enabled = False
  36. Command9.Enabled = False
  37. Command10.Enabled = False
  38. Label12.Caption = "Jugador:1"
  39. MsgBox "EL GANADOR ES EL JUGADOR 1!!!", vbExclamation, Me.Caption
  40. End If
  41. If Label4.Caption & Label5.Caption & Label6.Caption = "XXX" Then
  42. Command2.Enabled = False
  43. Command3.Enabled = False
  44. Command4.Enabled = False
  45. Command5.Enabled = False
  46. Command6.Enabled = False
  47. Command7.Enabled = False
  48. Command8.Enabled = False
  49. Command9.Enabled = False
  50. Command10.Enabled = False
  51. Label12.Caption = "Jugador:1"
  52. MsgBox "EL GANADOR ES EL JUGADOR 1!!!", vbExclamation, Me.Caption
  53. End If
  54. If Label7.Caption & Label8.Caption & Label9.Caption = "XXX" Then
  55. Command2.Enabled = False
  56. Command3.Enabled = False
  57. Command4.Enabled = False
  58. Command5.Enabled = False
  59. Command6.Enabled = False
  60. Command7.Enabled = False
  61. Command8.Enabled = False
  62. Command9.Enabled = False
  63. Command10.Enabled = False
  64. Label12.Caption = "Jugador:1"
  65. MsgBox "EL GANADOR ES EL JUGADOR 1!!!", vbExclamation, Me.Caption
  66. End If
  67. If Label1.Caption & Label4.Caption & Label7.Caption = "XXX" Then
  68. Command2.Enabled = False
  69. Command3.Enabled = False
  70. Command4.Enabled = False
  71. Command5.Enabled = False
  72. Command6.Enabled = False
  73. Command7.Enabled = False
  74. Command8.Enabled = False
  75. Command9.Enabled = False
  76. Command10.Enabled = False
  77. Label12.Caption = "Jugador:1"
  78. MsgBox "EL GANADOR ES EL JUGADOR 1!!!", vbExclamation, Me.Caption
  79. End If
  80. If Label2.Caption & Label5.Caption & Label8.Caption = "XXX" Then
  81. Command2.Enabled = False
  82. Command3.Enabled = False
  83. Command4.Enabled = False
  84. Command5.Enabled = False
  85. Command6.Enabled = False
  86. Command7.Enabled = False
  87. Command8.Enabled = False
  88. Command9.Enabled = False
  89. Command10.Enabled = False
  90. Label12.Caption = "Jugador:1"
  91. MsgBox "EL GANADOR ES EL JUGADOR 1!!!", vbExclamation, Me.Caption
  92. End If
  93. If Label3.Caption & Label6.Caption & Label9.Caption = "XXX" Then
  94. Command2.Enabled = False
  95. Command3.Enabled = False
  96. Command4.Enabled = False
  97. Command5.Enabled = False
  98. Command6.Enabled = False
  99. Command7.Enabled = False
  100. Command8.Enabled = False
  101. Command9.Enabled = False
  102. Command10.Enabled = False
  103. Label12.Caption = "Jugador:1"
  104. MsgBox "EL GANADOR ES EL JUGADOR 1!!!", vbExclamation, Me.Caption
  105. End If
  106. If Label1.Caption & Label5.Caption & Label9.Caption = "XXX" Then
  107. Command2.Enabled = False
  108. Command3.Enabled = False
  109. Command4.Enabled = False
  110. Command5.Enabled = False
  111. Command6.Enabled = False
  112. Command7.Enabled = False
  113. Command8.Enabled = False
  114. Command9.Enabled = False
  115. Command10.Enabled = False
  116. Label12.Caption = "Jugador:1"
  117. MsgBox "EL GANADOR ES EL JUGADOR 1!!!", vbExclamation, Me.Caption
  118. End If
  119. If Label3.Caption & Label5.Caption & Label7.Caption = "XXX" Then
  120. Command2.Enabled = False
  121. Command3.Enabled = False
  122. Command4.Enabled = False
  123. Command5.Enabled = False
  124. Command6.Enabled = False
  125. Command7.Enabled = False
  126. Command8.Enabled = False
  127. Command9.Enabled = False
  128. Command10.Enabled = False
  129. Label12.Caption = "Jugador:1"
  130. MsgBox "EL GANADOR ES EL JUGADOR 1!!!", vbExclamation, Me.Caption
  131. End If
  132. If Label1.Caption & Label2.Caption & Label3.Caption = "OOO" Then
  133. Command2.Enabled = False
  134. Command3.Enabled = False
  135. Command4.Enabled = False
  136. Command5.Enabled = False
  137. Command6.Enabled = False
  138. Command7.Enabled = False
  139. Command8.Enabled = False
  140. Command9.Enabled = False
  141. Command10.Enabled = False
  142. Label12.Caption = "Jugador:2"
  143. MsgBox "EL GANADOR ES EL JUGADOR 2!!!", vbExclamation, Me.Caption
  144. End If
  145. If Label4.Caption & Label5.Caption & Label6.Caption = "OOO" Then
  146. Command2.Enabled = False
  147. Command3.Enabled = False
  148. Command4.Enabled = False
  149. Command5.Enabled = False
  150. Command6.Enabled = False
  151. Command7.Enabled = False
  152. Command8.Enabled = False
  153. Command9.Enabled = False
  154. Command10.Enabled = False
  155. Label12.Caption = "Jugador:2"
  156. MsgBox "EL GANADOR ES EL JUGADOR 2!!!", vbExclamation, Me.Caption
  157. End If
  158. If Label7.Caption & Label8.Caption & Label9.Caption = "OOO" Then
  159. Command2.Enabled = False
  160. Command3.Enabled = False
  161. Command4.Enabled = False
  162. Command5.Enabled = False
  163. Command6.Enabled = False
  164. Command7.Enabled = False
  165. Command8.Enabled = False
  166. Command9.Enabled = False
  167. Command10.Enabled = False
  168. Label12.Caption = "Jugador:2"
  169. MsgBox "EL GANADOR ES EL JUGADOR 2!!!", vbExclamation, Me.Caption
  170. End If
  171. If Label1.Caption & Label4.Caption & Label7.Caption = "OOO" Then
  172. Command2.Enabled = False
  173. Command3.Enabled = False
  174. Command4.Enabled = False
  175. Command5.Enabled = False
  176. Command6.Enabled = False
  177. Command7.Enabled = False
  178. Command8.Enabled = False
  179. Command9.Enabled = False
  180. Command10.Enabled = False
  181. Label12.Caption = "Jugador:2"
  182. MsgBox "EL GANADOR ES EL JUGADOR 2!!!", vbExclamation, Me.Caption
  183. End If
  184. If Label2.Caption & Label5.Caption & Label8.Caption = "OOO" Then
  185. Command2.Enabled = False
  186. Command3.Enabled = False
  187. Command4.Enabled = False
  188. Command5.Enabled = False
  189. Command6.Enabled = False
  190. Command7.Enabled = False
  191. Command8.Enabled = False
  192. Command9.Enabled = False
  193. Command10.Enabled = False
  194. Label12.Caption = "Jugador:2"
  195. MsgBox "EL GANADOR ES EL JUGADOR 2!!!", vbExclamation, Me.Caption
  196. End If
  197. If Label3.Caption & Label6.Caption & Label9.Caption = "OOO" Then
  198. Command2.Enabled = False
  199. Command3.Enabled = False
  200. Command4.Enabled = False
  201. Command5.Enabled = False
  202. Command6.Enabled = False
  203. Command7.Enabled = False
  204. Command8.Enabled = False
  205. Command9.Enabled = False
  206. Command10.Enabled = False
  207. Label12.Caption = "Jugador:2"
  208. MsgBox "EL GANADOR ES EL JUGADOR 2!!!", vbExclamation, Me.Caption
  209. End If
  210. If Label1.Caption & Label5.Caption & Label9.Caption = "OOO" Then
  211. Command2.Enabled = False
  212. Command3.Enabled = False
  213. Command4.Enabled = False
  214. Command5.Enabled = False
  215. Command6.Enabled = False
  216. Command7.Enabled = False
  217. Command8.Enabled = False
  218. Command9.Enabled = False
  219. Command10.Enabled = False
  220. Label12.Caption = "Jugador:2"
  221. MsgBox "EL GANADOR ES EL JUGADOR 2!!!", vbExclamation, Me.Caption
  222. End If
  223. If Label3.Caption & Label5.Caption & Label7.Caption = "OOO" Then
  224. Command2.Enabled = False
  225. Command3.Enabled = False
  226. Command4.Enabled = False
  227. Command5.Enabled = False
  228. Command6.Enabled = False
  229. Command7.Enabled = False
  230. Command8.Enabled = False
  231. Command9.Enabled = False
  232. Command10.Enabled = False
  233. Label12.Caption = "Jugador:2"
  234. MsgBox "EL GANADOR ES EL JUGADOR 2!!!", vbExclamation, Me.Caption
  235. End If
  236.  
  237.  
  238.  
  239. End Function
  240.  
  241. Private Sub Command1_Click()
  242. Label11.Caption = "1"
  243. Label1.Caption = ""
  244. Label2.Caption = ""
  245. Label3.Caption = ""
  246. Label4.Caption = ""
  247. Label5.Caption = ""
  248. Label6.Caption = ""
  249. Label7.Caption = ""
  250. Label8.Caption = ""
  251. Label9.Caption = ""
  252. Label12.Caption = "Jugador:"
  253. Command2.Enabled = True
  254. Command3.Enabled = True
  255. Command4.Enabled = True
  256. Command5.Enabled = True
  257. Command6.Enabled = True
  258. Command7.Enabled = True
  259. Command8.Enabled = True
  260. Command9.Enabled = True
  261. Command10.Enabled = True
  262. End Sub
  263.  
  264. Private Sub Command2_Click()
  265. If Label1.Caption = "" Then
  266. Label1.Caption = Command2.Caption
  267. Call cambio
  268. Call ganador
  269. Else: MsgBox "ya se ha marcado esta casilla", vbInformation, Me.Caption
  270. End If
  271.  
  272. End Sub
  273.  
  274. Private Sub Command3_Click()
  275. If Label4.Caption = "" Then
  276. Label4.Caption = Command2.Caption
  277. Call cambio
  278. Call ganador
  279. Else: MsgBox "ya se ha marcado esta casilla", vbInformation, Me.Caption
  280. End If
  281. End Sub
  282.  
  283. Private Sub Command4_Click()
  284. If Label7.Caption = "" Then
  285. Label7.Caption = Command2.Caption
  286. Call cambio
  287. Call ganador
  288. Else: MsgBox "ya se ha marcado esta casilla", vbInformation, Me.Caption
  289. End If
  290. End Sub
  291.  
  292. Private Sub Command5_Click()
  293. If Label2.Caption = "" Then
  294. Label2.Caption = Command2.Caption
  295. Call cambio
  296. Call ganador
  297. Else: MsgBox "ya se ha marcado esta casilla", vbInformation, Me.Caption
  298. End If
  299. End Sub
  300.  
  301. Private Sub Command6_Click()
  302. If Label5.Caption = "" Then
  303. Label5.Caption = Command2.Caption
  304. Call cambio
  305. Call ganador
  306. Else: MsgBox "ya se ha marcado esta casilla", vbInformation, Me.Caption
  307. End If
  308. End Sub
  309.  
  310. Private Sub Command7_Click()
  311. If Label8.Caption = "" Then
  312. Label8.Caption = Command2.Caption
  313. Call cambio
  314. Call ganador
  315. Else: MsgBox "ya se ha marcado esta casilla", vbInformation, Me.Caption
  316. End If
  317. End Sub
  318.  
  319. Private Sub Command8_Click()
  320. If Label3.Caption = "" Then
  321. Label3.Caption = Command2.Caption
  322. Call cambio
  323. Call ganador
  324. Else: MsgBox "ya se ha marcado esta casilla", vbInformation, Me.Caption
  325. End If
  326. End Sub
  327.  
  328. Private Sub Command9_Click()
  329. If Label6.Caption = "" Then
  330. Label6.Caption = Command2.Caption
  331. Call cambio
  332. Call ganador
  333. Else: MsgBox "ya se ha marcado esta casilla", vbInformation, Me.Caption
  334. End If
  335. End Sub
  336.  


En línea

raul338


Desconectado Desconectado

Mensajes: 2.633


La sonrisa es la mejor forma de afrontar las cosas


Ver Perfil WWW
Re: tres en raya sencillito en vb
« Respuesta #1 en: 29 Octubre 2010, 19:00 pm »

el código creo que se podría optimizar un poco, ya que repito muchas veces el mismo código a ver si pueden decirme como

Aprende a usar arrays de controles :)


En línea

Daklon

Desconectado Desconectado

Mensajes: 57



Ver Perfil
Re: tres en raya sencillito en vb
« Respuesta #2 en: 29 Octubre 2010, 19:29 pm »

busque info sobre eso, pero tengo un problema,al crear una copia del mismo commandbutton, el código es el mismo que el del original,no puedo ponerle un código distinto, no se si me explico
En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: tres en raya sencillito en vb
« Respuesta #3 en: 29 Octubre 2010, 19:30 pm »

Aprende a usar arrays de controles :)

No lo mal acostumbres recuerda que en vb.NEt no se puede usar eso xS (maldito .Net ¬¬")

Un consejo ademas del ya dado

En lugar de de usar:
Código
  1.  
  2. if Label3.Caption = "" then
  3.  
  4.  

Ess alguna variable boolean asi se entenderia mas (Aun que aún asi se entiedne =).

Código
  1.  
  2. If VaribaleBoolean then
  3.  
  4.  

con respecto alo de los Arreglso de controles.... (Propiedad Index)

Código
  1.  
  2. Command2.Caption = "X"
  3. Command3.Caption = "X"
  4. Command4.Caption = "X"
  5. Command5.Caption = "X"
  6. Command6.Caption = "X"
  7. Command7.Caption = "X"
  8. Command8.Caption = "X"
  9. Command9.Caption = "X"
  10. Command10.Caption = "X"
  11.  
  12.  

con array quedaria:

Código
  1.  
  2. dim lng_i&
  3.    for lng_i& = command.lbound to command.ubound
  4.        Command(lng_index&).Caption = "X"
  5.    next i
  6.  
  7.  

Dulces Lunas!¡.
En línea

The Dark Shadow is my passion.
raul338


Desconectado Desconectado

Mensajes: 2.633


La sonrisa es la mejor forma de afrontar las cosas


Ver Perfil WWW
Re: tres en raya sencillito en vb
« Respuesta #4 en: 29 Octubre 2010, 19:34 pm »

Aprende a usar arrays de controles :)

No lo mal acostumbres recuerda que en vb.NEt no se puede usar eso xS (maldito .Net ¬¬")

WTF! Quien dice que no? Todo contenedor tiene su array de controles :P

Solo hay que hacer que los botones (por ejemplo) apunten al mismo evento, y despues separas segun el "sender" ej

Código
  1. Private Sub buttons_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click, Button2.Click
  2. ' Fijate despues de "Handles" :)
  3.    Dim miBoton as Button = (Button)sender
  4.    Msgbox(miBoton.Name) ' Button1 o Button segun el caso (:
  5. End sub
  6.  

Ademas el array de controles no se puede en modo gráfico, pero si se puede tranquilamente a través de código
« Última modificación: 29 Octubre 2010, 19:37 pm por raul338 » En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: tres en raya sencillito en vb
« Respuesta #5 en: 29 Octubre 2010, 19:39 pm »

.
Woo no lo sabia, bueno nunca se me ocurrio lo del Sender, busque en internet y en el guille encontre un codigo que dba vueltas a lo loco para hacer esto, esto es mas cortito xD

Dulce Lunas!¡.
En línea

The Dark Shadow is my passion.
Daklon

Desconectado Desconectado

Mensajes: 57



Ver Perfil
Re: tres en raya sencillito en vb
« Respuesta #6 en: 29 Octubre 2010, 19:45 pm »

Aprende a usar arrays de controles :)

No lo mal acostumbres recuerda que en vb.NEt no se puede usar eso xS (maldito .Net ¬¬")

Un consejo ademas del ya dado

En lugar de de usar:
Código
  1.  
  2. if Label3.Caption = "" then
  3.  
  4.  

Ess alguna variable boolean asi se entenderia mas (Aun que aún asi se entiedne =).

Código
  1.  
  2. If VaribaleBoolean then
  3.  
  4.  


eso ultimo no acabo de entenderlo,las variables tipo boolean no eran true y false?

como le digo lo que es true y lo que es false?

edit: otra cosa que me acabo de fijar:

con lo de lbound lo que haces es usar el command mas pequeño no?

eso no causaría conflicto con el command1 que es para hacer una nueva partida?

se solucionaría cambiándole el nombre no?
« Última modificación: 29 Octubre 2010, 20:49 pm por Daklon » En línea

Psyke1
Wiki

Desconectado Desconectado

Mensajes: 1.089



Ver Perfil WWW
Re: tres en raya sencillito en vb
« Respuesta #7 en: 29 Octubre 2010, 22:54 pm »

Si no pones nada en una variable Boolean cuenta como True, mira:
Código
  1. If A = True Then
Es lo mismo que :
Código
  1. If A Then

Y respecto a lo segundo, no, no originaria conflicto, lo único que haces con LBound() es obtener el index mas pequeño del array(en este caso de controles) y con UBound() el mas alto.
 
DoEvents! :P
« Última modificación: 29 Octubre 2010, 23:23 pm por Mr. Frog » En línea

Daklon

Desconectado Desconectado

Mensajes: 57



Ver Perfil
Re: tres en raya sencillito en vb
« Respuesta #8 en: 30 Octubre 2010, 01:12 am »

pero entonces como digo que a es verdadero cuando label1.caption & label2.caption & label3.caption son iguales a "x"?
Código
  1. a = Label1.Caption & Label2.Caption & Label3.Caption = "XXX"
En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: tres en raya sencillito en vb
« Respuesta #9 en: 30 Octubre 2010, 03:49 am »

asi

Código
  1.  
  2. VariableBoolean = Label1.Caption = Label2.Caption and Label2.Caption = Label3.Caption and Label3.Caption = "X" ' // por lo tanto Label3.Caption deberia ser =? Label1.Caption si fuese Toda la sentencia = true
  3.  
  4.  

o si que si deseas entenderlo mejor...

Código
  1.  
  2. VariableBoolean = cbool(Label1.Caption = Label2.Caption and Label2.Caption = Label3.Caption and Label3.Caption = "X") ' // por lo tanto Label3.Caption deberia ser =? Label1.Caption si fuese Toda la sentencia = true
  3.  
  4.  
En línea

The Dark Shadow is my passion.
Páginas: [1] 2 3 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
juego tres en raya
Java
bengy 2 14,390 Último mensaje 31 Octubre 2011, 08:17 am
por Debci
Juego de Tres en raya C#
.NET (C#, VB.NET, ASP)
AlexPro 4 15,941 Último mensaje 4 Julio 2012, 17:31 pm
por AlexPro
Juego tres en raya
Programación C/C++
carl221 6 3,317 Último mensaje 18 Mayo 2014, 22:21 pm
por MeCraniDOS
tres en raya
Scripting
jalbtercero 1 2,200 Último mensaje 11 Marzo 2016, 23:46 pm
por engel lex
Ayuda con código de Tres en Raya Java en Processing
Java
IO4 3 3,964 Último mensaje 17 Abril 2019, 15:59 pm
por CalgaryCorpus
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines