user23052036 / Puzzle-Game

This is a fun little side-project i have been working on for some time. Its a puzzle game. Where numbers will be arranged randomly and you have to move each numbers within limited set of moves and time to get a desired sequence. This game is written completely in C. Was inspired to create this game after i played a similar game in play store.
GNU General Public License v3.0
5 stars 2 forks source link

add arrow keys on linux. #2 #12

Closed josdorrod closed 3 months ago

josdorrod commented 3 months ago

Possibility of using arrows keys or asdw. Modified number of movements. Alphabetical arrangement of headers.

user23052036 commented 3 months ago

Thank you for contributing! I will definitely look into it. But as you have made it system specific. Could try making it universal. Have any idea ?

josdorrod commented 3 months ago

I could try to test on Windows. I am not sure but I think that on macOS and Linux the behaviour is the same.

Test It and let me know your opinion. Then i Will try to do the same for windows

user23052036 commented 3 months ago

Okei sure.. I would look into it by tomorrow

user23052036 commented 3 months ago

I creaked ur code works in linux fine.. But in windows its not working.. I have been also stuck in this problem trying to figure out a universal code independent of os.

josdorrod commented 3 months ago

Is it valid if I look for an alternative to make it work for Windows and another for Linux? Then using variable in C we will know which OS is being used and take one path or another

user23052036 commented 3 months ago

Yes sure that would work ...

user23052036 commented 3 months ago

Take a look at the below code.. We could use #if #ellif preprocessor execution statement to find out about the os

#if defined(_WIN32) || defined(_WIN64)
    printf("Operating System: Windows\n");

#elif defined(__APPLE__) && defined(__MACH__)
    printf("Operating System: macOS\n");

#elif defined(__linux__)
    printf("Operating System: Linux\n");

#elif defined(__unix__)
    printf("Operating System: Unix\n");

#else
    printf("Operating System: Unknown\n");
#endif

Kind of like this you can use it in algorithm.h function to determine the os and accordingly we can map the arrow keys to ASWD keys in algorithm.c

user23052036 commented 3 months ago

Okk.. give me 1 day time I will take a look at it by tomorrow

josdorrod commented 3 months ago

I add key recognisition for windows (without having to push enter) and for unix system (pushing enter) add .gitignore Add getkey.c and getkey.h Modified Cmake Tested on windows and linux. Let me know your opinion

josdorrod commented 3 months ago

I'll review all the points you've made

user23052036 commented 3 months ago

The logical part that you have written is correct. But when we are pressing the arrow key for a little long its shifting all the number in that directing and ending the game.

What we need to do is wait until the user stops pressing the arrow key and then return the character.

ex.. if we press arrow (left) for 5sec the program waits till i release the arrow key press.. and then it just retunes character 'a'...

user23052036 commented 3 months ago

Have you committed all the changes yet ?...Because I tried running and its not working. Clicking on arrow key its not moving the Numbers. Clicking on arrow key its generating some random character
Screenshot 2024-07-07 222515

josdorrod commented 3 months ago

Add minor change commented. Add waiting key release on get_key_window. Add validation to only take the first 4 characters on get_key. Change system(cls) for new function that use cls or clear depending on the system.

user23052036 commented 3 months ago

Great work.. Works good in windows i cheeked. Have you cheeked in Linux os ? Unfortunately for some reason my virtual engine turned off i am not able to use (Linux) right now.

josdorrod commented 3 months ago

So It is working correctly?Yeah, I checked on Linux but I have to press enter after each key. There is a way to do without pressing enter but you have to change the Shell properties and i didn't want to risk.El 7 jul 2024 21:36, nomad2036 @.***> escribió: Great work.. Works good in windows i cheeked. Have you cheeked in Linux os ? Unfortunately for some reason my virtual engine turned off i am not able to use (Linux) right now.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

user23052036 commented 3 months ago

Ok no prob.. I am merging it to the main branch