Created
June 2, 2019 15:52
-
-
Save gcentauri/dcebdf2ad63a6544a5369c97e8968c3b to your computer and use it in GitHub Desktop.
draft porc battle!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(setq *PlayerHealth NIL) | |
(setq *PlayerAgility NIL) | |
(setq *PlayerStrength NIL) | |
(setq *Monsters NIL) | |
(setq *MonsterBuilders NIL) | |
(setq *MonsterNum 6) | |
(de main () | |
(init-monsters) | |
(init-player) | |
(game-loop) | |
(when (dead?> *Player) | |
(prinl "You have been killed. Game over!") ) | |
(when (monsters-dead) | |
(prinl "Congratulations! You have slain all the porc!") ) | |
(bye) ) | |
(de game-loop () | |
(unless (or (dead?> *Player) (monsters-dead)) | |
(show> *Player) | |
(do (inc (/ (max 0 (get *Player 'agility)) 15) ) | |
(unless (monsters-dead) | |
(show-monsters) | |
(atk> *Player) ) ) | |
(prinl) | |
(mapcar | |
'((M) (or (dead?> M) (atk> M))) | |
*Monsters ) | |
(game-loop) ) ) | |
(de init-player () | |
(setq *PlayerHealth 30) | |
(setq *PlayerAgility 30) | |
(setq *PlayerStrength 30) | |
(setq *Player (new '(+Knight))) ) | |
(de init-monsters () | |
(do *MonsterNum (push '*Monsters (new '(+Slime)))) ) | |
(de show-monsters () | |
(prinl "The monsters gather near!") | |
(for (I . M) *Monsters (prin I ": ") (show> M)) ) | |
(de living-monsters () | |
(filter 'alive?> *Monsters) ) | |
(de monsters-dead () | |
(not (living-monsters)) ) | |
(de pick-monster () | |
(prin "Which monster to attack? ") | |
(get *Monsters (read)) ) | |
(de random-monster () | |
(get (living-monsters) (rand 1 (length (living-monsters)))) ) | |
(class +being) | |
# health | |
(dm alive?> () (> (: health) 0)) | |
(dm dead?> () (<= (: health) 0)) | |
(dm kill> () (=: health 0)) | |
(class +Knight +being) | |
(dm T () | |
(=: health *PlayerHealth) | |
(=: strength *PlayerStrength) | |
(=: agility *PlayerAgility) ) | |
(dm show> () | |
(prinl) | |
(prinl | |
"You are a valiant knight with a health of " (: health) ", " | |
"an agility of " (: agility) ", " | |
"and a strength of " (: strength) ) ) | |
(dm atk> () | |
(prinl) | |
(prin "Attack style: [s]tab [d]ouble swing [r]oundhouse: ") | |
(case (read) | |
(s (hit> (pick-monster) (+ 2 (rand 0 (>> 1 (: strength)))))) | |
(d (let (X (rand 0 (/ (: strength) 6))) | |
(prinl "Your double swing has a strength of " X) | |
(prinl) | |
(hit> (pick-monster) X) | |
(unless (monsters-dead) (hit> (pick-monster) X)) ) ) | |
(T (do (+ 1 (rand 0 (/ (: strength) 3))) | |
(unless (monsters-dead) | |
(hit> (random-monster) 1) ) ) ) ) ) | |
(class +Monster +being) | |
# health desc | |
(dm T () (=: health (rand 1 10))) | |
(dm show> () (prinl (if (dead?> This) (text "dead @1" (: desc)) (: desc)))) | |
(dm hit> (Dmg) | |
(dec (:: health) Dmg) | |
(if (dead?> This) | |
(prinl (text "You killed the @1" (: desc))) | |
(prinl (text "You hit the @1 for @2 health!" (: desc) Dmg)) ) ) | |
(class +Slime +Monster) | |
(dm T () (=: desc "gooey slime") (super)) | |
(dm atk> () (prinl "it goos all over you!")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment