[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/pacmacs a7b0530f65 152/472: Merge branch 'score-table-92'.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/pacmacs a7b0530f65 152/472: Merge branch 'score-table-92'. Close #92 |
Date: |
Thu, 6 Jan 2022 21:59:20 -0500 (EST) |
branch: elpa/pacmacs
commit a7b0530f6571931870fcf213c3b4bb3b09ec321e
Merge: a460cd8b06 e032089ab4
Author: rexim <reximkut@gmail.com>
Commit: rexim <reximkut@gmail.com>
Merge branch 'score-table-92'. Close #92
---
Cask | 1 +
pacmacs-score.el | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
pacmacs-utils.el | 5 +++
pacmacs.el | 93 +++++++++++++++++++++++++++--------------------------
4 files changed, 152 insertions(+), 45 deletions(-)
diff --git a/Cask b/Cask
index 11068714e4..96dab180fa 100644
--- a/Cask
+++ b/Cask
@@ -6,6 +6,7 @@
(files "*.el")
(depends-on "dash")
+(depends-on "dash-functional")
(development
(depends-on "el-mock")
diff --git a/pacmacs-score.el b/pacmacs-score.el
new file mode 100644
index 0000000000..d2aba7b6f3
--- /dev/null
+++ b/pacmacs-score.el
@@ -0,0 +1,98 @@
+;;; pacmacs-score.el --- Pacman for Emacs
+
+;; Copyright (C) 2015 Codingteam
+
+;; Author: Codingteam <codingteam@conference.jabber.ru>
+;; Maintainer: Alexey Kutepov <reximkut@gmail.com>
+;; URL: http://github.com/rexim/pacmacs.el
+
+;; Permission is hereby granted, free of charge, to any person
+;; obtaining a copy of this software and associated documentation
+;; files (the "Software"), to deal in the Software without
+;; restriction, including without limitation the rights to use, copy,
+;; modify, merge, publish, distribute, sublicense, and/or sell copies
+;; of the Software, and to permit persons to whom the Software is
+;; furnished to do so, subject to the following conditions:
+
+;; The above copyright notice and this permission notice shall be
+;; included in all copies or substantial portions of the Software.
+
+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+;; SOFTWARE.
+
+;;; Commentary:
+
+;; Routines for working with score
+
+;;; Code:
+
+(require 'dash)
+(require 'dash-functional)
+
+(defconst pacmacs--score-file-name "~/.pacmacs-score")
+(defconst pacmacs--score-buffer-name "*Pacmacs Score*")
+
+(defun pacmacs-score ()
+ (interactive)
+ (switch-to-buffer-other-window pacmacs--score-buffer-name)
+ (text-mode)
+ (read-only-mode)
+ (with-current-buffer pacmacs--score-buffer-name
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (-> (pacmacs--read-score-table)
+ (pacmacs--sort-score-table)
+ (pacmacs--render-score-table)))))
+
+(defun pacmacs--read-score-table ()
+ (-> pacmacs--score-file-name
+ (pacmacs--file-content)
+ (read-from-string)
+ (car)))
+
+(defun pacmacs--write-score-table (score-table)
+ (with-temp-buffer
+ (-> score-table
+ (pp-to-string)
+ (insert))
+ (write-file pacmacs--score-file-name)))
+
+(defun pacmacs--sort-score-table (score-table)
+ (sort score-table
+ (-lambda ((_ . score1) (_ . score2))
+ (> score1 score2))))
+
+(defun pacmacs--render-score-table (score-table)
+ (let ((max-nickname-length
+ (--> (pacmacs--read-score-table)
+ (-map (-compose #'length #'car) it)
+ (apply #'max it))))
+ (-each score-table
+ (-lambda ((nickname . score))
+ (insert (format "%s%s %d\n"
+ nickname
+ (make-string (- max-nickname-length
+ (length nickname))
+ ?\s)
+ score))))))
+
+(defun pacmacs--add-entry-to-score-table (nickname score)
+ (->> (pacmacs--read-score-table)
+ (cons (cons nickname score))
+ (pacmacs--sort-score-table)
+ (-take 10)
+ (pacmacs--write-score-table)))
+
+(defun pacmacs--register-new-score (score)
+ (let ((nickname (read-from-minibuffer "Nickname: ")))
+ (pacmacs--add-entry-to-score-table nickname score)))
+
+(provide 'pacmacs-score)
+
+;;; pacmacs-score.el ends here
diff --git a/pacmacs-utils.el b/pacmacs-utils.el
index f8301b5b62..798e7b4d31 100644
--- a/pacmacs-utils.el
+++ b/pacmacs-utils.el
@@ -65,6 +65,11 @@ side-effects."
(cdr (assoc direction-vector
direction-table))))
+(defun pacmacs--file-content (filename)
+ (with-temp-buffer
+ (insert-file-contents filename)
+ (buffer-string)))
+
(provide 'pacmacs-utils)
;;; pacmacs.el ends here
diff --git a/pacmacs.el b/pacmacs.el
index f9cef87e1f..07c0546e80 100644
--- a/pacmacs.el
+++ b/pacmacs.el
@@ -282,23 +282,21 @@
(defun pacmacs-tick ()
(interactive)
- (with-current-buffer pacmacs-buffer-name
- (let ((inhibit-read-only t))
- (cond
- ((equal pacmacs-game-state 'play)
- (pacmacs-play-state-logic))
- ((equal pacmacs-game-state 'death)
- (pacmacs-death-state-logic))
- ((equal pacmacs-game-state 'prepare)
- (pacmacs-waiting-logic #'pacmacs--switch-to-play-state))
- ((equal pacmacs-game-state 'level-beaten)
- (pacmacs-waiting-logic #'(lambda ()
- (pacmacs--load-next-level)
- (pacmacs--switch-to-prepare-state)))))
- (erase-buffer)
- (pacmacs-render-state))))
+ (cond
+ ((equal pacmacs-game-state 'play)
+ (pacmacs-play-state-logic))
+ ((equal pacmacs-game-state 'death)
+ (pacmacs-death-state-logic))
+ ((equal pacmacs-game-state 'prepare)
+ (pacmacs-waiting-logic #'pacmacs--switch-to-play-state))
+ ((equal pacmacs-game-state 'level-beaten)
+ (pacmacs-waiting-logic #'(lambda ()
+ (pacmacs--load-next-level)
+ (pacmacs--switch-to-prepare-state)))))
+
+ (pacmacs-render-state))
(defun pacmacs--step-ghosts ()
(dolist (ghost pacmacs-ghosts)
@@ -379,7 +377,8 @@
(defun pacmacs--switch-to-game-over-state ()
(setq pacmacs-game-state 'game-over)
- (pacmacs-load-map "game-over"))
+ (pacmacs-load-map "game-over")
+ (pacmacs--register-new-score pacmacs-score))
(defun pacmacs--switch-to-play-state ()
(setq pacmacs-game-state 'play)
@@ -397,35 +396,44 @@
(setq pacmacs-waiting-counter 1000))
(defun pacmacs-render-state ()
- (insert (format "Score: %d\n" pacmacs-score))
+ (with-current-buffer pacmacs-buffer-name
+ (let ((inhibit-read-only t))
+ (erase-buffer)
- (when pacmacs-debug-output
- (pacmacs--render-track-board pacmacs-track-board))
+ (insert (format "Score: %d\n" pacmacs-score))
- (pacmacs--fill-board pacmacs-board nil)
+ (when pacmacs-debug-output
+ (pacmacs--render-track-board pacmacs-track-board))
- (dolist (pill pacmacs-pills)
- (pacmacs--put-object pill))
+ (pacmacs--fill-board pacmacs-board nil)
- (dolist (ghost pacmacs-ghosts)
- (pacmacs--put-object ghost))
+ (dolist (pill pacmacs-pills)
+ (pacmacs--put-object pill))
- (pacmacs--put-object pacmacs-player-state)
-
- (dolist (wall pacmacs-wall-cells)
- (pacmacs--put-object wall))
-
- (plist-bind ((width :width)
- (height :height))
- pacmacs-board
- (dotimes (row height)
- (dotimes (column width)
- (let ((anim-object (pacmacs--cell-get pacmacs-board row column)))
- (pacmacs--render-object anim-object)))
- (insert "\n")))
- (insert "\n")
- (dotimes (i pacmacs-lives)
- (pacmacs--render-life-icon)))
+ (dolist (ghost pacmacs-ghosts)
+ (pacmacs--put-object ghost))
+
+ (pacmacs--put-object pacmacs-player-state)
+
+ (dolist (wall pacmacs-wall-cells)
+ (pacmacs--put-object wall))
+
+ (plist-bind ((width :width)
+ (height :height))
+ pacmacs-board
+ (dotimes (row height)
+ (dotimes (column width)
+ (let ((anim-object (pacmacs--cell-get pacmacs-board row column)))
+ (pacmacs--render-object anim-object)))
+ (insert "\n")))
+ (insert "\n")
+ (dotimes (i pacmacs-lives)
+ (pacmacs--render-life-icon))
+
+ (when (equal pacmacs-game-state 'game-over)
+ (-> (pacmacs--read-score-table)
+ (pacmacs--sort-score-table)
+ (pacmacs--render-score-table))))))
(defun pacmacs-up ()
(interactive)
@@ -447,11 +455,6 @@
(when (equal pacmacs-game-state 'play)
(pacmacs--switch-direction pacmacs-player-state 'right)))
-(defun pacmacs--file-content (filename)
- (with-temp-buffer
- (insert-file-contents filename)
- (buffer-string)))
-
(defun pacmacs-load-map (map-name)
(let* ((lines (split-string (pacmacs--file-content (format "maps/%s.txt"
map-name)) "\n" t))
(board-width (apply 'max (mapcar #'length lines)))
- [nongnu] elpa/pacmacs e5bd77740d 119/472: Fix NPEs (#74), (continued)
- [nongnu] elpa/pacmacs e5bd77740d 119/472: Fix NPEs (#74), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 286eb99ae0 130/472: Implement prepare phase. Close #80, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs d14cdd38e3 135/472: Fix last eaten pill visibility. Close #96, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 9cb186f10a 137/472: Refactor pacmacs-inversed-direction-table out. Close #103, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 91c317819c 123/472: Implement basic death mechanics (#69), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs be91d566cb 139/472: Implement Game Over state. Close #94, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs b8cd22229d 142/472: Introduce pacmacs--anim-object-list-next-frame, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 91e432111b 145/472: Implement basic score table mechnism (#92), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 7058b61e47 146/472: Implement adding entries to score table (#92), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs e032089ab4 151/472: Render score table on Game Over screen (#92), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs a7b0530f65 152/472: Merge branch 'score-table-92'. Close #92,
ELPA Syncer <=
- [nongnu] elpa/pacmacs 1b2ca64cd1 157/472: Merge branch 'resource-packaging-95'. Close #95, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 48ecc5cee9 159/472: Don't fail if the score file doesn't exist, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 10b8a997dd 037/472: More precise instructions in README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 7e04991d4e 030/472: Add UT for pacman-compare-aseprite-frames function (#22), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 327332d32d 036/472: Update README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 68f876d0ba 043/472: Merge pull request #29 from rexim/license-28, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 298b950310 062/472: Rename pacman-resources to pacman-image (#51), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs e9703e9ba2 061/472: Rename function for loading images (#51), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 0a65793037 071/472: Use plist-bind for pacman-anim-object-next-frame (#54), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 7f706e2159 074/472: Add UTs for plist-map (#54), ELPA Syncer, 2022/01/06