Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <windows.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdbool.h>
- #define LINES 25
- #define COLS 80
- #define fps 10
- int score;
- char canvas[LINES][COLS];
- char *buffer = (char *) &canvas;
- void drawCanvas()
- {
- system("cls");
- puts(buffer);
- printf("SCORE: %d", score);
- }
- bool isValid(int _sa6r, int _3amood)
- {
- if (_sa6r > LINES || _sa6r < 0 || _3amood > COLS || _sa6r < 0)
- return false;
- return true;
- }
- bool setElem(int _sa6r, int _3amood, char _7arf)
- {
- if (isValid(_sa6r, _3amood))
- {
- canvas[_sa6r][_3amood] = _7arf;
- return true;
- }
- return false;
- }
- char getElem(int _sa6r, int _3amood)
- {
- if (isValid(_sa6r, _3amood))
- return canvas[_sa6r][_3amood];
- return '\0';
- }
- enum {snake = '$', apple = 'o', box = 'X'};
- int main (void)
- {
- memset(buffer, ' ', sizeof canvas - 1);
- for (int i = 0; i < 100; i++)
- {
- if (!setElem(i, i, 'X')) break;
- drawCanvas();
- score += 10;
- Sleep(1000 / fps);
- setElem(i, i, ' ');
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement