-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Your Name
committed
Jul 21, 2020
0 parents
commit 0029cc9
Showing
9 changed files
with
500 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Rust | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install ncurses | ||
run: sudo apt-get install ncurses-dev | ||
- name: Build | ||
run: cargo build --verbose --release | ||
- name: Run tests | ||
run: cargo test --verbose | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: 'rs2048' | ||
path: /home/runner/work/rs2048/rs2048/target/release/rs2048 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "cargo", | ||
"subcommand": "build", | ||
"problemMatcher": [ | ||
"$rustc" | ||
], | ||
"group": "build", | ||
"label": "Rust: cargo build - rs2048" | ||
}, | ||
{ | ||
"type": "cargo", | ||
"subcommand": "run", | ||
"problemMatcher": [ | ||
"$rustc" | ||
], | ||
"label": "Rust: cargo run - rs2048", | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
} | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "rs2048" | ||
version = "0.1.0" | ||
authors = ["sanyi"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
ncurses = "5.99.0" | ||
rand = "0.7.3" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# rs2048 | ||
A TUI 2048-game, written in Rust. | ||
2048 is a simple logical game. If you don't know it yet, you can read it's [wikipedia page](https://en.wikipedia.org/wiki/2048_(video_game)). | ||
|
||
## Features | ||
- Basic features: collapsing contacting and same tiles on swipe, and putting a new tile to the board. | ||
- Randomly choose between 2 and 4 when adding new tiles. | ||
- If the table hasn't changed after swipe, no new tiles appearing. | ||
- Tiles coming from collapsing collapse further only after the next swipe. (E.g. 2 2 2 2 collapse to 4 4, and only after a second swipe collapse to 8.) | ||
- Game Over detection | ||
|
||
## Compatibility | ||
As it has only cross-platform (and statically linked) depencies (ncurses and rand), it should work on almost every OS. | ||
However, creating Windows builds is tedious, so I'll provide only Linux builds (I'll may reconsider). | ||
If you don't have Linux installed - and don't want to install it - you can use [onworks.net](https://www.onworks.net), that provides a virtualized Linux system that you can control from your browser. | ||
|
||
## Running | ||
It don't have any runtime dependencies, so you can download the [binary]() from the Releases page, open a terminal where you've put the binary, and start it with `./rs2048`. | ||
|
||
## Building from source | ||
First, clone the repo via git (if you don't have git, and don't want to install it, you can download the source code from GitHub directly):<br> | ||
`git clone https://github.com/Zoldszemesostoros/rs2048.git`<br> | ||
Then install cargo (rust's build system), and the ncurses developement package:<br> | ||
`sudo apt-get install cargo`<br> | ||
`sudo apt-get install ncurses-dev`<br> | ||
then go to the rs2048 dir:<br> | ||
`cd rs2048`<br> | ||
build the project<br> | ||
`cargo build --release`<br> | ||
and run the binary<br> | ||
`build/target/release/rs2048`<br> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use ncurses::*; | ||
use std::thread::sleep; | ||
use std::time::Duration; | ||
/// Waits for an arrow key | ||
/// Returns 0-3. | ||
pub fn arrow_wait(sleep_dur: Duration) -> i32 { | ||
|
||
// Arrow keys are represented with escape sequences: | ||
// 0x1b (esc), 0x5b (opening square bracket), and 0x41-0x44, depending on the arrow. | ||
let mut after_esc = false; | ||
let mut after_bracket = false; | ||
let result = loop { | ||
|
||
let ch = getch(); | ||
if after_bracket && ch >= 0x41 && ch <= 0x44 { | ||
break ch - 0x41; | ||
} | ||
if ch == 0x5b && after_esc { | ||
after_bracket = true; | ||
} else { | ||
after_bracket = false; | ||
} | ||
if ch == 0x1b { | ||
after_esc = true; | ||
} else { | ||
after_esc = false; | ||
} | ||
|
||
refresh(); | ||
sleep(sleep_dur); | ||
}; | ||
result | ||
} |
Oops, something went wrong.