Initial commit
This commit is contained in:
22
includes/Board.hpp
Normal file
22
includes/Board.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// Celebrating tetris by Ley 2024
|
||||
|
||||
#include "./Game.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
class Board {
|
||||
public:
|
||||
Board();
|
||||
~Board();
|
||||
void Draw(sf::RenderWindow &win);
|
||||
void Clear();
|
||||
int DoesFit(const Tetrominos::Names name, const int rot,
|
||||
const sf::Vector2<int> pos);
|
||||
void PlaceTetromino(const Tetrominos::Names name, const int rot,
|
||||
const sf::Vector2<int> pos);
|
||||
void CheckLines();
|
||||
protected:
|
||||
int isInBoard(const sf::Vector2<int> pos);
|
||||
private:
|
||||
int buffer_[10][20];
|
||||
};
|
||||
14
includes/Game.hpp
Normal file
14
includes/Game.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
// Celebrating tetris by Ley 2024
|
||||
|
||||
#pragma once
|
||||
|
||||
// SMFL headers
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/System.hpp>
|
||||
|
||||
// Cxx headers
|
||||
#include <iostream>
|
||||
|
||||
#include "./Tetrominos.hpp"
|
||||
|
||||
sf::Color getTetrominoColor(const Tetrominos::Names &name);
|
||||
212
includes/Tetrominos.hpp
Normal file
212
includes/Tetrominos.hpp
Normal file
@@ -0,0 +1,212 @@
|
||||
// Celebrating tetris by Ley 2024
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
|
||||
struct Tetrominos {
|
||||
enum Names {
|
||||
I,
|
||||
J,
|
||||
L,
|
||||
O,
|
||||
S,
|
||||
T,
|
||||
Z,
|
||||
None
|
||||
};
|
||||
|
||||
// [shape name][rot pos][y][z]
|
||||
constexpr static int shapes[8][4][4][4] = {
|
||||
{ // I
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{1, 1, 1, 1},
|
||||
{0, 0, 0, 0}
|
||||
},
|
||||
{
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 0}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{1, 1, 1, 1},
|
||||
{0, 0, 0, 0}
|
||||
},
|
||||
{
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 0}
|
||||
}
|
||||
},
|
||||
{ // J
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 1, 1, 1},
|
||||
{0, 0, 0, 1}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 1, 1, 0}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 1, 0, 0},
|
||||
{0, 1, 1, 1},
|
||||
{0, 0, 0, 0}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 1},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 0}
|
||||
}
|
||||
},
|
||||
{ // L
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 1, 1, 1},
|
||||
{0, 1, 0, 0}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 1, 1, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 0}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 1},
|
||||
{0, 1, 1, 1},
|
||||
{0, 0, 0, 0}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 1}
|
||||
}
|
||||
},
|
||||
{ // 0
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 1},
|
||||
{0, 0, 1, 1}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 1},
|
||||
{0, 0, 1, 1}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 1},
|
||||
{0, 0, 1, 1}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 1},
|
||||
{0, 0, 1, 1}
|
||||
}
|
||||
},
|
||||
{ // S
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 1},
|
||||
{0, 1, 1, 0}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 1},
|
||||
{0, 0, 0, 1}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 1},
|
||||
{0, 1, 1, 0}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 1},
|
||||
{0, 0, 0, 1}
|
||||
}
|
||||
},
|
||||
{ // T
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 1, 1, 1},
|
||||
{0, 0, 1, 0}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 1, 1, 0},
|
||||
{0, 0, 1, 0}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 1, 1, 1},
|
||||
{0, 0, 0, 0}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 1},
|
||||
{0, 0, 1, 0}
|
||||
}
|
||||
},
|
||||
{ // Z
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 1, 1, 0},
|
||||
{0, 0, 1, 1}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 1, 1, 0},
|
||||
{0, 1, 0, 0}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 1, 1, 0},
|
||||
{0, 0, 1, 1}
|
||||
},
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 1, 1, 0},
|
||||
{0, 1, 0, 0}
|
||||
}
|
||||
},
|
||||
{ // None
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user