Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
refactor: refactor some code
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenMian committed Dec 27, 2024
1 parent fdaaf35 commit c6c53cd
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/gomoku.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,20 @@ class Gomoku {
/ (_ / _ \/ ' \/ _ \/ '_/ // /
\___/\___/_/_/_/\___/_/\_\\_,_/
Free-style)");
std::println(R"(
1. Online
2. Offline)");

std::string choice;

std::println(R"(
1. Offline
2. Online)");
std::getline(std::cin, choice);

if (choice == "1") {
create_window();
piece_ = Piece::Black;

offline();
} else if (choice == "2") {
const uint16_t port = 1234;

std::println(R"(
Expand Down Expand Up @@ -121,11 +127,6 @@ class Gomoku {
socket.setBlocking(false);

online(socket);
} else if (choice == "2") {
create_window();
piece_ = Piece::Black;

offline();
} else
throw std::runtime_error("invalid option");
}
Expand Down Expand Up @@ -387,8 +388,9 @@ class Gomoku {

auto handle_piece_place() -> bool {
static sf::Clock clock;
if (clock.getElapsedTime() < sf::seconds(0.2f))
if (clock.getElapsedTime() < sf::seconds(0.2f)) {
return false;
}

const auto actions = get_actions();

Expand Down Expand Up @@ -434,11 +436,13 @@ class Gomoku {
do {
status = socket.send(packet);
} while (status == sf::Socket::Status::Partial);
if (status == sf::Socket::Status::Done)
if (status == sf::Socket::Status::Done) {
return;
}

if (status == sf::Socket::Status::Disconnected)
if (status == sf::Socket::Status::Disconnected) {
throw std::runtime_error("the network connection has been lost");
}
throw std::runtime_error("unknown network error");
}

Expand Down

0 comments on commit c6c53cd

Please sign in to comment.