[2005] Help with Class for Game Statistics
I'm trying to learn how to use classes correctly as I have just been using structures so far which isn't clean an efficient (or re-usable)
I am trying to create a class to accumulate the stats of a Volleyball game with.
I created a Game Class which has the team names and date and game number and I am trying to create a points class which will log the stats of each point which I will then export to a database. I can't seem to figure out how to do this correctly though.
I already have the algorithms that I will be using to get the data it is just correctly storing it in a class that has an array of points which has an array of plays which I can't figure out.
Rough structure would be something like:
Game Class
_HomeTeam
_AwayTeam
_Date
End Class
Points Class
inherits Game?
This class would hold an array of data
each point has numerous touches so I need a play array
which would be an array within the point
and each touch or play would hold
_TeamId (this is the team that performed the play)
_PlayType (this would be Serve/Pass/Dig/Set/Spike/Block)
_PlayerNumber
_PlayResult (this would represent if the play was a point for the team or just continued the rally or was a point for the other team such as -1/0/1)
End Class
So as an example:
points(1) would be the first point played in the game and then you would have the rallies that happened during the point so:
with point(1)
play(0).type = serve
play(0).team = 1
play(0).playerno = 5
play(0).result = 0
play(1).type = pass
play(1).team = 2
play(1).playerno = 10
play(1).result = 0
play(2).type = set
play(2).team = 2
play(2).playerno = 3
play(2).result = 0
play(3).type = pass
play(3).team = 2
play(3).playerno = 10
play(3).result = 1 (because it was a kill)
end with
Then the next point would be
with point(2)
play(0).type = serve
play(0).team = 2
play(0).playerno = 4
play(0).result = -1 (in this case the team missed the serve)
end with
Any help with how to do this is greatly appreciated. Please let me know if I need to be more clear about something.
Thanks
Re: [2005] Help with Class for Game Statistics
I noticed you have the resolved tick, did you figure it out? (I wasn't sure because you didn't make a new post and say you fixed it, so I am just checking)
Re: [2005] Help with Class for Game Statistics
No, I didn't get it figured out. I didn't mark it as figured out or if I did it was an accident. Hopefully someone can help.
Thanks
Re: [2005] Help with Class for Game Statistics
ah, well the 'Green Tick' post icon means 'resolved' (aka you're problem is fixed)
Anyway...
Something like this?
Code:
#Region " [Classes] "
#Region " [newTeam] "
Public Class newTeam
Public name As String = "unnamed_team"
Public id As Integer = -1
Public members As New List(Of newPlayer)
Sub New(ByVal teamName As String, ByVal teamID As Integer)
name = teamName
id = teamID
End Sub
Public Sub addPlayer(ByVal whichPlayer As newPlayer)
members.Add(whichPlayer)
whichPlayer.teamID = id
whichPlayer.teamName = name
End Sub
Public Sub removePlayer(ByVal whichPlayer As newPlayer)
members.Remove(whichPlayer)
whichPlayer.teamName = "no_team"
whichPlayer.teamID = -1 'has no team
End Sub
Public Sub addMultiplePlayers(ByVal whichPlayers() As newPlayer)
For Each np As newPlayer In whichPlayers
members.Add(np)
np.teamID = id
np.teamName = name
Next np
End Sub
Public Sub removeMultiplePlayers(ByVal whichPlayers() As newPlayer)
For Each np As newPlayer In whichPlayers
members.Remove(np)
np.teamName = "no_team"
np.teamID = -1
Next np
End Sub
End Class
#End Region
#Region " [newPlayer] "
Public Class newPlayer
Public number As Integer = -1
Public name As String = ""
Public teamID As Integer = -1
Public teamName As String = "no_team"
Sub New(ByVal playerName As String, ByVal playerID As Integer)
number = playerID
name = playerName
End Sub
End Class
#End Region
#End Region
to use it
Code:
Public p1 As New newPlayer("player1_name", 0) '0 is the player's index
Public team1 As New newTeam("team1_name", 0) '0 is team index
team1.AddPlayer(p1)
1 Attachment(s)
Re: [2005] Help with Class for Game Statistics
That somewhat helps. I am still unsure of how to hold an array within an array within an array since these are all classes.
Example:
Match holds an array of Points which holds an array of plays.
Here is a picture diagram to show what I mean.
Attachment 60962
Thanks
Re: [2005] Help with Class for Game Statistics
is this any better?
(I am rather unsure of what you are wanting to do, why do these have to be classes, can't you just have a 3 Dimensional Array to store all the values for Match/Point/Play in?
Anyway I wrote some code, which you can use to create what I saw in the image you attached.
Code:
Dim My3D(,,) As String = {}
My3D(0, 0, 0) 'Match, Point, Play
Code:
Public match As New newMatch(0)
Public point1 as New newPoint(0, match)
Public point2 as New newPoint(1, match)
Public point3 as New newPoint(2, match)
(and declare each play as 'point1_play1, point1_play2' with the parent 'point1' etc.. until you have as many as you want...)
Public Class newMatch
Dim id As Integer = -1
Dim pointList As New List(Of newPoint)
Sub New(ByVal matchID As Integer)
id = matchID
End Sub
Public Sub addPoint(ByVal point As newPoint)
pointList.add(point)
End Sub
Public removePoint(ByVal point As newPoint)
pointList.remove(point)
End Sub
End Class
Public Class newPoint
Dim id As Integer = -1
Dim playList As New List(of newPlay)
Sub New(ByVal pointID As Integer, ByVal Optional parent As newMatch = Nothing)
id = pointID
If newMatch IsNot Nothing Then
newMatch.pointList.add(Me)
End If
End Sub
Public Sub addPlay(ByVal play As newPlay)
playList.add(play)
End Sub
Public removePlay(ByVal play As newPlay)
playList.remove(play)
End Sub
End Class
Public Class newPlay
Dim id As Integer = -1
Dim parent As newPoint = Nothing
Sub New(ByVal playID As Integer, ByVal Optional parent As newPoint = Nothing)
id = playID
If newPoint IsNot Nothing Then
newPoint.playList.add(Me)
End If
End Sub
End Class
Re: [2005] Help with Class for Game Statistics
This gives me enough to work with. I will figure it out from here.
Thanks for the help.
Re: [2005] Help with Class for Game Statistics