-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyLib.h
134 lines (115 loc) · 3.16 KB
/
MyLib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/******************************************************************************
* ÁÈÁËÈÎÒÅÊÀ ÑÎÄÅÐÆÈÒ:
*******************************************************************************
* * ñòàíäàðòíûå áèáëèîòåêè
* * ïðîñòðàíñòâî èìåí std
* * ãëîáàëüíûå ïåðåìåííûå, íåîáõîäèìûå äëÿ ââîäà/âûâîäà èíôîðìàöèè
* * ñòðóêòóðó êîðàáëÿ
* * ïåðå÷èñëåíèå èñïîëüçîâàííûõ äëÿ îêðàøèâàíèÿ òåêñòóð
* * âñïîìîãàòåëüíûå ôóíêöèè, êîòîðûå ìîæíî èñïîëüçîâàòü è â äðóãèõ ïðîãðàììàõ
******************************************************************************/
#include <iostream>
#include <windows.h>
#include <ctime>
#include <string.h>
#include <conio.h>
#include <stdio.h>
/******************************************************************************/
using namespace std;
/******************************************************************************/
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
/******************************************************************************/
enum textures {
GENERAL = 0 * 16 + 15,
FRAME = 2 * 16 + 15,
BUTTON = 5 * 16 + 15,
BLINK = 13 * 16 + 15,
DATA_INPUT = 2 * 16 + 15,
MENU = 4 * 16 + 15,
DATA = 0 * 16 + 14,
CALM_WATER = 1 * 16 + 9,
HIT_WATER = 1 * 16 + 15,
OK_SHIP = 10 * 16 + 2,
DAMAGED_SHIP = 14 * 16 + 12,
SELECTED_SHIP = 15 * 16 + 10,
FROZEN_DECK = 11 * 16 + 15,
DROWN_SHIP = 4 * 16 + 12,
};
/******************************************************************************/
struct Counter
{
int one_deck;
int two_decks;
int three_decks;
int four_decks;
int five_decks;
int eight_decks;
};
/******************************************************************************/
void SetCursor(short x, short y, int color);
void PaintButton(short x, short y, short width, short height, int color, string text);
void ScreenCleaner(char * name);
void ClearMemory(int ** pc, int ** user, char * user_name);
void ChangeValues(int ** player, int in, int out, int scenario);
/******************************************************************************/
void SetCursor(short x, short y, int color)
{
COORD c;
c.X = x;
c.Y = y;
SetConsoleCursorPosition(hOut, c);
SetConsoleTextAttribute(hOut, color);
}
void PaintButton(short x, short y, short width, short height, int color, string text)
{
for (short j = y; j < y + height; ++j)
{
for (short i = x; i < x + width; ++i)
{
SetCursor(i, j, color);
cout << " ";
}
}
COORD t;
t.X = x + (width - strlen(text.c_str())) / 2;
t.Y = y + (height / 2);
for (short i = 0; i < short(strlen(text.c_str())); ++i)
{
SetCursor(t.X + i, t.Y, color);
cout << char(toupper(text[i]));
}
}
void ScreenCleaner(char * name)
{
system("cls");
SetCursor(5, 0, GENERAL);
cout << "Player: ";
SetConsoleTextAttribute(hOut, DATA);
cout << name << "\t";
SetConsoleTextAttribute(hOut, GENERAL);
}
void ClearMemory(int ** pc, int ** user, char * user_name)
{
for (int y = 0; y < 10; ++y)
{
delete[]user[y];
delete[]pc[y];
}
delete[]user_name;
delete[]user;
delete[]pc;
}
void ChangeValues(int ** player, int in, int out, int scenario)
{
for (int y = 0; y < 10; ++y)
{
for (int x = 0; x < 10; ++x)
{
if (player[x][y] == in)
{
player[x][y] = out;
}
}
}
}