-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,334 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
test.cpp | ||
test | ||
test.txt | ||
test2 | ||
mine | ||
.vscode/settings.json | ||
MineSweeper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Pranav Bhatnagar | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
OBJS = source/mine.cpp | ||
|
||
#Change compiler here if required | ||
CC = g++ | ||
|
||
OBJ_NAME = mine | ||
|
||
all : | ||
$(CC) $(OBJS) -std=c++11 -o $(OBJ_NAME) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,38 @@ | ||
Minesweeper Login | ||
# MineSweeper | ||
|
||
Command Line version of MineSweeper for Unix-like systems (GNU/Linux, macOS, BSD). | ||
|
||
<p align="center"> | ||
<img align="center" src="assets/demo.gif"></img> | ||
</p> | ||
|
||
## Prerequisites | ||
1. C++11 compiler | ||
|
||
|
||
## Installation | ||
|
||
1. Clone the repo. | ||
|
||
```bash | ||
$ git clone https://github.com/unknownblueguy6/MineSweeper.git | ||
``` | ||
|
||
2. cd to the MineSweeper folder, and then build it using the Makefile. | ||
|
||
(Change the compiler in the Makefile, if required. Default compiler is g++) | ||
|
||
```bash | ||
$ cd MineSweeper | ||
$ make | ||
``` | ||
|
||
3. Run it. | ||
|
||
```bash | ||
$ ./mine | ||
``` | ||
|
||
## TODO: | ||
|
||
1. Update the gif with new controls |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
|
||
class Buffer | ||
{ | ||
public: | ||
Buffer(); | ||
friend Buffer &operator<<(Buffer &curr, const std::string &str); | ||
void goToLine(int); | ||
int getCurrLine(); | ||
void disp(); | ||
void clear(); | ||
|
||
private: | ||
int line; | ||
std::vector<std::string> buf; | ||
int size; | ||
|
||
} writeBuf; | ||
|
||
Buffer::Buffer() | ||
{ | ||
buf.push_back(""); | ||
line = 0; | ||
size = 1; | ||
} | ||
|
||
Buffer &operator<<(Buffer &curr, const std::string &str) | ||
{ | ||
if (str == "\n") | ||
{ | ||
if (curr.line == curr.size - 1) | ||
{ | ||
curr.buf.push_back(""); | ||
++curr.line; | ||
++curr.size; | ||
} | ||
else | ||
{ | ||
++curr.line; | ||
} | ||
} | ||
else | ||
curr.buf[curr.line] += str; | ||
|
||
return curr; | ||
} | ||
|
||
void Buffer::goToLine(int n) | ||
{ | ||
if (n > size) | ||
return; | ||
else | ||
line = n; | ||
} | ||
|
||
int Buffer::getCurrLine() | ||
{ | ||
return line; | ||
} | ||
void Buffer::disp() | ||
{ | ||
goToLine(0); | ||
for (auto str : buf) | ||
std::cout << str << std::endl; | ||
} | ||
|
||
void Buffer::clear() | ||
{ | ||
std::vector<std::string> t(size, ""); | ||
buf = t; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <string> | ||
#include "colour.hpp" | ||
#include "setup.hpp" | ||
|
||
enum CELL_STATES | ||
{ | ||
EMPTY, | ||
MINE, | ||
ADJ_TO_MINE | ||
}; | ||
|
||
COLOUR ADJMINECOLOURS[] = { | ||
reset, | ||
cyan_fg, //1 | ||
green_fg, //2 | ||
red_fg, //3 | ||
magenta_fg, //4 | ||
yellow_fg, //5 | ||
white_fg, //6 | ||
magenta_fg, //7 | ||
red_fg //8 | ||
}; | ||
|
||
struct Cell | ||
{ | ||
Cell(); | ||
void toggleflag(); | ||
void reveal(); | ||
void setMine(); | ||
void markAdjMine(int); | ||
bool flagged; | ||
bool hidden; | ||
CELL_STATES state; | ||
int noOfAdjMines; | ||
std::string sym; | ||
}; | ||
|
||
Cell::Cell() | ||
{ | ||
hidden = true; | ||
flagged = false; | ||
state = EMPTY; | ||
sym = white_bg + " "; | ||
} | ||
|
||
void Cell::toggleflag() | ||
{ | ||
if (hidden) | ||
{ | ||
flagged = !flagged; | ||
if (flagged) | ||
sym = green_fg + "▶"; | ||
|
||
else | ||
sym = white_bg + " "; | ||
} | ||
} | ||
|
||
void Cell::reveal() | ||
{ | ||
if (!flagged && hidden) | ||
{ | ||
hidden = false; | ||
switch (state) | ||
{ | ||
case EMPTY: | ||
sym = reset + " "; | ||
return; | ||
case MINE: | ||
sym = red_fg + "✸"; | ||
return; | ||
case ADJ_TO_MINE: | ||
sym = ADJMINECOLOURS[noOfAdjMines] + std::to_string(noOfAdjMines); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
void Cell::markAdjMine(int mines) | ||
{ | ||
state = ADJ_TO_MINE; | ||
noOfAdjMines = mines; | ||
} | ||
|
||
void Cell::setMine() | ||
{ | ||
state = MINE; | ||
} | ||
|
||
using GRID = std::vector<std::vector<Cell>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
using COLOUR = const std::string; | ||
|
||
COLOUR red_fg = "\033[1;31m"; | ||
COLOUR green_fg = "\033[1;32m"; | ||
COLOUR yellow_fg = "\033[1;33m"; | ||
COLOUR blue_fg = "\033[1;34m"; | ||
COLOUR magenta_fg = "\033[1;35m"; | ||
COLOUR cyan_fg = "\033[1;36m"; | ||
COLOUR white_fg = "\033[1;37m"; | ||
COLOUR blue_bg = "\033[44m"; | ||
COLOUR white_bg = "\033[47m"; | ||
COLOUR reset = "\033[0m"; |
Oops, something went wrong.