1
0
mirror of https://github.com/abakh/nbsdgames.git synced 2024-06-08 17:20:41 +00:00

made it work on NetBSD

This commit is contained in:
BeToChe 2020-09-12 15:08:45 +04:30
parent 5ff99554c7
commit 15f8fb595d
16 changed files with 141 additions and 42 deletions

View File

@ -1,4 +1,7 @@
# -*- Makefile -*-
CFLAGS= -O3 --std=c99 -lncurses
#-O3 --std=c99 -lcurses -DNO_MOUSE for BSD curses
all: jewels sudoku mines reversi checkers battleship rabbithole sos pipes fifteen memoblocks fisher muncher miketron redsquare
scorefiles:
touch /usr/games/pp_scores
@ -13,35 +16,35 @@ scorefiles:
chmod 666 /usr/games/fsh_scores
jewels: jewels.c config.h
$(CC) jewels.c -lncurses -o ./jewels
$(CC) jewels.c $(CFLAGS) -o ./jewels
sudoku: sudoku.c
$(CC) sudoku.c -lncurses -lm -o ./sudoku
$(CC) sudoku.c $(CFLAGS) -lm -o ./sudoku
mines: mines.c
$(CC) mines.c -lncurses -o ./mines
$(CC) mines.c $(CFLAGS) -o ./mines
reversi: reversi.c
$(CC) reversi.c -lncurses -o ./reversi
$(CC) reversi.c $(CFLAGS) -o ./reversi
checkers: checkers.c
$(CC) checkers.c -lncurses -o ./checkers
$(CC) checkers.c $(CFLAGS) -o ./checkers
battleship: battleship.c
$(CC) battleship.c -lncurses -o ./battleship
$(CC) battleship.c $(CFLAGS) -o ./battleship
rabbithole: rabbithole.c
$(CC) rabbithole.c -lncurses -o ./rabbithole
$(CC) rabbithole.c $(CFLAGS) -o ./rabbithole
sos: sos.c
$(CC) sos.c -lncurses -o ./sos
$(CC) sos.c $(CFLAGS) -o ./sos
pipes: pipes.c config.h
$(CC) pipes.c -lncurses -o ./pipes
$(CC) pipes.c $(CFLAGS) -o ./pipes
fifteen: fifteen.c
$(CC) fifteen.c -lncurses -o ./fifteen
$(CC) fifteen.c $(CFLAGS) -o ./fifteen
memoblocks: memoblocks.c
$(CC) memoblocks.c -lncurses -o ./memoblocks
$(CC) memoblocks.c $(CFLAGS) -o ./memoblocks
fisher: fisher.c config.h
$(CC) fisher.c -lncurses -o ./fisher
$(CC) fisher.c $(CFLAGS) -o ./fisher
muncher: muncher.c config.h
$(CC) muncher.c -lncurses -o ./muncher
$(CC) muncher.c $(CFLAGS) -o ./muncher
miketron: miketron.c config.h
$(CC) miketron.c -lncurses -o ./miketron
$(CC) miketron.c $(CFLAGS) -o ./miketron
redsquare: redsquare.c
$(CC) redsquare.c -lncurses -o ./redsquare
$(CC) redsquare.c $(CFLAGS) -o ./redsquare
clean:
rm ./jewels ./sudoku ./checkers ./mines ./reversi ./battleship ./rabbithole ./sos ./pipes ./fifteen ./memoblocks ./fisher ./muncher ./miketron ./redsquare
uninstall:

View File

