Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  .
Language: C/C++
Code:
/* Load Libraries */
#include <conio.h>
#include <windows.h>
//#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
//#include <windows.h>
#include <iostream>
#include "ConsoleColor.h"
#include<winuser.h>
//#include <ncurses>
using namespace std;

//Victor Lam
//0857216 Electrical Engineering 29 3 2015 21.44

/* Declare Goto Function */
void gotoxy(int, int);

/* Init X and Y plus the Variables which hold
previous X and Y. */
//extr
int check20;
int spawn;
int speed=1;
int row4;
int column4;
int help = false;
int iteration;
int next4;
int next3;
int next2;
int next1;
//extr

int Count = 0;
int checkrow1;
int eraserow=false;
int mult = 0;
int x = 1;
int y = 1;
int lastx = 1;
int lasty = 1;
int lasty2 = 0;
int lasty3 = 0;
int lasty4 = 0;
int lasty5 = 0;
int lasty6 = 0;
int lasty7 = 0;
int lasty8 = 0;
int lasty9 = 0;
int lasty10 = 0;
int lasty11 = 1;
int lastx11=1;
/*int lasty12 = 0;
int lasty13 = 0;
int lasty14 = 0;
int lasty15 = 0;
int lasty16 = 0;
int lasty17 = 0;
int lasty18 = 0;
int lasty19 = 0;
int lasty20 = 0;
int lasty21 = 0;
int lasty22 = 0;
int lasty23 = 0;
int lasty24 = 0;
int lasty25 = 0;
int lasty26 = 0;
int lasty27 = 0;
int lasty28 = 0;
int lasty29 = 0;
int lasty30 = 0;
int lasty31 = 0;
int lasty32 = 0;
int lasty33 = 0;
int lasty34 = 0;
int lasty35 = 0;
int lasty36 = 0;
int lasty37 = 0;
int lasty38 = 0;
int lasty39 = 0;
int lasty40 = 0;
int lasty41 = 0;
int lasty42 = 0;
int lasty43 = 0;
int lasty44 = 0;
int lasty45 = 0;
int lasty46 = 0;
int lasty47 = 0;
int lasty48 = 0;
int lasty49 = 0;
int lasty50 = 0;
int lasty51 = 0;
int lasty52 = 0;
int lasty53 = 0;
int lasty54 = 0;
int lasty55 = 0;
int lasty56 = 0;
int lasty57 = 0;
int lasty58 = 0;
int lasty59 = 0;
int lasty60 = 0;
int lasty61 = 0;
int lasty62 = 0;
int lasty63 = 0;
int lasty64 = 0;
int lasty65 = 0;
int lasty66 = 0;
int lasty67 = 0;
int lasty68 = 0;
int lasty69 = 0;
int lasty70 = 0;
int lasty71 = 0;
int lasty72 = 0;
int lasty73 = 0;
int lasty74 = 0;
int lasty75 = 0;
int lasty76 = 0;
int lasty77 = 0;
int lasty78 = 0;
int lasty79 = 0;
int lasty80 = 0;
int lasty81 = 0;
int lasty82 = 0;
int lasty83 = 0;
int lasty84 = 0;
int lasty85 = 0;
int lasty86 = 0;
int lasty87 = 0;
int lasty88 = 0;
int lasty89 = 0;
int lasty90 = 0;
int lasty91 = 0;
int lasty92 = 0;
int lasty93 = 0;
int lasty94 = 0;
int lasty95 = 0;
int lasty96 = 0;
int lasty97 = 0;
int lasty98 = 0;
int lasty99 = 0;
int lasty100 = 0;
int lasty101 = 0;*/
//int lasty12 = 0;
int random = 0;
int i = 0;
int j = 0;
int lastrandom = 0;
int checktwice = 0;
int rotation = 0;
int lastrotation = 3;
int lower;
int low1;
int low2;
int low3;
int low4;
int lastlower;
/* Make a CHAR variable to get Key Input */
//char a;
char a = 0;
char z = 0;
int checkrow = 0;
int row = 0;
int column = 0;
int row2;
int column2;
//int duration = 0;
//int width = 12;
//int width = 20; origineel
int width ;
int width2;
//int height = 18;
//int height = 30; origineel
int height;
char grid[60][46] = { " " };
//char grid[30][20] = {" "}; origineel
int checkcolor[60][46] = { };
//int checkcolor[30][20] = {}; origineel
//int checkcolor2[30][20] = {};
int checkBottom;
int check1;
int check2;
int nextrandom;
int duration2 = 0;
int counting;
int press = true;
char character;
int start = false;
int paused = false;
int score=0;
int lastscore = 0;
int scoreplus = 0;
//int duration4=0;
int gameover = false;
int definition = true;
char define;
//char heightmat[4] = {};
//char widthmat[4] = {};


