-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPowerSneks_GameSettings.ps1
167 lines (166 loc) · 30 KB
/
PowerSneks_GameSettings.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# =======================================START=OF=COMPILER==========================================================|
# The Following Code was added by AP-Compiler Version [1.4] To Make this program independent of AP-Core Engine
# GitHub: https://github.com/avdaredevil/AP-Compiler
# ==================================================================================================================|
$Script:PSHell=$(if($PSHell){$PSHell}elseif($PSScriptRoot){$PSScriptRoot}else{"."});
function B64 {param([Parameter(ValueFromPipeline=$true)][String]$Text, [ValidateSet("UTF8","Unicode")][String]$Encoding = "UTF8")
[System.Text.Encoding]::$Encoding.GetString([System.Convert]::FromBase64String($Text))}
# This syntax is to prevent AV's from misclassifying this as anything but innocuous
& (Get-Alias iex) (B64 "ZnVuY3Rpb24gV3JpdGUtQVAgew0KICAgIFtDbWRsZXRCaW5kaW5nKCldDQogICAgcGFyYW0oW1BhcmFtZXRlcihWYWx1ZUZyb21QaXBlbGluZT0kdHJ1ZSwgTWFuZGF0b3J5PSRUcnVlKV0kVGV4dCxbU3dpdGNoXSROb1NpZ24sW1N3aXRjaF0kUGxhaW5UZXh0LFtWYWxpZGF0ZVNldCgiQ2VudGVyIiwiUmlnaHQiLCJMZWZ0IildW1N0cmluZ10kQWxpZ249J0xlZnQnLFtTd2l0Y2hdJFBhc3NUaHJ1KQ0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iQ2VudGVyIiwiUmlnaHQiLCJMZWZ0IildW1N0cmluZ10kQWxpZ249J0NlbnRlcicpDQoNCiAgICBpZiAoJFRleHQuY291bnQgLWd0IDEpIHsNCiAgICAgICAgJGFucyA9IEAoKQ0KICAgICAgICBmb3JlYWNoICgkbG4gaW4gJFRleHQpIHskQW5zICs9IEFsaWduLVRleHQgJGxuICRBbGlnbn0NCiAgICAgICAgcmV0dXJuICgkYW5zKQ0KICAgIH0gZWxzZSB7DQogICAgICAgICRXaW5TaXplID0gW2NvbnNvbGVdOjpCdWZmZXJXaWR0aA0KICAgICAgICAkQ2xlYW5UZXh0U2l6ZSA9IChTdHJpcC1Db2xvckNvZGVzICgiIiskVGV4dCkpLkxlbmd0aA0KICAgICAgICBpZiAoJENsZWFuVGV4dFNpemUgLWdlICRXaW5TaXplKSB7DQogICAgICAgICAgICAkQXBwZW5kZXIgPSBAKCIiKTsNCiAgICAgICAgICAgICRqID0gMA0KICAgICAgICAgICAgZm9yZWFjaCAoJHAgaW4gMC4uKCRDbGVhblRleHRTaXplLTEpKXsNCiAgICAgICAgICAgICAgICBpZiAoKCRwKzEpJSR3aW5zaXplIC1lcSAwKSB7JGorKzskQXBwZW5kZXIgKz0gIiJ9DQogICAgICAgICAgICAgICAgIyAiIiskaisiIC0gIiskcA0KICAgICAgICAgICAgICAgICRBcHBlbmRlclskal0gKz0gJFRleHQuY2hhcnMoJHApDQogICAgICAgICAgICB9DQogICAgICAgICAgICByZXR1cm4gKEFsaWduLVRleHQgJEFwcGVuZGVyICRBbGlnbikNCiAgICAgICAgfSBlbHNlIHsNCiAgICAgICAgICAgIGlmICgkQWxpZ24gLWVxICJDZW50ZXIiKSB7DQogICAgICAgICAgICAgICAgcmV0dXJuICgiICIqW21hdGhdOjp0cnVuY2F0ZSgoJFdpblNpemUtJENsZWFuVGV4dFNpemUpLzIpKyRUZXh0KQ0KICAgICAgICAgICAgfSBlbHNlaWYgKCRBbGlnbiAtZXEgIlJpZ2h0Iikgew0KIC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rdXAgPSAiJEZvbGRlci8kRmlsZSINCiAgICAgICAgICAgIGlmICgkSXNWZXJib3NlKSB7V3JpdGUtQVAgIipDaGVja2luZyBbJExvb2t1cF0ifQ0KICAgICAgICAgICAgaWYgKCEoVGVzdC1QYXRoIC1QYXRoVHlwZSBMZWFmICRMb29rdXApKSB7Y29udGludWV9DQogICAgICAgICAgICBSZXNvbHZlLVBhdGggJExvb2t1cCB8ICUgUGF0aA0KICAgICAgICAgICAgaWYgKCEkQWxsKSB7cmV0dXJufQ0KICAgICAgICB9IGVsc2Ugew0KICAgICAgICAgICAgZm9yZWFjaCAoJEV4dGVuc2lvbiBpbiAoR2V0LVBhdGggLVBhdGhWYXIgUEFUSEVYVCkpIHsNCiAgICAgICAgICAgICAgICAkTG9va3VwID0gIiRGb2xkZXIvJEZpbGUkRXh0ZW5zaW9uIg0KICAgICAgICAgICAgICAgIGlmICgkSXNWZXJib3NlKSB7V3JpdGUtQVAgIipDaGVja2luZyBbJExvb2t1cF0ifQ0KICAgICAgICAgICAgICAgIGlmICghKFRlc3QtUGF0aCAtUGF0aFR5cGUgTGVhZiAkTG9va3VwKSkge2NvbnRpbnVlfQ0KICAgICAgICAgICAgICAgIFJlc29sdmUtUGF0aCAkTG9va3VwIHwgJSBQYXRoDQogICAgICAgICAgICAgICAgaWYgKCEkQWxsKSB7cmV0dXJufQ0KICAgICAgICAgICAgfQ0KICAgICAgICB9DQogICAgfQ0KfQo=")
# ========================================END=OF=COMPILER===========================================================|
#= INIT =======================================================================================|
[int[]]$Script:Win = @(([Console]::WindowHeight-2), [Console]::WindowWidth)
$Script:TitleBkp = [Console]::Title
$Script:BkColBkp = [Console]::BackGroundColor
#= SETTINGS ===================================================================================|
$Script:SaveFile = "$env:APPDATA\AP-PowerSneks\AP-PowerSneks.Map.Save"
$Script:CharMap = Make-ReadOnly @{
Space = ' '
Symbol = Make-ReadOnly @{
Food = "♣"
Wall = "█"
Space = " "
}
SnakeMoves = @("▪","▪","▪","▪")
Wall = Make-ReadOnly @{
Top = "▀"
Bottom = "▄"
Vertical = "█"
}
Laser = "█"
}
$Script:SymbolMap = @{
Wall = 'W'
Food = 'F'
Space = ' '
}
$Script:ColorMap = Make-ReadOnly @{
Space = 'Black'
Wall = 'DarkRed'
Food = 'Yellow'
Laser = 'Yellow'
Game = Make-ReadOnly @{
Background = 'Black' #[Console]::BackgroundColor
ConsoleText = 'Yellow'
ConsoleTextBg = 'Red'
ConsoleBorder = 'DarkRed'
}
Snake = Make-ReadOnly @{
Head = "DarkGreen"
Body = "Red"
}
}
$Script:GameKnobs = Make-ReadOnly @{
ScoreIncr = 10
Obstruction = Make-ReadOnly @{
MaxWidth = 2/5 # 4/5 is hella fun!
MaxHeight = 2/5
SnakeDistanceRatio = 5/120 # How Many blocks away should the Snake Spawn from an Obstruction
}
Laser = Make-ReadOnly @{
PrintDelay = 15 # Laser draw delay per block in ms
InitialCount = 1 # Starting Count for lasers
AquireCost = 3 # How many food items to eat before acquiring laser
BombRadius = @(6, 3) # Radius for explosion near snake
}
Sleep = Make-ReadOnly @{
Tick = 40
SlowTime = 80 # Additional delay per tick
AdjPerFood = -.15
CursorRatio = 70/35 # Cursor height:width ratio
}
SnakeStartSz = 5
SlowTimeDeteriorate = 4/5 # SlowTime preservation per tick
}
$Script:LIB = Make-ReadOnly @{
Cell = [Management.Automation.Host.BufferCell]
CellType = [Management.Automation.Host.BufferCellType]
Rect = [Management.Automation.Host.Rectangle]
Coord = [System.Management.Automation.Host.Coordinates]
}
$Script:MapToSymbol = @{}
$Script:SymbolMap.getEnumerator() | % {
$Script:MapToSymbol[$_.Value] = $_.Key
}
$Script:MapToSymbol = Make-ReadOnly $Script:MapToSymbol
#= MAIN-GAME ==================================================================================|
function Get-PlayerSpawn([Game]$Game) {
$c = @(-1, -1)
$tmout = 100
$H, $W = $(gv win | % Value)
while (1) {
$x,$y = $c = $Game.getEmptyCoord()
if (--$tmout -gt 0 -and $x -lt (.1*$W) -or $x -gt (.9*$W) -or $y -lt (.45*$H) -or $y -gt (.95*$H)) {continue}
break
}
return $c
}
function Start-Game([ScriptBlock]$CustomHook = {}) {
[Console]::CursorVisible = $False
cls
$Map = $null
if (($MapFile -ne '/*\') -and (Test-path -type leaf $MapFile)) {
$Map = $MapFile
} elseif ($LoadDefaultSave) {
$Map = $SaveFile
}
$Game = [Game]::New($Map, $Trail)
if (!$Game.Players -and ($Snakes -or $Bots)) {
if ($Snakes) {
1..$Snakes | % {
$c = Get-PlayerSpawn $Game
$Game.attachPlayer([Snake]::new($c, $Game))
}
}
if ($Bots) {
1..$Bots | % {
$c = Get-PlayerSpawn $Game
$Game.attachPlayer([SnakeBot]::new($c, $Game))
}
}
}
$Game.Debug = gv Debug | % Value
$Game.Run({
param($Tick)
try {
if (!($Tick % 500)) {
$c = $Game.getEmptyCoord()
# Eventually a boss maybe?
} elseif (!($Tick % 100)) {
$c = $Game.getEmptyCoord()
$Game.attachLiveObject([GoldenSnitch]::New($c, $Game))
}
$CustomHook.Invoke($Game, $Tick)
} catch {
Write-Host Error ($_ | Out-String)
}
}.GetNewClosure())
}
function Write-ToPos ([string]$str, [int]$x = 0, [int]$y = 0, [ConsoleColor]$bgc = [console]::BackgroundColor, [ConsoleColor]$fgc = [Console]::ForegroundColor) {
if ($x -lt 0 -or $y -lt 0 -or $x -gt [Console]::WindowWidth -or $y -gt [Console]::WindowHeight) {return}
try {
$Host.UI.RawUI.SetBufferContents(
$Lib.Rect::new($x, ($WTY+$y), $x, $y),
$Lib.Cell::new(
$str[0],
$fgc,
$bgc,
$Lib.CellType::Complete))
} catch {}
}
function Modify-Coord ([int]$x, [int]$y, [Direction]$bgc, [int]$Scale = 1) {
switch ([int]$bgc) {
0 {$x-=$Scale}
1 {$y-=$Scale}
2 {$x+=$Scale}
3 {$y+=$Scale}
}
return @($x,$y)
}
function Place-BufferedContent($Text, $x, $y, [ConsoleColor]$ForegroundColor=[Console]::ForegroundColor, [ConsoleColor]$BackgroundColor=[Console]::BackgroundColor) {
$crd = [Management.Automation.Host.Coordinates]::new($x,$y)
$b = $Host.UI.RawUI
$arr = $b.NewBufferCellArray(@($Text), $ForegroundColor, $BackgroundColor)
$x = [Console]::BufferWidth-1-$Text.length
$b.SetBufferContents($crd, $arr)
}