|
-
Mar 13th, 2004, 04:59 AM
#1
Thread Starter
Fanatic Member
inherited class-check were ive gone wrong
can someone check where i am going wrong?
I have a form with a map on it. There are several doors. A person has to nevigate through the map. A person cannot be at location 1(represented by ID1 etc) and access door 6. They have to go through the certain doors. So basically they cannot just transport from one place to another.
Attached is a picture of the map.
I have two, classes, a door class and a location class.
I have a feeling ive gone wrong some where but i dont know where. can some one help? Any help will be extremly appreciated.
Public Class location
Private id As Integer
Private securityclearence As Integer
Sub New()
id = 1
securityclearence = 1
End Sub
Sub New(ByVal ids1 As Integer, ByVal isecurityclearence As Integer)
id = 1
securityclearence = 0
End Sub
Public ReadOnly Property ids() As Integer
Get
Return id
End Get
End Property
Public ReadOnly Property sc() As Integer
Get
Return securityclearence
End Get
End Property
Public Function access() As Boolean
If id = 1 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 2 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 3 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 4 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 5 Then
securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 6 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 7 Then
securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 8 Then
securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 9 Then
securityclearence = 2 Or securityclearence = 1
ElseIf id = 10 Then
securityclearence = 2 Or securityclearence = 1
End If
End Function
End Class
Public Class Door
Inherits location
Protected ID1 As Integer
Protected ID2 As Integer
Private door As String
Sub New()
ID1 = 0
ID2 = 1
Door = "doora"
End Sub
Sub New(ByVal IDs1 As Integer, ByVal IDs2 As Integer, ByVal idoor As String)
ID1 = IDs1
ID2 = IDs2
Door = idoor
End Sub
Public Property ids1() As Integer
Get
Return ID1
End Get
Set(ByVal Value As Integer)
End Set
End Property
Public Property ids2() As Integer
Get
Return ID2
End Get
Set(ByVal Value As Integer)
End Set
End Property
Public Property idoor() As String
Get
Return door
End Get
Set(ByVal Value As String)
End Set
End Property
Public Function doorlocation() As Boolean
If door = "DoorA" Then
ID1 = 0
ID2 = 1
ElseIf door = "Door1" Then
ID1 = 1
ID2 = 2
ElseIf door = "Door2" Then
ID1 = 2
ID2 = 3
ElseIf door = "Door3" Then
ID1 = 2
ID2 = 4
ElseIf door = "Door4" Then
ID1 = 2
ID2 = 5
ElseIf door = "Door5" Then
ID1 = 2
ID2 = 6
ElseIf door = "DoorC" Then
ID1 = 2
ID2 = 7
ElseIf door = "Door6" Then
ID1 = 8
ID2 = 7
ElseIf door = "Door7" Then
ID1 = 9
ID2 = 7
ElseIf door = "Door8" Then
ID1 = 10
ID2 = 7
ElseIf door = "DoorB" Then
ID1 = 0
ID2 = 7
ElseIf door = "DoorD" Then
ID1 = 7
ID2 = 0
End If
End Function
End Class
this is the where the classes are called.
Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
Dim s1 As Door
If s1.idoor <> "Door1" Then
MsgBox("You cannot access this room. You are not in the correct region", MsgBoxStyle.Critical, "Door A")
Else
s1.ids1 = 2
s1.ids2 = 1
End If
End Sub
-
Mar 13th, 2004, 06:53 AM
#2
First of All its alot easier to understand code formatted with [ vbcode ] [ /vbcode ] tags
And If your not gonna use the Set statement of the propertys declare it readonly
VB Code:
Public Class location
Private id As Integer
Private securityclearence As Integer
Sub New()
id = 1
securityclearence = 1
End Sub
Sub New(ByVal ids1 As Integer, ByVal isecurityclearence As Integer)
id = 1
securityclearence = 0
End Sub
Public ReadOnly Property ids() As Integer
Get
Return id
End Get
End Property
Public ReadOnly Property sc() As Integer
Get
Return securityclearence
End Get
End Property
Public Function access() As Boolean
If id = 1 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 2 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 3 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 4 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 5 Then
securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 6 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 7 Then
securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 8 Then
securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 9 Then
securityclearence = 2 Or securityclearence = 1
ElseIf id = 10 Then
securityclearence = 2 Or securityclearence = 1
End If
End Function
End Class
Public Class Door
Inherits location
Protected ID1 As Integer
Protected ID2 As Integer
Private door As String
Sub New()
ID1 = 0
ID2 = 1
Door = "doora"
End Sub
Sub New(ByVal IDs1 As Integer, ByVal IDs2 As Integer, ByVal idoor As String)
ID1 = IDs1
ID2 = IDs2
Door = idoor
End Sub
Public Readonl Property ids1() As Integer
Get
Return ID1
End Get
End Property
Public ReadOnly Property ids2() As Integer
Get
Return ID2
End Get
Set(ByVal Value As Integer)
End Set
End Property
Public ReadOnly Property idoor() As String
Get
Return door
End Get
End Property
Public Function doorlocation() As Boolean
If door = "DoorA" Then
ID1 = 0
ID2 = 1
ElseIf door = "Door1" Then
ID1 = 1
ID2 = 2
ElseIf door = "Door2" Then
ID1 = 2
ID2 = 3
ElseIf door = "Door3" Then
ID1 = 2
ID2 = 4
ElseIf door = "Door4" Then
ID1 = 2
ID2 = 5
ElseIf door = "Door5" Then
ID1 = 2
ID2 = 6
ElseIf door = "DoorC" Then
ID1 = 2
ID2 = 7
ElseIf door = "Door6" Then
ID1 = 8
ID2 = 7
ElseIf door = "Door7" Then
ID1 = 9
ID2 = 7
ElseIf door = "Door8" Then
ID1 = 10
ID2 = 7
ElseIf door = "DoorB" Then
ID1 = 0
ID2 = 7
ElseIf door = "DoorD" Then
ID1 = 7
ID2 = 0
End If
End Function
End Class
VB Code:
'this is the where the classes are called.
Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
Dim s1 As Door
If s1.idoor <> "Door1" Then
MsgBox("You cannot access this room. You are not in the correct region", MsgBoxStyle.Critical, "Door A")
Else
s1.ids1 = 2
s1.ids2 = 1
End If
End Sub
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Mar 13th, 2004, 07:14 AM
#3
VB Code:
Public Function access() As Boolean
If id = 1 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 2 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 3 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 4 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 5 Then
securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 6 Then
securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 7 Then
securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 8 Then
securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
ElseIf id = 9 Then
securityclearence = 2 Or securityclearence = 1
ElseIf id = 10 Then
securityclearence = 2 Or securityclearence = 1
End If
End Function
after you test the conditions you to not return a wither the player has access or not so it defaults to false
Test out this code and tell me if it solves ur problem
VB Code:
'it shorter but it should do what u wanted
Public Function Acceess() As Boolean
If (securityclearence = 1) Or (securityclearence = 2) Then
'They have access to everything
Return True
End If
If (securityclearence = 3) Or (securityclearence = 4) And (Not (id = 10) Or Not (id = 9)) Then
'has access to everthing except 10 + 9
Return True
End If
If (securityclearence = 5) And (Not (id = 5) Or (id > 6)) Then
Return True
End If
End Function
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Mar 13th, 2004, 07:44 AM
#4
Thread Starter
Fanatic Member
I appreciate the quick response. I have to go to work but i'll be sure to check out the code as soon as i return. The above code is were i was a bit 'iffy' on. I wasn't sure if i was calling the classes correctly. Is the above code ok? Each label represents a door. I'm espcecially a bit weary on the line:
If s1.idoor <> "Door1" Then
Is this the correct way to call the classes or is there a better method?
VB Code:
'this is the where the classes are called.
Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
Dim s1 As Door
If s1.idoor <> "Door1" Then
MsgBox("You cannot access this room. You are not in the correct region", MsgBoxStyle.Critical, "Door A")
Else
s1.ids1 = 2
s1.ids2 = 1
End If
End Sub
-
Mar 13th, 2004, 06:23 PM
#5
your right it wont work.
you should use:
VB Code:
Dim d1 as New Door()
'or
Dim d1 as New Door(2,1, "Door Name")
to create a door object but I dont think you are doing this right but i need more of the source to understand how you are trying to do this.
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|