From a415d8d20f878bfef86705721f1ef2d6d31263f6 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Wed, 7 Aug 2019 15:55:35 +0100 Subject: move stuff into play() -- add COPYING --- 2ls10.c | 53 +++++++++++++++++++++++++++++++++++------------------ COPYING | 19 +++++++++++++++++++ 2 files changed, 54 insertions(+), 18 deletions(-) create mode 100644 COPYING diff --git a/2ls10.c b/2ls10.c index c3b0d70..118423f 100644 --- a/2ls10.c +++ b/2ls10.c @@ -1,18 +1,25 @@ +/** +* +* 2ls10: a clone of the popular 2048 game +* +* (c) 2019 - Vincenzo "KatolaZ" Nicosia +* +* See COPYING for terms and conditions +* +*/ + #include #include #include #include #include -int st[1<<7], lo, li, ls; -int m, pt, n, pl, t; +#define cond(x) ((t) ? (x)/n : (x)%n) + +int st[1<<7], lo, li, ls, m, pt, n, pl, t; char nf; struct termios t1, t2; -int cond (int j){ - return t? j/n : j%n; -} - void clean(char *str){ if (str) printf("%s\n", str); tcsetattr(0, TCSANOW, &t1); @@ -108,21 +115,11 @@ void update(){ } } -int main(int argc, char *argv[]){ - srand(time(NULL)); - //srand(12345); - n = 4; - if (argc > 1) n = atoi(argv[1]); - nf = n * n; - tcgetattr(0, &t1); - t2 = t1; - t2.c_lflag &= ~(ICANON | ECHO); - tcsetattr(0, TCSANOW, &t2); +void play(){ set_rnd(); pt = 0; pl = 1; while(pl){ - //pr_st(); set_rnd(); print_state(); switch(getchar()){ @@ -156,8 +153,28 @@ int main(int argc, char *argv[]){ } update(); - } print_state(); clean("you won!"); } + + +int main(int argc, char *argv[]){ + srand(time(NULL)); + //srand(12345); + n = 4; + if (argc > 1) { + n = atoi(argv[1]); + if (n< 2 || n > 16){ + fprintf(stderr, "Usage: 2ls10 [2-16]\n"); + exit(1); + } + } + nf = n * n; + tcgetattr(0, &t1); + t2 = t1; + t2.c_lflag &= ~(ICANON | ECHO); + tcsetattr(0, TCSANOW, &t2); + + play(); +} diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..6957959 --- /dev/null +++ b/COPYING @@ -0,0 +1,19 @@ +Copyright (c) 2019 Vincenzo 'KatolaZ' Nicosia + +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. -- cgit v1.2.3