Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class MainGame
- Dim rnd As New Random
- Dim placedObjects As New List(Of Button)
- Dim resPiles As New List(Of Button)
- Dim humanCount As Integer = 0
- Dim boyNames(24) As String
- Dim girlNames(24) As String
- Dim wood As Integer = 200
- Dim gold As Integer = 50
- Dim food As Integer = 300
- Dim stone As Integer = 200
- Class human
- Inherits Button
- Private rnd As New Random
- Private humanName As String
- Private gender As String
- Private age As Integer
- Private energyLevelLimit As Integer = 10
- Private energyLevel As Integer = 10
- Private storageLimit As Integer = 50
- Private currentStorage As Integer
- Private typeOfResoureStored As Integer
- '1 = wood
- '2 = stone
- '3 = gold
- Public Sub createHuman(randomBoyName, randomGirlName)
- Dim boyOrGirl As Integer
- boyOrGirl = rnd.Next(2)
- If boyOrGirl = 0 Then
- gender = "boy"
- humanName = randomBoyName
- Else
- gender = "girl"
- humanName = randomGirlName
- End If
- age = 1
- End Sub
- Public Property setTypeOfResStored
- Get
- Return typeOfResoureStored
- End Get
- Set(value)
- typeOfResoureStored = value
- End Set
- End Property
- Public Property humanStorage
- Get
- Return currentStorage
- End Get
- Set(value)
- currentStorage += value
- End Set
- End Property
- Public Property getHumanStorageLimit
- Get
- Return storageLimit
- End Get
- Set(value)
- storageLimit += value
- End Set
- End Property
- Public Property changeEnergyLevel
- Get
- Return energyLevel
- End Get
- Set(value)
- energyLevel = value
- End Set
- End Property
- Public Property increaseEnergyLimit
- Get
- Return energyLevelLimit
- End Get
- Set(value)
- energyLevelLimit = value
- End Set
- End Property
- Public Function hasEnergy(energyNeeded) As Boolean
- If energyLevel >= energyNeeded Then
- Return True
- Else
- Return False
- End If
- End Function
- Public Sub setHumanProfileDetails(ByRef profileName As String, ByRef profileAge As String, ByRef energyBar As String, ByRef profileResType As String, ByRef profileResAmount As String)
- profileName = humanName
- profileAge = age
- energyBar = (energyLevel & "/" & energyLevelLimit).ToString
- profileResAmount = (currentStorage & "/" & storageLimit).ToString
- Select Case typeOfResoureStored
- Case 1
- profileResType = "wood"
- Case 2
- profileResType = "stone"
- Case 3
- profileResType = "gold"
- Case Else
- profileResType = "nothing"
- End Select
- End Sub
- Public Sub incrementAge()
- age += 1
- End Sub
- End Class
- Class building
- Inherits Button
- End Class
- Class storage
- Inherits Button
- Dim currentWoodStorage As Integer
- Dim currentStoneStorage As Integer
- Dim currentGoldStorage As Integer
- Dim maxWoodStorage As Integer
- Dim maxStoneStorage As Integer
- Dim maxGoldStorage
- End Class
- Private Sub MainGame_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- FormBorderStyle = FormBorderStyle.FixedToolWindow
- ShowInTaskbar = True
- player_name_text_box.Text = MainMenu.playerName.ToUpper
- loadHumanNames("human_boy_names.txt", boyNames)
- loadHumanNames("human_girl_names.txt", girlNames)
- generateNewRandomMap()
- placeHumans()
- End Sub
- Private Sub generateNewRandomMap()
- Select Case MainMenu.resourceDensityLevel
- Case 1
- addResources("tree", Color.Green, 25, 35, rnd.Next(20, 30))
- addResources("rock", Color.Gray, 17, 17, rnd.Next(14, 25))
- addResources("treasure", Color.Yellow, 20, 15, rnd.Next(4, 8))
- Case 2
- addResources("tree", Color.Green, 25, 35, rnd.Next(30, 50))
- addResources("rock", Color.Gray, 17, 17, rnd.Next(25, 40))
- addResources("treasure", Color.Yellow, 20, 15, rnd.Next(10, 15))
- End Select
- makeClearingAroundBase()
- placeFirstStoage()
- End Sub
- Private Sub loadHumanNames(ByVal fileName As String, ByVal nameArray() As String)
- Dim rows As Integer = 0
- Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(fileName)
- MyReader.TextFieldType = FileIO.FieldType.Delimited
- MyReader.SetDelimiters(",")
- Dim currentRow As String()
- While Not MyReader.EndOfData
- currentRow = MyReader.ReadFields()
- Dim currentField As String
- For Each currentField In currentRow
- nameArray(rows) = currentField
- rows += 1
- Next
- End While
- End Using
- End Sub
- Private Sub placeHumans()
- For i As Integer = 1 To 5
- Dim person As New human
- Dim randomName As Integer = Math.Floor(rnd.Next(24))
- AddHandler person.Click, AddressOf humanClicked
- person.createHuman(boyNames(randomName), girlNames(randomName))
- person.Location = New Point(rnd.Next(450, 750), rnd.Next(150, 350))
- person.Size = New Size(18, 25)
- person.BackColor = Color.Pink
- person.ForeColor = Color.DarkGreen
- person.FlatStyle = FlatStyle.Flat
- person.Text = ""
- person.Visible = True
- humanCount += 1
- person.Name = ("human" & humanCount).ToString
- person.Tag = "waiting"
- Controls.Add(person)
- person.BringToFront()
- Next
- End Sub
- Private Sub placeFirstStoage()
- Dim storage As New storage
- storage.Location = New Point(559, 283)
- storage.Size = New Size(30, 30)
- storage.BackColor = Color.BurlyWood
- storage.ForeColor = Color.DarkGreen
- storage.FlatStyle = FlatStyle.Flat
- storage.Text = ""
- storage.Visible = True
- storage.BringToFront()
- storage.Name = "Storage1"
- storage.Tag = "storage"
- Controls.Add(storage)
- End Sub
- Private Sub addResources(ByVal name As String, ByVal colour As Color, ByVal sizeX As Integer, ByVal sizeY As Integer, ByVal amountOfResource As Integer)
- Dim validLocation As Boolean
- For resourceCount As Integer = 0 To amountOfResource
- Dim resource As New Button
- If name = "tree" Then
- AddHandler resource.Click, AddressOf displayCutTreeButton
- ElseIf name = "rock" Then
- AddHandler resource.Click, AddressOf displayMineRockButton
- ElseIf name = "treasure" Then
- AddHandler resource.Click, AddressOf displayCollectTreasureButton
- End If
- Dim newResourceXCoord As Integer = rnd.Next(0, 1230)
- Dim newResourceYCoord As Integer = rnd.Next(0, 495)
- validLocation = False
- Do Until validLocation = True
- validLocation = True
- For Each placedItem In placedObjects
- If newResourceXCoord < placedItem.Location.X + 25 And newResourceXCoord > placedItem.Location.X - 25 Then
- If newResourceYCoord < placedItem.Location.Y + 35 And newResourceYCoord > placedItem.Location.Y - 35 Then
- validLocation = False
- End If
- End If
- Next
- If validLocation = False Then
- newResourceXCoord = rnd.Next(0, 1250)
- newResourceYCoord = rnd.Next(0, 495)
- End If
- Loop
- resource.Location = New Point(newResourceXCoord, newResourceYCoord)
- resource.Size = New Size(sizeX, sizeY)
- resource.BackColor = colour
- resource.ForeColor = Color.DarkGreen
- resource.FlatStyle = FlatStyle.Flat
- resource.Text = ""
- resource.Visible = True
- resource.BringToFront()
- resource.Name = (name & resourceCount).ToString
- resource.Tag = rnd.Next(Int(3))
- placedObjects.Add(resource)
- Controls.Add(resource)
- Next
- End Sub
- Private Sub makeClearingAroundBase()
- For Each item In placedObjects
- If item.Location.X > 500 And item.Location.X < 700 Then
- If item.Location.Y > 200 And item.Location.Y < 350 Then
- Controls.Remove(item)
- End If
- End If
- Next
- End Sub
- Private Sub humanClicked(ByVal sender As Object, ByVal e As EventArgs)
- For Each person In Controls.OfType(Of human)
- person.Tag = "waiting"
- Next
- sender.tag = "ready"
- updateDisplayHuamnProfile()
- End Sub
- Private Sub displayCutTreeButton(sender As Object, e As EventArgs)
- For Each person In Controls.OfType(Of human)
- If person.Tag = "ready" Then
- action_button_collect.Hide()
- action_button_mine.Hide()
- action_button_pick_up.Hide()
- action_button_cut.Show()
- action_button_cut.Tag = sender.name
- End If
- Next
- End Sub
- Dim pileCount As Integer
- Private Sub cutTree(ByVal sender As Object, ByVal e As EventArgs) Handles action_button_cut.Click
- For Each item In placedObjects
- If item.Name = sender.tag Then
- For Each person In Controls.OfType(Of human)
- If person.Tag = "ready" Then
- If person.hasEnergy(2) = True Then
- sender.hide()
- Controls.Remove(item)
- person.Location = New Point(item.Location.X, item.Location.Y)
- person.changeEnergyLevel -= 2
- If person.setTypeOfResStored <> 1 And person.setTypeOfResStored <> 2 And person.setTypeOfResStored <> 3 Or person.setTypeOfResStored = 1 Then
- person.setTypeOfResStored = 1
- If person.humanStorage <= person.getHumanStorageLimit - 10 Then
- person.setTypeOfResStored = 1
- person.humanStorage = 10
- Else
- addLeftOverResPile(item.Location.X, item.Location.Y, "woodPile", Color.Brown)
- End If
- Else
- addLeftOverResPile(item.Location.X, item.Location.Y, "woodPile", Color.Brown)
- End If
- End If
- End If
- Next
- End If
- Next
- updateDisplayHuamnProfile()
- End Sub
- Private Sub displayMineRockButton(sender As Object, e As EventArgs)
- For Each person In Controls.OfType(Of human)
- If person.Tag = "ready" Then
- action_button_collect.Hide()
- action_button_cut.Hide()
- action_button_pick_up.Hide()
- action_button_mine.Show()
- action_button_mine.Tag = sender.name
- End If
- Next
- End Sub
- Private Sub mineRock(ByVal sender As Object, ByVal e As EventArgs) Handles action_button_mine.Click
- For Each item In placedObjects
- If item.Name = sender.tag Then
- For Each person In Controls.OfType(Of human)
- If person.Tag = "ready" Then
- If person.hasEnergy(2) = True Then
- sender.hide()
- Controls.Remove(item)
- person.Location = New Point(item.Location.X, item.Location.Y)
- person.changeEnergyLevel -= 2
- If person.setTypeOfResStored <> 1 And person.setTypeOfResStored <> 2 And person.setTypeOfResStored <> 3 Or person.setTypeOfResStored = 2 Then
- person.setTypeOfResStored = 2
- If person.humanStorage <= person.getHumanStorageLimit - 10 Then
- person.setTypeOfResStored = 2
- person.humanStorage = 10
- Else
- addLeftOverResPile(item.Location.X, item.Location.Y, "rockPile", Color.DarkGray)
- End If
- Else
- addLeftOverResPile(item.Location.X, item.Location.Y, "rockPile", Color.DarkGray)
- End If
- End If
- End If
- Next
- End If
- Next
- updateDisplayHuamnProfile()
- End Sub
- Private Sub displayCollectTreasureButton(sender As Object, e As EventArgs)
- For Each person In Controls.OfType(Of human)
- If person.Tag = "ready" Then
- action_button_cut.Hide()
- action_button_mine.Hide()
- action_button_pick_up.Hide()
- action_button_collect.Show()
- action_button_collect.Tag = sender.name
- End If
- Next
- End Sub
- Private Sub collectTreasure(ByVal sender As Object, ByVal e As EventArgs) Handles action_button_collect.Click
- For Each item In placedObjects
- If item.Name = sender.tag Then
- For Each person In Controls.OfType(Of human)
- If person.Tag = "ready" Then
- If person.hasEnergy(2) = True Then
- sender.hide()
- Controls.Remove(item)
- person.Location = New Point(item.Location.X, item.Location.Y)
- person.changeEnergyLevel -= 2
- If person.setTypeOfResStored <> 1 And person.setTypeOfResStored <> 2 And person.setTypeOfResStored <> 3 Or person.setTypeOfResStored = 3 Then
- person.setTypeOfResStored = 3
- If person.humanStorage <= person.getHumanStorageLimit - 10 Then
- person.setTypeOfResStored = 3
- person.humanStorage = 10
- Else
- addLeftOverResPile(item.Location.X, item.Location.Y, "goldPile", Color.LightYellow)
- End If
- Else
- addLeftOverResPile(item.Location.X, item.Location.Y, "goldPile", Color.LightYellow)
- End If
- End If
- End If
- Next
- End If
- Next
- updateDisplayHuamnProfile()
- End Sub
- Private Sub addLeftOverResPile(locationx, locationy, tagName, colour)
- Dim pile As New Button
- AddHandler pile.Click, AddressOf pileClick
- pile.Location = New Point(locationx, locationy)
- pile.Size = New Size(20, 20)
- pile.BackColor = colour
- pile.ForeColor = Color.DarkGreen
- pile.FlatStyle = FlatStyle.Flat
- pile.Text = ""
- pile.Visible = True
- pile.BringToFront()
- pileCount += 1
- pile.Name = (tagName & pileCount).ToString
- pile.Tag = tagName
- Controls.Add(pile)
- resPiles.Add(pile)
- End Sub
- Dim pilePickUpLocationX As Integer
- Dim pilePickUpLocationY As Integer
- Private Sub pileClick(sender As Object, e As EventArgs)
- For Each person In Controls.OfType(Of human)
- If person.Tag = "ready" Then
- action_button_cut.Hide()
- action_button_mine.Hide()
- action_button_collect.Hide()
- action_button_pick_up.Show()
- action_button_pick_up.BringToFront()
- action_button_pick_up.Tag = sender.name
- pilePickUpLocationX = sender.location.x
- pilePickUpLocationY = sender.location.y
- End If
- Next
- End Sub
- Private Sub pickUpPile(ByVal sender As Object, ByVal e As EventArgs) Handles action_button_pick_up.Click
- Dim storageValue1 As Integer
- Dim storageValue2 As Integer
- Dim storageValue3 As Integer
- Select Case sender.tag.substring(0, 8)
- Case "woodPile"
- storageValue1 = 1
- storageValue2 = 2
- storageValue3 = 3
- Case "rockPile"
- storageValue1 = 2
- storageValue2 = 1
- storageValue3 = 3
- Case "goldPile"
- storageValue1 = 3
- storageValue2 = 1
- storageValue3 = 2
- End Select
- For Each item In resPiles
- If item.Name = sender.tag Then
- For Each person In Controls.OfType(Of human)
- If person.Tag = "ready" Then
- If person.hasEnergy(2) = True Then
- sender.hide()
- person.Location = New Point(pilePickUpLocationX, pilePickUpLocationY)
- person.changeEnergyLevel -= 2
- If person.setTypeOfResStored <> storageValue1 And person.setTypeOfResStored <> storageValue2 And person.setTypeOfResStored <> storageValue3 Or person.setTypeOfResStored = storageValue1 Then
- If person.humanStorage <= person.getHumanStorageLimit - 10 Then
- Me.Controls.Remove(item)
- person.setTypeOfResStored = storageValue1
- person.humanStorage = 10
- End If
- End If
- End If
- End If
- Next
- End If
- Next
- updateDisplayHuamnProfile()
- End Sub
- Private Sub updateDisplayHuamnProfile()
- Dim humanProfileName As String = ""
- Dim humanProfileAge As String = ""
- Dim humanProfileEnergyBar As String = ""
- Dim humanProfileResourceType As String = ""
- Dim humanProfileResourceAmount As String = ""
- For Each person In Controls.OfType(Of human)
- If person.Tag = "ready" Then
- person.setHumanProfileDetails(humanProfileName, humanProfileAge, humanProfileEnergyBar, humanProfileResourceType, humanProfileResourceAmount)
- human_profile_name.Text = humanProfileName
- human_profile_age.Text = humanProfileAge
- human_profile_energy.Text = humanProfileEnergyBar
- human_profile_resource_type.Text = humanProfileResourceType
- human_profile_resource_amount.Text = humanProfileResourceAmount
- End If
- Next
- human_profile_name.Visible = True
- human_profile_age.Visible = True
- human_profile_energy.Visible = True
- human_profile_resource_type.Visible = True
- human_profile_resource_amount.Visible = True
- End Sub
- Private Sub resourceTimerTick(sender As Object, e As EventArgs) Handles resource_timer.Tick
- For Each person In Controls.OfType(Of human)
- food -= 1
- food_amount_text.Text = "food = " & food
- Next
- End Sub
- Private Sub human_energy_level_timer_Tick(sender As Object, e As EventArgs) Handles human_energy_level_timer.Tick
- For Each person In Controls.OfType(Of human)
- If person.changeEnergyLevel < 10 Then
- person.changeEnergyLevel += 1
- updateDisplayHuamnProfile()
- End If
- Next
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement