Advertisement
Guest User

Untitled

a guest
Nov 15th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class MainGame
  2.     Dim rnd As New Random
  3.     Dim placedObjects As New List(Of Button)
  4.     Dim resPiles As New List(Of Button)
  5.     Dim humanCount As Integer = 0
  6.     Dim boyNames(24) As String
  7.     Dim girlNames(24) As String
  8.     Dim wood As Integer = 200
  9.     Dim gold As Integer = 50
  10.     Dim food As Integer = 300
  11.     Dim stone As Integer = 200
  12.  
  13.     Class human
  14.         Inherits Button
  15.         Private rnd As New Random
  16.         Private humanName As String
  17.         Private gender As String
  18.         Private age As Integer
  19.         Private energyLevelLimit As Integer = 10
  20.         Private energyLevel As Integer = 10
  21.         Private storageLimit As Integer = 50
  22.         Private currentStorage As Integer
  23.         Private typeOfResoureStored As Integer
  24.         '1 = wood
  25.        '2 = stone
  26.        '3 = gold
  27.  
  28.         Public Sub createHuman(randomBoyName, randomGirlName)
  29.             Dim boyOrGirl As Integer
  30.             boyOrGirl = rnd.Next(2)
  31.             If boyOrGirl = 0 Then
  32.                 gender = "boy"
  33.                 humanName = randomBoyName
  34.             Else
  35.                 gender = "girl"
  36.                 humanName = randomGirlName
  37.             End If
  38.             age = 1
  39.         End Sub
  40.  
  41.         Public Property setTypeOfResStored
  42.             Get
  43.                 Return typeOfResoureStored
  44.             End Get
  45.             Set(value)
  46.                 typeOfResoureStored = value
  47.             End Set
  48.         End Property
  49.  
  50.         Public Property humanStorage
  51.             Get
  52.                 Return currentStorage
  53.             End Get
  54.             Set(value)
  55.                 currentStorage += value
  56.             End Set
  57.         End Property
  58.  
  59.         Public Property getHumanStorageLimit
  60.             Get
  61.                 Return storageLimit
  62.             End Get
  63.             Set(value)
  64.                 storageLimit += value
  65.             End Set
  66.         End Property
  67.  
  68.         Public Property changeEnergyLevel
  69.             Get
  70.                 Return energyLevel
  71.             End Get
  72.             Set(value)
  73.                 energyLevel = value
  74.             End Set
  75.         End Property
  76.  
  77.         Public Property increaseEnergyLimit
  78.             Get
  79.                 Return energyLevelLimit
  80.             End Get
  81.             Set(value)
  82.                 energyLevelLimit = value
  83.             End Set
  84.         End Property
  85.  
  86.         Public Function hasEnergy(energyNeeded) As Boolean
  87.             If energyLevel >= energyNeeded Then
  88.                 Return True
  89.             Else
  90.                 Return False
  91.             End If
  92.         End Function
  93.  
  94.         Public Sub setHumanProfileDetails(ByRef profileName As String, ByRef profileAge As String, ByRef energyBar As String, ByRef profileResType As String, ByRef profileResAmount As String)
  95.             profileName = humanName
  96.             profileAge = age
  97.             energyBar = (energyLevel & "/" & energyLevelLimit).ToString
  98.             profileResAmount = (currentStorage & "/" & storageLimit).ToString
  99.             Select Case typeOfResoureStored
  100.                 Case 1
  101.                     profileResType = "wood"
  102.                 Case 2
  103.                     profileResType = "stone"
  104.                 Case 3
  105.                     profileResType = "gold"
  106.                 Case Else
  107.                     profileResType = "nothing"
  108.             End Select
  109.         End Sub
  110.  
  111.         Public Sub incrementAge()
  112.             age += 1
  113.         End Sub
  114.     End Class
  115.  
  116.     Class building
  117.         Inherits Button
  118.     End Class
  119.  
  120.     Class storage
  121.             Inherits Button
  122.             Dim currentWoodStorage As Integer
  123.             Dim currentStoneStorage As Integer
  124.             Dim currentGoldStorage As Integer
  125.             Dim maxWoodStorage As Integer
  126.             Dim maxStoneStorage As Integer
  127.             Dim maxGoldStorage
  128.  
  129.         End Class
  130.  
  131.     Private Sub MainGame_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  132.         FormBorderStyle = FormBorderStyle.FixedToolWindow
  133.         ShowInTaskbar = True
  134.         player_name_text_box.Text = MainMenu.playerName.ToUpper
  135.         loadHumanNames("human_boy_names.txt", boyNames)
  136.         loadHumanNames("human_girl_names.txt", girlNames)
  137.         generateNewRandomMap()
  138.         placeHumans()
  139.     End Sub
  140.  
  141.     Private Sub generateNewRandomMap()
  142.             Select Case MainMenu.resourceDensityLevel
  143.                 Case 1
  144.                     addResources("tree", Color.Green, 25, 35, rnd.Next(20, 30))
  145.                     addResources("rock", Color.Gray, 17, 17, rnd.Next(14, 25))
  146.                     addResources("treasure", Color.Yellow, 20, 15, rnd.Next(4, 8))
  147.                 Case 2
  148.                     addResources("tree", Color.Green, 25, 35, rnd.Next(30, 50))
  149.                     addResources("rock", Color.Gray, 17, 17, rnd.Next(25, 40))
  150.                     addResources("treasure", Color.Yellow, 20, 15, rnd.Next(10, 15))
  151.             End Select
  152.             makeClearingAroundBase()
  153.             placeFirstStoage()
  154.         End Sub
  155.  
  156.     Private Sub loadHumanNames(ByVal fileName As String, ByVal nameArray() As String)
  157.         Dim rows As Integer = 0
  158.         Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(fileName)
  159.             MyReader.TextFieldType = FileIO.FieldType.Delimited
  160.             MyReader.SetDelimiters(",")
  161.             Dim currentRow As String()
  162.             While Not MyReader.EndOfData
  163.                 currentRow = MyReader.ReadFields()
  164.                 Dim currentField As String
  165.                 For Each currentField In currentRow
  166.                     nameArray(rows) = currentField
  167.                     rows += 1
  168.                 Next
  169.             End While
  170.         End Using
  171.     End Sub
  172.  
  173.     Private Sub placeHumans()
  174.         For i As Integer = 1 To 5
  175.             Dim person As New human
  176.             Dim randomName As Integer = Math.Floor(rnd.Next(24))
  177.             AddHandler person.Click, AddressOf humanClicked
  178.             person.createHuman(boyNames(randomName), girlNames(randomName))
  179.             person.Location = New Point(rnd.Next(450, 750), rnd.Next(150, 350))
  180.             person.Size = New Size(18, 25)
  181.             person.BackColor = Color.Pink
  182.             person.ForeColor = Color.DarkGreen
  183.             person.FlatStyle = FlatStyle.Flat
  184.             person.Text = ""
  185.             person.Visible = True
  186.             humanCount += 1
  187.             person.Name = ("human" & humanCount).ToString
  188.             person.Tag = "waiting"
  189.             Controls.Add(person)
  190.             person.BringToFront()
  191.         Next
  192.     End Sub
  193.  
  194.     Private Sub placeFirstStoage()
  195.             Dim storage As New storage
  196.             storage.Location = New Point(559, 283)
  197.             storage.Size = New Size(30, 30)
  198.             storage.BackColor = Color.BurlyWood
  199.             storage.ForeColor = Color.DarkGreen
  200.             storage.FlatStyle = FlatStyle.Flat
  201.             storage.Text = ""
  202.             storage.Visible = True
  203.             storage.BringToFront()
  204.             storage.Name = "Storage1"
  205.             storage.Tag = "storage"
  206.             Controls.Add(storage)
  207.         End Sub
  208.  
  209.     Private Sub addResources(ByVal name As String, ByVal colour As Color, ByVal sizeX As Integer, ByVal sizeY As Integer, ByVal amountOfResource As Integer)
  210.         Dim validLocation As Boolean
  211.         For resourceCount As Integer = 0 To amountOfResource
  212.             Dim resource As New Button
  213.             If name = "tree" Then
  214.                 AddHandler resource.Click, AddressOf displayCutTreeButton
  215.             ElseIf name = "rock" Then
  216.                 AddHandler resource.Click, AddressOf displayMineRockButton
  217.             ElseIf name = "treasure" Then
  218.                 AddHandler resource.Click, AddressOf displayCollectTreasureButton
  219.             End If
  220.             Dim newResourceXCoord As Integer = rnd.Next(0, 1230)
  221.             Dim newResourceYCoord As Integer = rnd.Next(0, 495)
  222.             validLocation = False
  223.             Do Until validLocation = True
  224.                 validLocation = True
  225.                 For Each placedItem In placedObjects
  226.                     If newResourceXCoord < placedItem.Location.X + 25 And newResourceXCoord > placedItem.Location.X - 25 Then
  227.                         If newResourceYCoord < placedItem.Location.Y + 35 And newResourceYCoord > placedItem.Location.Y - 35 Then
  228.                             validLocation = False
  229.                         End If
  230.                     End If
  231.                 Next
  232.                 If validLocation = False Then
  233.                     newResourceXCoord = rnd.Next(0, 1250)
  234.                     newResourceYCoord = rnd.Next(0, 495)
  235.                 End If
  236.             Loop
  237.             resource.Location = New Point(newResourceXCoord, newResourceYCoord)
  238.             resource.Size = New Size(sizeX, sizeY)
  239.             resource.BackColor = colour
  240.             resource.ForeColor = Color.DarkGreen
  241.             resource.FlatStyle = FlatStyle.Flat
  242.             resource.Text = ""
  243.             resource.Visible = True
  244.             resource.BringToFront()
  245.             resource.Name = (name & resourceCount).ToString
  246.             resource.Tag = rnd.Next(Int(3))
  247.             placedObjects.Add(resource)
  248.             Controls.Add(resource)
  249.         Next
  250.     End Sub
  251.  
  252.     Private Sub makeClearingAroundBase()
  253.         For Each item In placedObjects
  254.             If item.Location.X > 500 And item.Location.X < 700 Then
  255.                 If item.Location.Y > 200 And item.Location.Y < 350 Then
  256.                     Controls.Remove(item)
  257.                 End If
  258.             End If
  259.         Next
  260.     End Sub
  261.  
  262.     Private Sub humanClicked(ByVal sender As Object, ByVal e As EventArgs)
  263.             For Each person In Controls.OfType(Of human)
  264.                 person.Tag = "waiting"
  265.             Next
  266.             sender.tag = "ready"
  267.             updateDisplayHuamnProfile()
  268.         End Sub
  269.  
  270.     Private Sub displayCutTreeButton(sender As Object, e As EventArgs)
  271.         For Each person In Controls.OfType(Of human)
  272.             If person.Tag = "ready" Then
  273.                 action_button_collect.Hide()
  274.                 action_button_mine.Hide()
  275.                 action_button_pick_up.Hide()
  276.                 action_button_cut.Show()
  277.                 action_button_cut.Tag = sender.name
  278.             End If
  279.         Next
  280.     End Sub
  281.  
  282.     Dim pileCount As Integer
  283.     Private Sub cutTree(ByVal sender As Object, ByVal e As EventArgs) Handles action_button_cut.Click
  284.         For Each item In placedObjects
  285.             If item.Name = sender.tag Then
  286.                 For Each person In Controls.OfType(Of human)
  287.                     If person.Tag = "ready" Then
  288.                         If person.hasEnergy(2) = True Then
  289.                             sender.hide()
  290.                             Controls.Remove(item)
  291.                             person.Location = New Point(item.Location.X, item.Location.Y)
  292.                             person.changeEnergyLevel -= 2
  293.                             If person.setTypeOfResStored <> 1 And person.setTypeOfResStored <> 2 And person.setTypeOfResStored <> 3 Or person.setTypeOfResStored = 1 Then
  294.                                 person.setTypeOfResStored = 1
  295.                                 If person.humanStorage <= person.getHumanStorageLimit - 10 Then
  296.                                     person.setTypeOfResStored = 1
  297.                                     person.humanStorage = 10
  298.                                 Else
  299.                                     addLeftOverResPile(item.Location.X, item.Location.Y, "woodPile", Color.Brown)
  300.                                 End If
  301.                             Else
  302.                                 addLeftOverResPile(item.Location.X, item.Location.Y, "woodPile", Color.Brown)
  303.                             End If
  304.                         End If
  305.                     End If
  306.                 Next
  307.             End If
  308.         Next
  309.         updateDisplayHuamnProfile()
  310.     End Sub
  311.  
  312.     Private Sub displayMineRockButton(sender As Object, e As EventArgs)
  313.             For Each person In Controls.OfType(Of human)
  314.                 If person.Tag = "ready" Then
  315.                     action_button_collect.Hide()
  316.                     action_button_cut.Hide()
  317.                     action_button_pick_up.Hide()
  318.                     action_button_mine.Show()
  319.                     action_button_mine.Tag = sender.name
  320.                 End If
  321.             Next
  322.         End Sub
  323.  
  324.     Private Sub mineRock(ByVal sender As Object, ByVal e As EventArgs) Handles action_button_mine.Click
  325.         For Each item In placedObjects
  326.             If item.Name = sender.tag Then
  327.                 For Each person In Controls.OfType(Of human)
  328.                     If person.Tag = "ready" Then
  329.                         If person.hasEnergy(2) = True Then
  330.                             sender.hide()
  331.                             Controls.Remove(item)
  332.                             person.Location = New Point(item.Location.X, item.Location.Y)
  333.                             person.changeEnergyLevel -= 2
  334.                             If person.setTypeOfResStored <> 1 And person.setTypeOfResStored <> 2 And person.setTypeOfResStored <> 3 Or person.setTypeOfResStored = 2 Then
  335.                                 person.setTypeOfResStored = 2
  336.                                 If person.humanStorage <= person.getHumanStorageLimit - 10 Then
  337.                                     person.setTypeOfResStored = 2
  338.                                     person.humanStorage = 10
  339.                                 Else
  340.                                     addLeftOverResPile(item.Location.X, item.Location.Y, "rockPile", Color.DarkGray)
  341.                                 End If
  342.                             Else
  343.                                 addLeftOverResPile(item.Location.X, item.Location.Y, "rockPile", Color.DarkGray)
  344.                             End If
  345.                         End If
  346.                     End If
  347.                 Next
  348.             End If
  349.         Next
  350.         updateDisplayHuamnProfile()
  351.     End Sub
  352.  
  353.     Private Sub displayCollectTreasureButton(sender As Object, e As EventArgs)
  354.         For Each person In Controls.OfType(Of human)
  355.             If person.Tag = "ready" Then
  356.                 action_button_cut.Hide()
  357.                 action_button_mine.Hide()
  358.                 action_button_pick_up.Hide()
  359.                 action_button_collect.Show()
  360.                 action_button_collect.Tag = sender.name
  361.             End If
  362.         Next
  363.     End Sub
  364.  
  365.     Private Sub collectTreasure(ByVal sender As Object, ByVal e As EventArgs) Handles action_button_collect.Click
  366.             For Each item In placedObjects
  367.                 If item.Name = sender.tag Then
  368.                     For Each person In Controls.OfType(Of human)
  369.                         If person.Tag = "ready" Then
  370.                             If person.hasEnergy(2) = True Then
  371.                                 sender.hide()
  372.                                 Controls.Remove(item)
  373.                                 person.Location = New Point(item.Location.X, item.Location.Y)
  374.                                 person.changeEnergyLevel -= 2
  375.                                 If person.setTypeOfResStored <> 1 And person.setTypeOfResStored <> 2 And person.setTypeOfResStored <> 3 Or person.setTypeOfResStored = 3 Then
  376.                                     person.setTypeOfResStored = 3
  377.                                     If person.humanStorage <= person.getHumanStorageLimit - 10 Then
  378.                                         person.setTypeOfResStored = 3
  379.                                         person.humanStorage = 10
  380.                                     Else
  381.                                         addLeftOverResPile(item.Location.X, item.Location.Y, "goldPile", Color.LightYellow)
  382.                                     End If
  383.                                 Else
  384.                                     addLeftOverResPile(item.Location.X, item.Location.Y, "goldPile", Color.LightYellow)
  385.                                 End If
  386.                             End If
  387.                         End If
  388.                     Next
  389.                 End If
  390.             Next
  391.             updateDisplayHuamnProfile()
  392.         End Sub
  393.  
  394.     Private Sub addLeftOverResPile(locationx, locationy, tagName, colour)
  395.         Dim pile As New Button
  396.         AddHandler pile.Click, AddressOf pileClick
  397.         pile.Location = New Point(locationx, locationy)
  398.         pile.Size = New Size(20, 20)
  399.         pile.BackColor = colour
  400.         pile.ForeColor = Color.DarkGreen
  401.         pile.FlatStyle = FlatStyle.Flat
  402.         pile.Text = ""
  403.         pile.Visible = True
  404.         pile.BringToFront()
  405.         pileCount += 1
  406.         pile.Name = (tagName & pileCount).ToString
  407.         pile.Tag = tagName
  408.         Controls.Add(pile)
  409.         resPiles.Add(pile)
  410.     End Sub
  411.  
  412.     Dim pilePickUpLocationX As Integer
  413.     Dim pilePickUpLocationY As Integer
  414.     Private Sub pileClick(sender As Object, e As EventArgs)
  415.         For Each person In Controls.OfType(Of human)
  416.             If person.Tag = "ready" Then
  417.                 action_button_cut.Hide()
  418.                 action_button_mine.Hide()
  419.                 action_button_collect.Hide()
  420.                 action_button_pick_up.Show()
  421.                 action_button_pick_up.BringToFront()
  422.                 action_button_pick_up.Tag = sender.name
  423.                 pilePickUpLocationX = sender.location.x
  424.                 pilePickUpLocationY = sender.location.y
  425.             End If
  426.         Next
  427.     End Sub
  428.  
  429.     Private Sub pickUpPile(ByVal sender As Object, ByVal e As EventArgs) Handles action_button_pick_up.Click
  430.         Dim storageValue1 As Integer
  431.         Dim storageValue2 As Integer
  432.         Dim storageValue3 As Integer
  433.         Select Case sender.tag.substring(0, 8)
  434.             Case "woodPile"
  435.                 storageValue1 = 1
  436.                 storageValue2 = 2
  437.                 storageValue3 = 3
  438.             Case "rockPile"
  439.                 storageValue1 = 2
  440.                 storageValue2 = 1
  441.                 storageValue3 = 3
  442.             Case "goldPile"
  443.                 storageValue1 = 3
  444.                 storageValue2 = 1
  445.                 storageValue3 = 2
  446.         End Select
  447.         For Each item In resPiles
  448.             If item.Name = sender.tag Then
  449.                 For Each person In Controls.OfType(Of human)
  450.                     If person.Tag = "ready" Then
  451.                         If person.hasEnergy(2) = True Then
  452.                             sender.hide()
  453.                             person.Location = New Point(pilePickUpLocationX, pilePickUpLocationY)
  454.                             person.changeEnergyLevel -= 2
  455.                             If person.setTypeOfResStored <> storageValue1 And person.setTypeOfResStored <> storageValue2 And person.setTypeOfResStored <> storageValue3 Or person.setTypeOfResStored = storageValue1 Then
  456.                                 If person.humanStorage <= person.getHumanStorageLimit - 10 Then
  457.                                     Me.Controls.Remove(item)
  458.                                     person.setTypeOfResStored = storageValue1
  459.                                     person.humanStorage = 10
  460.                                 End If
  461.                             End If
  462.                         End If
  463.                     End If
  464.                 Next
  465.             End If
  466.         Next
  467.         updateDisplayHuamnProfile()
  468.     End Sub
  469.  
  470.     Private Sub updateDisplayHuamnProfile()
  471.             Dim humanProfileName As String = ""
  472.             Dim humanProfileAge As String = ""
  473.             Dim humanProfileEnergyBar As String = ""
  474.             Dim humanProfileResourceType As String = ""
  475.             Dim humanProfileResourceAmount As String = ""
  476.             For Each person In Controls.OfType(Of human)
  477.                 If person.Tag = "ready" Then
  478.                     person.setHumanProfileDetails(humanProfileName, humanProfileAge, humanProfileEnergyBar, humanProfileResourceType, humanProfileResourceAmount)
  479.                     human_profile_name.Text = humanProfileName
  480.                     human_profile_age.Text = humanProfileAge
  481.                     human_profile_energy.Text = humanProfileEnergyBar
  482.                     human_profile_resource_type.Text = humanProfileResourceType
  483.                     human_profile_resource_amount.Text = humanProfileResourceAmount
  484.                 End If
  485.             Next
  486.             human_profile_name.Visible = True
  487.             human_profile_age.Visible = True
  488.             human_profile_energy.Visible = True
  489.             human_profile_resource_type.Visible = True
  490.             human_profile_resource_amount.Visible = True
  491.         End Sub
  492.  
  493.     Private Sub resourceTimerTick(sender As Object, e As EventArgs) Handles resource_timer.Tick
  494.         For Each person In Controls.OfType(Of human)
  495.             food -= 1
  496.             food_amount_text.Text = "food = " & food
  497.         Next
  498.     End Sub
  499.  
  500.     Private Sub human_energy_level_timer_Tick(sender As Object, e As EventArgs) Handles human_energy_level_timer.Tick
  501.         For Each person In Controls.OfType(Of human)
  502.             If person.changeEnergyLevel < 10 Then
  503.                 person.changeEnergyLevel += 1
  504.                 updateDisplayHuamnProfile()
  505.             End If
  506.         Next
  507.     End Sub
  508.  
  509. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement