Repository navigation
Expand file tree
/
Copy pathPoopJump.cpp
More file actions
222 lines (219 loc) · 5.84 KB
/
Copy pathPoopJump.cpp
File metadata and controls
222 lines (219 loc) · 5.84 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* PoopJump
* Copyright (C) 2026 WKf-0000
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <bits/stdc++.h>
#include "poopchoosefile.hpp"
#ifdef _WIN32
#include <windows.h>
#include <conio.h>
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif
using namespace std;
struct coords
{
int x, y;
};
void waitForAnyKey()
{
cout << "\nPress any key to continue...";
cout.flush();
#ifdef _WIN32
while (_kbhit()) _getch();
_getch();
#else
cin.get();
#endif
}
void forceEnglishInput()
{
keybd_event(VK_SHIFT, 0, 0, 0);
Sleep(50);
keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
}
bool init()
{
srand(time(0));
poop::init();
forceEnglishInput();
#ifdef _WIN32
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (hOut == INVALID_HANDLE_VALUE) return false;
DWORD dwMode = 0;
if (!GetConsoleMode(hOut, &dwMode)) return false;
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleOutputCP(CP_UTF8);
SetConsoleCP(CP_UTF8);
return SetConsoleMode(hOut, dwMode) != 0;
#else
return true;
#endif
}
vector <string> mp;// 地图
bool isFly = 0;// 飞起来!!
int flyHigh = 0;// 飞起来的高度
int flybeginY = 0;// 飞起来的起始高度
coords player = {10 , 0};
int left_x = 0 , right_x = 0;
int mayi = 0;
void getMap(string file/*地图的文件名*/)
{
ifstream in(file);
if(!in.is_open())
{
cerr << "地图文件打开失败!" << endl;
return;
}
string mapp = "";
while(getline(in , mapp))
{
mp.push_back(mapp);
}
}
void drawMap()
{
cout << "Gold coin count : " << mayi << "\n";
int max_height = min((int)mp.size(), 30);
for(int i = 0; i < max_height; i++)
{
int max_w = mp[i].size();
for(int j = left_x; j <= right_x; j++)
{
if(i == player.y && j == player.x)
{
cout << "\033[36mP\033[0m";
}
else if(j >= 0 && j < max_w && mp[i][j] == '$')
{
cout << "\033[33m$\033[0m";
}
else if(j >= 0 && j < max_w)
{
cout << mp[i][j];
}
else
{
cout << " ";
}
}
cout << '\n';
}
for(int i = max_height; i < 20; i++) {
cout << string(right_x - left_x + 1, ' ') << "\n";
}
}
bool canStandAt(int x, int y)
{
if(y < 0 || y >= mp.size()) return false;
if(x < 0 || x >= mp[y].size()) return false;
return mp[y][x] != '#';
}
void beginGame(string mapPath)
{
cout << "\033[2J\033[H" << flush;
getMap(mapPath);
right_x = player.x + 20;
while(1)
{
if(mp[player.y][player.x] == '$')
{
mayi ++;
mp[player.y][player.x] = ' ';
}
if(isFly)
{
if(player.y > flybeginY - flyHigh && canStandAt(player.x, player.y - 1))
{
player.y --;
}
else
{
isFly = false;
}
}
if(!isFly && canStandAt(player.x, player.y + 1))
{
player.y++;
}
if(GetAsyncKeyState('Q') & 0x8000)
{
cout << "\033[?25h";
cout << "\033[2J\033[H" << flush;
waitForAnyKey();
break;
}
if (!isFly && (GetAsyncKeyState(VK_UP) & 0x8000))
{
bool onGround = player.y + 1 < static_cast<int>(mp.size()) && player.x >= 0 && player.x < static_cast<int>(mp[player.y + 1].size()) && mp[player.y + 1][player.x] == '#';
if(onGround)
{
isFly = true;
flyHigh = rand() % 3 + 3;
flybeginY = player.y;
}
}
if((GetAsyncKeyState(VK_LEFT) & 0x8000) && canStandAt(player.x - 1 , player.y) && player.x - 1 >= left_x)
{
player.x --;
}
if((GetAsyncKeyState(VK_RIGHT) & 0x8000) && canStandAt(player.x + 1 , player.y))
{
player.x ++;
if(player.x > right_x - 5)
{
if(right_x + 1 <= mp[0].size()) right_x ++ , left_x ++;
}
}
cout << "\033[?25l";
cout << "\033[H";
drawMap();
#ifdef _WIN32
Sleep(30);
#endif
}
}
int main()
{
cout << R"(PoopJump
Copyright (C) 2026 WKf-0000
Disclaimer:
This program is provided for learning and research purposes only.
The author shall not be liable for any direct or indirect damages
caused by the use of this program.
This program is distributed under the GPL-2.0-or-later license.
)";
waitForAnyKey();
if(!init())
{
cout << "Can not Using VT Output!!!\n";
waitForAnyKey();
return 0;
}
while(1)
{
mp.clear();
mayi = 0;
player = {10, 0};
isFly = false;
left_x = 0;
string s = poop::chooseFile(15);
if(s.empty()) break;
cout << "\033[2J\033[H" << flush;
beginGame(s);
}
return 0;
}