I'm coding some tetris thing in C++ as practice, and I thought it was going well, until I tried to compile (hadn't compiled yet since there was nothing to look at anyway. Still isn't).
However, it throws a lot of errors that I don't even see the cause of. I'm building with MSVS, if that's any help. The first error is "syntax error : missing ';' before '*'" on line 33, which is just "block *tet = nullptr;". I don't see anything wrong with that.
(There's probably some legitimate errors with me doing stuff wrong that intellisense or w/e hasn't picked up, and the code is probably awful in places but I'm trying to do this without tutorials)
Errors:
1>------ Build started: Project: tetris, Configuration: Debug Win32 ------
1> tetris.cpp
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(33): error C2143: syntax error : missing ';' before '*'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(34): error C2143: syntax error : missing ';' before '*'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(34): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(34): error C2086: 'int block' : redefinition
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(33) : see declaration of 'block'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(39): error C2065: 'clear_box' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(39): error C2446: '>' : no conversion from 'int (*)[10]' to 'int'
1> There is no context in which this conversion is possible
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(39): error C2040: '>' : 'int' differs in levels of indirection from 'int [25][10]'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(60): error C2536: 'block::block::piece' : cannot specify explicit initializer for arrays
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(60) : see declaration of 'block::piece'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(87): error C3861: 'create_tetromino': identifier not found
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(98): error C2227: left of '->piece' must point to class/struct/union/generic type
1> type is 'int *'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(129): error C2143: syntax error : missing ';' before '*'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(129): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(129): error C2086: 'int block' : redefinition
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(33) : see declaration of 'block'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(130): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(131): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(131): error C2061: syntax error : identifier 'block'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(142): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(142): error C2227: left of '->piece' must point to class/struct/union/generic type
1> type is 'unknown-type'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(142): error C2780: 'void copy_array(int [][height],int [][width])' : expects 2 arguments - 1 provided
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(117) : see declaration of 'copy_array'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(143): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(144): error C2360: initialization of 'piece' is skipped by 'case' label
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(135) : see declaration of 'piece'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(145): error C2374: 'piece' : redefinition; multiple initialization
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(135) : see declaration of 'piece'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(152): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(152): error C2227: left of '->piece' must point to class/struct/union/generic type
1> type is 'unknown-type'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(153): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(153): error C2227: left of '->rotateable' must point to class/struct/union/generic type
1> type is 'unknown-type'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(154): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(155): error C2360: initialization of 'piece' is skipped by 'case' label
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(145) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(135) : see declaration of 'piece'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(156): error C2374: 'piece' : redefinition; multiple initialization
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(135) : see declaration of 'piece'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(163): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(163): error C2227: left of '->piece' must point to class/struct/union/generic type
1> type is 'unknown-type'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(164): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(165): error C2360: initialization of 'piece' is skipped by 'case' label
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(156) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(145) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(135) : see declaration of 'piece'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(166): error C2374: 'piece' : redefinition; multiple initialization
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(135) : see declaration of 'piece'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(173): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(173): error C2227: left of '->piece' must point to class/struct/union/generic type
1> type is 'unknown-type'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(174): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(175): error C2360: initialization of 'piece' is skipped by 'case' label
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(166) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(156) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(145) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(135) : see declaration of 'piece'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(176): error C2374: 'piece' : redefinition; multiple initialization
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(135) : see declaration of 'piece'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(183): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(183): error C2227: left of '->piece' must point to class/struct/union/generic type
1> type is 'unknown-type'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(184): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(185): error C2360: initialization of 'piece' is skipped by 'case' label
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(176) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(166) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(156) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(145) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(135) : see declaration of 'piece'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(186): error C2374: 'piece' : redefinition; multiple initialization
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(135) : see declaration of 'piece'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(193): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(193): error C2227: left of '->piece' must point to class/struct/union/generic type
1> type is 'unknown-type'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(194): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(195): error C2360: initialization of 'piece' is skipped by 'case' label
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(186) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(176) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(166) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(156) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(145) : see declaration of 'piece'
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(135) : see declaration of 'piece'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(196): error C2374: 'piece' : redefinition; multiple initialization
1> c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(135) : see declaration of 'piece'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(203): error C2065: 'newtet' : undeclared identifier
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(203): error C2227: left of '->piece' must point to class/struct/union/generic type
1> type is 'unknown-type'
1>c:\users\operand\_documents\ceeples\tetrisiguesstoo\tetris\tetris\tetris.cpp(204): error C2065: 'newtet' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Code:
/*
Some dumb tetris game, for learning purposes. v0.1
By Miauw/Operand.
I have no idea if this works on Linux, but it should, if you're willing to make it work.
*/
#include <curses.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
//defines
#define TERM_HEIGHT 30
#define TERM_WIDTH 20
#define FIELD_HEIGHT 25
#define FIELD_WIDTH 10
#define ORIGIN_X 2
#define ORIGIN_Y 2
char possible_tets[7] = { 'i', 'o', 't', 'l', 'j', 'z', 's' }; //b-but this isn't a define ;~;
//function definitions
void handle_input();
void handle_blocks();
void clear_field();
void rotate(int direction);
void copy_array(int from[][5], int to[][5]);
//global variable definitions and initialization
long tick = 0;
char input = ' ';
int fall_delay = 40;
int lines_cleared;
int field[FIELD_HEIGHT][FIELD_WIDTH];
block *tet = nullptr;
block * queuedtet = nullptr;
WINDOW *field_window;
int main()
{
clear_box<FIELD_HEIGHT, FIELD_WIDTH>(field);
initscr();
resize_term(TERM_WIDTH, TERM_HEIGHT);
resize_window(stdscr, TERM_WIDTH, TERM_HEIGHT);
cbreak();
while (true)
{
handle_input();
if (tick % fall_delay == 0)
{
handle_blocks();
}
tick++;
refresh();
_sleep(40);
}
}
struct block
{
int piece[5][5] = { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } };
bool rotateable = true;
};
void handle_input()
{
input = getch();
switch(input)
{
case 'q':
rotate(1);
break;
case 'e':
rotate(-1);
break;
case 'w': //debug
delete tet;
tet = nullptr;
break;
}
}
void handle_blocks()
{
if (tet == nullptr)
{
tet = queuedtet;
queuedtet = create_tetromino(possible_tets[rand() % 6]);
}
}
void rotate(int direction)
{
int newpiece[5][5];
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
newpiece[i][j] = tet->piece[(direction ? -1 : 1) * (2 - i)][(direction ? -1 : 1) * (2 - j)];
}
}
}
template <int height, int width> //thank you based templates
void clear_box(int inputarr[height][width])
{
for (int i = 0; i < height - 1; i++)
{
for (int j = 0; j < width - 1; i++)
{
inputarr[i][j] = 0;
}
}
}
template <int height, int width>
void copy_array(int from[][height], int to[][width])
{
for (int i = 0; i < height - 1; i++)
{
for (int j = 0; j < width - 1; j++)
{
to[i][j] = from[i][j];
}
}
}
//at the bottom because it's obnoxious
block * create_tetromino(char tettype)
{
block * newtet = new block;
switch (tettype)
{
case 'i':
int piece[5][5] = {
{ 0, 0, 0, 0, 0 },
{ 0, 0, 1, 0, 0 },
{ 0, 0, 1, 0, 0 },
{ 0, 0, 1, 0, 0 },
{ 0, 0, 1, 0, 0 }
};
copy_array<5, 5>(piece, newtet->piece);
return newtet;
case 'o':
int piece[5][5] = {
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 1, 1, 0, 0 },
{ 0, 1, 1, 0, 0 },
{ 0, 0, 0, 0, 0 }
};
copy_array<5, 5>(piece, newtet->piece);
newtet->rotateable = false;
return newtet;
case 't':
int piece[5][5] = {
{ 0, 0, 0, 0, 0 },
{ 0, 0, 1, 0, 0 },
{ 0, 1, 1, 1, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 }
};
copy_array<5, 5>(piece, newtet->piece);
return newtet;
case 'j':
int piece[5][5] = {
{ 0, 0, 0, 0, 0 },
{ 0, 0, 1, 0, 0 },
{ 0, 0, 1, 0, 0 },
{ 0, 1, 1, 0, 0 },
{ 0, 0, 0, 0, 0 }
};
copy_array<5, 5>(piece, newtet->piece);
return newtet;
case 'l':
int piece[5][5] = {
{ 0, 0, 0, 0, 0 },
{ 0, 0, 1, 0, 0 },
{ 0, 0, 1, 0, 0 },
{ 0, 0, 1, 1, 0 },
{ 0, 0, 0, 0, 0 }
};
copy_array<5, 5>(piece, newtet->piece);
return newtet;
case 's':
int piece[5][5] = {
{ 0, 0, 0, 0, 0 },
{ 0, 0, 1, 1, 0 },
{ 0, 1, 1, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 }
};
copy_array<5, 5>(piece, newtet->piece);
return newtet;
case 'z':
int piece[5][5] = {
{ 0, 0, 0, 0, 0 },
{ 0, 1, 1, 0, 0 },
{ 0, 0, 1, 1, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 }
};
copy_array<5, 5>(piece, newtet->piece);
return newtet;
}
}