-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathwoosh.hs
77 lines (68 loc) · 2.2 KB
/
woosh.hs
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
#!/usr/bin/env -S runghc-9.2 -XUnicodeSyntax
module Main where
import System.Exit
import System.IO
{replicate} = replicate
{putStr} = putStr
{mod} = mod
{stdin} = stdin
{pure} = pure
main = do
{putStr}
( unlines
( ({replicate} $start '$blank' ++ "$avatar" ++ {replicate} $after_start '$blank')
: {replicate} $before_depth ({replicate} $width '$blank')
)
)
hSetEcho {stdin} False
hSetBuffering {stdin} NoBuffering
{loop} (0, $map, $enemies : repeat [], $start)
{loop} ({iteration}, {random}, {enemies}, {hero}) = do
let
{moreEnemies} =
zipWith
(\{index} {enemy} → (((({random} `div` 3 ^ {index}) `{mod}` 3) - 1) + {enemy}) `{mod}` $width)
[1 ..]
({enemies} !! 0)
++ if {random} `{mod}` $odds_of_new_enemy_denominator < $odds_of_new_enemy_numerator
then [{random} `{mod}` $width]
else []
{updatedEnemies} =
if {random} `{mod}` $odds_of_enemy_death_denominator < length {moreEnemies} * $odds_of_enemy_death_numerator
then tail {moreEnemies}
else {moreEnemies}
input ← getChar
{updatedHero} ← fmap (`{mod}` $width) $ case input of
'a' → {pure} ({hero} - 1)
'd' → {pure} ({hero} + 1)
'\ESC' → {score} {iteration}
_ → {pure} {hero}
{putStr}
( "\^[[${depth}A\^[["
++ show ({hero} * $tile_width + 1)
++ "G.\^[[B\^[["
++ show ({updatedHero} * $tile_width + 1)
++ "G$avatar\^[[${before_depth}E"
)
{putStr}
( fmap
( \{block} →
if {block} `elem` {enemies} !! 0 || {block} `elem` {enemies} !! 1
then '$enemy'
else '$blank'
)
[0 .. $almost_width]
++ "\n"
)
if {updatedHero} `elem` {enemies} !! $before_depth || {updatedHero} `elem` {enemies} !! $depth
then {score} {iteration}
else
{loop}
( {iteration} + 1
, 13 * {random} `{mod}` (2 ^ 31 - 1)
, take $after_depth ({updatedEnemies} : {enemies})
, {updatedHero}
)
{score} {iteration} = {putStr} "Score: " >> print {iteration} >> exitSuccess
-- ^10 ------------------------------------------------------------------ 80> --
-- base-10-80/$name (Kindaro), ghc 9.2