Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <windows.h>
- #include <time.h>
- #include <stdlib.h>
- #define frame 20
- //the size of the gameframe (x * x)
- #define gamespeed 250
- //the amount of time the game will wait (in milliseconds) before drawing the next frame
- //if we change this we should probably make the gameclock reflect the change
- //but for now it just runs at double time
- char screen[frame][frame]; //global variables because fuck you
- int gameTime = 100;
- int score = 0;
- int main(void);
- void drawframe(void);
- void newline(void);
- void clearScreen(void);
- void waitFor(int millisecs);
- void checkForRow(void);
- void gravity(void);
- void generateObject(void);
- int gameOver(void);
- /*
- THIS CODE SUCKS MAJOR ASS
- Known Issues:
- gameOver() doesn't actually work
- no user input
- game clock is directly affected by the game speed (like a nes game lol)
- frameDraw is directly affected by the game speed
- */
- int main(void)
- {
- srand(time(NULL));
- //initialze the screen
- for (int x = 0; x < frame; x++)
- for (int y = 0; y < frame; y++)
- screen[x][y] = ' ';
- for (int i = 0; i < frame; ++i) {
- screen[0][i] = 'x';
- screen[frame - 1][i] = 'x';
- screen[i][0] = 'x';
- screen[i][frame - 1] = 'x';
- }
- printf("TimeLeft: %d Score: %d\n", gameTime--, score);
- generateObject();
- drawframe();
- while (gameTime > 0 && !gameOver())
- {
- waitFor(gamespeed);
- gravity();
- if(gameTime % 9 == 0)
- generateObject();
- checkForRow();
- clearScreen();
- printf("TimeLeft: %d Score: %d\n", gameTime--, score);
- printf("Game over? %d\n", gameOver());
- drawframe();
- }
- clearScreen();
- printf("Game over!\nYou lose idiot!\n");
- return 0;
- }
- void drawframe(void)
- {
- for (int x = 0; x < frame; x++)
- {
- newline();
- for (int y = 0; y < frame; y++)
- printf("%c", screen[x][y]);
- }
- }
- void newline(void)
- {
- printf("\n");
- }
- void clearScreen()
- {
- system("cls");
- }
- void waitFor(int millisecs)
- {
- Sleep(millisecs);
- }
- void checkForRow(void)
- {
- for (int x = 1; x < frame - 1; x++)
- {
- int count = 0;
- for (int y = 0; y < frame; y++)
- {
- if (screen[x][y] != 'x')
- break;
- count++;
- if (count == frame - 1)
- {
- for (int z = 0; z < frame; z++)
- screen[x][z] = ' ';
- screen[x][0] = 'x';
- screen[x][frame - 1] = 'x';
- score += 1000;
- }
- }
- }
- }
- void gravity(void)
- {
- for (int x = frame - 1 ; x > 0; x--)
- {
- for (int y = frame - 1; y > 1; y--)
- {
- if (screen[x][y] == 'x')
- {
- if (screen[x + 1][y] == ' ')
- {
- screen[x][y] = ' ';
- screen[x + 1][y] = 'x';
- }
- }
- }
- }
- }
- void generateObject(void)
- {
- int r = rand() % 6;
- switch (r)
- {
- //creates a box
- case 1:
- {
- screen[1][frame / 2] = 'x';
- screen[1][frame / 2 + 1] = 'x';
- screen[2][frame / 2] = 'x';
- screen[2][frame / 2 + 1] = 'x';
- break;
- }
- //creates an L
- case 2:
- {
- screen[1][frame / 2] = 'x';
- screen[1][frame / 2 + 1] = 'x';
- screen[2][frame / 2] = 'x';
- screen[3][frame / 2] = 'x';
- break;
- }
- //creates a line
- case 3:
- {
- screen[1][frame / 2] = 'x';
- screen[2][frame / 2] = 'x';
- screen[3][frame / 2] = 'x';
- screen[4][frame / 2] = 'x';
- break;
- }
- //creates a z
- case 4:
- {
- screen[1][frame / 2] = 'x';
- screen[2][frame / 2] = 'x';
- screen[2][frame / 2 - 1] = 'x';
- screen[3][frame / 2 - 1] = 'x';
- break;
- }
- //creates a T
- case 5:
- {
- screen[1][frame / 2] = 'x';
- screen[2][frame / 2] = 'x';
- screen[2][frame / 2 + 1] = 'x';
- screen[2][frame / 2 - 1] = 'x';
- break;
- }
- }
- }
- int gameOver(void)
- {
- int xfoundcount = 0;
- for (int x = 1; x < frame - 1; x++)
- {
- for (int y = 1; y < frame - 1; y++)
- {
- if (screen[x][y] == 'x')
- {
- xfoundcount++;
- break;
- }
- }
- }
- if (xfoundcount == frame - 1)
- return 1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement