Skip to content
Snippets Groups Projects
Commit 8187ec58 authored by Jake Feddersen's avatar Jake Feddersen
Browse files

More colors and ship names

parent 528a546b
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -135,7 +135,7 @@ int board::get_position_color(int x, int y) {
}
}
return BG_WHITE;
}
}
return BG_BLACK;
} else {
if (guesses[y][x]) {
......@@ -160,25 +160,41 @@ void board::draw() {
int x_offset = 0;
if (side == PLAYER) {
x_offset = 22;
x_offset = 57;
}
attron(COLOR_PAIR(TEXT_WHITE));
mvprintw(1, x_offset, " 1 2 3 4 5 6 7 8 9 10 ");
mvprintw(0, 4, "Opponent's Ships");
mvprintw(0, 64, "Your Ships");
mvprintw(1, x_offset, " 1 2 3 4 5 6 7 8 9 10 ");
for (int i = 0; i < 10; i++) {
mvaddch(2 + i, x_offset, 'A' + i);
mvaddch(3 + i, x_offset, 'A' + i);
mvaddch(3 + i, x_offset+1, '|');
mvaddch(3 + i, x_offset+22, '|');
}
for (int i = 0; i < 22; i++) {
mvaddch(2, x_offset+i+1, '-');
mvaddch(13, x_offset+i+1, '-');
}
attroff(COLOR_PAIR(TEXT_WHITE));
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
int color = get_position_color(j, i);
attron(COLOR_PAIR(color));
mvprintw(i+2, x_offset + 1 + (j*2), " ");
mvprintw(i+3, x_offset + 2 + (j*2), " ");
attroff(COLOR_PAIR(color));
}
}
for (int i = 0; i < 5; i++) {
ships[i]->print_ship(x_offset, 14+i);
}
refresh();
}
......
#define TEXT_RED 0
#define TEXT_GREEN 1
#define TEXT_WHITE 2
#define TEXT_RED 3
#define BG_RED 10
#define BG_BLUE 11
......
......@@ -143,6 +143,8 @@ client_connection::client_connection() {
std::string ip = getstring();
if (inet_pton(AF_INET, ip.c_str(), &serv_addr.sin_addr) <= 0) {
move(3, 0);
clrtoeol();
mvprintw(3, 0, "Invalid IP");
refresh();
continue;
......
#include <ncurses.h>
#include "ship.h"
#include "colors.h"
bool ship::contains(int x, int y) {
int dx = 0;
......@@ -28,7 +31,7 @@ void ship::hit() {
}
bool ship::is_sunk() {
return !(HP > 0);
return HP <= 0;
}
int ship::get_x() {
......@@ -42,3 +45,31 @@ int ship::get_y() {
int ship::get_dir() {
return dir;
}
void ship::print_ship(int x, int y) {
if (is_sunk()) {
attron(COLOR_PAIR(TEXT_RED));
} else {
attron(COLOR_PAIR(TEXT_WHITE));
}
mvprintw(y, x, name.c_str());
if (is_sunk()) {
attroff(COLOR_PAIR(TEXT_RED));
} else {
attroff(COLOR_PAIR(TEXT_WHITE));
}
attron(COLOR_PAIR(TEXT_GREEN));
for (int i = maxHP; i > (maxHP - HP); i--) {
mvaddch(y, x+23-i, '*');
}
attroff(COLOR_PAIR(TEXT_GREEN));
attron(COLOR_PAIR(TEXT_RED));
for (int i = maxHP-HP; i > 0; i--) {
mvaddch(y, x+23-(HP)-i, '*');
}
attroff(COLOR_PAIR(TEXT_RED));
}
......@@ -30,6 +30,8 @@ public:
int get_x();
int get_y();
int get_dir();
void print_ship(int x, int y);
};
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment