Refactoring and updating

Fix bug, when steps = 0, but player didn't lose
This commit is contained in:
2025-04-30 19:36:14 +03:00
parent 7f0e023e0c
commit d905c1a3f9
7 changed files with 85 additions and 65 deletions

View File

@@ -1,5 +1,5 @@
#ifndef CLIENT
#define CLIENT
#ifndef CLIENT_HPP
#define CLIENT_HPP
#include <iostream>
#include <cstring>
@@ -7,14 +7,17 @@
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
class Client{
private:
int sock;
public:
Client();
void run(const std::string& h = "localhost", const unsigned short p = 1024u);
int ping(struct sockaddr_in);
void run(const std::string&, const unsigned short);
void game();
int ping(struct sockaddr_in);
};
#endif

View File

@@ -11,24 +11,24 @@ const int MAZE_SIZE = 9;
const int DIRECTIONS = 4;
const int MIN_WALLS = 3;
const int MAX_WALLS = 5;
const int DEFAULT_MOVES = 10;
class Maze{
private:
std::unordered_map<int, std::vector<bool>> graph;
int moves_left;
bool is_path_exists(int, int);
private:
std::unordered_map<int, std::vector<bool>> graph;
int moves_left;
bool is_path_exists(int start, int end);
struct Edge {
int node1, dir1;
int node2, dir2;
};
public:
Maze(bool);
bool test_mode;
int get_moves_left() const;
bool is_wall(int, int) const;
struct Edge {
int node1, dir1;
int node2, dir2;
};
public:
bool test_mode;
void set_moves_left(int);
Maze(bool flag, int steps);
int get_moves_left() const;
bool is_wall(int node, int direction) const;
void set_moves_left(int _steps);
};
#endif

View File

@@ -12,16 +12,18 @@
#include <cstring>
const int MAX_CLIENTS = 512;
const int BUFFER_SIZE = 1024;
class Server {
private:
bool service_mode;
int server_fd;
void handle_client(int client_socket, bool _mode); // Принимает клиентский сокет
int server_socket;
void handle_client(int socket, bool flag, int steps);
bool check_status(Maze& maze);
public:
Server(const std::string& h = "localhost", const unsigned short p = 1024u, bool service_mode = false);
void start(); // Запуск сервера
Server(const std::string& host, const unsigned short port, bool service_flag);
void start(int steps = 10);
};
#endif