This repository was archived by the owner on Apr 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm2.vb
More file actions
381 lines (311 loc) · 12.5 KB
/
Copy pathForm2.vb
File metadata and controls
381 lines (311 loc) · 12.5 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
Public Class Form2
'Actualiza el texto de todo para que reflejen lo que esta guardado en el archivo de ajustes
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SettingSetup()
Form1.UpdateInfo(True)
End Sub
Sub SettingSetup()
SelectUI.SelectedItem = My.Settings.ThemeUI
CantManzanasText.Text = My.Settings.cantManz + 1
SnakeRB.Text = My.Settings.snakeRed
SnakeGB.Text = My.Settings.snakeGreen
SnakeBB.Text = My.Settings.snakeBlue
ManzRB.Text = My.Settings.manzRed
ManzGB.Text = My.Settings.manzGreen
ManzBB.Text = My.Settings.manzBlue
CampoRB.Text = My.Settings.campoRed
CampoGB.Text = My.Settings.campoGreen
CampoBB.Text = My.Settings.campoBlue
TrackBarSpeed.Value = My.Settings.PlayerSpeed
LabelSpeed.Text = My.Settings.PlayerSpeed
FieldSizeX.Text = My.Settings.gridSizeX
FieldSizeY.Text = My.Settings.gridSizeY
ShowDebug.Checked = My.Settings.debugMenu
End Sub
'Aplicar los cambios que se hagan desde el menu de ajustes, solo para colores
Sub UpdateColors()
Form1.rS = SnakeRB.Text
Form1.gS = SnakeGB.Text
Form1.bS = SnakeBB.Text
Form1.rM = ManzRB.Text
Form1.gM = ManzGB.Text
Form1.bM = ManzBB.Text
Form1.rC = CampoRB.Text
Form1.gC = CampoRB.Text
Form1.bC = CampoBB.Text
For q As Integer = 0 To 223 Step 1
Form1.snakeBody(q).BackColor = Color.FromArgb(Form1.rS, Form1.gS, Form1.bS)
Next
Form1.field.BackColor = Color.FromArgb(Form1.rC, Form1.gC, Form1.bC)
For x As Integer = 0 To Form1.cantManzanas Step 1
Form1.manzana(x).BackColor = Color.FromArgb(Form1.rM, Form1.gM, Form1.bM)
Next
End Sub
'Cambiar de tema
Public Sub UITheme_SelectedIndexChanged(sender As Object, e As EventArgs) Handles SelectUI.SelectedIndexChanged
If SelectUI.SelectedItem = "Oscuro" Then
ChangeTheme(Color.FromArgb(64, 64, 64), Color.LightGray, Color.White)
ElseIf SelectUI.SelectedItem = "Claro" Then
ChangeTheme(Color.White, Color.FromArgb(80, 80, 80), Color.Black)
End If
My.Settings.ThemeUI = SelectUI.SelectedItem
My.Settings.Save()
Form1.UpdateInfo(True)
End Sub
'Llama a la funcion correcta dependiendo de que tema fue elegido
Sub ApplySavedSettings()
If My.Settings.ThemeUI = "Oscuro" Then
ChangeTheme(Color.FromArgb(64, 64, 64), Color.LightGray, Color.White)
ElseIf My.Settings.ThemeUI = "Claro" Then
ChangeTheme(Color.White, Color.FromArgb(80, 80, 80), Color.Black)
End If
Form1.logGroup.Visible = My.Settings.debugMenu
If My.Settings.debugMenu Then
Form1.logPuntNormal.Location = New Point(-99, -99)
Else
Form1.logPuntNormal.Location = New Point((Form1.Width - 85), 9)
End If
Form1.UpdateInfo(True)
End Sub
Sub ChangeTheme(color1 As Color, color2 As Color, color3 As Color)
Form1.BackColor = color1
Form1.Label1.ForeColor = color2
Form1.Label2.ForeColor = color2
Form1.Label3.ForeColor = color2
Form1.Label4.ForeColor = color2
Form1.Label5.ForeColor = color2
Form1.Label6.ForeColor = color2
Form1.Label7.ForeColor = color2
Form1.LabelDebug.ForeColor = color2
Form1.logX.ForeColor = color3
Form1.logY.ForeColor = color3
Form1.logManzY.ForeColor = color3
Form1.logPunt.ForeColor = color3
Form1.logSize.ForeColor = color3
Form1.logSpeed.ForeColor = color3
Form1.logTheme.ForeColor = color3
LabelCSnake.ForeColor = color3
LabelCManz.ForeColor = color3
GroupColours.ForeColor = color3
GroupUI.ForeColor = color3
ShowDebug.ForeColor = color3
GroupGame.ForeColor = color3
LabelSpeedL.ForeColor = color3
LabelSpeed.ForeColor = color3
TrackBarSpeed.BackColor = color1
LabelFieldSize.ForeColor = color3
LabelX.ForeColor = color3
LabelCampo.ForeColor = color3
Me.BackColor = color1
End Sub
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Se que hacer esto no es correcto pero bue
If SnakeRB.Text > 255 Then
SnakeRB.Text = 255
ElseIf SnakeRB.Text < 0 Then
SnakeRB.Text = 0
End If
If SnakeGB.Text > 255 Then
SnakeGB.Text = 255
ElseIf SnakeGB.Text < 0 Then
SnakeGB.Text = 0
End If
If SnakeBB.Text > 255 Then
SnakeBB.Text = 255
ElseIf SnakeBB.Text < 0 Then
SnakeBB.Text = 0
End If
If ManzRB.Text > 255 Then
ManzRB.Text = 255
ElseIf ManzRB.Text < 0 Then
ManzRB.Text = 0
End If
If ManzGB.Text > 255 Then
ManzGB.Text = 255
ElseIf ManzGB.Text < 0 Then
ManzGB.Text = 0
End If
If ManzBB.Text > 255 Then
ManzBB.Text = 255
ElseIf ManzBB.Text < 0 Then
ManzBB.Text = 0
End If
If CampoRB.Text > 255 Then
CampoRB.Text = 255
ElseIf CampoRB.Text < 0 Then
CampoRB.Text = 0
End If
If CampoGB.Text > 255 Then
CampoGB.Text = 255
ElseIf CampoGB.Text < 0 Then
CampoGB.Text = 0
End If
If CampoBB.Text > 255 Then
CampoBB.Text = 255
ElseIf CampoBB.Text < 0 Then
CampoBB.Text = 0
End If
UpdateColors()
My.Settings.snakeRed = Form1.rS
My.Settings.snakeGreen = Form1.gS
My.Settings.snakeBlue = Form1.bS
My.Settings.manzRed = Form1.rM
My.Settings.manzGreen = Form1.gM
My.Settings.manzBlue = Form1.bM
My.Settings.campoRed = Form1.rC
My.Settings.campoGreen = Form1.gC
My.Settings.campoBlue = Form1.bC
My.Settings.Save()
End Sub
'Mostrar Info
Public Sub ShowDebug_CheckedChanged(sender As Object, e As EventArgs) Handles ShowDebug.CheckedChanged
If ShowDebug.Checked Then
Form1.UpdateInfo(True)
Form1.logGroup.Visible = True
Form1.logPuntNormal.Location = New Point(-99, -99)
Else
Form1.logGroup.Visible = False
Form1.logPuntNormal.Location = New Point((Form1.Width - 85), 9)
End If
My.Settings.debugMenu = Form1.logGroup.Visible
My.Settings.Save()
End Sub
'Cambiador de Tick Rate
Private Sub TrackBarSpeed_Scroll(sender As Object, e As EventArgs) Handles TrackBarSpeed.Scroll
LabelSpeed.Text = TrackBarSpeed.Value
Form1.snakeSpeed = TrackBarSpeed.Value
My.Settings.PlayerSpeed = TrackBarSpeed.Value
End Sub
'Actualizar datos guardados solo cuando se suelta el mouse
Private Sub TrackBarSpeed_MouseUp(sender As Object, e As MouseEventArgs) Handles TrackBarSpeed.MouseUp
My.Settings.Save()
Form1.UpdateInfo(True)
End Sub
'Actualiza el tamaño del campo
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Form1.gridY = (FieldSizeY.Text * 20) - 20
Form1.gridX = (FieldSizeX.Text * 20) - 20
Form1.field.Width = (FieldSizeY.Text * 20)
Form1.field.Height = (FieldSizeX.Text * 20)
My.Settings.gridSizeX = FieldSizeX.Text
My.Settings.gridSizeY = FieldSizeY.Text
My.Settings.Save()
QuickLogicReset()
Form1.UpdateInfo(True)
End Sub
'Resize
Private Sub Form2_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize
GroupUI.Width = Me.Width - 44
GroupGame.Width = Me.Width - 44
GroupColours.Width = Me.Width - 44
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles InvertirColores.Click
InvertColors()
End Sub
'Invertir colores
Sub InvertColors()
SnakeRB.Text = 255 - SnakeRB.Text
SnakeGB.Text = 255 - SnakeGB.Text
SnakeBB.Text = 255 - SnakeBB.Text
ManzRB.Text = 255 - ManzRB.Text
ManzGB.Text = 255 - ManzGB.Text
ManzBB.Text = 255 - ManzBB.Text
CampoRB.Text = 255 - CampoRB.Text
CampoGB.Text = 255 - CampoGB.Text
CampoBB.Text = 255 - CampoBB.Text
UpdateColors()
End Sub
'Resetea la mayoria de cosas posibles para que el juego vuelva al principio, no resetea ajustes definidos por el usuario
Private Sub resetButton_Click(sender As Object, e As EventArgs) Handles resetButton.Click
Form1.gameLoop.Suspend()
Form1.field.BackColor = Color.FromArgb(64, 64, 64)
Try
For x As Integer = 0 To 999 Step 1
Form1.snakeBody(x).Location = Form1.startingPicPoint
Next
Catch ex As Exception
End Try
For Each manz In Form1.manzana
manz.Location = Form1.startingPicPoint
manz.Location = Form1.startingPicPoint
Next
Form1.LabelTitle.Visible = True
Form1.LabelDesc.Visible = True
Form1.LabelAutor.Visible = True
Form1.logPuntNormal.Visible = False
QuickLogicReset()
Form1.puntos = -1
Form1.comenzo = False
If Form1.pause Then
Form1.pause = False
Form1.LabelPause.Visible = False
End If
End Sub
'Resetea la posicion del jugador y activa manzComida, para simular que el juego recien se abrio
Sub QuickLogicReset()
Form1.xPos = 0
Form1.yPos = 0
Form1.ManzListAdditioner()
Form1.manzComida = True
End Sub
'Añade la cantidad de manzanas que ingrese el usuario
Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click
If CantManzanasText.Text <> 0 OrElse CantManzanasText.Text <> "" Then
Form1.cantManzanas = CantManzanasText.Text - 1
Form1.AddedManzanaUpdater()
End If
End Sub
''' <summary>
''' Toda esta seccion hace lo mismo:
''' Si la tecla presionada es un numero o una tecla de control, deja que sean escritos
''' pero en caso de que sea otra cosa (Letra), no lo deja.
'''
''' Todo esto probablemente lo elimine en algun momento ya que tengo la idea de poner
''' un selector de color visual, asi no tener que escribir los numeros de cada valor.
''' </summary>
Private Sub SnakeRB_KeyPress(sender As Object, e As KeyPressEventArgs) Handles SnakeRB.KeyPress
If Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
e.KeyChar = ""
End If
End Sub
Private Sub SnakeGB_KeyPress(sender As Object, e As KeyPressEventArgs) Handles SnakeGB.KeyPress
If Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
e.KeyChar = ""
End If
End Sub
Private Sub SnakeBB_KeyPress(sender As Object, e As KeyPressEventArgs) Handles SnakeBB.KeyPress
If Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
e.KeyChar = ""
End If
End Sub
Private Sub ManzRB_KeyPress(sender As Object, e As KeyPressEventArgs) Handles ManzRB.KeyPress
If Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
e.KeyChar = ""
End If
End Sub
Private Sub ManzGB_KeyPress(sender As Object, e As KeyPressEventArgs) Handles ManzGB.KeyPress
If Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
e.KeyChar = ""
End If
End Sub
Private Sub ManzBB_KeyPress(sender As Object, e As KeyPressEventArgs) Handles ManzBB.KeyPress
If Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
e.KeyChar = ""
End If
End Sub
Private Sub CampoRB_KeyPress(sender As Object, e As KeyPressEventArgs) Handles CampoRB.KeyPress
If Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
e.KeyChar = ""
End If
End Sub
Private Sub CampoGB_KeyPress(sender As Object, e As KeyPressEventArgs) Handles CampoGB.KeyPress
If Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
e.KeyChar = ""
End If
End Sub
Private Sub CampoBB_KeyPress(sender As Object, e As KeyPressEventArgs) Handles CampoBB.KeyPress
If Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
e.KeyChar = ""
End If
End Sub
End Class