summaryrefslogtreecommitdiff
path: root/2ls10.c
diff options
context:
space:
mode:
Diffstat (limited to '2ls10.c')
-rw-r--r--2ls10.c53
1 files changed, 35 insertions, 18 deletions
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 <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();
+}