Skip to content

Commit d96b457

Browse files
committed
doc: update readme
1 parent 4c1ef0f commit d96b457

File tree

2 files changed

+92
-5
lines changed

2 files changed

+92
-5
lines changed

README.org

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#+title: 2048-cljs
2+
3+
2048 game implementation in [[https://clojurescript.org/][ClojureScript]] using [[https://day8.github.io/re-frame/][re-frame]], [[https://react.dev/][React]], and [[https://tailwindcss.com/][tailwindcss]]
4+
5+
This project uses [[https://shadow-cljs.github.io/docs/UsersGuide.html][Shadow CLJS]] for development and build setup.
6+
7+
* Core
8+
9+
The core of this project is in =board.cljs=. The board is represented as a vector of vectors that represents rows and colums. Each cell is a vector that has a value and a state.
10+
11+
#+begin_src clojurescript
12+
(def board
13+
[[[2 :random] [0] [0] [0]]
14+
[[0] [0] [0] [0]]
15+
[[4] [0] [0] [0]]
16+
[[8 :merged] [0] [0] [0]]])
17+
#+end_src
18+
19+
* Movements
20+
There are 4 movements possible in the game, move up ⬆️, move down ⬇️, move left ⬅️, and move right ➡️.
21+
22+
Instead of implementing separate logic for each movement, all movements are based on the logic to move left, and move left is simply merges each row in the board towards left.
23+
24+
** Move Right
25+
- Reverse the board
26+
- Move left
27+
- Reserve it back
28+
➡️ =️ ⤴️ ◀️ ⤵️
29+
30+
** Move up
31+
- Rotate the board to left
32+
- Move left
33+
- Rotate it back
34+
⬆️ = ⬅️ ◀️ ➡️
35+
36+
** Move down
37+
- Rotate the board to right
38+
- Move left
39+
- Rotate it back
40+
⬇️ = ➡️ ◀️ ⬅️
41+
42+
#+begin_src clojurescript
43+
(merg-left [[4 :random] [4 :merged] [0] [0]]) ;; [[8] [0] [0] [0]]
44+
45+
(defn move-left
46+
"Move tiles to left and combine equal tiles"
47+
[board]
48+
(mapv b/merge-left board))
49+
50+
(defn move-right
51+
"Move tiles to right and combine equal tiles"
52+
[board]
53+
(-> board
54+
(b/reverse-board)
55+
(move-left)
56+
(b/reverse-board)))
57+
58+
(defn move-up
59+
"Move tiles to up and combine equal tiles"
60+
[board]
61+
(-> board
62+
(b/rotate-left)
63+
(move-left)
64+
(b/rotate-right)))
65+
66+
(defn move-down
67+
"Move tiles to down and combine equal tiles"
68+
[board]
69+
(-> board
70+
(b/rotate-right)
71+
(move-left)
72+
(b/rotate-left)))
73+
#+end_src
74+
75+
* Development
76+
77+
Clone the repository using git
78+
79+
#+begin_src sh
80+
git clone [email protected]:WarFox/2048-cljs
81+
#+end_src
82+
83+
** Commands
84+
85+
1. =npm run watch=
86+
87+
This will start =shadow-cljs= and tests on watch mode
88+
89+
** References
90+
91+
- https://www.youtube.com/watch?v=vI0QArPnkUc
92+
- https://github.com/Nathen-Smith/2048/

README.md docs/re-frame.md

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# cljs-2048
2-
3-
A [re-frame](https://github.com/day8/re-frame) application designed to ... well, that part is up to
4-
you.
5-
61
## Getting Started
72

83
### Project Overview

0 commit comments

Comments
 (0)