Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream> //cout cin
- #include <cstdlib> //atoi(*arr)
- #include <Windows.h> //Sleep()
- #include <conio.h> //_kbhit, _getch()
- #include <clocale> //setlocale()
- #include <ctime> //srand(time(0))
- using namespace std;
- class IChar {
- char symbol = '#';
- int value = rand() % 32000;
- public:
- char getSymbol() {
- return symbol;
- }
- void setSymbol(char sym) {
- symbol = sym;
- }
- int getValue() {
- return value;
- }
- void setValue(int val) {
- value = val;
- }
- };
- int Write_int(bool anyNumber);
- IChar** pixels;
- int sizeX, sizeY, x, y;
- bool onWrite;
- enum eDirection { STOP = 0, LEFT, RIGHT, UP, DOWN };
- enum eSelect { NUN = 0, SYMBOL, VALUE };
- eDirection dir;
- eSelect sel;
- void Setup() {
- cout << "Введите размер Массива 2x2:\nSizeX: ";
- sizeX = Write_int(false);
- cout << "SizeY: ";
- sizeY = Write_int(false);
- srand(time(0));
- pixels = new IChar*[sizeX];
- for (int i = 0; i < sizeX; i++)
- pixels[i] = new IChar[sizeY];
- x, y = 0;
- onWrite = false;
- dir = STOP;
- sel = NUN;
- }
- void Draw() {
- system("cls");
- HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
- for (int i = 0; i < sizeX; i++) {
- for (int j = 0; j < sizeY; j++) {
- if (i == x && j == y)
- SetConsoleTextAttribute(console, FOREGROUND_GREEN);
- else
- SetConsoleTextAttribute(console, FOREGROUND_BLUE);
- cout << pixels[i][j].getSymbol();
- }
- cout << endl;
- }
- SetConsoleTextAttribute(console, FOREGROUND_RED);
- cout << "\nValue: " << pixels[x][y].getValue() << endl;
- cout << "WASD - Управление\nE - Change symbol\nF - Change value";
- }
- void Input() {
- if (_kbhit) {
- switch (_getch()) {
- case 'w':
- dir = UP;
- break;
- case 'a':
- dir = LEFT;
- break;
- case 'd':
- dir = RIGHT;
- break;
- case 's':
- dir = DOWN;
- break;
- case 'e':
- sel = SYMBOL;
- break;
- case 'f':
- sel = VALUE;
- default:
- break;
- }
- }
- }
- void Logic() {
- switch (dir) {
- case UP:
- x--;
- break;
- case LEFT:
- y--;
- break;
- case RIGHT:
- y++;
- break;
- case DOWN:
- x++;
- break;
- default:
- break;
- }
- switch (sel) {
- case SYMBOL:
- pixels[x][y].setSymbol(_getch());
- break;
- case VALUE:
- pixels[x][y].setValue(Write_int(true));
- break;
- default:
- break;
- }
- dir = STOP;
- sel = NUN;
- if (x < 0) x = sizeX - 1;
- if (x >= sizeX) x = 0;
- if (y < 0) y = sizeY - 1;
- if (y >= sizeY) y = 0;
- }
- int main()
- {
- setlocale(LC_ALL, "Rus");
- Setup();
- while (true) {
- Draw();
- Input();
- Logic();
- Sleep(10);
- }
- for (int i = 0; i < sizeX; i++)
- delete[] pixels[i];
- return 0;
- }
- int Write_int(bool anyNumber) {
- char array[10];
- while (true) {
- cin >> array;
- if ((atoi(array) && atoi(array) > 0 && !anyNumber) || (atoi(array) && anyNumber))
- break;
- else {
- if (anyNumber)
- printf("Введите значение n: ");
- else
- printf("Введите значение n > 0: ");
- }
- }
- return atoi(array);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement