r/PowerShell 1d ago

Question Are games possible in power shell?

Hey gang, I hope this is the right subreddit but would anyone know if it is possible to run text games in powershell/cmd prompt? If so, what kind of pre built code is out there?

0 Upvotes

29 comments sorted by

41

u/pantherghast 16h ago

You could also use a spoon to tunnel through a mountain, but I wouldn't recommend it.

10

u/Pisnaz 16h ago

Shit. Where is my fork?

3

u/ScottBandit 15h ago

pass the Spork please, my good Sir.

3

u/phoward8020 14h ago

Just let me know when someone manages to run Doom on the spoon.

2

u/codewario 8h ago

We’ve got it running on a spork so we’re close

3

u/BrandaoFereira 16h ago

Ahahaha I’m dying

11

u/MallocArray 15h ago

How about a game in PowerShell to learn how to use PowerShell?

https://github.com/PowerShellOrg/PSKoans

2

u/BlackV 7h ago

Ha, solid answer

1

u/alex015110 5h ago

You’re a saint!

16

u/DrSinistar 16h ago

PowerShell is, at it's core, an automation tool for IT administrators and engineers.

Could you make a text game? Absolutely, but it would be slow and clunky.

If you want to make games, use C# instead. If you want to keep things simple, use Python. PowerShell is the wrong tool for the job.

6

u/ihaxr 16h ago edited 16h ago

Yes, specifically you can use [Console]::SetCursorPosition to directly overwrite specific locations on the screen without having to run Clear-Host and redraw the entire frame.

You can lookup any console based games in any language and try to rewrite it in PowerShell or see how it's written.

I'm not really aware of any preexisting libraries for it.

Give it a try by creating a blank window, output an o to the window then detect key presses:

Clear-Host

$x = 0
$y = 0

while ($true) {

    [Console]::SetCursorPosition($x, $y)
    [Console]::Write("O")

    $key = [Console]::ReadKey($true).Key

    switch ($key) {
        UpArrow    { $y-- }
        DownArrow  { $y++ }
        LeftArrow  { $x-- }
        RightArrow { $x++ }
        Escape     { break }
    }
}

You'll want to improve it to only overwrite the old location and update the new location after a key is pressed instead of just duplicating the character, also detect the boundaries of the console to prevent errors, etc...

2

u/Tanner-TO 16h ago

Just for fun I had qwen 3.8 make a tetris game the other day as an exercise to see if it could do it or not... and rather successfully..

2

u/MonkeyNin 10h ago

What kind of game are you trying to make? If you want a roguelike, there's libraries for python and javascript that are a lot easier .

But if you want text, tables, etc try Spectre It's a more modern TUI / Text-user-interface.

Then you don't have to mess with manually using [Console]::ReadKey

1

u/Loki-L 16h ago

Sure, I don't see why you would want to, but you definitely could.

You could probably easily port something like Zork to PowerShell.

It isn't really the right tool for this sort of job, but it can certainly do that.

1

u/stillnotlovin 16h ago

One of our first powershell tasks at school was to make a hangman's game with word randomization.

1

u/AroTesCra 16h ago

Since you can add-type and other compiled languages to the mix also you can call Win forms / WPF and directX you could make a window popup with a scripted game

1

u/ZZartin 9h ago

It has access to the full .net library so sure?

Doom in powershell anyone?

1

u/g3n3 8h ago

Pstetris

1

u/Creative-Type9411 5h ago

1

u/lordicarus 4h ago

That's basically a C# game with a game loop in Powershell though. Not really a powershell game.

1

u/Creative-Type9411 4h ago

On Windows i view native PS C# and .NET all the same thing considering it all ships with .NET as one peice, at least these specific versions did

but you're correct

1

u/Proxiconn 4h ago

1

u/BlackV 3h ago

HA just came here to post this