diff options
author | KatolaZ <katolaz@freaknet.org> | 2019-08-07 15:55:35 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2019-08-07 15:55:35 +0100 |
commit | a415d8d20f878bfef86705721f1ef2d6d31263f6 (patch) | |
tree | 7d5477a8547a94dcd4904b6ca005b56b0073af24 | |
parent | 74eb7a909896551721df941a2988cfd2bcc3cb92 (diff) |
move stuff into play() -- add COPYING
-rw-r--r-- | 2ls10.c | 53 | ||||
-rw-r--r-- | COPYING | 19 |
2 files changed, 54 insertions, 18 deletions
@@ -1,18 +1,25 @@ +/** +* +* 2ls10: a clone of the popular 2048 game +* +* (c) 2019 - Vincenzo "KatolaZ" Nicosia <katolaz@freaknet.org> +* +* See COPYING for terms and conditions +* +*/ + #include <stdio.h> #include <stdlib.h> #include <time.h> #include <termios.h> #include <unistd.h> -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(); +} @@ -0,0 +1,19 @@ +Copyright (c) 2019 Vincenzo 'KatolaZ' Nicosia <katolaz@freaknet.org> + +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. |