@ -15,6 +15,7 @@ compile with -lncurses
#include <stdlib.h>
#include <signal.h>
#include <stdbool.h>
#include "config.h"
#define MISS -2
#define SEA -1
#define HIT 0
@ -47,6 +48,7 @@ void sigint_handler(int x){
exit(x);
}
void mouseinput(bool ingame){
#ifndef NO_MOUSE
MEVENT minput;
#ifdef PDCURSES
nc_getmouse(&minput);
@ -67,6 +69,7 @@ void mouseinput(bool ingame){
ungetch('\n');
if(minput.bstate & (BUTTON2_CLICKED|BUTTON2_RELEASED|BUTTON3_CLICKED|BUTTON3_RELEASED) )
ungetch('r');
#endif
}
void rectangle(byte sy,byte sx){
for(byte y=0;y<=10+1;++y){
@ -522,7 +525,9 @@ void gameplay(bool side){//side is only there to feed header()
}
int main(void){
initscr();
#ifndef NO_MOUSE
mousemask(ALL_MOUSE_EVENTS,NULL);
#endif
curs_set(0);
noecho();
cbreak();

View File

@ -18,6 +18,7 @@ Compile with -lncurses
#include <signal.h>
#include <math.h>
#include <stdbool.h>
#include "config.h"
#define LIGHT -1
#define DARK 1
#define KING 2
@ -442,6 +443,7 @@ void sigint_handler(int x){
}
void mouseinput(void){
#ifndef NO_MOUSE
MEVENT minput;
#ifdef PDCURSES
nc_getmouse(&minput);
@ -456,6 +458,7 @@ void mouseinput(void){
return;
if(minput.bstate & (BUTTON1_CLICKED|BUTTON1_PRESSED|BUTTON1_RELEASED) )
ungetch('\n');
#endif
}
void help(void){
erase();
@ -512,7 +515,9 @@ int main(int argc,char** argv){
}
}
initscr();
#ifndef NO_MOUSE
mousemask(ALL_MOUSE_EVENTS,NULL);
#endif
noecho();
cbreak();
keypad(stdscr,1);

View File

@ -1,3 +1,6 @@
//for easier access
//the default scorefiles
#ifdef Plan9
#define PP_SCORES "/sys/lib/games/pp_scores"
#define JW_SCORES "/sys/lib/games/jw_scores"
@ -11,4 +14,37 @@
#define MNCH_SCORES "/usr/games/mnch_scores"
#define MT_SCORES "/usr/games/mt_scores"
#endif
//for easier access
#ifdef Plan9
#define NO_VLA
//Many ancient compilers don't have VLA support, including the Plan9 compiler
//thought it would be nicer if it had its own flag instead of Plan9.
#endif
//#define NO_MOUSE
//it seems there wasn't mouse support in original curses, and the variants
//developed it indepedently, use if mouse doesn't work in your variant (e.g. BSD curses)
#ifdef __unix__
#define rand() random()
#define srand(x) srandom(x)
//At the time of writing, NetBSD's rand() is damn stupid.
//rand()%4 constantly gives 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3.
#endif
// It seems usleep is obsoleted in favor of nanosleep,
// and some POSIX implementations lack it. but i refuse
// to end using it! what the hell, filling a struct for
// something as trivial as sleeping 0.1 seconds??
// the function is written by Jens Staal for Plan9
int microsleep(long usec){
int second = usec/1000000;
long nano = usec*1000 - second*1000000;
struct timespec sleepy = {0};
sleepy.tv_sec = second;
sleepy.tv_nsec = nano;
nanosleep(&sleepy, (struct timespec *) NULL);
return 0;
}
#define usleep(x) microsleep(x)

View File

@ -14,10 +14,11 @@ compile with -lncurses
#include <limits.h>
#include <time.h>
#include <signal.h>
#include "config.h"
typedef signed char byte;
/* The Plan9 compiler can not handle VLAs */
#ifdef Plan9
#ifdef NO_VLA
#define size 4
#else
byte size;
@ -119,21 +120,28 @@ bool issolved(char board[size][size],char check[size][size]){
return 1;
}
void shuffle(char board[size][size]){
for(int m=0;m<1000;++m){
for(int m=0;m<10000;++m){
switch(rand()%4){
case 0:
addch('0');
slide_one(board,ey,ex+1);
break;
case 1:
addch('1');
slide_one(board,ey,ex-1);
break;
case 2:
addch('2');
slide_one(board,ey+1,ex);
break;
case 3:
addch('3');
slide_one(board,ey-1,ex);
break;
}
}
refresh();
getch();
}
//peacefully close when ^C is pressed
void sigint_handler(int x){
@ -142,6 +150,7 @@ void sigint_handler(int x){
exit(x);
}
void mouseinput(void){
#ifndef NO_MOUSE
MEVENT minput;
#ifdef PDCURSES
nc_getmouse(&minput);
@ -156,6 +165,7 @@ void mouseinput(void){
return;
if(minput.bstate & BUTTON1_CLICKED)
ungetch('\n');
#endif
}
void help(void){
erase();
@ -186,7 +196,7 @@ void gameplay(void){
erase();
}
int main(int argc, char** argv){
#ifndef Plan9
#ifndef NO_VLA
size=4;
if(argc==2){
if(!strcmp("help",argv[1])){
@ -203,7 +213,9 @@ int main(int argc, char** argv){
signal(SIGINT,sigint_handler);
srand(time(NULL)%UINT_MAX);
initscr();
#ifndef NO_MOUSE
mousemask(ALL_MOUSE_EVENTS,NULL);
#endif
noecho();
cbreak();
keypad(stdscr,1);

View File

@ -10,7 +10,7 @@ A pair of jewels appear on top of the window, And you can move and rotate them w
If you make a vertical or horizontal row of 4 jewels they will explode and add up to your score.
Like Tetris,You will lose the game when the center of the uppermost row is filled.
TODO make it like puyo puyo instead of the remake of of what i poorly remembered*/
TODO make it like puyo puyo instead of the remake of what i poorly remembered*/
#include <curses.h>
#include <time.h>
#include <limits.h>

View File

@ -14,11 +14,12 @@ compile with -lncurses
#include <string.h>
#include <time.h>
#include <signal.h>
#include "config.h"
typedef signed char byte;
typedef unsigned char ubyte;
/* The Plan9 compiler can not handle VLAs */
#ifdef Plan9
#ifdef NO_VLA
#define size 8
#define size2 16
#else
@ -122,6 +123,7 @@ void sigint_handler(int x){
exit(x);
}
void mouseinput(void){
#ifndef NO_MOUSE
MEVENT minput;
#ifdef PDCURSES
nc_getmouse(&minput);
@ -136,6 +138,7 @@ void mouseinput(void){
return;
if(minput.bstate & BUTTON1_CLICKED)
ungetch('\n');
#endif
}
void help(void){
erase();
@ -169,11 +172,11 @@ void gameplay(void){
erase();
}
int main(int argc, char** argv){
#ifndef Plan9
#ifndef NO_VLA
size=8;
#endif
if(argc>=2){
#ifndef Plan9
#ifndef NO_VLA
size=atoi(argv[1]);
#endif
if(size<3 || size>19){
@ -188,7 +191,9 @@ int main(int argc, char** argv){
signal(SIGINT,sigint_handler);
srand(time(NULL)%UINT_MAX);
initscr();
#ifndef NO_MOUSE
mousemask(ALL_MOUSE_EVENTS,NULL);
#endif
noecho();
cbreak();
keypad(stdscr,1);
@ -209,7 +214,7 @@ int main(int argc, char** argv){
}
}
}
#ifndef Plan9
#ifndef NO_VLA
else if(size>8)//big sizes depend on color display
size=8;
size2=size*2;

View File

@ -26,9 +26,11 @@ enum {UP=1,RIGHT,DOWN,LEFT,FLIGHT,NOTRAIL,BOMB,SPAWN,STOP,SUPERFOOD,TRAIL};
typedef signed char byte;
/* The Plan9 compiler can not handle VLAs and usleep is a POSIX function */
#ifdef Plan9
#ifdef NO_VLA
#define len 10
#define wid 40
#ifdef Plan9
int usleep(long usec) {
int second = usec/1000000;
long nano = usec*1000 - second*1000000;
@ -38,9 +40,11 @@ int usleep(long usec) {
nanosleep(&sleepy, (struct timespec *) NULL);
return 0;
}
#endif
#else
int len,wid;
#endif
#endif//NO_VLA
int py,px;
int immunity,flight,notrail;
@ -358,7 +362,7 @@ void sigint_handler(int x){
exit(x);
}
int main(int argc, char** argv){
#ifndef Plan9
#ifndef NO_VLA
bool autoset=0;
signal(SIGINT,sigint_handler);
if(argc>3 || (argc==2 && !strcmp("help",argv[1])) ){
@ -386,7 +390,7 @@ int main(int argc, char** argv){
}
#endif
initscr();
#ifndef Plan9
#ifndef NO_VLA
if(autoset){
len=LINES-7;
if(len<MINLEN)

View File

@ -14,11 +14,12 @@ compile with -lncurses
#include <time.h>
#include <signal.h>
#include <stdbool.h>
#include "config.h"
#define FLAG 9
#define UNCLEAR 10
typedef signed char byte;
#ifdef Plan9 //The Plan9 compiler can not handle VLAs
#ifdef NO_VLA //The Plan9 compiler can not handle VLAs
#define len 8
#define wid 8
#else
@ -157,6 +158,7 @@ void sigint_handler(int x){
exit(x);
}
void mouseinput(int sy, int sx){
#ifndef NO_MOUSE
MEVENT minput;
#ifdef PDCURSES
nc_getmouse(&minput);
@ -173,6 +175,7 @@ void mouseinput(int sy, int sx){
ungetch('\n');
if(minput.bstate & (BUTTON2_CLICKED|BUTTON3_CLICKED) )
ungetch(' ');
#endif
}
void help(void){
erase();
@ -214,7 +217,7 @@ void gameplay(void){
}
int main(int argc, char** argv){
signal(SIGINT,sigint_handler);
#ifndef Plan9
#ifndef NO_VLA
if(argc>4 || (argc==2 && !strcmp("help",argv[1])) ){
printf("Usage: %s [len wid [minescount]]\n",argv[0]);
return EXIT_FAILURE;
@ -254,7 +257,9 @@ int main(int argc, char** argv){
#endif
srand(time(NULL)%UINT_MAX);
initscr();
#ifndef NO_MOUSE
mousemask(ALL_MOUSE_EVENTS,NULL);
#endif
noecho();
cbreak();
keypad(stdscr,1);

View File

@ -25,9 +25,11 @@ enum {UP=1,RIGHT,DOWN,LEFT,FOOD,SUPERFOOD,TRAP};
typedef signed char byte;
/* The Plan9 compiler can not handle VLAs */
#ifdef Plan9
#ifdef NO_VLA
#define len 10
#define wid 40
#ifdef Plan9
int usleep(long usec) {
int second = usec/1000000;
long nano = usec*1000 - second*1000000;
@ -37,9 +39,12 @@ int usleep(long usec) {
nanosleep(&sleepy, (struct timespec *) NULL);
return 0;
}
#endif
#else
int len,wid;
#endif
#endif//NO_VLA
int py,px;//pointer
@ -318,7 +323,7 @@ void sigint_handler(int x){
int main(int argc, char** argv){
bool autoset=0;
signal(SIGINT,sigint_handler);
#ifndef Plan9
#ifndef NO_VLA
if(argc>3 || (argc==2 && !strcmp("help",argv[1])) ){
printf("Usage: %s [len wid]\n",argv[0]);
return EXIT_FAILURE;
@ -344,7 +349,7 @@ int main(int argc, char** argv){
}
#endif
initscr();
#ifndef Plan9
#ifndef NO_VLA
if(autoset){
len=LINES-7;
if(len<MINLEN)

View File

@ -31,7 +31,7 @@ typedef signed char byte;
typedef unsigned char bitbox;
/* The Plan9 compiler can not handle VLAs */
#ifdef Plan9
#ifdef NO_VLA
#define wid 20
#define len 14
#else
@ -286,6 +286,7 @@ void draw(bitbox board[len][wid]){
}
void mouseinput(void){
#ifndef NO_MOUSE
MEVENT minput;
#ifdef PDCURSES
nc_getmouse(&minput);
@ -300,6 +301,7 @@ void mouseinput(void){
return;
if(minput.bstate & BUTTON1_CLICKED)
ungetch('\n');
#endif //NO_MOUSE
}
//peacefully close when ^C is pressed
void sigint_handler(int x){
@ -350,7 +352,7 @@ void gameplay(void){
}
int main(int argc, char** argv){
signal(SIGINT,sigint_handler);
#ifndef Plan9
#ifndef NO_VLA
if(argc>3 || (argc==2 && !strcmp("help",argv[1])) ){
printf("Usage: %s [len wid]\n",argv[0]);
return EXIT_FAILURE;
@ -377,7 +379,9 @@ int main(int argc, char** argv){
}
#endif
initscr();
#ifndef NO_MOUSE
mousemask(ALL_MOUSE_EVENTS,NULL);
#endif
time_t tstart , now, lasttime, giventime=len*wid/4;
srand(time(NULL)%UINT_MAX);
bitbox direction,board[len][wid];

View File

@ -15,6 +15,7 @@ compile with -lncurses
#include <limits.h>
#include <time.h>
#include <signal.h>
#include "config.h"
#define UP 1
#define RIGHT 2
#define DOWN 4
@ -25,7 +26,7 @@ typedef signed char byte;
typedef unsigned char bitbox;
/* The Plan9 compiler can not handle VLAs */
#ifdef Plan9
#ifdef NO_VLA
#define len 10
#define wid 20
#else
@ -178,7 +179,7 @@ void sigint_handler(int x){
int main(int argc, char** argv){
bool autoset=0;
signal(SIGINT,sigint_handler);
#ifndef Plan9
#ifndef NO_VLA
if(argc>3 || (argc==2 && !strcmp("help",argv[1])) ){
printf("Usage: %s [len wid]\n",argv[0]);
return EXIT_FAILURE;
@ -204,7 +205,7 @@ int main(int argc, char** argv){
}
#endif
initscr();
#ifndef Plan9
#ifndef NO_VLA
if(autoset){
if((LINES-7)/2 < 10)
len=10;

View File

@ -14,6 +14,7 @@ compile with -lncurses
#include <limits.h>
#include <time.h>
#include <signal.h>
#include "config.h"
#define LEN 35
#define WID 50
#define RLEN LEN //real
@ -444,7 +445,6 @@ int main(void){
signal(SIGINT,sigint_handler);
srand(time(NULL)%UINT_MAX);
initscr();
mousemask(ALL_MOUSE_EVENTS,NULL);
noecho();
cbreak();
keypad(stdscr,1);

View File

@ -216,6 +216,7 @@ void sigint_handler(int x){
exit(x);
}
void mouseinput(void){
#ifndef NO_MOUSE
MEVENT minput;
#ifdef PDCURSES
nc_getmouse(&minput);
@ -230,6 +231,7 @@ void mouseinput(void){
return;
if(minput.bstate & BUTTON1_CLICKED)
ungetch('\n');
#endif
}
void help(void){
erase();
@ -280,7 +282,9 @@ int main(int argc , char** argv){
}
signal(SIGINT,sigint_handler);
initscr();
#ifndef NO_MOUSE
mousemask(ALL_MOUSE_EVENTS,NULL);
#endif
noecho();
cbreak();
keypad(stdscr,1);

9
sos.c
View File

@ -14,10 +14,11 @@ compile with -lncurses
#include <limits.h>
#include <time.h>
#include <signal.h>
#include "config.h"
#define NOTHING 123
typedef signed char byte;
#ifdef Plan9
#ifdef NO_VLA
#define len 5
#define wid 6
#else
@ -186,6 +187,7 @@ void sigint_handler(int x){
exit(x);
}
void mouseinput(int sy,int sx){
#ifndef NO_MOUSE
MEVENT minput;
#ifdef PDCURSES
nc_getmouse(&minput);
@ -202,6 +204,7 @@ void mouseinput(int sy,int sx){
ungetch('S');
if(minput.bstate & (BUTTON2_CLICKED|BUTTON3_CLICKED) )
ungetch('O');
#endif
}
void help(void){
erase();
@ -243,7 +246,7 @@ void gameplay(void){
int main(int argc, char** argv){
int dpt=1;
signal(SIGINT,sigint_handler);
#ifndef Plan9
#ifndef NO_VLA
if(argc>4 || (argc==2 && !strcmp("help",argv[1])) ){
printf("Usage: %s [len wid [AIpower]]\n",argv[0]);
return EXIT_FAILURE;
@ -299,7 +302,9 @@ int main(int argc, char** argv){
srand(time(NULL)%UINT_MAX);
int input;
initscr();
#ifndef NO_MOUSE
mousemask(ALL_MOUSE_EVENTS,NULL);
#endif
curs_set(0);
noecho();
cbreak();

View File

@ -17,6 +17,7 @@ NOTE: This program is only made for entertainment porpuses. The puzzles are gene
#include <limits.h>
#include <signal.h>
#include <math.h>
#include "config.h"
typedef signed char byte;
byte _wait=0, waitcycles=0;//apparently 'wait' conflicts with a variable in a library macOS includes by default
@ -249,6 +250,7 @@ void sigint_handler(int x){
exit(x);
}
void mouseinput(int sy, int sx){
#ifndef NO_MOUSE
MEVENT m;
#ifdef PDCURSES
nc_getmouse(&m);
@ -265,6 +267,7 @@ void mouseinput(int sy, int sx){
ungetch('\n');
if(m.bstate & (BUTTON2_CLICKED|BUTTON3_CLICKED) )
ungetch(' ');
#endif //NO_MOUSE
}
void help(void){
erase();
@ -362,7 +365,9 @@ int main(int argc,char** argv){
#endif
bool fastgen= !(!getenv("SUDOKU_FASTGEN"));
initscr();
#ifndef NO_MOUSE
mousemask(ALL_MOUSE_EVENTS,NULL);
#endif //NO_MOUSE
noecho();
cbreak();
keypad(stdscr,1);