-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module1
392 lines (389 loc) · 16.1 KB
/
Module1
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
382
383
384
385
386
387
388
389
390
391
392
Module Module1
Const MapSize As Integer = 50
Const DisplaySize As Integer = 9
Dim Loc(2) As Integer
Dim SelectedRow As Integer = 5
Dim SelectedColumn As Integer = 5
Sub Main()
Dim TerrianMap(MapSize, MapSize) As String
Dim Map(MapSize, MapSize) As String
Dim PlayerOne(9, 6) As String
Dim GameOver As Boolean = True
TerrianGenerator(TerrianMap)
StartLocation(TerrianMap)
InitialiseGame(Map, TerrianMap)
AddUnit(PlayerOne, "V", Loc(0), Loc(1), Map)
Console.WriteLine("Display Terrian Map? (y)")
If Console.ReadLine() = "y" Then
TMap(TerrianMap)
End If
Display(Map, TerrianMap, PlayerOne(0, 1), PlayerOne(0, 2))
While GameOver <> False
Console.WriteLine("Would you like to select a Tile? (y)")
If Console.ReadLine = "y" Then
GridSelector()
Console.Clear()
Display(Map, TerrianMap, PlayerOne(0, 1), PlayerOne(0, 2))
ElseIf Console.ReadLine = "q" Then
End
Else
Console.WriteLine("No Other Functions avaliable. q to quit (q)")
End If
Console.WriteLine("Do you want to move current Unit to this title? (y)")
If Console.ReadLine.ToUpper = "Y" Then
Move(PlayerOne, Map)
Console.ReadLine()
Console.Clear()
Display(Map, TerrianMap, PlayerOne(0, 1), PlayerOne(0, 2))
End If
End While
Console.ReadLine()
End Sub
Sub TerrianGenerator(ByRef TerrianMap(,) As String)
For x = 1 To 5
For Row = 1 To MapSize
For Column = 1 To MapSize
If TerrianMap(Row - 1, Column) = "" And TerrianMap(Row, Column - 1) = "" Then
TerrianMap(Row, Column) = RandomTerrian()
ElseIf TerrianMap(Row - 1, Column) = "P" And TerrianMap(Row, Column - 1) = "P" And RandomNumberPercentage() < 20 Then
TerrianMap(Row, Column) = "P"
ElseIf TerrianMap(Row - 1, Column) = "P" Or TerrianMap(Row, Column - 1) = "P" And RandomNumberPercentage() < 20 Then
TerrianMap(Row, Column) = "P"
ElseIf TerrianMap(Row - 1, Column) = "D" And TerrianMap(Row, Column - 1) = "D" And RandomNumberPercentage() < 80 Then
TerrianMap(Row, Column) = "D"
ElseIf TerrianMap(Row - 1, Column) = "D" Or TerrianMap(Row, Column - 1) = "D" And RandomNumberPercentage() < 65 Then
TerrianMap(Row, Column) = "D"
Else
TerrianMap(Row, Column) = RandomTerrian()
End If
Next
Next
Next
Randomize()
For x = 1 To CInt(Int((225 * Rnd()) + 50))
TerrianMap(RandomLocation(), RandomLocation()) = "M"
Next
Randomize()
For x = 1 To CInt(Int((300 * Rnd()) + 150))
TerrianMap(RandomLocation(), RandomLocation()) = "H"
Next
Randomize()
For x = 1 To CInt(Int((20 * Rnd()) + 1))
Dim RowLoc As Integer = RandomLocation()
Dim ColumnLoc As Integer = RandomLocation()
Dim Expand As Integer = 50
Do Until Expand > 99
If ColumnLoc >= 50 Or RowLoc >= 50 Then
Expand = 100
Else
If RandomNumberPercentage() <> 100 Then
ColumnLoc = ColumnLoc + 1
Else
RowLoc = RowLoc + 1
End If
TerrianMap(RowLoc, ColumnLoc) = "R"
Expand = RandomNumberPercentage()
End If
Loop
Next
Randomize()
For x = 1 To CInt(Int((3 * Rnd()) + 1))
Dim RowLoc As Integer = RandomLocation()
Dim ColumnLoc As Integer = RandomLocation()
Next
End Sub
Function RandomTerrian() As String
Randomize()
Dim value As Integer = CInt(Int((100 * Rnd()) + 1))
If value >= 1 And value < 55 Then
Return "P"
ElseIf value >= 55 And value <= 100 Then
Return "D"
Else : Return "F"
End If
End Function
Function RandomNumberPercentage() As Integer
Randomize()
Dim value As Integer = CInt(Int((100 * Rnd()) + 1))
Return value
End Function
Function RandomLocation() As Integer
Randomize()
Dim value As Integer = CInt(Int((50 * Rnd()) + 1))
Return value
End Function
Sub TMap(ByVal TerrianMap(,) As String)
For Row = 1 To MapSize
For Column = 1 To MapSize
If TerrianMap(Row, Column) = "R" Then
Console.ForegroundColor = ConsoleColor.Blue
ElseIf TerrianMap(Row, Column) = "P" Then
Console.ForegroundColor = ConsoleColor.Green
ElseIf TerrianMap(Row, Column) = "D" Then
Console.ForegroundColor = ConsoleColor.Yellow
ElseIf TerrianMap(Row, Column) = "M" Then
Console.ForegroundColor = ConsoleColor.DarkGray
ElseIf TerrianMap(Row, Column) = "M" Then
Console.ForegroundColor = ConsoleColor.Gray
End If
Console.Write(TerrianMap(Row, Column))
Console.ResetColor()
Next
Next
Console.ReadLine()
Console.Clear()
End Sub
Sub Display(ByRef Map(,) As String, ByVal TerrianMap(,) As String, ByRef FocusRow As Integer, ByRef FocusColumn As Integer)
Dim Row As Integer
Dim Column As Integer
Dim StartRangeR As Integer
Dim FinishRangeR As Integer
Dim StartRangeC As Integer
Dim FinishRangeC As Integer
Dim TempHolder As Integer
StartRangeR = (FocusRow - 5) + 50
If StartRangeR > 50 Then
StartRangeR = 5
Else
TempHolder = 50 - StartRangeR
StartRangeR = 5 - TempHolder
End If
FinishRangeR = 50 - FocusRow + 4
If FinishRangeR > 0 Then
FinishRangeR = 4
Else
TempHolder = 4 - Math.Abs(FinishRangeR)
FinishRangeR = TempHolder
End If
StartRangeC = (FocusColumn - 5) + 50
If StartRangeC > 50 Then
StartRangeC = 5
Else
TempHolder = 50 - StartRangeC
StartRangeC = 5 - TempHolder
End If
FinishRangeC = 50 - FocusColumn + 4
If FinishRangeC > 0 Then
FinishRangeC = 4
Else
TempHolder = 4 - Math.Abs(FinishRangeC)
FinishRangeC = TempHolder
End If
For Row = FocusRow - StartRangeR + 1 To FocusRow + FinishRangeR
DisplayHighlightRow(Row)
Console.ForegroundColor = ConsoleColor.White
Console.Write(Row & " ")
For Column = FocusColumn - StartRangeC + 1 To FocusColumn + FinishRangeC
DisplayHighlightColumn(Row, Column)
If TerrianMap(Row, Column) = "R" Then
Console.ForegroundColor = ConsoleColor.Blue
ElseIf TerrianMap(Row, Column) = "P" Then
Console.ForegroundColor = ConsoleColor.Green
ElseIf TerrianMap(Row, Column) = "D" Then
Console.ForegroundColor = ConsoleColor.Yellow
ElseIf TerrianMap(Row, Column) = "M" Then
Console.ForegroundColor = ConsoleColor.DarkGray
ElseIf TerrianMap(Row, Column) = "M" Then
Console.ForegroundColor = ConsoleColor.Gray
End If
Console.Write(TerrianMap(Row, Column))
Console.ResetColor()
Console.ForegroundColor = ConsoleColor.Magenta
Console.Write(Map(Row, Column))
Console.ResetColor()
Next
If SelectedColumn = 9 Then
Console.ForegroundColor = ConsoleColor.Red
Else
Console.ForegroundColor = ConsoleColor.White
End If
Console.WriteLine("|")
Console.ResetColor()
Next
If SelectedColumn = 9 Then
Console.ForegroundColor = ConsoleColor.Red
Else
Console.ForegroundColor = ConsoleColor.White
End If
Console.WriteLine(" ____________________________")
Console.ForegroundColor = ConsoleColor.White
Console.Write(" ")
For Column = FocusColumn - StartRangeC + 1 To FocusColumn + FinishRangeC
If Column < 10 Then
Console.Write(Column & " ")
Else
Console.Write(Column & " ")
End If
Next
Console.WriteLine()
Console.WriteLine()
Console.ResetColor()
End Sub
Sub InitialiseGame(ByRef Map(,) As String, ByVal TerrianMap(,) As String)
For Row = 1 To MapSize
For Column = 1 To MapSize
Map(Row, Column) = " "
Next
Next
End Sub
Sub AddUnit(ByRef PlayerData(,) As String, ByVal Unit As String, ByVal Row As Integer, ByVal Column As Integer, ByRef Map(,) As String)
Dim Movement As Integer
Dim AttackMin As Integer
Dim AttackMax As Integer
Dim Slot As Integer
If Unit = "V" Then
Movement = 5
AttackMax = 20
AttackMin = 1
End If
For index = 0 To PlayerData.GetUpperBound(0)
If PlayerData(index, 0) = "" Then
Slot = index
Exit For
End If
Next
PlayerData(Slot, 0) = Unit
PlayerData(Slot, 1) = Row
PlayerData(Slot, 2) = Column
PlayerData(Slot, 3) = Movement
PlayerData(Slot, 4) = AttackMin
PlayerData(Slot, 5) = AttackMax
Map(Row, Column) = Unit
End Sub
Sub StartLocation(ByVal TerrianMap(,) As String)
Loc(0) = RandomLocation()
Loc(1) = RandomLocation()
While TerrianMap(Loc(0), Loc(1)) = "R" Or TerrianMap(Loc(0), Loc(1)) = "S" Or TerrianMap(Loc(0), Loc(1)) = "M"
Loc(0) = RandomLocation()
Loc(1) = RandomLocation()
End While
End Sub
Sub GridSelector()
Console.WriteLine("Which title would you like to select? (RowColumn)")
SelectedRow = Console.ReadLine()
SelectedColumn = Console.ReadLine()
End Sub
Sub DisplayHighlightRow(ByVal Row As Integer)
If Row = SelectedRow Or Row = SelectedRow + 1 Then
Select Case SelectedColumn
Case 1
Console.ForegroundColor = ConsoleColor.Red
Console.Write(" ____")
Console.ForegroundColor = ConsoleColor.White
Console.Write("________________________ ")
Console.WriteLine()
Case 2
Console.ForegroundColor = ConsoleColor.White
Console.Write(" ___")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("____")
Console.ForegroundColor = ConsoleColor.White
Console.Write("_____________________")
Console.WriteLine()
Case 3
Console.ForegroundColor = ConsoleColor.White
Console.Write(" ______")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("____")
Console.ForegroundColor = ConsoleColor.White
Console.Write("__________________")
Console.WriteLine()
Case 4
Console.ForegroundColor = ConsoleColor.White
Console.Write(" _________")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("____")
Console.ForegroundColor = ConsoleColor.White
Console.Write("_______________")
Console.WriteLine()
Case 5
Console.ForegroundColor = ConsoleColor.White
Console.Write(" ____________")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("____")
Console.ForegroundColor = ConsoleColor.White
Console.Write("____________")
Console.WriteLine()
Case 6
Console.ForegroundColor = ConsoleColor.White
Console.Write(" _______________")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("____")
Console.ForegroundColor = ConsoleColor.White
Console.Write("_________")
Console.WriteLine()
Case 7
Console.ForegroundColor = ConsoleColor.White
Console.Write(" __________________")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("____")
Console.ForegroundColor = ConsoleColor.White
Console.Write("______")
Console.WriteLine()
Case 8
Console.ForegroundColor = ConsoleColor.White
Console.Write(" _____________________")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("____")
Console.ForegroundColor = ConsoleColor.White
Console.Write("___")
Console.WriteLine()
Case 9
Console.ForegroundColor = ConsoleColor.White
Console.Write(" ________________________")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("____")
Console.WriteLine()
Case Else
Console.ForegroundColor = ConsoleColor.White
Console.Write(" ____________________________")
Console.WriteLine()
End Select
Else
Console.ForegroundColor = ConsoleColor.White
Console.WriteLine(" ____________________________")
End If
Console.ResetColor()
End Sub
Sub DisplayHighlightColumn(ByVal Row As Integer, ByVal Column As Integer)
If Row = SelectedRow And Column = SelectedColumn Or Column = SelectedColumn + 1 And Row = SelectedRow Then
Console.ForegroundColor = ConsoleColor.Red
Else
Console.ForegroundColor = ConsoleColor.White
End If
Console.Write("|")
Console.ResetColor()
End Sub
Function Move(ByVal PlayerOne(,) As String, ByRef Map(,) As String) As Boolean
Dim Loc As Integer
For Check = PlayerOne.GetLowerBound(0) To PlayerOne.GetUpperBound(0)
If PlayerOne(Check, 1) = SelectedRow Then
Loc = Check
Exit For
End If
Next
Dim Movement As Integer = PlayerOne(Loc, 3)
Dim Distance As Integer = (Math.Abs(SelectedRow - PlayerOne(Loc, 1)) + Math.Abs(SelectedColumn - PlayerOne(Loc, 2)))
If PlayerOne(Loc, 1) = SelectedRow And PlayerOne(Loc, 2) = SelectedColumn Then
Console.WriteLine("You can't move the unit to the same place!")
Return False
ElseIf Distance > Movement Then
Console.WriteLine("This unit can't move more than " & Movement & " tiles! You tried to move: " & Distance)
Return False
Else
Console.WriteLine("Are you Sure? (y)")
If Console.ReadLine.ToUpper = "Y" Then
Map(PlayerOne(Loc, 1), PlayerOne(Loc, 2)) = ""
Map(SelectedRow, SelectedColumn) = PlayerOne(Loc, 0)
PlayerOne(Loc, 1) = SelectedRow
PlayerOne(Loc, 2) = SelectedColumn
Return True
Else
Return False
End If
End If
End Function
Sub GUI()
'GUI Screen
End Sub
End Module