fix: removed some random things
This commit is contained in:
@@ -12,7 +12,6 @@ struct Point {
|
|||||||
int m_id;
|
int m_id;
|
||||||
char m_symbol;
|
char m_symbol;
|
||||||
bool m_collided;
|
bool m_collided;
|
||||||
void to_string();
|
|
||||||
void assign(int row, int col);
|
void assign(int row, int col);
|
||||||
void move();
|
void move();
|
||||||
void check_collision(std::vector<Point> &points_list);
|
void check_collision(std::vector<Point> &points_list);
|
||||||
@@ -23,7 +22,6 @@ struct Player {
|
|||||||
char m_symbol;
|
char m_symbol;
|
||||||
bool m_turn;
|
bool m_turn;
|
||||||
void input_tile(int col, std::vector<Point> &points);
|
void input_tile(int col, std::vector<Point> &points);
|
||||||
// bool check_chain(std::array<std::array<char, COL>, ROW> &m_board);
|
|
||||||
bool check_chain(std::array<std::array<char, COL>, ROW> &m_board, std::vector<Point> &points_list);
|
bool check_chain(std::array<std::array<char, COL>, ROW> &m_board, std::vector<Point> &points_list);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
struct Window {
|
struct Window {
|
||||||
std::array<std::array<char, COL>, ROW> m_board = {};
|
std::array<std::array<char, COL>, ROW> m_board = {};
|
||||||
void update_display(std::vector<Point> &points_list);
|
void update_display(std::vector<Point> &points_list);
|
||||||
bool check_chain();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+2
-10
@@ -2,7 +2,6 @@
|
|||||||
#include "globals.hpp"
|
#include "globals.hpp"
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
void Point::assign(int row, int col) {
|
void Point::assign(int row, int col) {
|
||||||
m_row = row;
|
m_row = row;
|
||||||
@@ -10,15 +9,8 @@ void Point::assign(int row, int col) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Point::move() {
|
void Point::move() {
|
||||||
if(m_row < ROW - 1) {
|
if(m_row < ROW - 1) m_row++;
|
||||||
m_row++;
|
else m_collided = true;
|
||||||
} else {
|
|
||||||
m_collided = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Point::to_string() {
|
|
||||||
std::cout << "(" << m_row << ", " << m_col << ")";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Point::check_collision(std::vector<Point> &points_list) {;
|
void Point::check_collision(std::vector<Point> &points_list) {;
|
||||||
|
|||||||
+1
-2
@@ -23,8 +23,7 @@ int main() {
|
|||||||
if(one.check_chain(window.m_board, points_list)) {
|
if(one.check_chain(window.m_board, points_list)) {
|
||||||
std::cout << "Player 1 wins!" << std::endl;
|
std::cout << "Player 1 wins!" << std::endl;
|
||||||
running = false;
|
running = false;
|
||||||
}
|
} else if(two.check_chain(window.m_board, points_list)) {
|
||||||
if(two.check_chain(window.m_board, points_list)) {
|
|
||||||
std::cout << "Player 2 wins!" << std::endl;
|
std::cout << "Player 2 wins!" << std::endl;
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
|
||||||
void Window::update_display(std::vector<Point> &points_list) {
|
void Window::update_display(std::vector<Point> &points_list) {
|
||||||
for(std::array<char, COL> &row : m_board) { row.fill('.'); }
|
for(std::array<char, COL> &row : m_board) { row.fill('.'); }
|
||||||
for(int i = 0; i < points_list.size(); i++) {
|
for(int i = 0; i < points_list.size(); i++) {
|
||||||
@@ -19,25 +18,3 @@ void Window::update_display(std::vector<Point> &points_list) {
|
|||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // 1000 / fps; 200ms = 5fps
|
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // 1000 / fps; 200ms = 5fps
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::check_chain() {
|
|
||||||
char symbol = ' ';
|
|
||||||
bool d = true;
|
|
||||||
bool result = false;
|
|
||||||
for(int i = 0; i < ROW - 1; i++) {
|
|
||||||
for(int j = 0; j < COL - 1; j++) {
|
|
||||||
if(m_board[i][j] == ' ') continue;
|
|
||||||
symbol = m_board[i][j];
|
|
||||||
d = true;
|
|
||||||
if(d) {
|
|
||||||
for(int k = 1; k <= 3; k++) {
|
|
||||||
if(m_board[i][j + k] != symbol) d = false;
|
|
||||||
}
|
|
||||||
if(d) {
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user