Compare commits
10 Commits
a65787b674
...
v1.25
| Author | SHA1 | Date | |
|---|---|---|---|
| e379d5e8ee | |||
| 4c9335e73c | |||
| cd4004dc23 | |||
| 7949ee4ab4 | |||
| 02156d4a66 | |||
| 5689e8c9bc | |||
| 8cca2eb3ee | |||
| 8ff364db5a | |||
| 80a10a157e | |||
| d71f5e2a2e |
@@ -15,6 +15,8 @@ SRC_DIR := src
|
|||||||
BIN_DIR := bin
|
BIN_DIR := bin
|
||||||
DBG_DIR := $(BIN_DIR)/debug
|
DBG_DIR := $(BIN_DIR)/debug
|
||||||
RLS_DIR := $(BIN_DIR)/release
|
RLS_DIR := $(BIN_DIR)/release
|
||||||
|
DBG_EXEC := $(DBG_DIR)/debug
|
||||||
|
RLS_STRIPPED_EXEC := $(RLS_DIR)/tuimine
|
||||||
|
|
||||||
# sources and objects
|
# sources and objects
|
||||||
SRCS := $(wildcard $(SRC_DIR)/*.cpp)
|
SRCS := $(wildcard $(SRC_DIR)/*.cpp)
|
||||||
@@ -29,22 +31,19 @@ $(shell mkdir -p $(BUILD_DIR))
|
|||||||
# phony rules
|
# phony rules
|
||||||
.PHONY := all debug release clean
|
.PHONY := all debug release clean
|
||||||
|
|
||||||
all: debug
|
all: release
|
||||||
|
|
||||||
debug: $(DBG_DIR)/debug
|
debug: $(DBG_EXEC)
|
||||||
release: $(RLS_DIR)/release $(RLS_DIR)/release_stripped
|
release: $(RLS_STRIPPED_EXEC)
|
||||||
both: debug release
|
both: debug release
|
||||||
|
|
||||||
# linking
|
# linking
|
||||||
$(DBG_DIR)/debug: $(DBG_OBJS)
|
$(DBG_EXEC): $(DBG_OBJS)
|
||||||
$(CXX) -o $@ $^ $(DBG_LDFLAGS)
|
$(CXX) -o $@ $^ $(DBG_LDFLAGS)
|
||||||
|
|
||||||
$(RLS_DIR)/release_stripped: $(RLS_OBJS)
|
$(RLS_STRIPPED_EXEC): $(RLS_OBJS)
|
||||||
$(CXX) -o $@ $^ $(RLS_LDFLAGS)
|
$(CXX) -o $@ $^ $(RLS_LDFLAGS)
|
||||||
|
|
||||||
$(RLS_DIR)/release: $(RLS_OBJS)
|
|
||||||
$(CXX) -o $@ $^ $(LDFLAGS)
|
|
||||||
|
|
||||||
# compiling
|
# compiling
|
||||||
$(BUILD_DIR)/debug_%.o: $(SRC_DIR)/%.cpp
|
$(BUILD_DIR)/debug_%.o: $(SRC_DIR)/%.cpp
|
||||||
$(CXX) -c -o $@ $< $(DBG_CXXFLAGS)
|
$(CXX) -c -o $@ $< $(DBG_CXXFLAGS)
|
||||||
|
|||||||
15
Makefile.win
15
Makefile.win
@@ -16,6 +16,8 @@ BIN_DIR := bin
|
|||||||
DBG_DIR := $(BIN_DIR)\debug
|
DBG_DIR := $(BIN_DIR)\debug
|
||||||
RLS_DIR := $(BIN_DIR)\release
|
RLS_DIR := $(BIN_DIR)\release
|
||||||
LIB_DIR := lib
|
LIB_DIR := lib
|
||||||
|
DBG_EXEC := $(DBG_DIR)\debug.exe
|
||||||
|
RLS_STRIPPED_EXEC := $(RLS_DIR)\tuimine.exe
|
||||||
|
|
||||||
# sources and objects
|
# sources and objects
|
||||||
LIBS := $(wildcard $(LIB_DIR)/*.dll)
|
LIBS := $(wildcard $(LIB_DIR)/*.dll)
|
||||||
@@ -33,25 +35,22 @@ $(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: debug
|
all: release
|
||||||
|
|
||||||
debug: $(DBG_DIR)/debug.exe libraries_debug
|
debug: $(DBG_EXEC) libraries_debug
|
||||||
release: $(RLS_DIR)/release_stripped.exe $(RLS_DIR)/release.exe libraries_release
|
release: $(RLS_STRIPPED_EXEC) libraries_release
|
||||||
both: debug release
|
both: debug release
|
||||||
|
|
||||||
libraries_debug: $(LIBS_DBG)
|
libraries_debug: $(LIBS_DBG)
|
||||||
libraries_release: $(LIBS_RLS)
|
libraries_release: $(LIBS_RLS)
|
||||||
|
|
||||||
# linking
|
# linking
|
||||||
$(DBG_DIR)/debug.exe: $(DBG_OBJS)
|
$(DBG_EXEC): $(DBG_OBJS)
|
||||||
$(CXX) -o $@ $^ $(DBG_LDFLAGS)
|
$(CXX) -o $@ $^ $(DBG_LDFLAGS)
|
||||||
|
|
||||||
$(RLS_DIR)/release_stripped.exe: $(RLS_OBJS)
|
$(RLS_STRIPPED_EXEC): $(RLS_OBJS)
|
||||||
$(CXX) -o $@ $^ $(RLS_STRP_LDFLAGS)
|
$(CXX) -o $@ $^ $(RLS_STRP_LDFLAGS)
|
||||||
|
|
||||||
$(RLS_DIR)/release.exe: $(RLS_OBJS)
|
|
||||||
$(CXX) -o $@ $^ $(LDFLAGS)
|
|
||||||
|
|
||||||
# compiling
|
# compiling
|
||||||
$(BUILD_DIR)/debug_%.o: $(SRC_DIR)/%.cpp
|
$(BUILD_DIR)/debug_%.o: $(SRC_DIR)/%.cpp
|
||||||
$(CXX) -c -o $@ $< $(DBG_CXXFLAGS)
|
$(CXX) -c -o $@ $< $(DBG_CXXFLAGS)
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ R to restart.
|
|||||||
P to pause.
|
P to pause.
|
||||||
Q to quit.
|
Q to quit.
|
||||||
|
|
||||||
|
You can't chord if the number isn't equal to the number of flags it's near.
|
||||||
|
You can't see the board if you're paused to (help) prevent cheating.
|
||||||
|
You can't flag already revealed cells.
|
||||||
|
|
||||||
## Compilation
|
## Compilation
|
||||||
|
|
||||||
By default, the Makefile compiles in debug mode, so to compile both, use `make both`.
|
By default, the Makefile compiles in debug mode, so to compile both, use `make both`.
|
||||||
|
|||||||
44
src/main.cpp
44
src/main.cpp
@@ -18,13 +18,15 @@ void startGame(Board &board)
|
|||||||
refresh();
|
refresh();
|
||||||
bool gameRunning = true;
|
bool gameRunning = true;
|
||||||
|
|
||||||
time_t startTime = time(nullptr);
|
time_t startTime = 0;
|
||||||
int elapsedTime = 0;
|
int elapsedTime = 0;
|
||||||
|
|
||||||
bool isPaused = false;
|
bool isPaused = false;
|
||||||
time_t startPauseTime = 0;
|
time_t startPauseTime = 0;
|
||||||
time_t pauseTime = 0;
|
time_t pauseTime = 0;
|
||||||
time_t totalpausetime = 0;
|
time_t totalpausetime = 0;
|
||||||
|
bool somethingHasBeenDone = false;
|
||||||
|
|
||||||
while (gameRunning)
|
while (gameRunning)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -33,7 +35,7 @@ void startGame(Board &board)
|
|||||||
{
|
{
|
||||||
gameRunning = false;
|
gameRunning = false;
|
||||||
}
|
}
|
||||||
if (!isPaused)
|
if (!isPaused && somethingHasBeenDone)
|
||||||
elapsedTime = difftime(time(NULL), startTime) - totalpausetime;
|
elapsedTime = difftime(time(NULL), startTime) - totalpausetime;
|
||||||
char flags[5];
|
char flags[5];
|
||||||
char tim[5];
|
char tim[5];
|
||||||
@@ -84,6 +86,9 @@ void startGame(Board &board)
|
|||||||
displayChar = 'X';
|
displayChar = 'X';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isPaused)
|
||||||
|
displayChar = '#';
|
||||||
|
|
||||||
if (x == cursorX && y == cursorY)
|
if (x == cursorX && y == cursorY)
|
||||||
{
|
{
|
||||||
attron(A_REVERSE);
|
attron(A_REVERSE);
|
||||||
@@ -151,12 +156,24 @@ 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':
|
||||||
return;
|
exit(0);
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
|
if (!somethingHasBeenDone)
|
||||||
|
{
|
||||||
|
startTime = time(nullptr);
|
||||||
|
somethingHasBeenDone = true;
|
||||||
|
}
|
||||||
board.revealCellAt(cursorX, cursorY);
|
board.revealCellAt(cursorX, cursorY);
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
|
if (board.getCellStateAt(cursorX, cursorY) == Cell::State::Revealed)
|
||||||
|
break;
|
||||||
|
if (!somethingHasBeenDone)
|
||||||
|
{
|
||||||
|
startTime = time(nullptr);
|
||||||
|
somethingHasBeenDone = true;
|
||||||
|
}
|
||||||
if (board.getCellStateAt(cursorX, cursorY) == Cell::State::Flagged)
|
if (board.getCellStateAt(cursorX, cursorY) == Cell::State::Flagged)
|
||||||
{
|
{
|
||||||
minesLeft++;
|
minesLeft++;
|
||||||
@@ -168,9 +185,11 @@ void startGame(Board &board)
|
|||||||
board.flagCellAt(cursorX, cursorY);
|
board.flagCellAt(cursorX, cursorY);
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
startTime = time(NULL);
|
startTime = 0;
|
||||||
minesLeft = board.getMineCount();
|
minesLeft = board.getMineCount();
|
||||||
board.regenerateBoard();
|
board.regenerateBoard();
|
||||||
|
somethingHasBeenDone = false;
|
||||||
|
elapsedTime = 0;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if (isPaused)
|
if (isPaused)
|
||||||
@@ -185,7 +204,24 @@ void startGame(Board &board)
|
|||||||
isPaused = !isPaused;
|
isPaused = !isPaused;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
|
if (board.getCellStateAt(cursorX, cursorY) != Cell::State::Revealed)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!somethingHasBeenDone)
|
||||||
|
{
|
||||||
|
startTime = time(nullptr);
|
||||||
|
somethingHasBeenDone = true;
|
||||||
|
}
|
||||||
auto neighbors = board.getNeighborsOf(cursorX, cursorY);
|
auto neighbors = board.getNeighborsOf(cursorX, cursorY);
|
||||||
|
int flagCount = 0;
|
||||||
|
for (const Cell &neighbor : neighbors)
|
||||||
|
{
|
||||||
|
if (neighbor.getState() == Cell::State::Flagged)
|
||||||
|
flagCount++;
|
||||||
|
}
|
||||||
|
if (static_cast<int>(board.revealCellAt(cursorX, cursorY).getContent()) > flagCount)
|
||||||
|
break;
|
||||||
for (const Cell &neighbor : neighbors)
|
for (const Cell &neighbor : neighbors)
|
||||||
{
|
{
|
||||||
if (neighbor.getState() == Cell::State::Flagged)
|
if (neighbor.getState() == Cell::State::Flagged)
|
||||||
|
|||||||
Reference in New Issue
Block a user