basic gameplay

This commit is contained in:
PoliEcho 2024-06-06 11:52:27 +02:00
parent 5a0bc0823e
commit 2b8e133d90
7 changed files with 61 additions and 6 deletions

17
src/color.hpp Normal file
View File

@ -0,0 +1,17 @@
#define RESET "\033[0m"
#define BLACK "\033[30m" /* Black */
#define RED "\033[31m" /* Red */
#define GREEN "\033[32m" /* Green */
#define YELLOW "\033[33m" /* Yellow */
#define BLUE "\033[34m" /* Blue */
#define MAGENTA "\033[35m" /* Magenta */
#define CYAN "\033[36m" /* Cyan */
#define WHITE "\033[37m" /* White */
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */

View File

@ -1,10 +1,14 @@
#include <iostream>
#include "gameplay.hpp"
#include "global.hpp"
#include "color.hpp"
using std::cout;
using std::cin;
using std::cerr;
int points_my;
int points_en;
void printBoard(const std::vector<std::vector<char>>& board) {
cout << "\n";
for (int i = 0; i < board_size; i++) {
@ -38,4 +42,8 @@ void printBoard(const std::vector<std::vector<char>>& board) {
cout << "─┘";
}
}
}
void print_gameinfo() {
cout << "\npoint info:\nyou: " << BLUE << points_my << RESET << "\nenemy: " << RED << points_en << RESET << "\n";
}

View File

@ -3,5 +3,8 @@ extern int board_size;
extern bool ishost;
extern unsigned short port;
extern int length;
extern int points_req;
extern std::string serverIp_str;
extern int points_req;
extern int points_req;
extern int points_my;
extern int points_en;

View File

@ -1,8 +1,10 @@
#include <string.h>
#include <iostream>
#include <string>
#include<array>
#include "global.hpp"
#include "input.hpp"
#include "net.hpp"
using std::cout;
using std::cin;
@ -145,7 +147,7 @@ void ip_check() {
}
}
std::string choise_check() {
std::array<int,2> choise_check() {
int x_cord;
int y_cord;
char sure;
@ -169,7 +171,6 @@ std::string choise_check() {
break;
}
}
std::string loc;
loc = std::to_string(x_cord) + " " + std::to_string(y_cord);
std::array<int,2> loc={x_cord,y_cord};
return loc;
}

View File

@ -1,6 +1,8 @@
#include <array>
void ishost_check();
void board_size_check();
void length_check();
void port_check();
void ip_check();
void points_requied();
void points_requied();
extern std::array<int,2> choise_check();

View File

@ -107,6 +107,17 @@ int init_net() {
handshake_failed();
}
data = std::to_string(points_req);
memset(&msg, 0, sizeof(msg)); //clear the buffer
strcpy(msg, data.c_str());
bytesWritten += send(newSd, (char *)&msg, strlen(msg), 0);
memset(&msg, 0, sizeof(msg)); //clear the buffer
bytesRead += recv(newSd, (char *)&msg, sizeof(msg), 0);
if (points_req != std::stoi(msg)) {
handshake_failed();
}
} else {
// code for client
const char *serverIp = serverIp_str.c_str();
@ -156,7 +167,20 @@ int init_net() {
memset(&msg, 0, sizeof(msg)); //clear the buffer
strcpy(msg, data.c_str());
bytesWritten += send(clientSd, (char *)&msg, strlen(msg), 0);
memset(&msg, 0, sizeof(msg)); //clear the buffer
bytesRead += recv(clientSd, (char *)&msg, sizeof(msg), 0);
points_req = std::stoi(msg);
data = std::to_string(length);
memset(&msg, 0, sizeof(msg)); //clear the buffer
strcpy(msg, data.c_str());
bytesWritten += send(clientSd, (char *)&msg, strlen(msg), 0);
}
return 0;
}
void end_conn() {
}

View File

@ -1,2 +1,2 @@
extern int init_net();
void init_var();
void end_conn();