mirror of
https://github.com/abakh/nbsdgames.git
synced 2025-02-02 15:07:27 -05:00
fifteen
This commit is contained in:
parent
78f5b087a4
commit
bff304279b
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
--.
|
.--
|
||||||
|__
|
|__
|
||||||
| IFTEEN
|
| IFTEEN
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ compile with -lncurses
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
typedef signed char byte;
|
typedef /*signed char*/ uint8_t byte;
|
||||||
|
|
||||||
/* The Plan9 compiler can not handle VLAs */
|
/* The Plan9 compiler can not handle VLAs */
|
||||||
#ifdef Plan9
|
#ifdef Plan9
|
||||||
@ -22,6 +22,7 @@ typedef signed char byte;
|
|||||||
#else
|
#else
|
||||||
byte size;
|
byte size;
|
||||||
#endif
|
#endif
|
||||||
|
FILE *lol;
|
||||||
byte py,px;
|
byte py,px;
|
||||||
byte ey,ex; //the empty tile
|
byte ey,ex; //the empty tile
|
||||||
chtype green=A_BOLD; //bold when there is no color
|
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);
|
mvaddch(sy+size+1,sx+size*2,ACS_LRCORNER);
|
||||||
}
|
}
|
||||||
void logo(byte sy,byte sx){
|
void logo(byte sy,byte sx){
|
||||||
mvaddstr(sy,sx, "--.");
|
mvaddstr(sy,sx, ".--");
|
||||||
mvaddstr(sy+1,sx,"|__");
|
mvaddstr(sy+1,sx,"|__");
|
||||||
mvaddstr(sy+2,sx,"| IFTEEN");
|
mvaddstr(sy+2,sx,"| IFTEEN");
|
||||||
}
|
}
|
||||||
@ -86,22 +87,24 @@ void fill(char board[size][size]){
|
|||||||
board[size-1][size-1]=' ';
|
board[size-1][size-1]=' ';
|
||||||
}
|
}
|
||||||
void slide_one(char board[size][size],byte y,byte x){
|
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[ey][ex]=board[y][x];
|
||||||
board[y][x]=' ';
|
board[y][x]=' ';
|
||||||
ey=y;
|
ey=y;//ey/x moves one tile
|
||||||
ex=x;
|
ex=x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void slide_multi(char board[size][size],byte y,byte x){
|
void slide_multi(char board[size][size],byte y,byte x){
|
||||||
byte dy,dx;
|
byte dy,dx;
|
||||||
|
dy=dx=0;
|
||||||
if( (ey==y) ^ (ex==x) ){
|
if( (ey==y) ^ (ex==x) ){
|
||||||
if(ey!=y)
|
if(ey!=y)//d's are steps from ey/x to y/x
|
||||||
dy=(y-ey)/abs(y-ey);
|
dy=(y-ey >0)? 1:-1;
|
||||||
if(ex!=x)
|
if(ex!=x)
|
||||||
dx=(x-ex)/abs(x-ex);
|
dx=(x-ex >0)? 1:-1;
|
||||||
while(ex!=x || ey!=y)
|
while(ex!=x || ey!=y){
|
||||||
slide_one(board,ey+dy,ex+dx);//ey/x comes forth itself
|
slide_one(board,ey+dy,ex+dx);//ey/x comes forth itself
|
||||||
|
}
|
||||||
ey=y;
|
ey=y;
|
||||||
ex=x;
|
ex=x;
|
||||||
}
|
}
|
||||||
@ -198,6 +201,7 @@ int main(int argc, char** argv){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
lol=fopen("lol","w");
|
||||||
signal(SIGINT,sigint_handler);
|
signal(SIGINT,sigint_handler);
|
||||||
srand(time(NULL)%UINT_MAX);
|
srand(time(NULL)%UINT_MAX);
|
||||||
initscr();
|
initscr();
|
||||||
|
@ -92,7 +92,7 @@ void draw(void){
|
|||||||
|
|
||||||
if(clbtime){
|
if(clbtime){
|
||||||
if(count[clb]!=1){
|
if(count[clb]!=1){
|
||||||
mvprintw(2,10,"%d ",count[clb]);
|
mvprintw(9,43,"%d ",count[clb]);
|
||||||
switch(clb){
|
switch(clb){
|
||||||
case 0:
|
case 0:
|
||||||
addstr("plastic bags!");
|
addstr("plastic bags!");
|
||||||
@ -127,6 +127,7 @@ void draw(void){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
move(9,43);
|
||||||
switch(clb){
|
switch(clb){
|
||||||
case 0:
|
case 0:
|
||||||
addstr("A plastic bag!");
|
addstr("A plastic bag!");
|
||||||
|
@ -465,7 +465,7 @@ int main(void){
|
|||||||
byte board[RLEN][RWID];
|
byte board[RLEN][RWID];
|
||||||
memset(board,0,RLEN*RWID);
|
memset(board,0,RLEN*RWID);
|
||||||
char result[70];
|
char result[70];
|
||||||
int input;
|
int input=0;
|
||||||
int prey,prex;
|
int prey,prex;
|
||||||
int cinred;
|
int cinred;
|
||||||
Start:
|
Start:
|
||||||
@ -535,6 +535,7 @@ int main(void){
|
|||||||
printw(". ");
|
printw(". ");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
halfdelay(9);
|
||||||
input = getch();
|
input = getch();
|
||||||
live(board);
|
live(board);
|
||||||
count(board);//apparently this should come at both sides of live+draw. resulting from trial and error.
|
count(board);//apparently this should come at both sides of live+draw. resulting from trial and error.
|
||||||
|
Loading…
Reference in New Issue
Block a user