mo

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
1.9 kB
23
Indexable
Never
#include<iostream>
#include<conio.h>
using namespace std;
void ClearAndDrawFixedObject(char x[][80])
{
	for (int r = 0; r < 24; r++)
	{
		for (int c = 0; c < 80; c++)
		{
			x[r][c] = ' ';
		}
	}
	int rselem = 10;
	int cselem = 20;
	for (int i = 0; i < 3; i++)
	{
		for (int a = 0; a < 5; a++)
		{
			x[rselem][cselem] = '-';
			cselem++;
		}
		rselem++;
	}
}
void CoutMatToScreen(char x[][80])
{
	system("cls");
	for (int r = 0; r < 24; r++)
	{
		for (int c = 0; c < 80; c++)
		{
			cout << x[r][c];
		}
	}
	cout.flush();
}
void MoveDababa(int& rDababa, int& cDababa, int& dir)
{
	if (dir == 1)
	{
		if (cDababa + 10 == 79)
		{
			dir *= -1;
		}
	}
	else
	{
		if (cDababa == 0)
		{
			dir *= -1;
		}
	}
	cDababa += dir;
}
void DrawDababa(char x[][80], int rDababa, int cDababa)
{
	x[rDababa][cDababa] = '4';
	for (int i = 0; i < 2; i++)
	{
		x[rDababa][cDababa + 4 + i] = '_';
	}
	for (int i = 0; i < 4; i++)
	{
		x[rDababa][cDababa + 7 + i] = '_';
	}
	for (int i = 0; i < 8; i += 2)
	{
		x[rDababa + 1][cDababa + 4 + i] = '\\';
		x[rDababa + 1][cDababa + 4 + i + 1] = ' ';
	}
}
void MoveHero(int& rHero, int& cHero, char userMove)
{
	if (userMove == 'w')
	{
		rHero--;
	}
	if (userMove == 's')
	{
		rHero++;
	}
	if (userMove == 'a')
	{
		cHero--;
	}
	if (userMove == 'd')
	{
		cHero++;
	}
}
void DrawHero(char x[][80], int rHero, int cHero)
{
	x[rHero][cHero] = 1;
}
void main()
{
	char x[24][80];
	int rDababa = 18, cDababa = 5, dirDababa = 1;
	int rHero = 15, cHero = 22;
	char UMove;
	for (;;)
	{
		for (; !_kbhit ;)
		{
			ClearAndDrawFixedObject(x);
			MoveDababa(rDababa, cDababa, dirDababa);
			DrawDababa(x, rDababa, cDababa);
			DrawHero(x, rHero, cHero);
			CoutMatToScreen(x);
		}
		UMove = _getch();
		MoveHero(rHero, cHero, UMove);
		DrawHero(x, rHero, cHero);
	}
}
Leave a Comment