not important just continuing over to mac
This commit is contained in:
@@ -4,13 +4,13 @@
|
||||
#include <vector>
|
||||
|
||||
struct Point {
|
||||
Point() : m_row(0), m_col(0), m_id(0), m_active(true) {}
|
||||
Point(int row, int col, int id) : m_row(row), m_col(col), m_id(id), m_active(true) {}
|
||||
Point() : m_row(0), m_col(0), m_id(0) {}
|
||||
Point(int row, int col, int id) : m_row(row), m_col(col), m_id(id) {}
|
||||
int m_row;
|
||||
int m_col;
|
||||
int m_id;
|
||||
bool m_active;
|
||||
char m_symbol;
|
||||
void to_string();
|
||||
void assign(int row, int col);
|
||||
void move();
|
||||
void check_collision(std::vector<Point> &points_list);
|
||||
@@ -20,7 +20,6 @@ struct Player {
|
||||
Player(char symbol, bool turn) : m_symbol(symbol), m_turn(turn) {}
|
||||
char m_symbol;
|
||||
bool m_turn;
|
||||
std::vector<Point> m_points;
|
||||
void input_tile(int col, std::vector<Point> &points);
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
struct Window {
|
||||
std::array<std::array<char, COL>, ROW> m_board = {};
|
||||
void update_display(std::vector<Point> &points_list);
|
||||
bool check_chain();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+5
-1
@@ -1,6 +1,7 @@
|
||||
#include "elements.hpp"
|
||||
#include "globals.hpp"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
void Point::assign(int row, int col) {
|
||||
m_row = row;
|
||||
@@ -13,13 +14,16 @@ void Point::move() {
|
||||
}
|
||||
}
|
||||
|
||||
void Point::to_string() {
|
||||
std::cout << "(" << m_row << ", " << m_col << ")";
|
||||
}
|
||||
|
||||
void Point::check_collision(std::vector<Point> &points_list) {;
|
||||
for(int i = 0; i < points_list.size(); i++) {
|
||||
if(points_list[i].m_id == m_id) continue;
|
||||
if(points_list[i].m_row != m_row) continue;
|
||||
if(points_list[i].m_col != m_col) continue;
|
||||
m_row = points_list[i].m_row - 1;
|
||||
m_active = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+22
-2
@@ -14,14 +14,34 @@ int main() {
|
||||
|
||||
bool running = true;
|
||||
std::thread input_thread(&Input::get_input, &input, std::ref(running), std::ref(one), std::ref(two), std::ref(points_list));
|
||||
char symbol = ' ';
|
||||
bool d = true;
|
||||
bool result = false;
|
||||
while(running) {
|
||||
window.update_display(points_list);
|
||||
for(int i = 0; i < points_list.size(); i++) {
|
||||
if(!points_list[i].m_active) continue;
|
||||
points_list[i].move();
|
||||
points_list[i].check_collision(points_list);
|
||||
}
|
||||
std::cout << points_list.size() << std::endl;
|
||||
for(int i = 0; i < ROW - 1; i++) {
|
||||
for(int j = 0; j < COL - 1; j++) {
|
||||
if(window.m_board[i][j] == ' ') continue;
|
||||
symbol = window.m_board[i][j];
|
||||
d = true;
|
||||
if(d) {
|
||||
for(int k = 1; k <= 3; k++) {
|
||||
if(window.m_board[i][j + k] != symbol) d = false;
|
||||
}
|
||||
if(d) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if(window.check_chain()) {
|
||||
// std::cout << "Chain is active" << std::endl;
|
||||
// }
|
||||
std::cout << result << std::endl;
|
||||
}
|
||||
|
||||
input_thread.join();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
|
||||
void Window::update_display(std::vector<Point> &points_list) {
|
||||
for(std::array<char, COL> &row : m_board) { row.fill('.'); }
|
||||
for(int i = 0; i < points_list.size(); i++) {
|
||||
@@ -18,3 +19,25 @@ void Window::update_display(std::vector<Point> &points_list) {
|
||||
}
|
||||
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