/* Main Function */
int main()
{
     while (definition == true)
     {
          if (_kbhit())
          {
               cin >> height;
               //heightmat = height;
               if (!cin>>height)
               {
                    
                    //system("cls");
                    cout << white << "Enter height (max 61, min 10)"<<endl;
                    
                    cin.clear();
                    cin.ignore();
                    //cin >> height;
                    //definition = true;
               }
               else
               {
                    if ((height < 10) || (height>61))
                    {
                         cout << white << "Enter height (max 61, min 10)" << endl;

                         cin.clear();
                         cin.ignore();
                    }
                    else
                    {
                         definition = false;
                    }
               }

          }
          else if (!_kbhit())
          {
               system("cls");
               cout << white << "Enter height (max 61, min 10)"<<endl;
               
          }
     }
     
     system("cls");
     definition = true;

     while (definition == true)
     {
          if (_kbhit())
          {
               cin >> width;
               //heightmat = height;
               if (!cin >> width)
               {

                    //system("cls");
                    cout << white << "Enter width (max 46 min 10)" << endl;

                    cin.clear();
                    cin.ignore();
                    //cin >> height;
                    //definition = true;
               }
               else
               {
                    if ((width < 10) || (width>46))
                    {
                         cout << white << "Enter width (max 46, min 10)" << endl;

                         cin.clear();
                         cin.ignore();
                    }
                    else
                    {
                         definition = false;
                    }
               }

          }
          else if (!_kbhit())
          {
               system("cls");
               cout << white << "Enter width (max 46, min 10)" << endl;

          }
     }

     system("cls");

     width2 = width - 2;

     for (i = 0; i < 5; i++)
     {
          BlockInput(true);
          a = 0;
          counting = 3 - i;
          if (counting == 3)
          {
               gotoxy(0, 0);
               cout << white << " OOO";
               gotoxy(0, 1);
               cout << white << "O   O";
               gotoxy(0, 2);
               cout << white << "    O";
               gotoxy(0, 3);
               cout << white << " OOO";
               gotoxy(0, 4);
               cout << white << "    O";
               gotoxy(0, 5);
               cout << white << "O   O";
               gotoxy(0, 6);
               cout << white << " OOO";
               //gotoxy(0, 7);
               //cout << white << "Press Tab to start tetris";
               //character = _getch();
          }
          else if (counting == 2)
          {
               gotoxy(0, 0);
               cout << "         ";
               gotoxy(0, 1);
               cout << "         ";
               gotoxy(0, 2);
               cout << "         ";
               gotoxy(0, 3);
               cout << "        ";
               gotoxy(0, 4);
               cout << "        ";
               gotoxy(0, 5);
               cout << "        ";
               gotoxy(0, 6);
               cout << "         ";
               gotoxy(0, 0);
               cout << red << " OOO";
               gotoxy(0, 1);
               cout << red << "O   O";
               gotoxy(0, 2);
               cout << red << "    O";
               gotoxy(0, 3);
               cout << red << "   O";
               gotoxy(0, 4);
               cout << red << "  O";
               gotoxy(0, 5);
               cout << red << " O ";
               gotoxy(0, 6);
               cout << red << "OOOOO";
               //gotoxy(0, 7);
               //cout << white << "Press Tab to start tetris";
               //character = _getch();
          }
          else if (counting == 1)
          {
               gotoxy(0, 0);
               cout << "         ";
               gotoxy(0, 1);
               cout << "         ";
               gotoxy(0, 2);
               cout << "         ";
               gotoxy(0, 3);
               cout << "         ";
               gotoxy(0, 4);
               cout << "         ";
               gotoxy(0, 5);
               cout << "         ";
               gotoxy(0, 6);
               cout << "         ";
               gotoxy(0, 0);
               cout << blue << "  O";
               gotoxy(0, 1);
               cout << blue << " OO";
               gotoxy(0, 2);
               cout << blue << "O O";
               gotoxy(0, 3);
               cout << blue << "  O";
               gotoxy(0, 4);
               cout << blue << "  O";
               gotoxy(0, 5);
               cout << blue << "  O";
               gotoxy(0, 6);
               cout << blue << "OOOOO";
               //gotoxy(0, 7);
               //cout << white << "Press Tab to start tetris";
               //character = _getch();
          }
          else if (counting == 0)
          {
               gotoxy(0, 0);
               cout << "         ";
               gotoxy(0, 1);
               cout << "         ";
               gotoxy(0, 2);
               cout << "         ";
               gotoxy(0, 3);
               cout << "         ";
               gotoxy(0, 4);
               cout << "         ";
               gotoxy(0, 5);
               cout << "         ";
               gotoxy(0, 6);
               cout << "         ";

               gotoxy(0, 0);
               cout << green << " OOO";
               gotoxy(0, 1);
               cout << green << "O   O";
               gotoxy(0, 2);
               cout << green << "O";
               gotoxy(0, 3);
               cout << green << " OOO";
               gotoxy(0, 4);
               cout << green << "    O";
               gotoxy(0, 5);
               cout << green << "O   O";
               gotoxy(0, 6);
               cout << green << " OOO";

               gotoxy(6, 0);
               cout << yellow << "OOOOO";
               gotoxy(6, 1);
               cout << yellow << "  O  ";
               gotoxy(6, 2);
               cout << yellow << "  O  ";
               gotoxy(6, 3);
               cout << yellow << "  O  ";
               gotoxy(6, 4);
               cout << yellow << "  O  ";
               gotoxy(6, 5);
               cout << yellow << "  O  ";
               gotoxy(6, 6);
               cout << yellow << "  O  ";

               gotoxy(12, 0);
               cout << darkblue << "  O  ";
               gotoxy(12, 1);
               cout << darkblue << " O O ";
               gotoxy(12, 2);
               cout << darkblue << " O O ";
               gotoxy(12, 3);
               cout << darkblue << " O O ";
               gotoxy(12, 4);
               cout << darkblue << "OOOOO";
               gotoxy(12, 5);
               cout << darkblue << "O   O";
               gotoxy(12, 6);
               cout << darkblue << "O   O";

               gotoxy(18, 0);
               cout << colorcolor << "OOOO ";
               gotoxy(18, 1);
               cout << colorcolor << "O   O";
               gotoxy(18, 2);
               cout << colorcolor << "O   O";
               gotoxy(18, 3);
               cout << colorcolor << "OOOO ";
               gotoxy(18, 4);
               cout << colorcolor << "O   O";
               gotoxy(18, 5);
               cout << colorcolor << "O   O";
               gotoxy(18, 6);
               cout << colorcolor << "O   O";

               gotoxy(24, 0);
               cout << red << "OOOOO";
               gotoxy(24, 1);
               cout << red << "  O  ";
               gotoxy(24, 2);
               cout << red << "  O  ";
               gotoxy(24, 3);
               cout << red << "  O  ";
               gotoxy(24, 4);
               cout << red << "  O  ";
               gotoxy(24, 5);
               cout << red << "  O  ";
               gotoxy(24, 6);
               cout << red << "  O  ";
               //gotoxy(0, 7);
               //cout << white << "Press Tab to start tetris";
               //character = _getch();
          }
          else if (counting == -1)
          {
               gotoxy(0, 0);
               cout << "                                                                                                          ";
               gotoxy(0, 1);
               cout << "                                                                                                          ";
               gotoxy(0, 2);
               cout << "                                                                                                          ";
               gotoxy(0, 3);
               cout << "                                                                                                          ";
               gotoxy(0, 4);
               cout << "                                                                                                          ";
               gotoxy(0, 5);
               cout << "                                                                                                          ";
               gotoxy(0, 6);
               cout << "                                                                                                          ";
               break;
          }
          Sleep(1000);
     }

     while (press == true)
     {
          if (_kbhit())
          {
               character = _getch();
               if (character == 9)
               {
                    //test
                    press = false;
                    //test
               }
               else
               {
                    cout <<white<< "Press Tab to start tetris";
                    system("cls");
               }
          }
          else if (!_kbhit())
          {
               cout <<white<< "Press Tab to start tetris";
               system("cls");
          }
     }

               system("cls");
          


     
     system("cls");
     //
     for (i = 0; i < height; i++)
     {
          for (j = 0; j < width; j++)
          {
               grid[i][j] = ' ';
          }
     }

     for (i = 0; i < height; i++)
     {
          grid[i][0] = 'O';
     }
     for (i = 0; i < height; i++)
     {
          grid[i][width - 1] = 'O';
     }
     for (i = 1; i < (width - 1); i++)
     {
          grid[0][i] = 'O';
     }
     for (i = 1; i < (width - 1); i++)
     {
          grid[height - 1][i] = 'O';
     }
     //output
     for (i = 0; i < height; i++)
     {
          gotoxy(0, i);
          cout << white << 'O';
     }
     for (i = 0; i < height; i++)
     {
          gotoxy(width - 1, i);
          cout << white << 'O';
     }
     for (i = 1; i < (width - 1); i++)
     {
          gotoxy(i, 0);
          cout << white << 'O';
     }
     for (i = 1; i < (width - 1); i++)
     {
          gotoxy(i, height - 1);
          cout << white << 'O';
     }
     
     srand(time(NULL));
     for (i = 0; i < 6; i++)
     {
          if (i == 0)
          {     //srand(time(NULL));
          random = rand() % 7 + 1;
     }
          
          else if (i == 1)
          {
               //srand(time(NULL));
               nextrandom = rand() % 7 + 1;
               //nextrandom = rand() % 7 + 1;
          }
          else if (i == 2)
               //extr
          {
               //srand(time(NULL));
               next1 = rand() % 7 + 1;
          }
          else if (i == 3)
          {
               //srand(time(NULL));
               next2 = rand() % 7 + 1;
          }
          else if (i == 4)
          {
               //srand(time(NULL));
               next3 = rand() % 7 + 1;
          }
          else if (i == 5)
          {
               //srand(time(NULL));
               next4 = rand() % 7 + 1;
          }
     }
     //extr

     /* Give a value to all integer variables we declared */
     for (i = 0; i < 100; i++)
     {
          if (width2 <= 0)
          {
               break;
          }
          else
          {
               width2 = width2 - 2;
               mult++;
          }
     }
     x = mult;

     y = 1;
     lastx = x; lasty = y;


     //start = true;
     /* start an Infinite Loop */
     srand(time(NULL));
     //while (start)
     while (1==1)
     {
          if ((y<1) || (y>(height - 1)))
          {
               y = 1;
          }
          if ((x<1) || (x>(width - 1)))
          {
               x = 1;
          }
          
          //random=4;
          //comment for clearity
          /*for (i = 0; i < height; i++)
          {
               for (j = 0; j < width; j++)
               {
                    gotoxy(j, height + 13 + i);
                    cout << white << grid[i][j];
               }
          }
          for (i = 0; i < height; i++)
          {
               for (j = 0; j < width; j++)
               {
                    gotoxy(j, 2 * height + 14 + i);
                    cout << white << checkcolor[i][j];
               }
          }*/
          
          gotoxy(width + 1, 57);
          cout << yellow << "1=-1,2=+1,4=-10,5=+10,7=-100";
          gotoxy(width + 1, 58);
          cout << yellow << "8=+100,-=-1000,==+1000";
          gotoxy(width + 1, 59);
          cout << "                  ";
          gotoxy(width + 1, 59);
          cout << red << "speed:"<<speed;

          gotoxy(width + 1, 36);
          cout <<white<< "                 ";
          gotoxy(width + 1, 36);
          cout << white << "duration2:" << duration2;
          gotoxy(width + 1, 37);
          cout << white << "                 ";
          gotoxy(width + 1, 37);
          cout << white << "y:" << y;

          gotoxy(width + 1, 38);
          cout << white << "                 ";
          gotoxy(width + 1, 38);
          cout << white << "lasty11:" << lasty11;

          if (gameover == true)
          {
               gotoxy(width + 1, 39);
               cout << white << "                    ";
               gotoxy(width + 1, 39);
               cout << white << "gameover:true";
          }
          if (gameover == false)
          {
               gotoxy(width + 1, 39);
               cout << white << "                 ";
               gotoxy(width + 1, 39);
               cout << white << "gameover:false";
          }

          gotoxy(width + 1, 40);
          cout << white << "                 ";
          gotoxy(width + 1, 40);
          cout << white << "rotation:" << rotation;
          
          
          gotoxy(width + 1, 41);
          cout << white << "                 ";
          gotoxy(width + 1, 41);
          cout << white << "lastrotation:" << lastrotation;

          gotoxy(width + 1, 42);
          cout << white << "                 ";
          gotoxy(width + 1, 42);
          cout << white << "checkBottom:" << checkBottom;

          gotoxy(width + 1, 43);
          cout << white << "                 ";
          gotoxy(width + 1, 43);
          cout << white << "check1:" << check1;

          gotoxy(width + 1, 44);
          cout << white << "                 ";
          gotoxy(width + 1, 44);
          cout << white << "check2:" << check2;

          gotoxy(width + 1, 45);
          cout << white << "                 ";
          gotoxy(width + 1, 45);
          cout << white << "lower:" << lower;

          gotoxy(width + 1, 46);
          cout << white << "                 ";
          gotoxy(width + 1, 46);
          cout << white << "lastlower:" << lastlower;
          
          gotoxy(width + 1, 47);
          cout << white << "                   ";
          gotoxy(width + 1, 47);
          cout << white << "x:" << x;
          
          gotoxy(width + 1, 48);
          cout << white << "                   ";
          gotoxy(width + 1, 48);
          cout << white << "lastx:" << lastx;

          gotoxy(width + 1, 49);
          cout << white << "                   ";
          gotoxy(width + 1, 49);
          cout << white << "lastx11:" << lastx11;

          gotoxy(width + 1, 50);
          cout << white << "                   ";
          gotoxy(width + 1, 50);
          cout << white << "y:" << y;

          gotoxy(width + 1, 51);
          cout << white << "                   ";
          gotoxy(width + 1, 51);
          cout << white << "lasty:" << lasty;

          gotoxy(width + 1, 52);
          cout << white << "                   ";
          gotoxy(width + 1, 52);
          cout << white << "lasty11:" << lasty11;

          gotoxy(width + 1, 53);
          cout << white << "                   ";
          gotoxy(width + 1, 53);
          cout << white << "low1:" << low1;

          gotoxy(width + 1, 54);
          cout << white << "                   ";
          gotoxy(width + 1, 54);
          cout << white << "low2:" << low2;

          gotoxy(width + 1, 55);
          cout << white << "                   ";
          gotoxy(width + 1, 55);
          cout << white << "low3:" << low3;

          gotoxy(width + 1, 56);
          cout << white << "                   ";
          gotoxy(width + 1, 56);
          cout << white << "low4:" << low4;

          gotoxy(width + 1, 61);
          cout << white << "VICTOR LAM 0857216";
          gotoxy(width + 1, 62);
          cout<<white<<"Electrical Engineering";
          //comment for clearity


          if (paused == false)
          {
               //if (checkcolor2[width + 1][ 31] == 1)
               //{
               gotoxy(width + 1, 31);
               cout << "                     ";
               gotoxy(width + 1, 60);
               cout << "                     ";
               //     checkcolor2[width + 1][31] = 0;
               //     Sleep(1000);
               //}
               //else if (checkcolor2[width + 1][31] != 1)
               //{
               //     ;
               //}
               //cout.flush();
               //Sleep(1000);

               //for (check2 = 1; check20 < (height - 1); check20++)
               //{
                    
                    //for (j = (height-1); j > 0; j--)
                    
                    //official deleterow check
                    for (j = 1; j < (height-1); j++)
                    //j = 1;
                    //eraserow = true;
                    /*for (column = 1; column < (width - 1); column++)
                    {
                         if (grid[j][column] == 'O')
                         {
                              eraserow = true;
                         }
                         else if (grid[j][column] != 'O')
                         {
                              eraserow = false;
                              break;
                         }
                    }*/
                    //while (j < (height - 1))
                    //while (j>0)
                    {
                         //eraserow = true;
                         if (
                              //((grid[j][1] == 'O') && (grid[j][2] == 'O') && (grid[j][3] == 'O') && (grid[j][4] == 'O')
                              //&& (grid[j][5] == 'O') && (grid[j][6] == 'O') && (grid[j][7] == 'O') && (grid[j][8] == 'O')
                              //&& (grid[j][9] == 'O') && (grid[j][10] == 'O')) &&
                              ((((random == 1 && (grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O')) //BBottom detection o turned officieel officieel
                              || (random == 2 && (grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
                              || (random == 3 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
                              || (random == 4 && (grid[lasty + 1][lastx + 3] == 'O' || grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
                              || (random == 5 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
                              || (random == 6 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
                              || (random == 7 && (grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))) && (lastrotation % 4 == 0)) ||

                              (((random == 1 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O')) //Bottom detection 90 turned
                              || (random == 2 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
                              || (random == 3 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O'))
                              || (random == 4 && (grid[lasty + 4][lastx] == 'O'))
                              || (random == 5 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
                              || (random == 6 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O'))
                              || (random == 7 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))) && (lastrotation % 4 == 1)) ||

                              (((random == 1 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O')) //Bottom detection 18o turned
                              || (random == 2 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
                              || (random == 3 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
                              || (random == 4 && (grid[lasty + 1][lastx + 3] == 'O' || grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
                              || (random == 5 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
                              || (random == 6 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
                              || (random == 7 && (grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))) && (lastrotation % 4 == 2)) ||

                              (((random == 1 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O')) //Bottom detection 270 turned
                              || (random == 2 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O'))
                              || (random == 3 && (grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O'))
                              || (random == 4 && (grid[lasty + 4][lastx] == 'O'))
                              || (random == 5 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
                              || (random == 6 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O'))
                              || (random == 7 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))) && (lastrotation % 4 == 3))

                              ))
                         {
                              for (column = 1; column < (width - 1); column++)
                              {
                                   if (grid[j][column] == 'O')
                                   {
                                        eraserow = true;
                                   }
                                   else if (grid[j][column] != 'O')
                                   {
                                        eraserow = false;
                                        break;
                                   }
                              }

                              //gotoxy(width + 1, 31);
                              //cout << "                     ";
                              while (eraserow == true)
                              {
                                   for (i = 1; i < (width - 1); i++)
                                   {
                                        //checkcolor[j][i] = 0;
                                        grid[j][i] = ' ';

                                   }
                                   gotoxy(0, j);
                                   cout << white << "O";
                                   for (iteration = 1; iteration < (width - 1); iteration++)
                                   {


                                        gotoxy(iteration, j);
                                        cout << white << " ";


                                   }
                                   gotoxy(width - 1, j);
                                   cout << white << "O";
                                   score = score + 100; //+100 score when row cleared
                                   scoreplus = score - lastscore;
                                   gotoxy(width + 1, 31);
                                   cout << "plus " << scoreplus << "points!";
                                   //checkcolor2[width + 1][31] = 1;


                                   //cout  << "O          O";
                                   for (row4 = 1; row4 < (j); row4++)
                                   {
                                        for (column4 = 1; column4 < (width - 1); column4++)
                                        {


                                             grid[j + 1 - row4][column4] = grid[j - row4][column4];




                                             gotoxy(column4, j + 1 - row4);

                                             if (checkcolor[j + 1 - row4][column4] == 1)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];

                                                  cout << white << grid[j - row4][column4];
                                                  //+0.5
                                                  //+1

                                                  //cout << grid[j - row][column];
                                             }
                                             if (checkcolor[j + 1 - row4][column4] == 2)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << red << grid[j - row4][column4];
                                                  //+0.5
                                                  //+1     
                                             }
                                             if (checkcolor[j + 1 - row4][column4] == 3)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << blue << grid[j - row4][column4];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[j + 1 - row4][column4] == 4)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << green << grid[j - row4][column4];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[j + 1 - row4][column4] == 5)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << yellow << grid[j - row4][column4];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[j + 1 - row4][column4] == 6)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << darkblue << grid[j - row4][column4];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[j + 1 - row4][column4] == 7)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << colorcolor << grid[j - row4][column4];
                                                  //+0.5
                                                  //+1
                                             }
                                             checkcolor[j + 1 - row4][column4] = checkcolor[j - row4][column4];

                                        }
                                   }

                                   for (row2 = 1; row2 < (height - 1); row2++)
                                   {
                                        for (column2 = 1; column2 < (width - 1); column2++)
                                        {



                                             gotoxy(column2, height - 1 - row2);
                                             if (checkcolor[height - 1 - row2][column2] == 0)
                                             {
                                                  cout << grid[height - 1 - row2][column2];
                                             }

                                             if (checkcolor[height - 1 - row2][column2] == 1)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];

                                                  cout << white << grid[height - 1 - row2][column2];
                                                  //+0.5
                                                  //+1

                                                  //cout << grid[j - row][column];
                                             }
                                             if (checkcolor[height - 1 - row2][column2] == 2)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << red << grid[height - 1 - row2][column2];
                                                  //+0.5
                                                  //+1     
                                             }
                                             if (checkcolor[height - 1 - row2][column2] == 3)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << blue << grid[height - 1 - row2][column2];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[height - 1 - row2][column2] == 4)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << green << grid[height - 1 - row2][column2];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[height - 1 - row2][column2] == 5)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << yellow << grid[height - 1 - row2][column2];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[height - 1 - row2][column2] == 6)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << darkblue << grid[height - 1 - row2][column2];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[height - 1 - row2][column2] == 7)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << colorcolor << grid[height - 1 - row2][column2];
                                                  //+0.5
                                                  //+1
                                             }

                                        }
                                   }


                                   eraserow = false;
                                   //j = 1;
                                   //break;
                              }


                              //break;
                         }
                         else
                         {
                              ;
                         }
                         /*for (column = 1; column < (width - 1); column++)
                         {
                              if (grid[j][column] == 'O')
                              {
                                   eraserow = true;
                              }
                              else if (grid[j][column] != 'O')
                              {
                                   eraserow = false;
                                   break;
                              }
                         }
                              //j = 1;
                         if (eraserow==false)
                         {
                              j = 1;
                              j++;
                              eraserow = true;
                              
                         }
                         else if(eraserow==true)
                         {
                              j = 1;
                              j = j;
                         }*/


                    }
                    //official deleterow check

                    //official deleterow check2
                    //for (j = 1; j < (height - 1); j++)
                    for (j = (height - 2); j > 0;j--)
                         //j = 1;
                         //eraserow = true;
                         /*for (column = 1; column < (width - 1); column++)
                         {
                         if (grid[j][column] == 'O')
                         {
                         eraserow = true;
                         }
                         else if (grid[j][column] != 'O')
                         {
                         eraserow = false;
                         break;
                         }
                         }*/
                         //while (j < (height - 1))
                         //while (j>0)
                    {
                         //eraserow = true;
                         if (
                              //((grid[j][1] == 'O') && (grid[j][2] == 'O') && (grid[j][3] == 'O') && (grid[j][4] == 'O')
                              //&& (grid[j][5] == 'O') && (grid[j][6] == 'O') && (grid[j][7] == 'O') && (grid[j][8] == 'O')
                              //&& (grid[j][9] == 'O') && (grid[j][10] == 'O')) &&
                              ((((random == 1 && (grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O')) //BBottom detection o turned officieel officieel
                              || (random == 2 && (grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
                              || (random == 3 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
                              || (random == 4 && (grid[lasty + 1][lastx + 3] == 'O' || grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
                              || (random == 5 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
                              || (random == 6 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
                              || (random == 7 && (grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))) && (lastrotation % 4 == 0)) ||

                              (((random == 1 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O')) //Bottom detection 90 turned
                              || (random == 2 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
                              || (random == 3 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O'))
                              || (random == 4 && (grid[lasty + 4][lastx] == 'O'))
                              || (random == 5 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
                              || (random == 6 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O'))
                              || (random == 7 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))) && (lastrotation % 4 == 1)) ||

                              (((random == 1 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O')) //Bottom detection 18o turned
                              || (random == 2 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
                              || (random == 3 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
                              || (random == 4 && (grid[lasty + 1][lastx + 3] == 'O' || grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
                              || (random == 5 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
                              || (random == 6 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
                              || (random == 7 && (grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))) && (lastrotation % 4 == 2)) ||

                              (((random == 1 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O')) //Bottom detection 270 turned
                              || (random == 2 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O'))
                              || (random == 3 && (grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O'))
                              || (random == 4 && (grid[lasty + 4][lastx] == 'O'))
                              || (random == 5 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
                              || (random == 6 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O'))
                              || (random == 7 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))) && (lastrotation % 4 == 3))

                              ))
                         {
                              for (column = 1; column < (width - 1); column++)
                              {
                                   if (grid[j][column] == 'O')
                                   {
                                        eraserow = true;
                                   }
                                   else if (grid[j][column] != 'O')
                                   {
                                        eraserow = false;
                                        break;
                                   }
                              }

                              //gotoxy(width + 1, 31);
                              //cout << "                     ";
                              while (eraserow == true)
                              {
                                   for (i = 1; i < (width - 1); i++)
                                   {
                                        //checkcolor[j][i] = 0;
                                        grid[j][i] = ' ';

                                   }
                                   gotoxy(0, j);
                                   cout << white << "O";
                                   for (iteration = 1; iteration < (width - 1); iteration++)
                                   {


                                        gotoxy(iteration, j);
                                        cout << white << " ";


                                   }
                                   gotoxy(width - 1, j);
                                   cout << white << "O";
                                   score = score + 100; //+100 score when row cleared
                                   scoreplus = score - lastscore;
                                   gotoxy(width + 1, 31);
                                   cout << "plus " << scoreplus << "points!";
                                   //checkcolor2[width + 1][31] = 1;


                                   //cout  << "O          O";
                                   for (row4 = 1; row4 < (j); row4++)
                                   {
                                        for (column4 = 1; column4 < (width - 1); column4++)
                                        {


                                             grid[j + 1 - row4][column4] = grid[j - row4][column4];




                                             gotoxy(column4, j + 1 - row4);

                                             if (checkcolor[j + 1 - row4][column4] == 1)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];

                                                  cout << white << grid[j - row4][column4];
                                                  //+0.5
                                                  //+1

                                                  //cout << grid[j - row][column];
                                             }
                                             if (checkcolor[j + 1 - row4][column4] == 2)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << red << grid[j - row4][column4];
                                                  //+0.5
                                                  //+1     
                                             }
                                             if (checkcolor[j + 1 - row4][column4] == 3)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << blue << grid[j - row4][column4];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[j + 1 - row4][column4] == 4)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << green << grid[j - row4][column4];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[j + 1 - row4][column4] == 5)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << yellow << grid[j - row4][column4];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[j + 1 - row4][column4] == 6)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << darkblue << grid[j - row4][column4];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[j + 1 - row4][column4] == 7)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << colorcolor << grid[j - row4][column4];
                                                  //+0.5
                                                  //+1
                                             }
                                             checkcolor[j + 1 - row4][column4] = checkcolor[j - row4][column4];

                                        }
                                   }

                                   for (row2 = 1; row2 < (height - 1); row2++)
                                   {
                                        for (column2 = 1; column2 < (width - 1); column2++)
                                        {



                                             gotoxy(column2, height - 1 - row2);
                                             if (checkcolor[height - 1 - row2][column2] == 0)
                                             {
                                                  cout << grid[height - 1 - row2][column2];
                                             }

                                             if (checkcolor[height - 1 - row2][column2] == 1)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];

                                                  cout << white << grid[height - 1 - row2][column2];
                                                  //+0.5
                                                  //+1

                                                  //cout << grid[j - row][column];
                                             }
                                             if (checkcolor[height - 1 - row2][column2] == 2)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << red << grid[height - 1 - row2][column2];
                                                  //+0.5
                                                  //+1     
                                             }
                                             if (checkcolor[height - 1 - row2][column2] == 3)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << blue << grid[height - 1 - row2][column2];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[height - 1 - row2][column2] == 4)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << green << grid[height - 1 - row2][column2];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[height - 1 - row2][column2] == 5)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << yellow << grid[height - 1 - row2][column2];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[height - 1 - row2][column2] == 6)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << darkblue << grid[height - 1 - row2][column2];
                                                  //+0.5
                                                  //+1
                                             }
                                             if (checkcolor[height - 1 - row2][column2] == 7)
                                             {
                                                  //checkcolor[j + 1 - row][column] = checkcolor[j - row][column];
                                                  cout << colorcolor << grid[height - 1 - row2][column2];
                                                  //+0.5
                                                  //+1
                                             }

                                        }
                                   }


                                   eraserow = false;
                                   //j = 1;
                                   //break;
                              }


                              //break;
                         }
                         else
                         {
                              ;
                         }
                         /*for (column = 1; column < (width - 1); column++)
                         {
                         if (grid[j][column] == 'O')
                         {
                         eraserow = true;
                         }
                         else if (grid[j][column] != 'O')
                         {
                         eraserow = false;
                         break;
                         }
                         }
                         //j = 1;
                         if (eraserow==false)
                         {
                         j = 1;
                         j++;
                         eraserow = true;

                         }
                         else if(eraserow==true)
                         {
                         j = 1;
                         j = j;
                         }*/


                    }
                    //official deleterow check2
               
          
          //ELSE
               
          if (random == lastrandom)
          {
               checktwice = 1;
          }
          else
          {
               checktwice = 0;
          }
          //Sleep(1);

          //time_t start, end;
          //int elapsed;
          //time(&start);
          //do
          //{
          //     time(&end);
          //     elapsed = difftime(end, start);
          //     ////printf("%dn", elapsed);
          //} 
          //while (elapsed < 10000);
          /* Head to LastX and LastY and clear old O*/
          //again:
          //gotoxy(lastx, lasty);
          ////printf("      ");
          /* Draw New O */
          //gotoxy(x, y);
          ////printf("VICTOR");
          /* Get Input */
          //void printshape();
          
          /*for (j = 1; j < (height - 1); j++)
               {
               if ((grid[j][1] == 'O') && (grid[j][2] == 'O') && (grid[j][3] == 'O') && (grid[j][4] == 'O')
               && (grid[j][5] == 'O') && (grid[j][6] == 'O') && (grid[j][7] == 'O') && (grid[j][8] == 'O')
               && (grid[j][9] == 'O') && (grid[j][10] == 'O'))
               for (column = 1; column < (width - 1); column++)
               {
               if (grid[j][column] == 'O')
               {
               eraserow = true;
               }
               else if (grid[j][column] != 'O')
               {
               eraserow = false;
               break;
               }
               }
               
               
               while (eraserow == true)
               {
               for (i = 1; i < (width - 1); i++)
               {
               grid[j][i] = ' ';

               }
               gotoxy(0, j);
               cout << "O          O";
               for (row = 1; row < (j + 2); row++)
               {
               for (column = 1; column < (width - 1); column++)
               {
               grid[j + 1 - row][column] = grid[j - row][column];
               gotoxy(column, row);
               cout << grid[row][column];
               }
               }
               eraserow = false;
               }


               }*/
          //srand(time(NULL)); //this is original
          //nextrandom = rand() % 7 + 1;
          //if ((y == 16)||(grid[lasty+2][lastx]=='O'))
          /*if ((random == 1 && (grid[lasty + 1][lastx] == 'O' || grid[lasty + 2][lastx+1] == 'O' || grid[lasty + 1][lastx+2] == 'O'))
               || (random == 2 && (grid[lasty + 2][lastx] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 1][lastx + 2] == 'O'))
               || (random == 3 && (grid[lasty + 1][lastx] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 2][lastx + 2] == 'O'))
               || (random == 4 && (grid[lasty + 1][lastx] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 1][lastx + 3] == 'O'))
               || (random == 5 && (grid[lasty + 2][lastx] == 'O' || grid[lasty + 2][lastx + 1] == 'O'))
               || (random == 6 && (grid[lasty + 1][lastx] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx + 2] == 'O'))
               || (random == 7 && (grid[lasty + 2][lastx] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 1][lastx + 2] == 'O')))*/
          /*if ((random == 1 && (grid[y + 1][x] == 'O' || grid[y + 2][x + 1] == 'O' || grid[y + 1][x + 2] == 'O'))
               || (random == 2 && (grid[y + 2][x] == 'O' || grid[y + 1][x + 1] == 'O' || grid[y + 1][x + 2] == 'O'))
               || (random == 3 && (grid[y + 1][x] == 'O' || grid[y + 1][x + 1] == 'O' || grid[y + 2][x + 2] == 'O'))
               || (random == 4 && (grid[y + 1][x] == 'O' || grid[y + 1][x + 1] == 'O' || grid[y + 1][x + 2] == 'O' || grid[y + 1][x + 3] == 'O'))
               || (random == 5 && (grid[y + 2][x] == 'O' || grid[y + 2][x + 1] == 'O'))
               || (random == 6 && (grid[y + 1][x] == 'O' || grid[y + 2][x + 1] == 'O' || grid[y + 2][x + 2] == 'O'))
               || (random == 7 && (grid[y + 2][x] == 'O' || grid[y + 2][x + 1] == 'O' || grid[y + 1][x + 2] == 'O')))*/
          /*for (i = 1; i < (width - 1); i++)
          {
               if (grid[1][i] == 'O')
               {
                    checkrow1 = true;
                    break;
               }
               else
               {
                    checkrow1 = false;
               }
          }*/
          //for (column = 1; column < (width - 1); column++)
          //{
          //     if ((grid[1][column] != 'O'))
          //     {
          //          spawn = false;
          //     }
          //     else if ((grid[1][column] == 'O'))
          //     {
          //          spawn = true;
          //          break;
          //     }
          //}
          if (((((((random == 1 && (grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O')) //Bottom detection o turned
               || (random == 2 && (grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
               || (random == 3 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
               || (random == 4 && (grid[lasty + 1][lastx + 3] == 'O' || grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
               || (random == 5 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
               || (random == 6 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
               || (random == 7 && (grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O')))&&(lastrotation%4==0))||
               
               (((random == 1 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 2][lastx ] == 'O' )) //Bottom detection 90 turned
               || (random == 2 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O' ))
               || (random == 3 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O'))
               || (random == 4 && (grid[lasty + 4][lastx] == 'O' ))
               || (random == 5 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
               || (random == 6 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 3][lastx ] == 'O' ))
               || (random == 7 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 2][lastx ] == 'O'))) && (lastrotation%4 == 1)) || 

               (((random == 1 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O')) //Bottom detection 18o turned
               || (random == 2 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
               || (random == 3 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
               || (random == 4 && (grid[lasty + 1][lastx + 3] == 'O' || grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
               || (random == 5 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
               || (random == 6 && (grid[lasty + 2][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 1][lastx] == 'O'))
               || (random == 7 && (grid[lasty + 1][lastx + 2] == 'O' || grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))) && (lastrotation%4 == 2)) ||

               (((random == 1 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O')) //Bottom detection 270 turned
               || (random == 2 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O'))
               || (random == 3 && (grid[lasty + 1][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O'))
               || (random == 4 && (grid[lasty + 4][lastx] == 'O'))
               || (random == 5 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))
               || (random == 6 && (grid[lasty + 2][lastx + 1] == 'O' || grid[lasty + 3][lastx] == 'O'))
               || (random == 7 && (grid[lasty + 3][lastx + 1] == 'O' || grid[lasty + 2][lastx] == 'O'))) && (lastrotation%4 == 3))))
               
                )
                //&&!_kbhit()
                 //|| (y<0) || (y>(height - 1)) || (x<0) || (x>(width - 1)) 
                 //|| (spawn == false)
                 )
          {
               /*if (random==1)
               {
                    gotoxy(lastx, lasty);
                    ////printf("   ");
                    cout << "OOO";
                    for (z = 0; z < 3; z++)
                    {
                         grid[lasty][lastx] = 'O';
                    }
                    gotoxy(lastx + 1, lasty + 1);
                    ////printf(" ");
                    cout << "O";
                    grid[lasty + 1][lastx + 1] = 'O';
               }
               else if (random==2)
               {
                    gotoxy(lastx, lasty);
                    //printf("   ");
                    cout << "OOO";
                    for (z = 0; z < 3; z++)
                    {
                         grid[lasty][lastx] = 'O';
                    }
                    gotoxy(lastx, lasty + 1);
                    //printf(" ");
                    cout << "O";
                    grid[lasty + 1][lastx] = 'O';
               }
               else if (random==3)
               {
                    gotoxy(lastx, lasty);
                    //printf("   ");
                    cout << "OOO";
                    for (z = 0; z < 3; z++)
                    {
                         grid[lasty][lastx] = 'O';
                    }
                    gotoxy(lastx + 2, lasty + 1);
                    //printf(" ");
                    cout << "O";
                    grid[lasty + 1][lastx + 2] = 'O';
               }
               else if (random==4)
               {
                    gotoxy(lastx, lasty);
                    //printf("    ");
                    cout << "OOOO";
                    for (z = 0; z < 4; z++)
                    {
                         grid[lasty][lastx] = 'O';
                    }
               }
               else if (random==5)
               {
                    gotoxy(lastx, lasty);
                    //printf("  ");
                    cout << "OO";
                    for (z = 0; z < 2; z++)
                    {
                         grid[lasty][lastx] = 'O';
                    }
                    gotoxy(lastx, lasty + 1);
                    //printf("  ");
                    cout << "OO";
                    for (z = 0; z < 2; z++)
                    {
                         grid[lasty + 1][lastx] = 'O';
                    }
               }
               else if (random==6)
               {
                    gotoxy(lastx, lasty);
                    //printf("  ");
                    cout << "OO";
                    for (z = 0; z < 2; z++)
                    {
                         grid[lasty][lastx] = 'O';
                    }
                    gotoxy(lastx + 1, lasty + 1);
                    //printf("  ");
                    cout << "OO";
                    for (z = 0; z < 2; z++)
                    {
                         grid[lasty + 1][lastx + 1] = 'O';
                    }
               }
               else if (random==7)
               {
                    gotoxy(lastx + 1, lasty);
                    //printf("  ");
                    cout << "OO";
                    for (z = 0; z < 2; z++)
                    {
                         grid[lasty][lastx + 1] = 'O';
                    }
                    gotoxy(lastx, lasty + 1);
                    //printf("  ");
                    cout << "O";
                    for (z = 0; z < 2; z++)
                    {
                         grid[lasty + 1][lastx] = 'O';
                    }
               }*/
               
               //random = rand() % 7 + 1;
               
               
               //int lastrandom = random;
               
               y = 1;
               //x = 4;
               for (i = 0; i < 100; i++)
               {
                    if (width2<=0)
                    {
                         break;
                    }
                    else
                    {
                         width2 = width2 - 2;
                         mult++;
                    }
               }
               x = mult;
               lastx11 = mult;
               lastrotation = 3;
               rotation = 0;
               //make random
               //duration = 0;
               //duration = duration;
               //duration2 = 0;
               //duration = 0;
               lasty = 1;
               lasty11 = 1;
               //duration2 = 0;
               
               
               random = nextrandom;
               //nextrandom = rand() % 7 + 1;
               //extr
               nextrandom = next1;
               next1 = next2;
               next2 = next3;
               next3 = next4;
               next4 = rand() % 7 + 1;
               //extr
          }
          //else if (duration2 == 0)
          //{
          //     nextrandom = rand() % 7 + 1;
          //}
          else 
          {
               //duration4 = duration4;
               random = random;
               checktwice = 0;
               rotation = rotation;
               //duration = duration;
               nextrandom = nextrandom;
               duration2 = duration2;
               lasty11 = lasty11;
               y = y;
          }
          
          gotoxy(width + 1, 21);
          cout << "                   ";
          gotoxy(width + 1, 21);
          cout <<red<< "Press b to pause";

          gotoxy(width + 1, 22);
          cout << white << "Use left arrow, right arrow to";

          gotoxy(width + 1, 23);
          cout << white << "move to left or right. Use down";
          gotoxy(width + 1, 24);
          cout << white << " arrow to move down, use up";
               gotoxy(width + 1, 25);
               cout << white << "arrow to rotate clockwise. Use ";
               gotoxy(width + 1, 26);
               cout<<white<<"Enter to move to minimum";

          gotoxy(width + 1, 28);
          cout << "        ";
          gotoxy(width + 1, 28);
          cout << white << "Score: " << score<< "points";

          
          for (i = 0; i < 29; i++)
          {
               gotoxy(width + 1 + i, 12);
               cout <<white<< "O";
          }
          for (i = 0; i < 29; i++)
          {
               gotoxy(width + 1 + i, 17);
               cout <<white<< "O";
          }
          for (i = 0; i < 4; i++)
          {
               gotoxy(width + 1, 13 + i);
               cout <<white<< "O";
          }
          for (i = 0; i < 4; i++)
          {
               gotoxy(width + 29, 13 + i);
               cout <<white<< "O";
          }

          gotoxy(width + 1, 19);
          cout << white << "  next nxt1 nxt2 nxt3 nxt4";

          //void printshape();
          //extr
          if (next4 == 1)
          {
               if (next3 == 1)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 24, 15);
                    cout << " ";
               }
               else if (next3 == 2)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 23, 15);
                    cout << " ";
               }
               else if (next3 == 3)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 25, 15);
                    cout << " ";
               }
               else if (next3 == 4)
               {
                    gotoxy(width + 23, 14);
                    cout << "    ";

               }
               else if (next3 == 5)
               {
                    gotoxy(width + 23, 14);
                    cout << "  ";
                    gotoxy(width + 23, 15);
                    cout << "  ";
               }
               else if (next3 == 6)
               {
                    gotoxy(width + 23, 14);
                    cout << "  ";
                    gotoxy(width + 24, 15);
                    cout << "  ";
               }
               else if (next3 == 7)
               {
                    gotoxy(width + 24, 14);
                    cout << "  ";
                    gotoxy(width + 23, 15);
                    cout << "  ";
               }
               gotoxy(width + 23, 14);
               cout << white << "OOO";
               gotoxy(width + 24, 15);
               cout << white << "O";
          }
          else if (next4 == 2)
          {
               if (next3 == 1)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 24, 15);
                    cout << " ";
               }
               else if (next3 == 2)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 23, 15);
                    cout << " ";
               }
               else if (next3 == 3)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 25, 15);
                    cout << " ";
               }
               else if (next3 == 4)
               {
                    gotoxy(width + 23, 14);
                    cout << "    ";

               }
               else if (next3 == 5)
               {
                    gotoxy(width + 23, 14);
                    cout << "  ";
                    gotoxy(width + 23, 15);
                    cout << "  ";
               }
               else if (next3 == 6)
               {
                    gotoxy(width + 23, 14);
                    cout << "  ";
                    gotoxy(width + 24, 15);
                    cout << "  ";
               }
               else if (next3 == 7)
               {
                    gotoxy(width + 24, 14);
                    cout << "  ";
                    gotoxy(width + 23, 15);
                    cout << "  ";
               }
               gotoxy(width + 23, 14);
               cout << red << "OOO";
               gotoxy(width + 23, 15);
               cout << red << "O";

          }
          else if (next4 == 3)
          {
               if (next3 == 1)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 24, 15);
                    cout << " ";
               }
               else if (next3 == 2)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 23, 15);
                    cout << " ";
               }
               else if (next3 == 3)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 25, 15);
                    cout << " ";
               }
               else if (next3 == 4)
               {
                    gotoxy(width + 23, 14);
                    cout << "    ";

               }
               else if (next3 == 5)
               {
                    gotoxy(width + 23, 14);
                    cout << "  ";
                    gotoxy(width + 23, 15);
                    cout << "  ";
               }
               else if (next3 == 6)
               {
                    gotoxy(width + 23, 14);
                    cout << "  ";
                    gotoxy(width + 24, 15);
                    cout << "  ";
               }
               else if (next3 == 7)
               {
                    gotoxy(width + 24, 14);
                    cout << "  ";
                    gotoxy(width + 23, 15);
                    cout << "  ";
               }
               gotoxy(width + 23, 14);
               cout << blue << "OOO";
               gotoxy(width + 25, 15);
               cout << blue << "O";

          }
          else if (next4 == 4)
          {
               if (next3 == 1)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 24, 15);
                    cout << " ";
               }
               else if (next3 == 2)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 23, 15);
                    cout << " ";
               }
               else if (next3 == 3)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 25, 15);
                    cout << " ";
               }
               else if (next3 == 4)
               {
                    gotoxy(width + 23, 14);
                    cout << "    ";

               }
               else if (next3 == 5)
               {
                    gotoxy(width + 23, 14);
                    cout << "  ";
                    gotoxy(width + 23, 15);
                    cout << "  ";
               }
               else if (next3 == 6)
               {
                    gotoxy(width + 23, 14);
                    cout << "  ";
                    gotoxy(width + 24, 15);
                    cout << "  ";
               }
               else if (next3 == 7)
               {
                    gotoxy(width + 24, 14);
                    cout << "  ";
                    gotoxy(width + 23, 15);
                    cout << "  ";
               }
               gotoxy(width + 23, 14);
               cout << green << "OOOO";

          }
          else if (next4 == 5)
          {
               if (next3 == 1)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 24, 15);
                    cout << " ";
               }
               else if (next3 == 2)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 23, 15);
                    cout << " ";
               }
               else if (next3 == 3)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 25, 15);
                    cout << " ";
               }
               else if (next3 == 4)
               {
                    gotoxy(width + 23, 14);
                    cout << "    ";

               }
               else if (next3 == 5)
               {
                    gotoxy(width + 23, 14);
                    cout << "  ";
                    gotoxy(width + 23, 15);
                    cout << "  ";
               }
               else if (next3 == 6)
               {
                    gotoxy(width + 23, 14);
                    cout << "  ";
                    gotoxy(width + 24, 15);
                    cout << "  ";
               }
               else if (next3 == 7)
               {
                    gotoxy(width + 24, 14);
                    cout << "  ";
                    gotoxy(width + 23, 15);
                    cout << "  ";
               }
               gotoxy(width + 23, 14);
               cout << yellow << "OO";
               gotoxy(width + 23, 15);
               cout << yellow << "OO";

          }
          else if (next4 == 6)
          {
               if (next3 == 1)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 24, 15);
                    cout << " ";
               }
               else if (next3 == 2)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 23, 15);
                    cout << " ";
               }
               else if (next3 == 3)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 25, 15);
                    cout << " ";
               }
               else if (next3 == 4)
               {
                    gotoxy(width + 23, 14);
                    cout << "    ";

               }
               else if (next3 == 5)
               {
                    gotoxy(width + 23, 14);
                    cout << "  ";
                    gotoxy(width + 23, 15);
                    cout << "  ";
               }
               else if (next3 == 6)
               {
                    gotoxy(width + 23, 14);
                    cout << "  ";
                    gotoxy(width + 24, 15);
                    cout << "  ";
               }
               else if (next3 == 7)
               {
                    gotoxy(width + 24, 14);
                    cout << "  ";
                    gotoxy(width + 23, 15);
                    cout << "  ";
               }
               gotoxy(width + 23, 14);
               cout << darkblue << "OO";
               gotoxy(width + 24, 15);
               cout << darkblue << "OO";

          }
          else if (next4 == 7)
          {
               if (next3 == 1)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 24, 15);
                    cout << " ";
               }
               else if (next3 == 2)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 23, 15);
                    cout << " ";
               }
               else if (next3 == 3)
               {
                    gotoxy(width + 23, 14);
                    cout << "   ";
                    gotoxy(width + 25, 15);
                    cout << " ";
               }
               else if (next3 == 4)
               {
                    gotoxy(width + 23, 14);
                    cout << "    ";

               }
               else if (next3 == 5)
               {
                    gotoxy(width + 23, 14);
                    cout << "  ";
                    gotoxy(width + 23, 15);
                    cout << "  ";
               }
               else if (next3 == 6)
               {
                    gotoxy(width + 23, 14);
                    cout << "  ";
                    gotoxy(width + 24, 15);
                    cout << "  ";
               }
               else if (next3 == 7)
               {
                    gotoxy(width + 24, 14);
                    cout << "  ";
                    gotoxy(width + 23, 15);
                    cout << "  ";
               }
               gotoxy(width + 24, 14);
               cout << colorcolor << "OO";
               gotoxy(width + 23, 15);
               cout << colorcolor << "OO";
          }
          
          if (next3 == 1)
          {
               if (next2 == 1)
               {
                    gotoxy(width + 18, 14);
                    cout << "   ";
                    gotoxy(width + 19, 15);
                    cout << " ";
               }
               else if (next2 == 2)
               {
                    gotoxy(width + 18, 14);
                    cout << "   ";
                    gotoxy(width + 18, 15);
                    cout << " ";
               }
               else if (next2 == 3)
               {
                    gotoxy(width + 18, 14);
                    cout << "   ";
                    gotoxy(width + 20, 15);
                    cout << " ";
               }
               else if (next2 == 4)
               {
                    gotoxy(width + 18, 14);
                    cout << "    ";

               }
               else if (next2 == 5)
               {
                    gotoxy(width + 18, 14);
                    cout << "  ";
                    gotoxy(width + 18, 15);
                    cout << "  ";
               }
               else if (next2 == 6)
               {
                    gotoxy(width + 18, 14);
                    cout << "  ";
                    gotoxy(width + 19, 15);
                    cout << "  ";
               }
               else if (next2 == 7)
               {
                    gotoxy(width + 19, 14);
                    cout << "  ";
                    gotoxy(width + 18, 15);
                    cout << "  ";
               }
               gotoxy(width + 18, 14);
               cout << white << "OOO";
               gotoxy(width + 19, 15);
               cout << white << "O";
          }
          else if (next3 == 2)
          {
               if (next2 == 1)
               {
                    gotoxy(width + 18, 14);
                    cout << "   ";
                    gotoxy(width + 19, 15);
                    cout << " ";
               }
               else if (next2 == 2)
               {
                    gotoxy(width + 18, 14);
                    cout << "   ";
                    gotoxy(width + 18, 15);
                    cout << " ";
               }
               else if (next2 == 3)
               {
                    gotoxy(width + 18, 14);
                    cout << "   ";
                    gotoxy(width + 20, 15);
                    cout << " ";
               }
               else if (next2 == 4)
               {
                    gotoxy(width + 18, 14);
                    cout << "    ";

               }
               else if (next2 == 5)
               {
Comments: