Skip to content
Snippets Groups Projects
Commit 0dd2df8b authored by Eila Aurora Huru Bergene's avatar Eila Aurora Huru Bergene
Browse files

Added handout files for O12

parent 30d460e2
No related branches found
No related tags found
No related merge requests found
#include "TetrisWindow.h"
#include <iostream>
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) {
std::cout << "Hello from z\n";
}
if(currentUpKeyState && !lastUpKeyState) {
std::cout << "Hello from up\n";
}
lastZKeyState = currentZKeyState;
lastUpKeyState = currentUpKeyState;
}
#pragma once
#include "AnimationWindow.h"
#include "Tetromino.h"
#include "widgets/TextInput.h"
#include "widgets/Button.h"
class TetrisWindow : public TDT4102::AnimationWindow {
public:
TetrisWindow();
void run();
private:
void handleInput();
};
\ No newline at end of file
#include "Tetromino.h"
#include <map>
const std::map<TetrominoType, std::vector<std::vector<int>>> initialMatrixMap {
{
TetrominoType::J,
{
{0, 0, 0},
{1, 1, 1},
{0, 0, 1}
}
}
};
Tetromino::Tetromino(TDT4102::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]);
}
}
}
\ No newline at end of file
#pragma once
#include "Point.h"
#include <vector>
enum class TetrominoType{J, L, T, S, Z, O, I, NONE};
class Tetromino {
public:
static constexpr int blockSize {30};
Tetromino(TDT4102::Point startingPoint, TetrominoType tetType);
void rotateClockwise();
void rotateCounterClockwise();
private:
int matrixSize;
TDT4102::Point topLeftCorner;
std::vector<std::vector<TetrominoType>> blockMatrix;
};
\ No newline at end of file
#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