-
Notifications
You must be signed in to change notification settings - Fork 4
/
ClassBasics.ps1
51 lines (42 loc) · 1.18 KB
/
ClassBasics.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
return "This is a walkthrough demo file, not a script."
Class MyStarShip {
#properties
[string]$Name
[int]$Crew
[datetime]$ManufactureDate
[int]$QuantumTorpedoCount
#methods
#must define what they write to the pipeline, if anything
[void]FireTorpedo() {
Write-Host "Fire!" -ForegroundColor Red
$this.QuantumTorpedoCount--
}
[void]FireTorpedo([int]$Count) {
Write-Host "Fire $Count!!" -ForegroundColor Red
$this.QuantumTorpedoCount-=$Count
}
[timespan]GetAge() {
$age = (Get-Date).AddYears(123) - $this.ManufactureDate
#methods must use RETURN is writing something to the pipeline
return $age
}
#constructors
myStarShip([string]$Name,[int]$CrewSize) {
$this.name = $Name
$this.Crew = $CrewSize
$this.QuantumTorpedoCount = 50
$this.ManufactureDate = (Get-Date).AddYears(120).AddMonths(4).AddDays(3)
}
}
[MyStarShip]::new
[MyStarShip]::new("Proxima",20)
$ship = new-object -TypeName MyStarShip -ArgumentList "USS Snover",100
$ship
$ship | get-member
$ship.GetAge()
$ship.GetAge().ToString()
$ship
$ship.FireTorpedo()
$ship.FireTorpedo(3)
$ship.QuantumTorpedoCount
#have more fun with starships at https://github.com/jdhitsolutions/myStarShip