Compare commits
17 Commits
2b6fd74849
...
v1.28
| Author | SHA1 | Date | |
|---|---|---|---|
| 2855b64f03 | |||
| 9c45259962 | |||
| b1256014e3 | |||
| b1af7b4f41 | |||
| bbaf2f50f9 | |||
| 6915a0d827 | |||
| cf2fa8a9c2 | |||
| 082f4df08c | |||
| 2b0f20d65a | |||
| e394d0986e | |||
| d8eb655dd7 | |||
| b878c2ddb3 | |||
| a0e5850e68 | |||
| 84972ed9bb | |||
| 08f6ee7161 | |||
| f7d2f138ea | |||
| 1d07cee01a |
@@ -39,7 +39,7 @@ $(shell mkdir -p $(RLS_DIR))
|
|||||||
$(shell mkdir -p $(BUILD_DIR))
|
$(shell mkdir -p $(BUILD_DIR))
|
||||||
|
|
||||||
# phony rules
|
# phony rules
|
||||||
.PHONY := all debug release clean install uninstall
|
.PHONY = all debug release clean install uninstall
|
||||||
|
|
||||||
all: release
|
all: release
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ $(shell if not exist $(RLS_DIR) mkdir $(RLS_DIR))
|
|||||||
$(shell if not exist $(BUILD_DIR) mkdir $(BUILD_DIR))
|
$(shell if not exist $(BUILD_DIR) mkdir $(BUILD_DIR))
|
||||||
|
|
||||||
# phony rules
|
# phony rules
|
||||||
.PHONY := all debug release clean libraries_debug libraries_release both
|
.PHONY = all debug release clean libraries_debug libraries_release both
|
||||||
|
|
||||||
all: release
|
all: release
|
||||||
|
|
||||||
|
|||||||
53
src/main.cpp
53
src/main.cpp
@@ -8,6 +8,15 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "Board.h"
|
#include "Board.h"
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <signal.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
struct winsize w;
|
||||||
|
void handleSIGWINCH(int sig)
|
||||||
|
{
|
||||||
|
ioctl(STDIN_FILENO, TIOCGWINSZ, &w);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MAX_TIME 60
|
#define MAX_TIME 60
|
||||||
|
|
||||||
@@ -33,8 +42,17 @@ void startGame(Board &board)
|
|||||||
|
|
||||||
while (gameRunning)
|
while (gameRunning)
|
||||||
{
|
{
|
||||||
|
|
||||||
usleep((1000 / MAX_TIME) * 1000);
|
usleep((1000 / MAX_TIME) * 1000);
|
||||||
|
#ifndef _WIN32
|
||||||
|
if ((w.ws_row < boardSize.x + 3) || (w.ws_col < boardSize.y + 2))
|
||||||
|
{
|
||||||
|
mvprintw(w.ws_col / 2, w.ws_row / 2, "Your terminal is too small:");
|
||||||
|
mvprintw(w.ws_col / 2 + 1, w.ws_row / 2, "Current size: %dx%d", w.ws_row, w.ws_col);
|
||||||
|
mvprintw(w.ws_col / 2 + 2, w.ws_row / 2, "Min size: %dx%d", boardSize.x + 3, boardSize.y + 2);
|
||||||
|
refresh();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (board.isGameOver() || board.isGameWon())
|
if (board.isGameOver() || board.isGameWon())
|
||||||
{
|
{
|
||||||
gameRunning = false;
|
gameRunning = false;
|
||||||
@@ -160,6 +178,9 @@ void startGame(Board &board)
|
|||||||
cursorX = (cursorX < boardSize.x - 1) ? cursorX + 1 : 0;
|
cursorX = (cursorX < boardSize.x - 1) ? cursorX + 1 : 0;
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
|
echo();
|
||||||
|
cbreak();
|
||||||
|
endwin();
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
@@ -255,13 +276,21 @@ void startGame(Board &board)
|
|||||||
mvprintw(1, 8, "%s", tim);
|
mvprintw(1, 8, "%s", tim);
|
||||||
attroff(COLOR_PAIR(3));
|
attroff(COLOR_PAIR(3));
|
||||||
refresh();
|
refresh();
|
||||||
while ((c = getch()) != 'q')
|
while (true)
|
||||||
{
|
{
|
||||||
|
c = getch();
|
||||||
if (c == 'r')
|
if (c == 'r')
|
||||||
{
|
{
|
||||||
Board newBoard(boardSize.x, boardSize.y, board.getMineCount());
|
Board newBoard(boardSize.x, boardSize.y, board.getMineCount());
|
||||||
startGame(newBoard);
|
startGame(newBoard);
|
||||||
}
|
}
|
||||||
|
else if (c == 'q')
|
||||||
|
{
|
||||||
|
echo();
|
||||||
|
cbreak();
|
||||||
|
endwin();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (board.isGameWon())
|
else if (board.isGameWon())
|
||||||
@@ -279,25 +308,39 @@ void startGame(Board &board)
|
|||||||
attroff(COLOR_PAIR(3));
|
attroff(COLOR_PAIR(3));
|
||||||
refresh();
|
refresh();
|
||||||
int c;
|
int c;
|
||||||
while ((c = getch()) != 'q')
|
while (true)
|
||||||
{
|
{
|
||||||
|
c = getch();
|
||||||
if (c == 'r')
|
if (c == 'r')
|
||||||
{
|
{
|
||||||
Board newBoard(boardSize.x, boardSize.y, board.getMineCount());
|
Board newBoard(boardSize.x, boardSize.y, board.getMineCount());
|
||||||
startGame(newBoard);
|
startGame(newBoard);
|
||||||
}
|
}
|
||||||
|
else if (c == 'q')
|
||||||
|
{
|
||||||
|
echo();
|
||||||
|
cbreak();
|
||||||
|
endwin();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
|
signal(SIGWINCH, handleSIGWINCH);
|
||||||
|
#endif
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
initscr();
|
initscr();
|
||||||
noecho();
|
noecho();
|
||||||
cbreak();
|
cbreak();
|
||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
nodelay(stdscr, TRUE);
|
nodelay(stdscr, TRUE);
|
||||||
|
#ifndef _WIN32
|
||||||
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||||
|
#endif
|
||||||
|
|
||||||
start_color();
|
start_color();
|
||||||
init_pair(1, COLOR_BLUE, COLOR_BLACK);
|
init_pair(1, COLOR_BLUE, COLOR_BLACK);
|
||||||
@@ -328,9 +371,9 @@ int main()
|
|||||||
attroff(A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
mvprintw(3, 2, choice == 1 ? "" : "Intermediate (16x16, 40 mines)");
|
mvprintw(3, 2, choice == 1 ? "" : "Intermediate (16x16, 40 mines)");
|
||||||
attron(A_REVERSE);
|
attron(A_REVERSE);
|
||||||
mvprintw(4, 2, choice == 2 ? "Expert (16x30, 99 mines)" : "");
|
mvprintw(4, 2, choice == 2 ? "Expert (30x16, 99 mines)" : "");
|
||||||
attroff(A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
mvprintw(4, 2, choice == 2 ? "" : "Expert (16x30, 99 mines)");
|
mvprintw(4, 2, choice == 2 ? "" : "Expert (30x16, 99 mines)");
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
int ch = getch();
|
int ch = getch();
|
||||||
|
|||||||
Reference in New Issue
Block a user