Well, I've been working on my console tetris for a while and I ran into an unexpected error! I got a Error Report.. Here's my code:
#include <iostream>
#include <windows.h>
#include <string>
#include "Globals.h"
using namespace std;
int Rnd(int min, int max) {
return (rand() / static_cast<double>(RAND_MAX + 1)) * (max - min + 1) + min;
}
string PlayingField[25];
int Block = 0;
int MaxLeft = 0;
int MaxRight = 0;
int CurrBLine = 0;
char BlockFrag = '0';
void Refresh()
{
system("CLS");
cout<<PlayingField[1]<<PlayingField[2]<<PlayingField[3]<<PlayingField[4];
cout<<PlayingField[5]<<PlayingField[6]<<PlayingField[7]<<PlayingField[8];
cout<<PlayingField[9]<<PlayingField[10]<<PlayingField[11]<<PlayingField[12];
cout<<PlayingField[13]<<PlayingField[14]<<PlayingField[15]<<PlayingField[16];
cout<<PlayingField[17]<<PlayingField[18]<<PlayingField[19]<<PlayingField[20];
cout<<PlayingField[21]<<PlayingField[22]<<PlayingField[23]<<PlayingField[24];
}
void BlockDown()
{
if ( Block == 1 )
{
PlayingField[CurrBLine - 1] = " | |\n";
PlayingField[CurrBLine] = " | 00 |\n";
PlayingField[CurrBLine + 1] = " | 00 |\n";
CurrBLine = CurrBLine + 1;
}
if ( Block == 2 )
{
}
if ( Block == 3 )
{
}
if ( Block == 4 )
{
}
if ( Block == 5 )
{
}
if ( Block == 6 )
{
}
if ( Block == 7 )
{
}
Refresh();
}
void MakeBlock()
{
Block = Rnd(1, 7);
if ( Block == 1 )
{
PlayingField[2] = " | 00 |\n";
PlayingField[3] = " | 00 |\n";
PlayingField[4] = " | |\n";
PlayingField[5] = " | |\n";
MaxLeft = 7;
MaxRight = 7;
CurrBLine = 3;
}
if ( Block == 2 )
{
PlayingField[2] = " | 0 |\n";
PlayingField[3] = " | 0 |\n";
PlayingField[4] = " | 0 |\n";
PlayingField[5] = " | 0 |\n";
MaxLeft = 7;
MaxRight = 8;
CurrBLine = 5;
}
if ( Block == 3 )
{
PlayingField[2] = " | 0 |\n";
PlayingField[3] = " | 0 |\n";
PlayingField[4] = " | 00 |\n";
PlayingField[5] = " | |\n";
MaxLeft = 7;
MaxRight = 7;
CurrBLine = 4;
}
if ( Block == 4 )
{
PlayingField[2] = " | 0 |\n";
PlayingField[3] = " | 0 |\n";
PlayingField[4] = " | 00 |\n";
PlayingField[5] = " | |\n";
MaxLeft = 7;
MaxRight = 8;
CurrBLine = 4;
}
if ( Block == 5 )
{
PlayingField[2] = " | 0 |\n";
PlayingField[3] = " | 00 |\n";
PlayingField[4] = " | 0 |\n";
PlayingField[5] = " | |\n";
MaxLeft = 7;
MaxRight = 7;
CurrBLine = 4;
}
if ( Block == 6 )
{
PlayingField[2] = " | 0 |\n";
PlayingField[3] = " | 00 |\n";
PlayingField[4] = " | 0 |\n";
PlayingField[5] = " | |\n";
MaxLeft = 7;
MaxRight = 8;
CurrBLine = 4;
}
if ( Block == 7 )
{
PlayingField[2] = " | 0 |\n";
PlayingField[3] = " | 000 |\n";
PlayingField[4] = " | |\n";
PlayingField[5] = " | |\n";
MaxLeft = 6;
MaxRight = 7;
CurrBLine = 3;
}
Refresh();
}
int main()
{
int Looper = 0;
PlayingField[1] = " |----------------|\n";
PlayingField[2] = " | |\n";
PlayingField[3] = " | |\n";
PlayingField[4] = " | |\n";
PlayingField[5] = " | |\n";
PlayingField[6] = " | |\n";
PlayingField[7] = " | |\n";
PlayingField[8] = " | |\n";
PlayingField[9] = " | |\n";
PlayingField[10] = " | |\n";
PlayingField[11] = " | |\n";
PlayingField[12] = " | |\n";
PlayingField[13] = " | |\n";
PlayingField[14] = " | |\n";
PlayingField[15] = " | |\n";
PlayingField[16] = " | |\n";
PlayingField[17] = " | |\n";
PlayingField[18] = " | |\n";
PlayingField[19] = " | |\n";
PlayingField[20] = " | |\n";
PlayingField[21] = " | |\n";
PlayingField[22] = " | |\n";
PlayingField[23] = " | |\n";
PlayingField[24] = " |----------------|\n";
// Draw the playing field:
cout<<PlayingField[1]<<PlayingField[2]<<PlayingField[3]<<PlayingField[4];
cout<<PlayingField[5]<<PlayingField[6]<<PlayingField[7]<<PlayingField[8];
cout<<PlayingField[9]<<PlayingField[10]<<PlayingField[11]<<PlayingField[12];
cout<<PlayingField[13]<<PlayingField[14]<<PlayingField[15]<<PlayingField[16];
cout<<PlayingField[17]<<PlayingField[18]<<PlayingField[19]<<PlayingField[20];
cout<<PlayingField[21]<<PlayingField[22]<<PlayingField[23]<<PlayingField[24];
// Start the main game loop:
MakeBlock();
while ( Looper != '1' )
{
BlockDown();
Sleep(500);
}
cin.get();
system("CLS");
}
Globals.h:
extern string PlayingField[25];
extern int Block;
extern int MaxLeft = 0;
extern int MaxRight = 0;
extern int CurrBLine = 0;
extern char BlockFrag = '0';
Please note that it is NOT completed. Using Windows XP, with Dev-C++. Someone else try this; I want to know if anyone else gets this error. THIS PROGRAM COMPILES PERFECTLY, I get the error report when it runs it.
[Edited by - orcfan32 on July 20, 2005 11:14:45 AM]
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit