#You can check my snake in console in C++.
29 messages · Page 1 of 1 (latest)
https://github.com/tomasmark79/snake-in-console/blob/main/main.cpp#L30
illegal variable-length array. You can either make MAX_PLAYERS definitely known at compiletime with constexpr, or use std::vector<std::string> instead of a c-style array
https://github.com/tomasmark79/snake-in-console/blob/main/main.cpp#L85
not absolutely necessary but you could use C++'s <random> header
https://github.com/tomasmark79/snake-in-console/blob/main/main.cpp#L105
exit is not guaranteed to exist outside the std namespace
https://github.com/tomasmark79/snake-in-console/blob/main/main.cpp#L96
you could accept a const std::string& or std::string_view here to avoid copying the question every time
https://github.com/tomasmark79/snake-in-console/blob/main/main.cpp#L56
instead of .compare() you could use the != and == operators
https://github.com/tomasmark79/snake-in-console/blob/main/main.cpp#L134
you should probably avoid c-style casts, instead you can static_cast<int>(answer.length()), or make min and max of type std::size_t, or possibly allow it to cast implicitly
https://github.com/tomasmark79/snake-in-console/blob/main/src/Compiler.cpp#L27
kindof pedantic but __cplusplus represents the c++ version, which is different from the compiler version
https://github.com/tomasmark79/snake-in-console/blob/main/src/Compiler.cpp#L36
const on the return type is redundant unless you return a reference maybe?
https://github.com/tomasmark79/snake-in-console/blob/main/src/Field.cpp#L29
more redundant consts on return types
https://github.com/tomasmark79/snake-in-console/blob/main/src/Fruit.cpp#L50
i'm pretty sure this is a redundant cast to (int*), since fruitXArr is already of that type.
you could probably use a std::vector<int> here also
https://github.com/tomasmark79/snake-in-console/blob/main/src/Graphics.cpp#L170
?
https://github.com/tomasmark79/snake-in-console/blob/main/src/Process.cpp#L33-L60
could use std::unique_ptrs
Thank you for your checks. I will try to fix all these.
if you have any questions feel free to ask
Almost all done:
I am not sure about the return const, but returned string will be never changed. Then can be const although it is questions method?
https://github.com/tomasmark79/snake-in-console/blob/8bdfb3cfd276e1712236ffaf44386fabf4da3dbb/src/Cpp.cpp#L36
the const doesn't mean anything here because the string is copied entirely anyway
;compile ```cpp
const int foo() {
return 3;
}
int main() {
int x = foo();
x = 5;
}
Compilation successful
No output.
eczbek | 53ms | c++ | x86-64 gcc 13.2 | godbolt.org
Windows-only
Yes. Due console keyboard events.
I am open for pool requests :-).
For adding support for Linux keys events.
The console output is also windows-specific
Hmm, then I have to try to check the code and try to get information about Windows vs Linux console compatibility.
ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals and terminal emulators. Certain sequences of bytes, most starting with an ASCII escape character and a bracket character, are embedded into text. The terminal interprets these sequences as command...
@patent pumice I have refactored several pointers to smart pointers. If you will have more recommendations how to write in modern C++ I will appreciate.
not needly asap
more refactors
I guess it is already fine with C++ rules. Only one class (graphic) I want to left with C type arrays so I don't forget how language C looks 😄
Still is here lot of possible optimalisations, which I will do later.