\r\n\r\n
Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Shorter code


\r\n \r\n
 
 
Thread Tools Display Modes

\r\n\r\n\r\n
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.
\r\nIs there a way that I can have better code?
\r\ne_enemy() has an array of 20 but the level can be extended are far as it can go.
\r\n
\r\n
\r\n
Code:
\r\n
Function LevelDone(ByVal Level As Integer) As Boolean\r\n\r\nIf Level = 1 Then\r\n    \'The FinalDead should never change in a level or campain module!\r\n    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.\r\n        LevelDone = True \'End the level\r\n        fMain.ResetGame \' Reset the game.    \r\n    End If\r\n    \r\nElseIf Level = 2 Then\r\n    If e_Enemy(0).FinalDead = True And e_Enemy(1).FinalDead = True And e_Enemy(2).FinalDead = True Then\r\n        LevelDone = True\r\n        fMain.ResetGame\r\n    End If\r\nElseIf Level = 3 Then\r\n    If e_Enemy(0).FinalDead = True And e_Enemy(1).FinalDead = True And e_Enemy(2).FinalDead = True Then\r\n        LevelDone = True\r\n        fMain.ResetGame\r\n    End If\r\n    \r\nElseIf Level = 4 Then\r\n    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\r\n        LevelDone = True\r\n        fMain.ResetGame\r\n    End If\r\n    \r\nElseIf Level = 5 Then\r\n    If e_Enemy(0).FinalDead = True And e_Enemy(1).FinalDead = True Then\r\n        LevelDone = True\r\n        fMain.ResetGame\r\n    End If\r\nEnd If\r\nEnd Function
\r\n
\r\n \r\n\r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n'; pd[892008] = '\r\n\r\n \r\n\r\n
\r\n
\r\n
\r\n\r\n
\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n
\r\n
\r\n  \r\n #2  \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n Old\r\n \r\n 11-20-2004, 04:37 PM\r\n \r\n \r\n \r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n anhmytran\r\n anhmytran is offline\r\n\r\n\r\n
Prev Previous Post   Next Post Next
  #1  
Old 11-20-2004, 04:07 PM
VB_MASTER VB_MASTER is offline
Freshman
 
Join Date: Oct 2004
Posts: 48
Default Shorter code


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.

Code:
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
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->