-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTextfile.cpp
More file actions
164 lines (143 loc) · 3.59 KB
/
Textfile.cpp
File metadata and controls
164 lines (143 loc) · 3.59 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <thread>
#include <chrono>
#include <vector>
#include <cmath>
#include<iostream>
#include<windows.h>
#include<conio.h>
#include"Textfile.h"
#include "PlayervsPlayer.h"
#include "Charactars.h"
using namespace std;
// Hàm để tạo hiệu ứng đi lên và xuống
std::string applyVerticalMotion(const std::string& frame, int frameIndex, float n) {
int motion = static_cast<int>((std::sin(frameIndex / n) + 1) * int(n)); // Tạo hiệu ứng di chuyển mượt mà
return std::string(motion, '\n') + frame;
}
const std::vector<int> COLORS = {
Blue ,
Green ,
Red ,
Violet
};
void Textdecorate(std::string filename, float vertical, int times, int sleep) {
std::string line;
std::ifstream file(filename);
std::vector<std::string> frames;
int frameIndex = 0;
if (file.is_open()) {
while (getline(file, line)) {
if (line == "###") {
frames.push_back("");
continue;
}
if (!frames.empty()) {
frames.back() += line + "\n";
}
}
file.close();
}
else {
std::cout << "Can not open file!" << std::endl;
return;
}
while (times) {
system("color F0");
times--;
system("cls");
std::string frame = frames[frameIndex % frames.size()];
frame = applyVerticalMotion(frame, frameIndex, vertical); // Áp dụng hiệu ứng di chuyển
int color = COLORS[frameIndex % COLORS.size()]; // Lấy màu sắc hiện tại
Textcolor(color); // Sử dụng hàm Textcolor để đặt màu chữ
std::cout << frame;
Textcolor(Black);
std::this_thread::sleep_for(std::chrono::milliseconds(sleep));
frameIndex++;
}
}
void In_Tep(const char* FileName,int Color) {
FILE* file;
if (fopen_s(&file, FileName, "r") != 0) {
cout << "Khong the mo tep" << endl;
return;
}
char buffer[1000];
char line[1000];
int i = 0;
while (fgets(line, sizeof(line), file)) {
if (strstr(line, "^")) {
Textcolor(Red);
cout << line;
}
else if (strstr(line, ".")) {
Textcolor(Green);
cout << line;
}
else if (strstr(line, "*")) {
Textcolor(Blue);
cout << line;
}
else {
Textcolor(Black);
cout << line;
}
}
fclose(file);
}
void DRAW() {
playSound(5);
Textdecorate("DRAW.txt", 3.0, 10, 175);
}
void COMPUTERWIN() {
playSound(4);
Textdecorate("BOTWIN.txt", 3.0, 10, 175);
}
void YOUWIN() {
playSound(4);
Textdecorate("YOUWIN.txt", 3.0, 10, 175);
}
void CARO1() {
Textdecorate("CARO.txt", 2.0, 6, 175);
system("cls");
}
void WINO() {
playSound(4);
Textdecorate("OWIN.txt", 5.0, 7, 250);
}
void WINX() {
playSound(4);
Textdecorate("XWIN.txt", 5.0, 7, 250);
}
void PrintCaro()
{
CARO1();
}
void LoadHumansBar() {
playSound(11);
Textdecorate("LOADHUMANSBAR.txt", 0.5, 5, 200);
}
void LoadBotBar() {
playSound(11);
Textdecorate("LOADBOTBAR.txt",0.5,5,200);
}
void PVPBAR() {
playSound(11);
Textdecorate("PlayerVsPlayer.txt", 0.5, 3, 300);
}
void PVCBAR() {
playSound(11);
Textdecorate("PVSC.txt", 0.5, 3, 300);
}
void LoadHumans() {
playSound(12);
InFIle1N("LOADBOT.txt", 14, 43, Red, 0);
}
void LoadBot() {
// In_Tep("LOADHUMANS.txt", Blue);
playSound(12);
InFIle1N("LOADHUMANS.txt", 14,43, Red, 0);
}