1
0
mirror of https://github.com/abakh/nbsdgames.git synced 2024-06-08 17:20:41 +00:00
This commit is contained in:
untakenstupidnick 2020-06-21 08:05:03 +04:30
parent 78f5b087a4
commit bff304279b
3 changed files with 17 additions and 11 deletions

View File

@ -1,5 +1,5 @@
/*
--.
.--
|__
| IFTEEN
@ -14,7 +14,7 @@ compile with -lncurses
#include <limits.h>
#include <time.h>
#include <signal.h>
typedef signed char byte;
typedef /*signed char*/ uint8_t byte;
/* The Plan9 compiler can not handle VLAs */
#ifdef Plan9
@ -22,6 +22,7 @@ typedef signed char byte;
#else
byte size;
#endif
FILE *lol;
byte py,px;
byte ey,ex; //the empty tile
chtype green=A_BOLD; //bold when there is no color
@ -40,7 +41,7 @@ void rectangle(byte sy,byte sx){
mvaddch(sy+size+1,sx+size*2,ACS_LRCORNER);
}
void logo(byte sy,byte sx){
mvaddstr(sy,sx, "--.");
mvaddstr(sy,sx, ".--");
mvaddstr(sy+1,sx,"|__");
mvaddstr(sy+2,sx,"| IFTEEN");
}
@ -86,22 +87,24 @@ void fill(char board[size][size]){
board[size-1][size-1]=' ';
}
void slide_one(char board[size][size],byte y,byte x){
if( (y>=0 && y<size && x>=0 && x<size) &&(abs(y-ey)==1)^(abs(x-ex)==1) ){
if( (y>=0 && y<size && x>=0 && x<size) && ((abs(y-ey)==1)^(abs(x-ex)==1)) ){
board[ey][ex]=board[y][x];
board[y][x]=' ';
ey=y;
ey=y;//ey/x moves one tile
ex=x;
}
}
void slide_multi(char board[size][size],byte y,byte x){
byte dy,dx;
dy=dx=0;
if( (ey==y) ^ (ex==x) ){
if(ey!=y)
dy=(y-ey)/abs(y-ey);
if(ey!=y)//d's are steps from ey/x to y/x
dy=(y-ey >0)? 1:-1;
if(ex!=x)
dx=(x-ex)/abs(x-ex);
while(ex!=x || ey!=y)
dx=(x-ex >0)? 1:-1;
while(ex!=x || ey!=y){
slide_one(board,ey+dy,ex+dx);//ey/x comes forth itself
}
ey=y;
ex=x;
}
@ -198,6 +201,7 @@ int main(int argc, char** argv){
}
}
#endif
lol=fopen("lol","w");
signal(SIGINT,sigint_handler);
srand(time(NULL)%UINT_MAX);
initscr();

View File

@ -92,7 +92,7 @@ void draw(void){
if(clbtime){
if(count[clb]!=1){
mvprintw(2,10,"%d ",count[clb]);
mvprintw(9,43,"%d ",count[clb]);
switch(clb){
case 0:
addstr("plastic bags!");
@ -127,6 +127,7 @@ void draw(void){
}
}
else{
move(9,43);
switch(clb){
case 0:
addstr("A plastic bag!");

View File

@ -465,7 +465,7 @@ int main(void){
byte board[RLEN][RWID];
memset(board,0,RLEN*RWID);
char result[70];
int input;
int input=0;
int prey,prex;
int cinred;
Start:
@ -535,6 +535,7 @@ int main(void){
printw(". ");
break;
}
halfdelay(9);
input = getch();
live(board);
count(board);//apparently this should come at both sides of live+draw. resulting from trial and error.