mirror of
https://github.com/abakh/nbsdgames.git
synced 2025-01-03 14:56:23 -05:00
Version 2
This commit is contained in:
parent
f297b69021
commit
a30c092df7
18
README.md
18
README.md
@ -1,5 +1,5 @@
|
||||
# New BSD Games
|
||||
<!To anyone who has been involved in development of this display system: f.. fu.. FUCK Y'ALL ! WHAT KIND OF HELLISH SHIT IS THIS?!?!?!?!??>
|
||||
<!To anyone who has been involved in development of this readme system: FUCK Y'ALL ! WHAT KIND OF HELLISH SHIT IS THIS?!?!?!?!??>
|
||||
*You have a computing machine from 1980's and you wonder how you can use it? <br/>
|
||||
You deal with a GUI-less machine at work and are looking for ways to kill time? <br/>
|
||||
You have to make a Reversi AI for your homework and you don't know where to copy it from? <br/>
|
||||
@ -8,8 +8,7 @@
|
||||
|
||||
**Don't worry** anymore as you've got nbsdgames now!
|
||||
|
||||
I originally made these to be added to NetBSD ( but the few i talked with preferred to have games in the repositories rather than in /usr/games itself) .
|
||||
|
||||
I originally made these in hope of them being added to NetBSD ( but the few i talked with preferred to have games in the repositories rather than in /usr/games itself) .
|
||||
|
||||
These include:
|
||||
|
||||
@ -22,7 +21,8 @@ These include:
|
||||
* SOS
|
||||
* Rabbithole (A maze-exploring game where you have to gather items from all around the maze rather than reaching an end, the idea maybe mine)
|
||||
* Pipes (Same as the famous Pipe Mania, unplayable on the environments that don't support the line characters)
|
||||
|
||||
* Fifteen
|
||||
* Memoblocks (or Memory blocks. A similar game was included in Windows 7)
|
||||
## Prerequisites
|
||||
|
||||
* git (optional)
|
||||
@ -41,7 +41,7 @@ These include:
|
||||
Like this:
|
||||
|
||||
``` sh
|
||||
git clone https://github.com/untakenstupidnick/nbsdgames
|
||||
git clone https://github.com/untakenstupidnick/nbsdgames
|
||||
cd ~/nbsdgames/sources
|
||||
export PREFIX= ~/bin
|
||||
make install
|
||||
@ -58,8 +58,8 @@ It's been made available for openSUSE thanks to Zinjanthropus: https://build.ope
|
||||
|
||||
|
||||
## How to contribute
|
||||
Thanks for your generousity! You can...
|
||||
Oh, You are so kind! You can...
|
||||
* Share these with your friends
|
||||
* Tell me your suggestions, bug reports, games you want to be added etc.
|
||||
* Make a package for your distro ( This additional repo is made to make it easier https://github.com/untakenstupidnick/nbsdgames-sources )
|
||||
* Port it to other OSes with help from PDcurses (Not very hard, but there are incompatibilities between PDcurses and ncurses)
|
||||
* Tell me your feature requests, bug reports, games you want to be added etc.
|
||||
* Make a package for your distro
|
||||
* Tell me if you're interested in porting it to non-Unix (Possible in theory since there is PDCurses for SDL, and SDL for everything)
|
||||
|
BIN
sources/.fifteen.c.swp
Normal file
BIN
sources/.fifteen.c.swp
Normal file
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
# -*- Makefile -*-
|
||||
|
||||
all: jewels sudoku mines reversi checkers battleship rabbithole sos pipes
|
||||
all: jewels sudoku mines reversi checkers battleship rabbithole sos pipes fifteen memoblocks
|
||||
|
||||
jewels: jewels.c config.h
|
||||
$(CC) jewels.c -lncurses -o ./jewels
|
||||
@ -20,12 +20,16 @@ sos: sos.c
|
||||
$(CC) sos.c -lncurses -o ./sos
|
||||
pipes: pipes.c config.h
|
||||
$(CC) pipes.c -lncurses -o ./pipes
|
||||
fifteen: fifteen.c
|
||||
$(CC) fifteen.c -lncurses -o ./fifteen
|
||||
memoblocks: memoblocks.c
|
||||
$(CC) memoblocks.c -lncurses -o ./memoblocks
|
||||
clean:
|
||||
rm ./jewels ./sudoku ./checkers ./mines ./reversi ./battleship ./rabbithole ./sos ./pipes
|
||||
rm ./jewels ./sudoku ./checkers ./mines ./reversi ./battleship ./rabbithole ./sos ./pipes ./fifteen ./memoblocks
|
||||
uninstall:
|
||||
rm $(PREFIX)/jewels $(PREFIX)/sudoku $(PREFIX)/checkers $(PREFIX)/mines $(PREFIX)/reversi $(PREFIX)/battleship $(PREFIX)/rabbithole $(PREFIX)/sos $(PREFIX)/pipes
|
||||
rm $(PREFIX)/jewels $(PREFIX)/sudoku $(PREFIX)/checkers $(PREFIX)/mines $(PREFIX)/reversi $(PREFIX)/battleship $(PREFIX)/rabbithole $(PREFIX)/sos $(PREFIX)/pipes $(PREFIX)/fifteen $(PREFIX)/memoblocks
|
||||
copy_sources:
|
||||
cp Makefile config.h jewels.c sudoku.c mines.c reversi.c checkers.c battleship.c rabbithole.c sos.c pipes.c $(PREFIX)
|
||||
install: jewels sudoku mines reversi checkers battleship rabbithole sos pipes
|
||||
cp jewels sudoku mines reversi checkers battleship rabbithole sos pipes $(PREFIX)
|
||||
cp Makefile config.h jewels.c sudoku.c mines.c reversi.c checkers.c battleship.c rabbithole.c sos.c pipes.c fifteen.c memoblocks.c $(PREFIX)
|
||||
install: jewels sudoku mines reversi checkers battleship rabbithole sos pipes fifteen memoblocks
|
||||
cp jewels sudoku mines reversi checkers battleship rabbithole sos pipes fifteen memoblocks $(PREFIX)
|
||||
|
||||
|
@ -552,6 +552,7 @@ int main(int argc,char** argv){
|
||||
double adv = 1;//used to determine when the game is a draw
|
||||
double previousadv =1;
|
||||
Turn:
|
||||
curs_set(0);
|
||||
jumpagainy=jumpagainx=-1;
|
||||
kinged=0;
|
||||
turn =-turn;
|
||||
@ -577,7 +578,7 @@ int main(int argc,char** argv){
|
||||
result=-1;
|
||||
goto End;
|
||||
}
|
||||
else if(todraw==50){ // 50 turns without any gains for each side
|
||||
else if(todraw==50){ // 50 turns without any gain for either side
|
||||
result=0;
|
||||
goto End;
|
||||
}
|
||||
|
247
sources/fifteen.c
Normal file
247
sources/fifteen.c
Normal file
@ -0,0 +1,247 @@
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
/*
|
||||
.--
|
||||
|__
|
||||
| IFTEEN
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
typedef signed char byte;
|
||||
byte size;
|
||||
byte py,px;
|
||||
byte ey,ex; //the empty tile
|
||||
chtype green=A_BOLD; //bold when there is no color
|
||||
void rectangle(byte sy,byte sx){
|
||||
for(byte y=0;y<=size+1;y++){
|
||||
mvaddch(sy+y,sx,ACS_VLINE);
|
||||
mvaddch(sy+y,sx+size*2,ACS_VLINE);
|
||||
}
|
||||
for(byte x=0;x<=size*2;x++){
|
||||
mvaddch(sy,sx+x,ACS_HLINE);
|
||||
mvaddch(sy+size+1,sx+x,ACS_HLINE);
|
||||
}
|
||||
mvaddch(sy,sx,ACS_ULCORNER);
|
||||
mvaddch(sy+size+1,sx,ACS_LLCORNER);
|
||||
mvaddch(sy,sx+size*2,ACS_URCORNER);
|
||||
mvaddch(sy+size+1,sx+size*2,ACS_LRCORNER);
|
||||
}
|
||||
void logo(byte sy,byte sx){
|
||||
mvaddstr(sy,sx, ".--");
|
||||
mvaddstr(sy+1,sx,"|__");
|
||||
mvaddstr(sy+2,sx,"| IFTEEN");
|
||||
}
|
||||
//convert integer to representing sign
|
||||
char int2sgn(byte num){
|
||||
if(!num)
|
||||
return ' ';
|
||||
else if(0< num && num <= 9)
|
||||
return num+'0';
|
||||
else if(10<=num && num <=35)
|
||||
return num-10+'a';
|
||||
else if(36<=num && num <=51)
|
||||
return num-36+'A';
|
||||
return 0;
|
||||
}
|
||||
/*bool isinorder(byte board[size][size],byte y,byte x){ using check[][] is much cheaper
|
||||
return (board[y][x] == y*size+x+1);
|
||||
} */
|
||||
|
||||
//display
|
||||
void draw(byte sy,byte sx,char board[size][size],char check[size][size]){
|
||||
rectangle(sy,sx);
|
||||
chtype prnt;
|
||||
byte y,x;
|
||||
for(y=0;y<size;y++){
|
||||
for(x=0;x<size;x++){
|
||||
prnt=board[y][x];
|
||||
if(check[y][x]==board[y][x] && check[y][x] != ' ')
|
||||
prnt |= green;
|
||||
if(y==py && x==px)
|
||||
prnt |= A_STANDOUT;
|
||||
mvaddch(sy+1+y,sx+x*2+1,prnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
void fill(char board[size][size]){
|
||||
byte y,x;
|
||||
for(y=0;y<size;y++){
|
||||
for(x=0;x<size;x++){
|
||||
board[y][x]= int2sgn(y*size+x+1);
|
||||
}
|
||||
}
|
||||
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) ){
|
||||
board[ey][ex]=board[y][x];
|
||||
board[y][x]=' ';
|
||||
ey=y;
|
||||
ex=x;
|
||||
}
|
||||
}
|
||||
void slide_multi(char board[size][size],byte y,byte x){
|
||||
byte dy,dx;
|
||||
if( (ey==y) ^ (ex==x) ){
|
||||
if(ey!=y)
|
||||
dy=(y-ey)/abs(y-ey);
|
||||
if(ex!=x)
|
||||
dx=(x-ex)/abs(x-ex);
|
||||
while(ex!=x || ey!=y)
|
||||
slide_one(board,ey+dy,ex+dx);//ey/x comes forth itself
|
||||
ey=y;
|
||||
ex=x;
|
||||
}
|
||||
}
|
||||
bool issolved(char board[size][size],char check[size][size]){
|
||||
byte y,x;
|
||||
for(y=0;y<size;y++){
|
||||
for(x=0;x<size;x++){
|
||||
if(board[y][x]!=check[y][x])
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
void shuffle(char board[size][size]){
|
||||
for(int m=0;m<1000;m++){
|
||||
switch(random()%4){
|
||||
case 0:
|
||||
slide_one(board,ey,ex+1);
|
||||
break;
|
||||
case 1:
|
||||
slide_one(board,ey,ex-1);
|
||||
break;
|
||||
case 2:
|
||||
slide_one(board,ey+1,ex);
|
||||
break;
|
||||
case 3:
|
||||
slide_one(board,ey-1,ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
//peacefully close when ^C is pressed
|
||||
void sigint_handler(int x){
|
||||
endwin();
|
||||
puts("Quit.");
|
||||
exit(x);
|
||||
}
|
||||
void mouseinput(void){
|
||||
MEVENT minput;
|
||||
getmouse(&minput);
|
||||
if( minput.y-4<size && minput.x-1<size*2){
|
||||
py=minput.y-4;
|
||||
px=(minput.x-1)/2;
|
||||
}
|
||||
else
|
||||
return;
|
||||
if(minput.bstate & BUTTON1_CLICKED)
|
||||
ungetch('\n');
|
||||
}
|
||||
void help(void){
|
||||
erase();
|
||||
logo(0,0);
|
||||
attron(A_BOLD);
|
||||
mvprintw(3,0," **** THE CONTROLS ****");
|
||||
mvprintw(8,0,"YOU CAN ALSO USE THE MOUSE!");
|
||||
attroff(A_BOLD);
|
||||
mvprintw(4,0,"RETURN/ENTER : Slide");
|
||||
mvprintw(5,0,"hjkl/ARROW KEYS : Move cursor");
|
||||
mvprintw(6,0,"q : Quit");
|
||||
mvprintw(7,0,"F1 & F2 : Help on controls & gameplay");
|
||||
mvprintw(10,0,"Press a key to continue");
|
||||
refresh();
|
||||
getch();
|
||||
erase();
|
||||
}
|
||||
void gameplay(void){
|
||||
erase();
|
||||
logo(0,0);
|
||||
attron(A_BOLD);
|
||||
mvprintw(3,0," **** THE GAMEPLAY ****");
|
||||
attroff(A_BOLD);
|
||||
mvprintw(4,0,"Slide the tiles until the numbers and characters are\n");
|
||||
printw("in the right order.\n");
|
||||
refresh();
|
||||
getch();
|
||||
erase();
|
||||
}
|
||||
int main(int argc, char** argv){
|
||||
size=4;
|
||||
if(argc==2){
|
||||
if(!strcmp("help",argv[1])){
|
||||
printf("Usage: %s [size]\n",argv[0]);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
size=atoi(argv[1]);
|
||||
if(size<3 || size>7){
|
||||
fprintf(stderr,"3<=size<=7\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
signal(SIGINT,sigint_handler);
|
||||
srandom(time(NULL)%UINT_MAX);
|
||||
initscr();
|
||||
mousemask(ALL_MOUSE_EVENTS,NULL);
|
||||
noecho();
|
||||
cbreak();
|
||||
keypad(stdscr,1);
|
||||
if(has_colors()){
|
||||
start_color();
|
||||
use_default_colors();
|
||||
init_pair(1,COLOR_GREEN,-1);
|
||||
green=COLOR_PAIR(1);
|
||||
}
|
||||
char board[size][size];
|
||||
char check[size][size];
|
||||
fill(check);
|
||||
int input;
|
||||
Start:
|
||||
py=px=0;
|
||||
ey=ex=size-1;
|
||||
curs_set(0);
|
||||
fill(board);
|
||||
shuffle(board);
|
||||
while(1){
|
||||
erase();
|
||||
logo(0,0);
|
||||
draw(3,0,board,check);
|
||||
refresh();
|
||||
if(issolved(board,check))
|
||||
break;
|
||||
input = getch();
|
||||
if( input==KEY_F(1) || input=='?' )
|
||||
help();
|
||||
if( input==KEY_F(2) )
|
||||
gameplay();
|
||||
if( input==KEY_MOUSE )
|
||||
mouseinput();
|
||||
if( (input=='k' || input==KEY_UP) && py>0)
|
||||
py--;
|
||||
if( (input=='j' || input==KEY_DOWN) && py<size-1)
|
||||
py++;
|
||||
if( (input=='h' || input==KEY_LEFT) && px>0)
|
||||
px--;
|
||||
if( (input=='l' || input==KEY_RIGHT) && px<size-1)
|
||||
px++;
|
||||
if( input=='q')
|
||||
sigint_handler(0);
|
||||
if(input=='\n'){
|
||||
slide_multi(board,py,px);
|
||||
}
|
||||
}
|
||||
mvprintw(size+5,0,"You solved it! Wanna play again?(y/n)");
|
||||
curs_set(1);
|
||||
input=getch();
|
||||
if(input != 'N' && input != 'n' && input != 'q')
|
||||
goto Start;
|
||||
endwin();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
254
sources/memoblocks.c
Normal file
254
sources/memoblocks.c
Normal file
@ -0,0 +1,254 @@
|
||||
#include <curses.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
/*
|
||||
. . _
|
||||
|\/| |_)
|
||||
| |EMORY|_)LOCKS
|
||||
|
||||
Authored by Hossein Bakhtiarifar <abakh@tuta.io>
|
||||
No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law.
|
||||
|
||||
compile with -lncurses
|
||||
*/
|
||||
typedef signed char byte;
|
||||
typedef unsigned char ubyte;
|
||||
byte size,size2;//size2 is there to avoid a lot of multiplications
|
||||
byte py,px;
|
||||
byte fy,fx; //the first tile
|
||||
chtype colors[6]={0};
|
||||
void rectangle(byte sy,byte sx){
|
||||
for(byte y=0;y<=size+1;y++){
|
||||
mvaddch(sy+y,sx,ACS_VLINE);
|
||||
mvaddch(sy+y,sx+size2+1,ACS_VLINE);
|
||||
}
|
||||
for(byte x=0;x<=size2+1;x++){
|
||||
mvaddch(sy,sx+x,ACS_HLINE);
|
||||
mvaddch(sy+size+1,sx+x,ACS_HLINE);
|
||||
}
|
||||
mvaddch(sy,sx,ACS_ULCORNER);
|
||||
mvaddch(sy+size+1,sx,ACS_LLCORNER);
|
||||
mvaddch(sy,sx+size2+1,ACS_URCORNER);
|
||||
mvaddch(sy+size+1,sx+size2+1,ACS_LRCORNER);
|
||||
}
|
||||
void logo(byte sy,byte sx){
|
||||
mvaddstr(sy,sx, ". . _");
|
||||
mvaddstr(sy+1,sx,"|\\/| |_)");
|
||||
mvaddstr(sy+2,sx,"| |EMORY|_)LOCKS");
|
||||
}
|
||||
//convert integer to representing sign
|
||||
char int2sgn(byte num){
|
||||
if(0< num && num <= 9)
|
||||
return num+'0';
|
||||
else if(10<=num && num <=35)
|
||||
return num-10+'a';
|
||||
else if(36<=num && num <=51)
|
||||
return num-36+'A';
|
||||
else if(52<=num && num<=64)
|
||||
return num-52+'!';
|
||||
return 0;
|
||||
}
|
||||
//display
|
||||
void draw(byte sy,byte sx,chtype board[size][size2],bool show[size][size2]){
|
||||
rectangle(sy,sx);
|
||||
byte y,x;
|
||||
chtype prnt;
|
||||
for(y=0;y<size;y++){
|
||||
for(x=0;x<size2;x++){
|
||||
if(show[y][x] || (y==fy && x==fx) )
|
||||
prnt=board[y][x];
|
||||
else
|
||||
prnt='.';
|
||||
if(y==py && x==px)
|
||||
prnt|=A_STANDOUT;
|
||||
|
||||
mvaddch(sy+1+y,sx+1+x,prnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
void fill(chtype board[size][size2]){
|
||||
ubyte y,x,m;
|
||||
int n;
|
||||
for(y=0;y<size;y++){
|
||||
for(x=0;x<size2;x++){
|
||||
n=(y*size2+x)/2;
|
||||
if(size*size<193) //(1+0*64)%6 == (1+3*64)%6 so this won't work in n=193 and above
|
||||
m=n%6;
|
||||
else //this for default wouldn't be colorful enough blow n=193
|
||||
m=(n/64)%6;
|
||||
board[y][x]=int2sgn((n%64)+1)|colors[m];
|
||||
//fills with 1,1,2,2,.. with colored pairs
|
||||
}
|
||||
}
|
||||
}
|
||||
bool issolved(bool show[size][size2]){
|
||||
byte y,x;
|
||||
for(y=0;y<size;y++){
|
||||
for(x=0;x<size2;x++){
|
||||
if(!show[y][x])
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
void shuffle(chtype board[size][size2]){
|
||||
int n=size*size*3;
|
||||
chtype a;
|
||||
byte ay,ax,by,bx;
|
||||
for(int m=0;m<n;m++){
|
||||
ay=random()%size;
|
||||
ax=random()%(size2);
|
||||
by=random()%size;
|
||||
bx=random()%(size2);
|
||||
a=board[ay][ax];
|
||||
board[ay][ax]=board[by][bx];
|
||||
board[by][bx]=a;
|
||||
}
|
||||
}
|
||||
//peacefully close when ^C is pressed
|
||||
void sigint_handler(int x){
|
||||
endwin();
|
||||
puts("Quit.");
|
||||
exit(x);
|
||||
}
|
||||
void mouseinput(void){
|
||||
MEVENT minput;
|
||||
getmouse(&minput);
|
||||
if( minput.y-4<size && minput.x-1<size2){
|
||||
py=minput.y-4;
|
||||
px=(minput.x-1);
|
||||
}
|
||||
else
|
||||
return;
|
||||
if(minput.bstate & BUTTON1_CLICKED)
|
||||
ungetch('\n');
|
||||
}
|
||||
void help(void){
|
||||
erase();
|
||||
logo(0,0);
|
||||
attron(A_BOLD);
|
||||
mvprintw(3,0," **** THE CONTROLS ****");
|
||||
mvprintw(8,0,"YOU CAN ALSO USE THE MOUSE!");
|
||||
attroff(A_BOLD);
|
||||
mvprintw(4,0,"RETURN/ENTER : Reveal");
|
||||
mvprintw(5,0,"hjkl/ARROW KEYS : Move cursor");
|
||||
mvprintw(6,0,"q : Quit");
|
||||
mvprintw(7,0,"F1 & F2 : Help on controls & gameplay");
|
||||
mvprintw(10,0,"Press a key to continue");
|
||||
refresh();
|
||||
getch();
|
||||
erase();
|
||||
}
|
||||
void gameplay(void){
|
||||
erase();
|
||||
logo(0,0);
|
||||
attron(A_BOLD);
|
||||
mvprintw(3,0," **** THE GAMEPLAY ****");
|
||||
attroff(A_BOLD);
|
||||
mvprintw(4,0,"Click on a tile to see the gylph it contains,\n");
|
||||
printw( "then try to find a matching gylph the same way.\n");
|
||||
printw( "They form a pair only when you click a tile\n");
|
||||
printw( "directly after the match. The game ends when \n");
|
||||
printw( "you have found all the matching pairs.\n");
|
||||
refresh();
|
||||
getch();
|
||||
erase();
|
||||
}
|
||||
int main(int argc, char** argv){
|
||||
size=8;
|
||||
if(argc>=2){
|
||||
size=atoi(argv[1]);
|
||||
if(size<3 || size>19){
|
||||
fprintf(stderr,"3<=size<=19\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(!strcmp("help",argv[1])){
|
||||
printf("Usage: %s [size]\n",argv[0]);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
signal(SIGINT,sigint_handler);
|
||||
srandom(time(NULL)%UINT_MAX);
|
||||
initscr();
|
||||
mousemask(ALL_MOUSE_EVENTS,NULL);
|
||||
noecho();
|
||||
cbreak();
|
||||
keypad(stdscr,1);
|
||||
if(has_colors()){
|
||||
start_color();
|
||||
use_default_colors();
|
||||
if( has_colors() ){
|
||||
start_color();
|
||||
use_default_colors();
|
||||
init_pair(1,COLOR_YELLOW,-1);
|
||||
init_pair(2,COLOR_GREEN,-1);
|
||||
init_pair(3,COLOR_BLUE,-1);
|
||||
init_pair(4,COLOR_CYAN,-1);
|
||||
init_pair(5,COLOR_MAGENTA,-1);
|
||||
init_pair(6,COLOR_RED,-1);
|
||||
for(byte b=0;b<6;b++){
|
||||
colors[b]=COLOR_PAIR(b+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(size>8)//big sizes depend on color display
|
||||
size=8;
|
||||
size2=size*2;
|
||||
chtype board[size][size2];
|
||||
bool show[size][size2];
|
||||
int input;
|
||||
time_t tstart,now;
|
||||
Start:
|
||||
tstart=time(NULL);
|
||||
py=px=0;
|
||||
fy=fx=-1;
|
||||
curs_set(0);
|
||||
memset(show,0,size*size2);
|
||||
fill(board);
|
||||
shuffle(board);
|
||||
while(1){
|
||||
erase();
|
||||
logo(0,0);
|
||||
draw(3,0,board,show);
|
||||
refresh();
|
||||
if(issolved(show))
|
||||
break;
|
||||
input = getch();
|
||||
if( input==KEY_F(1) || input=='?' )
|
||||
help();
|
||||
if( input==KEY_F(2) )
|
||||
gameplay();
|
||||
if( input==KEY_MOUSE )
|
||||
mouseinput();
|
||||
if( (input=='k' || input==KEY_UP) && py>0)
|
||||
py--;
|
||||
if( (input=='j' || input==KEY_DOWN) && py<size-1)
|
||||
py++;
|
||||
if( (input=='h' || input==KEY_LEFT) && px>0)
|
||||
px--;
|
||||
if( (input=='l' || input==KEY_RIGHT) && px<size2-1)
|
||||
px++;
|
||||
if( input=='q')
|
||||
sigint_handler(0);
|
||||
if(input=='\n'){
|
||||
if(fy!=-1 && board[py][px]==board[fy][fx] && !(fy==py && fx==px) )
|
||||
show[py][px]=show[fy][fx]=1;
|
||||
else{
|
||||
fy=py;
|
||||
fx=px;
|
||||
}
|
||||
}
|
||||
}
|
||||
now=time(NULL)-tstart;
|
||||
mvprintw(size+7,0,"Time spent: %d:%2d:%2d",now/3600,(now%3600)/60,now%60);
|
||||
mvprintw(size+5,0,"You solved it! Wanna play again?(y/n)");
|
||||
curs_set(1);
|
||||
input=getch();
|
||||
if(input != 'N' && input != 'n' && input != 'q')
|
||||
goto Start;
|
||||
endwin();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue
Block a user