使用Windows Power Shell写“人生重开模拟器”

使用Windows Power Shell写“人生重开模拟器”

# 人生重开模拟器(PowerShell 版)

# 生成随机属性函数

function Generate-Traits {

return @{ "体质" = Get-Random -Minimum 1 -Maximum 10

"智力" = Get-Random -Minimum 1 -Maximum 10

"魅力" = Get-Random -Minimum 1 -Maximum 10

"财富" = Get-Random -Minimum 1 -Maximum 10

"寿命" = Get-Random -Minimum 50 -Maximum 100 }

}

# 显示角色信息函数

function Show-Traits ($traits) {

Write-Host "你的初始属性:"

$traits.GetEnumerator() | ForEach-Object { Write-Host "$($_.Key): $($_.Value)" }

}

# 进行人生模拟函数

function Simulate-Life ($traits) {

$age = 0

Write-Host "你的人生开始了……"

while ($age -lt $traits["寿命"]) {

$age++

$event = Get-Random @("学习新技能", "遇到人生低谷", "结识新朋友", "获得升职", "经历经济危机", "健康出现问题", "有了孩子", "中了彩票", "旅行探险")

Write-Host "[$age 岁] $event"

Start-Sleep -Milliseconds 500 # 增加沉浸感

}

Write-Host "你在 $age 岁时走完了人生旅程。愿你在下次重开时拥有更好的人生!"

}

# 运行人生模拟器

$traits = Generate-Traits

Show-Traits $traits

Simulate-Life $traits