#include "GameField.h" void GameField::resize( size_t width, size_t height ) { m_Width = width; m_Height = height; m_Field = std::vector< std::vector >( m_Height - 2, std::vector( m_Width - 2, 0x0387 ) ); } void GameField::render( PaintDevice& paintDevice ) { for (int x = 1; x < m_Width - 1; x++) { paintDevice.set_char( Vector2(x,0), '-' ); paintDevice.set_char( Vector2( x, m_Height - 1 ), '-' ); } for (int y = 1; y < m_Height - 1; y++) { paintDevice.set_char( Vector2(0,y), '|' ); paintDevice.set_char( Vector2( m_Width - 1, y ), '|' ); } paintDevice.set_char( Vector2(0,0), '+' ); paintDevice.set_char( Vector2( m_Width - 1, 0 ), '+' ); paintDevice.set_char( Vector2( 0, m_Height - 1 ), '+' ); paintDevice.set_char( Vector2( m_Width - 1, m_Height - 1 ), '+' ); for (size_t y = 0; y < m_Field.size(); y++) { for (size_t x = 0; x < m_Field[y].size(); x++) { paintDevice.set_char( Vector2( x + 1, y + 1 ), m_Field[y][x] ); } } } bool GameField::has_collision( const Figure& figure) { Point position = figure.get_position(); for (const Point& point : figure.get_body()) { int x = point.x + position.x; int y = point.y + position.y; if (x < 1 || x > m_Width - 2) return true; if (y < 1 || y > m_Height - 2) return true; if ( m_Field[y - 1][x - 1] != 0x0387 ) return true; } return false; } void GameField::merge(const Figure& figure) { Point position = figure.get_position(); for (const Point& point : figure.get_body()) { int x = point.x + position.x; int y = point.y + position.y; if (x < 1 || x > m_Width - 2 || y < 1 || y > m_Height - 2) continue; m_Field[y - 1][x - 1] = L'#'; } } int GameField::clear_lines() { int cleared = 0; for (int y = (int)m_Field.size() - 1; y >= 0; y--) { bool full = true; for (size_t x = 0; x < m_Field[y].size(); x++) { if (m_Field[y][x] == L' ') { full = false; break; } } if (full) { cleared++; for (int j = y; j > 0; j--) { m_Field[j] = m_Field[j - 1]; } m_Field[0] = std::vector( m_Width - 2, L' ' ); y++; // 🔥 ВАЖНО: перескан строки после сдвига } } return cleared; }