VB_MASTER
11-20-2004, 04:07 PM
Hello, I what to be able to make better code here. Since my game is going to extendeble out side of the VB enviorment, I want to be able to check if a level is done, meaning all the enemys in that level are dead, as shown in the code below. The problem is I want to be able to check for all the enemy's dead and check which level is done or not. The code below works fine. But to expand the campain of the game you need to add more if statements.
Is there a way that I can have better code?
e_enemy() has an array of 20 but the level can be extended are far as it can go.
Function LevelDone(ByVal Level As Integer) As Boolean
If Level = 1 Then
'The FinalDead should never change in a level or campain module!
If e_Enemy(0).FinalDead = True And e_Enemy(1).FinalDead = True And e_Enemy(2).FinalDead = True Then 'Check to see if all the enemys are dead.
LevelDone = True 'End the level
fMain.ResetGame ' Reset the game.
End If
ElseIf Level = 2 Then
If e_Enemy(0).FinalDead = True And e_Enemy(1).FinalDead = True And e_Enemy(2).FinalDead = True Then
LevelDone = True
fMain.ResetGame
End If
ElseIf Level = 3 Then
If e_Enemy(0).FinalDead = True And e_Enemy(1).FinalDead = True And e_Enemy(2).FinalDead = True Then
LevelDone = True
fMain.ResetGame
End If
ElseIf Level = 4 Then
If e_Enemy(0).FinalDead = True And e_Enemy(1).FinalDead = True And e_Enemy(2).FinalDead = True And e_Enemy(3).FinalDead = True Then
LevelDone = True
fMain.ResetGame
End If
ElseIf Level = 5 Then
If e_Enemy(0).FinalDead = True And e_Enemy(1).FinalDead = True Then
LevelDone = True
fMain.ResetGame
End If
End If
End Function
Is there a way that I can have better code?
e_enemy() has an array of 20 but the level can be extended are far as it can go.
Function LevelDone(ByVal Level As Integer) As Boolean
If Level = 1 Then
'The FinalDead should never change in a level or campain module!
If e_Enemy(0).FinalDead = True And e_Enemy(1).FinalDead = True And e_Enemy(2).FinalDead = True Then 'Check to see if all the enemys are dead.
LevelDone = True 'End the level
fMain.ResetGame ' Reset the game.
End If
ElseIf Level = 2 Then
If e_Enemy(0).FinalDead = True And e_Enemy(1).FinalDead = True And e_Enemy(2).FinalDead = True Then
LevelDone = True
fMain.ResetGame
End If
ElseIf Level = 3 Then
If e_Enemy(0).FinalDead = True And e_Enemy(1).FinalDead = True And e_Enemy(2).FinalDead = True Then
LevelDone = True
fMain.ResetGame
End If
ElseIf Level = 4 Then
If e_Enemy(0).FinalDead = True And e_Enemy(1).FinalDead = True And e_Enemy(2).FinalDead = True And e_Enemy(3).FinalDead = True Then
LevelDone = True
fMain.ResetGame
End If
ElseIf Level = 5 Then
If e_Enemy(0).FinalDead = True And e_Enemy(1).FinalDead = True Then
LevelDone = True
fMain.ResetGame
End If
End If
End Function