Zaktualizuj 'Main.cpp'
This commit is contained in:
parent
4aaf4d9cb8
commit
2237e98044
485
Main.cpp
485
Main.cpp
@ -1,242 +1,243 @@
|
|||||||
#include<iostream>
|
#include<iostream>
|
||||||
#include<stdlib.h>
|
#include<stdlib.h>
|
||||||
#include<windows.h>
|
#include<windows.h>
|
||||||
#include<conio.h>
|
#include<conio.h>
|
||||||
#include<string>
|
#include<string>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
char pole[27][27][2];
|
char pole[27][27][2];
|
||||||
int pozycjaTraktoraX = 1, pozycjaTraktoraY = 1;
|
int pozycjaTraktoraX = 1, pozycjaTraktoraY = 1;
|
||||||
|
|
||||||
void color(string foregroundColor,string backgroundColor)
|
void color(string foregroundColor,string backgroundColor)
|
||||||
{
|
{
|
||||||
HANDLE hOut;
|
HANDLE hOut;
|
||||||
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
int foregroundCode = 15;
|
int foregroundCode = 15;
|
||||||
if (foregroundColor == "black")
|
if (foregroundColor == "black")
|
||||||
foregroundCode = 0;
|
foregroundCode = 0;
|
||||||
if (foregroundColor == "dark_blue")
|
if (foregroundColor == "dark_blue")
|
||||||
foregroundCode = 1;
|
foregroundCode = 1;
|
||||||
if (foregroundColor == "green")
|
if (foregroundColor == "green")
|
||||||
foregroundCode = 2;
|
foregroundCode = 2;
|
||||||
if (foregroundColor == "cyan")
|
if (foregroundColor == "cyan")
|
||||||
foregroundCode = 3;
|
foregroundCode = 3;
|
||||||
if (foregroundColor == "dark_red")
|
if (foregroundColor == "dark_red")
|
||||||
foregroundCode = 4;
|
foregroundCode = 4;
|
||||||
if (foregroundColor == "purple")
|
if (foregroundColor == "purple")
|
||||||
foregroundCode = 5;
|
foregroundCode = 5;
|
||||||
if (foregroundColor == "dark_yellow")
|
if (foregroundColor == "dark_yellow")
|
||||||
foregroundCode = 6;
|
foregroundCode = 6;
|
||||||
if (foregroundColor == "light_gray")
|
if (foregroundColor == "light_gray")
|
||||||
foregroundCode = 7;
|
foregroundCode = 7;
|
||||||
if (foregroundColor == "gray")
|
if (foregroundColor == "gray")
|
||||||
foregroundCode = 8;
|
foregroundCode = 8;
|
||||||
if (foregroundColor == "blue")
|
if (foregroundColor == "blue")
|
||||||
foregroundCode = 9;
|
foregroundCode = 9;
|
||||||
if (foregroundColor == "lime")
|
if (foregroundColor == "lime")
|
||||||
foregroundCode = 10;
|
foregroundCode = 10;
|
||||||
if (foregroundColor == "light_blue")
|
if (foregroundColor == "light_blue")
|
||||||
foregroundCode = 11;
|
foregroundCode = 11;
|
||||||
if (foregroundColor == "red")
|
if (foregroundColor == "red")
|
||||||
foregroundCode = 12;
|
foregroundCode = 12;
|
||||||
if (foregroundColor == "magenta")
|
if (foregroundColor == "magenta")
|
||||||
foregroundCode = 13;
|
foregroundCode = 13;
|
||||||
if (foregroundColor == "yellow")
|
if (foregroundColor == "yellow")
|
||||||
foregroundCode = 14;
|
foregroundCode = 14;
|
||||||
if (foregroundColor == "white")
|
if (foregroundColor == "white")
|
||||||
foregroundCode = 15;
|
foregroundCode = 15;
|
||||||
|
|
||||||
int backgroundCode = 0;
|
int backgroundCode = 0;
|
||||||
if (backgroundColor == "black")
|
if (backgroundColor == "black")
|
||||||
backgroundCode = 0;
|
backgroundCode = 0;
|
||||||
if (backgroundColor == "dark_blue")
|
if (backgroundColor == "dark_blue")
|
||||||
backgroundCode = 1;
|
backgroundCode = 1;
|
||||||
if (backgroundColor == "green")
|
if (backgroundColor == "green")
|
||||||
backgroundCode = 2;
|
backgroundCode = 2;
|
||||||
if (backgroundColor == "cyan")
|
if (backgroundColor == "cyan")
|
||||||
backgroundCode = 3;
|
backgroundCode = 3;
|
||||||
if (backgroundColor == "dark_red")
|
if (backgroundColor == "dark_red")
|
||||||
backgroundCode = 4;
|
backgroundCode = 4;
|
||||||
if (backgroundColor == "purple")
|
if (backgroundColor == "purple")
|
||||||
backgroundCode = 5;
|
backgroundCode = 5;
|
||||||
if (backgroundColor == "dark_yellow")
|
if (backgroundColor == "dark_yellow")
|
||||||
backgroundCode = 6;
|
backgroundCode = 6;
|
||||||
if (backgroundColor == "light_gray")
|
if (backgroundColor == "light_gray")
|
||||||
backgroundCode = 7;
|
backgroundCode = 7;
|
||||||
if (backgroundColor == "gray")
|
if (backgroundColor == "gray")
|
||||||
backgroundCode = 8;
|
backgroundCode = 8;
|
||||||
if (backgroundColor == "blue")
|
if (backgroundColor == "blue")
|
||||||
backgroundCode = 9;
|
backgroundCode = 9;
|
||||||
if (backgroundColor == "lime")
|
if (backgroundColor == "lime")
|
||||||
backgroundCode = 10;
|
backgroundCode = 10;
|
||||||
if (backgroundColor == "light_blue")
|
if (backgroundColor == "light_blue")
|
||||||
backgroundCode = 11;
|
backgroundCode = 11;
|
||||||
if (backgroundColor == "red")
|
if (backgroundColor == "red")
|
||||||
backgroundCode = 12;
|
backgroundCode = 12;
|
||||||
if (backgroundColor == "magenta")
|
if (backgroundColor == "magenta")
|
||||||
backgroundCode = 13;
|
backgroundCode = 13;
|
||||||
if (backgroundColor == "yellow")
|
if (backgroundColor == "yellow")
|
||||||
backgroundCode = 14;
|
backgroundCode = 14;
|
||||||
if (backgroundColor == "white")
|
if (backgroundColor == "white")
|
||||||
backgroundCode = 15;
|
backgroundCode = 15;
|
||||||
SetConsoleTextAttribute(hOut, foregroundCode + backgroundCode*16);
|
SetConsoleTextAttribute(hOut, foregroundCode + backgroundCode*16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetWindow(int Width, int Height)
|
void SetWindow(int Width, int Height)
|
||||||
{
|
{
|
||||||
_COORD coord;
|
_COORD coord;
|
||||||
coord.X = Width;
|
coord.X = Width;
|
||||||
coord.Y = Height;
|
coord.Y = Height;
|
||||||
|
|
||||||
_SMALL_RECT Rect;
|
_SMALL_RECT Rect;
|
||||||
Rect.Top = 0;
|
Rect.Top = 0;
|
||||||
Rect.Left = 0;
|
Rect.Left = 0;
|
||||||
Rect.Bottom = Height - 1;
|
Rect.Bottom = Height - 1;
|
||||||
Rect.Right = Width - 1;
|
Rect.Right = Width - 1;
|
||||||
|
|
||||||
HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE); // Get Handle
|
HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE); // Get Handle
|
||||||
SetConsoleScreenBufferSize(Handle, coord); // Set Buffer Size
|
SetConsoleScreenBufferSize(Handle, coord); // Set Buffer Size
|
||||||
SetConsoleWindowInfo(Handle, TRUE, &Rect); // Set Window Size
|
SetConsoleWindowInfo(Handle, TRUE, &Rect); // Set Window Size
|
||||||
}
|
}
|
||||||
|
|
||||||
void updatePola()
|
void updatePola()
|
||||||
{
|
{
|
||||||
system("cls");
|
system("cls");
|
||||||
for (int i = 0; i < 27; i++)
|
for (int i = 0; i < 27; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 27; j++)
|
for (int j = 0; j < 27; j++)
|
||||||
{
|
{
|
||||||
char item = pole[i][j][0];
|
char item = pole[i][j][0];
|
||||||
switch (item)
|
switch (item)
|
||||||
{
|
{
|
||||||
case 'B':
|
case 'B':
|
||||||
{
|
{
|
||||||
color("purple", "dark_yellow");
|
color("purple", "dark_yellow");
|
||||||
}break;
|
}break;
|
||||||
case 'T':
|
case 'T':
|
||||||
{
|
{
|
||||||
color("red", "dark_yellow");
|
color("red", "dark_yellow");
|
||||||
}break;
|
}break;
|
||||||
case '.':
|
case '.':
|
||||||
{
|
{
|
||||||
color("yellow", "dark_yellow");
|
color("yellow", "dark_yellow");
|
||||||
}break;
|
}break;
|
||||||
case '#':
|
case '#':
|
||||||
{
|
{
|
||||||
color("light_gray", "gray");
|
color("light_gray", "gray");
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
cout << pole[i][j][0];
|
cout << pole[i][j][0];
|
||||||
|
|
||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
color("white", "black");
|
color("white", "black");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Move(char kierunek)
|
void Move(char kierunek)
|
||||||
{
|
{
|
||||||
switch (kierunek)
|
switch (kierunek)
|
||||||
{
|
{
|
||||||
//góra-(w)
|
//góra-(w)
|
||||||
case 'w':
|
case 'w':
|
||||||
{
|
{
|
||||||
if (pole[pozycjaTraktoraX - 1][pozycjaTraktoraY][0] != '#')
|
if (pole[pozycjaTraktoraX - 1][pozycjaTraktoraY][0] != '#')
|
||||||
{
|
{
|
||||||
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = '.';
|
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = '.';
|
||||||
pozycjaTraktoraX--;
|
pozycjaTraktoraX--;
|
||||||
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = 'T';
|
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = 'T';
|
||||||
|
|
||||||
}
|
}
|
||||||
updatePola();
|
updatePola();
|
||||||
}break;
|
}break;
|
||||||
//dó³-(s)
|
//dó³-(s)
|
||||||
case 's':
|
case 's':
|
||||||
{
|
{
|
||||||
if (pole[pozycjaTraktoraX + 1][pozycjaTraktoraY][0] != '#')
|
if (pole[pozycjaTraktoraX + 1][pozycjaTraktoraY][0] != '#')
|
||||||
{
|
{
|
||||||
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = '.';
|
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = '.';
|
||||||
pozycjaTraktoraX++;
|
pozycjaTraktoraX++;
|
||||||
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = 'T';
|
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = 'T';
|
||||||
|
|
||||||
}
|
}
|
||||||
updatePola();
|
updatePola();
|
||||||
}break;
|
}break;
|
||||||
//lewo-(a)
|
//lewo-(a)
|
||||||
case 'a':
|
case 'a':
|
||||||
{
|
{
|
||||||
if (pole[pozycjaTraktoraX][pozycjaTraktoraY - 1][0] != '#')
|
if (pole[pozycjaTraktoraX][pozycjaTraktoraY - 1][0] != '#')
|
||||||
{
|
{
|
||||||
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = '.';
|
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = '.';
|
||||||
pozycjaTraktoraY--;
|
pozycjaTraktoraY--;
|
||||||
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = 'T';
|
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = 'T';
|
||||||
|
|
||||||
}
|
}
|
||||||
updatePola();
|
updatePola();
|
||||||
}break;
|
}break;
|
||||||
//prawo-(d)
|
//prawo-(d)
|
||||||
case 'd':
|
case 'd':
|
||||||
{
|
{
|
||||||
if (pole[pozycjaTraktoraX][pozycjaTraktoraY + 1][0] != '#')
|
if (pole[pozycjaTraktoraX][pozycjaTraktoraY + 1][0] != '#')
|
||||||
{
|
{
|
||||||
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = '.';
|
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = '.';
|
||||||
pozycjaTraktoraY++;
|
pozycjaTraktoraY++;
|
||||||
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = 'T';
|
pole[pozycjaTraktoraX][pozycjaTraktoraY][0] = 'T';
|
||||||
|
|
||||||
}
|
}
|
||||||
updatePola();
|
updatePola();
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
SetWindow(50, 30);
|
SetWindow(50, 30);
|
||||||
|
|
||||||
//create pola//
|
//create pola//
|
||||||
for (int i = 0; i < 27; i++)
|
for (int i = 0; i < 27; i++)
|
||||||
{
|
{
|
||||||
pole[i][0][0] = '#';
|
pole[i][0][0] = '#';
|
||||||
pole[0][i][0] = '#';
|
pole[0][i][0] = '#';
|
||||||
pole[26][i][0] = '#';
|
pole[26][i][0] = '#';
|
||||||
pole[i][26][0] = '#';
|
pole[i][26][0] = '#';
|
||||||
}
|
}
|
||||||
for (int i = 1; i < 26; i++)
|
for (int i = 1; i < 26; i++)
|
||||||
{
|
{
|
||||||
for (int j = 1; j < 26; j++)
|
for (int j = 1; j < 26; j++)
|
||||||
{
|
{
|
||||||
pole[i][j][0] = '.';
|
pole[i][j][0] = '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pole[1][1][0] = 'T';
|
for (int i = 0; i < 25; i++)
|
||||||
|
{
|
||||||
for (int i = 0; i < 25; i++)
|
pole[i+1][i+1][0] = 'B';
|
||||||
{
|
}
|
||||||
pole[i+1][i+1][0] = 'B';
|
|
||||||
}
|
pole[1][1][0] = 'T';
|
||||||
updatePola();
|
|
||||||
|
updatePola();
|
||||||
|
|
||||||
//---------start---------//
|
|
||||||
bool traktorDziala = true;
|
//---------start---------//
|
||||||
|
bool traktorDziala = true;
|
||||||
char akcja;
|
|
||||||
|
char akcja;
|
||||||
do
|
|
||||||
{
|
do
|
||||||
akcja = _getch();
|
{
|
||||||
if (akcja == 'w' || akcja == 's' || akcja == 'a' || akcja == 'd')
|
akcja = _getch();
|
||||||
{
|
if (akcja == 'w' || akcja == 's' || akcja == 'a' || akcja == 'd')
|
||||||
Move(akcja);
|
{
|
||||||
}
|
Move(akcja);
|
||||||
if (akcja == '0')
|
}
|
||||||
{
|
if (akcja == '0')
|
||||||
traktorDziala = false;
|
{
|
||||||
}
|
traktorDziala = false;
|
||||||
} while (traktorDziala);
|
}
|
||||||
//---------end---------//
|
} while (traktorDziala);
|
||||||
|
//---------end---------//
|
||||||
return 0;
|
|
||||||
}
|
return 0;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user