refactoring
This commit is contained in:
parent
efcc81f339
commit
bae11647e4
20
Makefile
20
Makefile
@ -1,9 +1,17 @@
|
||||
|
||||
all: main.o net.o
|
||||
g++ main.o net.o -o over_the_network_tic_tac_toe
|
||||
|
||||
main.o: main.cpp
|
||||
g++ -c main.cpp
|
||||
all: build/obj/main.o build/obj/net.o build/obj/input.o
|
||||
g++ build/obj/main.o build/obj/net.o build/obj/input.o -o build/bin/over_the_network_tic_tac_toe
|
||||
|
||||
net.o: net.cpp
|
||||
g++ -c net.cpp
|
||||
build/obj/main.o: src/main.cpp
|
||||
g++ -c src/main.cpp -o build/obj/main.o
|
||||
|
||||
build/obj/net.o: src/net.cpp
|
||||
g++ -c src/net.cpp -o build/obj/net.o
|
||||
|
||||
build/obj/input.o: src/input.cpp
|
||||
g++ -c src/input.cpp -o build/obj/input.o
|
||||
|
||||
clean:
|
||||
rm build/obj/*
|
||||
rm build/bin/*
|
2
src/global.hpp
Normal file
2
src/global.hpp
Normal file
@ -0,0 +1,2 @@
|
||||
extern int board_size;
|
||||
extern bool ishost;
|
55
src/input.cpp
Normal file
55
src/input.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include<iostream>
|
||||
#include"global.hpp"
|
||||
#include"input.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
|
||||
int board_size;
|
||||
bool ishost;
|
||||
bool repeat = true;
|
||||
void ishost_check() {
|
||||
|
||||
char charishost;
|
||||
while (repeat) {
|
||||
cout << "will you be host or guest of this game?\n" << "(h/g): ";
|
||||
cin >> charishost;
|
||||
|
||||
repeat = false;
|
||||
|
||||
switch(charishost) {
|
||||
case 'h':
|
||||
ishost = true;
|
||||
break;
|
||||
case 'g':
|
||||
ishost = false;
|
||||
break;
|
||||
default:
|
||||
repeat = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
void board_size_check() {
|
||||
repeat = true;
|
||||
|
||||
while (repeat) {
|
||||
cout << "\nplease enter board size(for example: 3 for 3x3): ";
|
||||
|
||||
cin >> board_size;
|
||||
if(cin.fail()) {
|
||||
cout << "integer please\n";
|
||||
cin.clear();
|
||||
cin.ignore(256,'\n');
|
||||
} else {
|
||||
if(board_size > 0) {
|
||||
repeat = false;
|
||||
} else {
|
||||
cout << "positive integer please\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
2
src/input.hpp
Normal file
2
src/input.hpp
Normal file
@ -0,0 +1,2 @@
|
||||
void ishost_check();
|
||||
void board_size_check();
|
@ -1,4 +1,8 @@
|
||||
#include<iostream>
|
||||
#include"global.hpp"
|
||||
#include"net.hpp"
|
||||
#include"input.hpp"
|
||||
|
||||
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
@ -34,54 +38,20 @@ cout << R"( ___ __ _______ ___ ________ ________ _____ ______
|
||||
\|__| \|__|\|_______| \|__| \|__|\|__|\|_______| \|__| \|_______|\|_______|
|
||||
)" << '\n';
|
||||
|
||||
|
||||
bool ishost;
|
||||
bool repeat = true;
|
||||
int board_size;
|
||||
|
||||
ishost_check();
|
||||
board_size_check();
|
||||
|
||||
{
|
||||
char charishost;
|
||||
while (repeat) {
|
||||
cout << "will you be host or guest of this game?\n" << "(h/g): ";
|
||||
cin >> charishost;
|
||||
|
||||
repeat = false;
|
||||
|
||||
switch(charishost) {
|
||||
case 'h':
|
||||
ishost = true;
|
||||
break;
|
||||
case 'g':
|
||||
ishost = false;
|
||||
break;
|
||||
default:
|
||||
repeat = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
repeat = true;
|
||||
|
||||
while (repeat) {
|
||||
cout << "\nplease enter board size(for example: 3 for 3x3): ";
|
||||
|
||||
cin >> board_size;
|
||||
if(cin.fail()) {
|
||||
cout << "integer please\n";
|
||||
cin.clear();
|
||||
cin.ignore(256,'\n');
|
||||
} else {
|
||||
if(board_size > 0) {
|
||||
repeat = false;
|
||||
} else {
|
||||
cout << "positive integer please\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
int init_net_status = init_net();
|
||||
if(init_net_status != 0){
|
||||
cout << "failed to initialize network\n";
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char board[board_size*board_size];
|
||||
|
||||
return 0;
|
9
src/net.cpp
Normal file
9
src/net.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include"net.hpp"
|
||||
|
||||
|
||||
int init_net() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
1
src/net.hpp
Normal file
1
src/net.hpp
Normal file
@ -0,0 +1 @@
|
||||
extern int init_net();
|
Loading…
x
Reference in New Issue
Block a user