Skip to content
Snippets Groups Projects
Commit dc3f3be2 authored by Charlotte Borge Hunskår's avatar Charlotte Borge Hunskår
Browse files

Added O12 handout code

parent ae5de66f
No related branches found
No related tags found
No related merge requests found
#include "TetrisWindow.h"
void TetrisWindow::run() {
unsigned int framesSinceLastTetronimoMove = 0;
const unsigned int framesPerTetronimoMove = 20;
while(!should_close()) {
framesSinceLastTetronimoMove++;
if(framesSinceLastTetronimoMove >= framesPerTetronimoMove) {
framesSinceLastTetronimoMove = 0;
/********************************************************/
//Kall moveTetrominoDown() her
/********************************************************/
}
handleInput();
/********************************************************/
//Kall draw-funksjonene her
/********************************************************/
next_frame();
}
}
void TetrisWindow::handleInput() {
static bool lastZKeyState = false;
static bool lastUpKeyState = false;
bool currentZKeyState = is_key_down(KeyboardKey::Z);
bool currentUpKeyState = is_key_down(KeyboardKey::UP);
if(currentZKeyState && !lastZKeyState) {
cout << "Hello from z\n";
}
if(currentUpKeyState && !lastUpKeyState) {
cout << "Hello from up\n";
}
lastZKeyState = currentZKeyState;
lastUpKeyState = currentUpKeyState;
}
#pragma once
#include "AnimationWindow.h"
#include "Tetromino.h"
#include "GUI.h"
#include <atomic>
class TetrisWindow : public AnimationWindow {
public:
TetrisWindow();
void run();
private:
void handleInput();
};
#include "Tetromino.h"
const map<TetrominoType, vector<vector<int>>> initialMatrixMap {
{
TetrominoType::J,
{
{0, 0, 0},
{1, 1, 1},
{0, 0, 1}
}
},
{
TetrominoType::L,
{
{0, 0, 0},
{1, 1, 1},
{1, 0, 0}
}
},
{
TetrominoType::I,
{
//Denne er representert som en 6x6 matrise for å få en bedre rotasjonsfunksjonalitet
{0, 0, 1, 0, 0, 0},
{0, 0, 1, 0, 0, 0},
{0, 0, 1, 0, 0, 0},
{0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0}
}
}
};
Tetromino::Tetromino(Point startingPoint, TetrominoType tetType) :
topLeftCorner{startingPoint}
{
}
void Tetromino::rotateCounterClockwise() {
//Første rotasjon, med hensyn på diagonalen
for(int row = 0; row < matrixSize; row++){
for(int column = 0; column < row; column++){
std::swap(blockMatrix[row][column], blockMatrix[column][row]);
}
}
//Andre rotasjon, med hensyn på den midtre raden
for(int row = 0; row < matrixSize/2; row++){
for(int column = 0; column < matrixSize; column++){
std::swap(blockMatrix[row][column], blockMatrix[matrixSize-row-1][column]);
}
}
}
void Tetromino::rotateClockwise() {
//Første rotasjon, med hensyn på diagonalen
for(int row = 0; row < matrixSize; row++){
for(int column = 0; column < row; column++){
std::swap(blockMatrix[row][column], blockMatrix[column][row]);
}
}
//Andre rotasjon, med hensyn på den midtre kolonnen
for(int row = 0; row < matrixSize; row++){
for(int column = 0; column < matrixSize/2; column++){
std::swap(blockMatrix[row][column], blockMatrix[row][matrixSize-column-1]);
}
}
}
#pragma once
#include "Graph.h"
enum class TetrominoType{J, L, T, S, Z, O, I, NONE};
class Tetromino {
public:
static constexpr int blockSize {30};
Tetromino(Point startingPoint, TetrominoType tetType);
void rotateClockwise();
void rotateCounterClockwise();
private:
int matrixSize;
Point topLeftCorner;
vector<vector<TetrominoType>> blockMatrix;
};
#include "Tetromino.h"
#include "TetrisWindow.h"
int main()
{
/********************************************************/
//Opprett vindu her
/********************************************************/
//kall run på det her
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment