[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/pacmacs 0eeb82ebc9 425/472: Merge pull request #193 from c
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/pacmacs 0eeb82ebc9 425/472: Merge pull request #193 from codingteam/rework-nick-after-death-134 |
Date: |
Thu, 6 Jan 2022 21:59:45 -0500 (EST) |
branch: elpa/pacmacs
commit 0eeb82ebc9ad2e2110513c62b49b5063de4f3fa9
Merge: 98816141d5 2e881d27e0
Author: Alexey Kutepov <reximkut@gmail.com>
Commit: Alexey Kutepov <reximkut@gmail.com>
Merge pull request #193 from codingteam/rework-nick-after-death-134
Rework nick after death
---
pacmacs-score.el | 34 ++++++++++++------------
pacmacs.el | 66 ++++++++++++++++++++++++++++++++++++++++------
test/pacmacs-score-test.el | 18 ++++++++-----
test/pacmacs-test.el | 31 ++++++++++++++++++++++
4 files changed, 118 insertions(+), 31 deletions(-)
diff --git a/pacmacs-score.el b/pacmacs-score.el
index 75912014b2..17f50f0588 100644
--- a/pacmacs-score.el
+++ b/pacmacs-score.el
@@ -36,6 +36,8 @@
(require 'dash)
(require 'dash-functional)
+(defconst pacmacs--max-score-nick-size 8)
+(defconst pacmacs--max-score-table-size 10)
(defconst pacmacs--score-file-name "~/.pacmacs-score")
(defconst pacmacs--score-buffer-name "*Pacmacs Score*")
@@ -70,31 +72,29 @@
(-lambda ((_ . score1) (_ . score2))
(> score1 score2))))
+(defun pacmacs--position-of-new-score (score-table new-score)
+ (->> score-table
+ (-take-while (-lambda ((_ . score)) (< new-score score)))
+ (length)))
+
(defun pacmacs--render-score-table (score-table)
- (let ((max-nickname-length
- (->> score-table
- (-map (-compose #'length #'car))
- (apply #'max))))
- (insert "Best Scores:\n------------\n")
- (-each score-table
- (-lambda ((nickname . score))
- (insert (format "%s%s %d\n"
- nickname
- (make-string (- max-nickname-length
- (length nickname))
- ?\s)
- score))))))
+ (-each score-table #'pacmacs--render-score-record))
(defun pacmacs--add-entry-to-score-table (nickname score)
(->> (pacmacs--read-score-table)
(cons (cons nickname score))
(pacmacs--sort-score-table)
- (-take 10)
+ (-take pacmacs--max-score-table-size)
(pacmacs--write-score-table)))
-(defun pacmacs--register-new-score (score)
- (let ((nickname (read-from-minibuffer "Nickname: ")))
- (pacmacs--add-entry-to-score-table nickname score)))
+(defun pacmacs--render-score-record (record)
+ (-let (((nickname . score) record))
+ (insert (format "%s%s %d\n"
+ nickname
+ (make-string (- pacmacs--max-score-nick-size
+ (length nickname))
+ ?\s)
+ score))))
(provide 'pacmacs-score)
diff --git a/pacmacs.el b/pacmacs.el
index a320969594..2e5df3a255 100644
--- a/pacmacs.el
+++ b/pacmacs.el
@@ -39,6 +39,8 @@
(require 'cl-lib)
(require 'dash)
(require 'f)
+(require 'widget)
+(require 'wid-edit)
(require 'pacmacs-anim)
(require 'pacmacs-board)
@@ -52,6 +54,7 @@
(defconst pacmacs-tick-duration-ms 100)
(defconst pacmacs--ghost-blinking-threshold-ms 2500)
(defconst pacmacs--ghost-terrified-time-ms 5000)
+(defconst pacmacs--score-table-render-offset 3)
(defvar pacmacs-debug-output nil)
@@ -100,6 +103,8 @@
(defun pacmacs--initialize-game (tick-function)
(pacmacs--clear-wall-tiles-cache)
+ (when (get-buffer pacmacs-buffer-name)
+ (kill-buffer pacmacs-buffer-name))
(switch-to-buffer pacmacs-buffer-name)
(buffer-disable-undo pacmacs-buffer-name)
@@ -116,6 +121,7 @@
tick-function))))
(defun pacmacs-destroy ()
+ "Destroys the game timer without killing the game buffer."
(when pacmacs-timer
(cancel-timer pacmacs-timer)
(setq pacmacs-timer nil)))
@@ -392,7 +398,8 @@
(pacmacs--load-next-level)
(pacmacs--switch-to-prepare-state)))))
- (pacmacs--render-state))
+ (when (not (equal pacmacs-game-state 'game-over))
+ (pacmacs--render-state)))
(defun pacmacs--step-ghosts ()
(dolist (ghost pacmacs--ghosts)
@@ -552,10 +559,58 @@
(plist-put ghost :current-animation
(pacmacs-load-anim "Red-Ghost-Win"))))
+(defun pacmacs--align-score-record-nickname (nickname)
+ (let* ((padding-size (max 0 (- pacmacs--max-score-nick-size
+ (length nickname))))
+ (padding (make-string padding-size ?\s)))
+ (concat nickname padding)))
+
+(defun pacmacs--make-submit-nickname-action (score)
+ (lambda (widget &optional event)
+ (ignore event)
+ (let ((nickname (widget-value widget)))
+ (pacmacs--add-entry-to-score-table nickname score)
+ (widget-value-set widget (pacmacs--align-score-record-nickname nickname))
+ (widget-delete widget))))
+
(defun pacmacs--switch-to-game-over-state ()
- (setq pacmacs-game-state 'game-over)
(pacmacs--load-map "game-over")
- (pacmacs--register-new-score pacmacs-score))
+ (pacmacs-destroy)
+ (setq pacmacs-game-state 'game-over)
+ (pacmacs--render-state)
+
+ (fundamental-mode)
+ (read-only-mode 0)
+
+ (with-current-buffer pacmacs-buffer-name
+ (goto-char (point-max))
+
+ (let* ((score-table (pacmacs--sort-score-table
+ (pacmacs--read-score-table)))
+ (new-score-position (pacmacs--position-of-new-score
+ score-table
+ pacmacs-score)))
+ (if (< new-score-position pacmacs--max-score-table-size)
+ (progn
+ (->> score-table
+ (-take new-score-position)
+ (pacmacs--render-score-table))
+ (widget-create 'editable-field
+ :size pacmacs--max-score-nick-size
+ :action (pacmacs--make-submit-nickname-action
pacmacs-score))
+ (insert (format " %d\n" pacmacs-score))
+ (->> score-table
+ (-drop new-score-position)
+ (pacmacs--render-score-table))
+
+ (plist-bind ((height :height))
+ pacmacs--object-board
+ (goto-char (point-min))
+ (forward-line (+ height pacmacs--score-table-render-offset
new-score-position))))
+ (pacmacs--render-score-table score-table)
+ (goto-char (point-min)))
+ (use-local-map widget-keymap)
+ (widget-setup))))
(defun pacmacs--switch-to-play-state ()
(setq pacmacs-game-state 'play)
@@ -610,11 +665,6 @@
(dotimes (i pacmacs-lives)
(ignore i)
(pacmacs--render-life-icon))
-
- (when (equal pacmacs-game-state 'game-over)
- (-> (pacmacs--read-score-table)
- (pacmacs--sort-score-table)
- (pacmacs--render-score-table)))
(goto-char 0))))
(defun pacmacs--unpaused-play-state-p ()
diff --git a/test/pacmacs-score-test.el b/test/pacmacs-score-test.el
index e22426e26b..85b63f2786 100644
--- a/test/pacmacs-score-test.el
+++ b/test/pacmacs-score-test.el
@@ -15,13 +15,19 @@
("hello" . 30)
("world" . 20)
("bar" . 10)))
- (expected-string (concat "Best Scores:\n"
- "------------\n"
- "foo 40\n"
- "hello 30\n"
- "world 20\n"
- "bar 10\n")))
+ (expected-string (concat "foo 40\n"
+ "hello 30\n"
+ "world 20\n"
+ "bar 10\n")))
(with-temp-buffer
(pacmacs--render-score-table input-table)
(should (equal expected-string
(buffer-string))))))
+
+(ert-deftest pacmacs--position-of-new-score-test ()
+ (let ((score-table '(("hello" . 40)
+ ("world" . 30)
+ ("foo" . 20)
+ ("bar" . 10)))
+ (new-score 25))
+ (should (= 2 (pacmacs--position-of-new-score score-table new-score)))))
diff --git a/test/pacmacs-test.el b/test/pacmacs-test.el
index 1b1e08c238..697fcb2c0c 100644
--- a/test/pacmacs-test.el
+++ b/test/pacmacs-test.el
@@ -126,3 +126,34 @@
(should (null pacmacs--ghosts))
(should (= 11 (length pacmacs--terrified-ghosts))))))
+
+(ert-deftest pacmacs--align-score-record-nickname-test ()
+ (let ((pacmacs--max-score-nick-size 5)
+ (nickname "abc"))
+ (should (equal "abc "
+ (pacmacs--align-score-record-nickname nickname)))))
+
+(ert-deftest pacmacs--make-submit-nickname-action-test ()
+ (with-mock
+ (mock (widget-value 'widget) => 'nickname)
+ (mock (pacmacs--add-entry-to-score-table 'nickname 'score))
+ (mock (pacmacs--align-score-record-nickname 'nickname) => 'aligned-nickname)
+ (mock (widget-value-set 'widget 'aligned-nickname))
+ (mock (widget-delete 'widget))
+ (funcall (pacmacs--make-submit-nickname-action 'score)
+ 'widget
+ 'khooy)))
+
+(ert-deftest pacmacs--make-wall-cell-test ()
+ (should (equal (list :current-animation nil
+ :row 10
+ :column 20
+ :type 'wall)
+ (pacmacs--make-wall-cell 10 20))))
+
+(ert-deftest pacmacs--step-ghosts-test ()
+ (let ((pacmacs--ghosts (make-list 10 'ghost)))
+ (with-mock
+ (mock (pacmacs--track-object-to-player 'ghost) :times 10)
+ (mock (pacmacs--step-object 'ghost) :times 10)
+ (pacmacs--step-ghosts))))
- [nongnu] elpa/pacmacs 3e25c67590 345/472: Add script for semi-automatic ATT measuring, (continued)
- [nongnu] elpa/pacmacs 3e25c67590 345/472: Add script for semi-automatic ATT measuring, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 70d381a0ca 362/472: UT for terrify-all-ghosts (#173), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs dec42c790d 374/472: Update the screenshots, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 10705b45c5 376/472: Rename bits-to-xpm to wall-tile-to-xpm (#138), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs a5583b6255 377/472: Fix wall-tile-to-xpm UT (#138), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 93f031ae4e 382/472: Fix create-wall-tile UT (#138), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 2c7e23070b 380/472: Fix put-vertical-bar UT (#138), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs dc14097468 400/472: Add emacs mode for game over (#134), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 98816141d5 398/472: Merge pull request #189 from codingteam/remove-make-terrified-ghost, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 30442797d3 404/472: Add consts for nick and table sizes (#134), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 0eeb82ebc9 425/472: Merge pull request #193 from codingteam/rework-nick-after-death-134,
ELPA Syncer <=
- [nongnu] elpa/pacmacs ce1054fab3 433/472: Remove redundant find-resource-file call (#191), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 21a99294ad 440/472: Add score sign (#203), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 9fd3009e5a 442/472: Merge pull request #206 from codingteam/bug/quit-game-over-with-q-202, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 95cce606fd 024/472: Support for Aseprite animation format. Close #16, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 09aa49c6b0 065/472: UTs for pacman-image. Close #52, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs ee893d28bd 180/472: Add module for recording action (#115), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 95c046205a 187/472: Compilation warnings as errors (#123), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs fe40eb20c7 190/472: Merge branch 'coverage-dropped-124' (#124), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 8e36b66a6f 199/472: Make object-board contain list of object (#126), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 6b43cde65d 223/472: Add big pill game object (#81), ELPA Syncer, 2022/01/06