Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nagan319/2048-lisp
Just a fun implementation of the 2048 game using Racket, a dialect of Lisp.
https://github.com/nagan319/2048-lisp
2048-game lisp racket-lang
Last synced: about 2 months ago
JSON representation
Just a fun implementation of the 2048 game using Racket, a dialect of Lisp.
- Host: GitHub
- URL: https://github.com/nagan319/2048-lisp
- Owner: nagan319
- License: mit
- Created: 2024-06-11T16:53:20.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-06-11T17:16:14.000Z (8 months ago)
- Last Synced: 2024-11-09T12:25:15.021Z (3 months ago)
- Topics: 2048-game, lisp, racket-lang
- Language: Racket
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license.txt
Awesome Lists containing this project
README
# 2048 Game in Racket
![GitHub stars](https://img.shields.io/github/stars/nagan319/2048-LISP?style=social)
![GitHub forks](https://img.shields.io/github/forks/nagan319/2048-LISP?style=social)
![GitHub license](https://img.shields.io/github/license/nagan319/2048-LISP)This is an implementation of the 2048 game in Racket, a dialect of Lisp. Feel free to play around!
## Getting Started
### Prerequisites
- [Racket](https://racket-lang.org/) (Make sure Racket is installed on your system)
### Running the Game
1. Clone the repository:
```sh
git clone https://github.com/yourusername/2048-racket.git
```
2. Navigate to the project directory:
```sh
cd 2048-racket
```
3. Run the game:
```sh
racket main.rkt
```## How to Play
1. Use the command line to input your moves:
- `w`: Move tiles up
- `a`: Move tiles left
- `s`: Move tiles down
- `d`: Move tiles right
2. The game will print the board and your score after each move.
3. Combine tiles of the same number to create larger numbers.
4. The game ends when no more moves are possible.### Functions
- `append`: Appends two lists.
- `reverse`: Reverses a list.
- `len`: Returns the length of a list.
- `index`: Retrieves an element at a specified index in a list.
- `flatten`: Flattens a 2D board into a 1D list.
- `unflatten`: Converts a 1D list back into a 2D board.
- `game-over`: Prints the game over message and the score.
- `print`: Prints the current state of the board and the score.
- `new-num`: Adds a new number (2) to a random empty spot on the board.
- `player-move`: Handles the player's move, combines tiles, and updates the board and score.
- `main`: The main game loop that initializes the board, handles moves, and checks for game over conditions.