2048 Game

Post your working scripts, libraries and tools
Hellbent
Posts: 143
Joined: 23 Sep 2017, 13:34

2048 Game

16 May 2018, 01:28

I had a few hours to kill so I thought I would take a stab at the game 2048.
I did this in one sitting and was getting very bored/tired by the end so I didn't bother cleaning up my code,
I might clean up the code and redo the gui later (That's code for never).
I did a fair amount of play testing and everything seems to be working fine, if you find a bug let me know and I'll do a quick fix.


Use your arrow keys to move the tiles around and try to get the highest score you can.

Image

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus




EDIT: If your computer doesn't have the Segoe UI Black Font type, the script will switch to Arial.
This will cause the spacing of the text to get messed up a bit, but it is still "Good enough".
Last edited by Hellbent on 16 May 2018, 19:11, edited 2 times in total.
User avatar
nnnik
Posts: 3061
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: 2048 Game

16 May 2018, 03:18

Looks good.
Recommends AHK Studio
User avatar
kczx3
Posts: 586
Joined: 06 Oct 2015, 21:39

Re: 2048 Game

16 May 2018, 09:04

This is quite impressive! I would have expected some of your functions to actually be methods of the Game_Board class. Such as Move_Tiles, Merge, and Remove_Bot.
User avatar
SpeedMaster
Posts: 204
Joined: 12 Nov 2016, 16:09

Re: 2048 Game

16 May 2018, 12:08

Good game. Thank you for sharing :bravo:

Works good on windows 10 :thumbup:
but... Not working on my win 7 64 bit Home Edition :? (Font error!, The font you have specified does not exist on the system)
the game works well after replacing the missing font with arial ;)

cheers,
Hellbent
Posts: 143
Joined: 23 Sep 2017, 13:34

Re: 2048 Game

16 May 2018, 14:06

kczx3 wrote:I would have expected some of your functions to actually be methods of the Game_Board class. Such as Move_Tiles, Merge, and Remove_Bot.


I had started out with everything being in the classes, but because my time was limited and because classes are something that I have only been trying to force myself to learn (really wish there were video tutorials on them, the documentation is so full of terminology and so little simple ground up working examples that it is pretty much useless to me), I decided to go with hotkeys to first work out the logic and then to cut down on the code I worked out a quick function that could deal with all four hotkeys. Even the function is incomplete and I just said "to hell with it" and tried to just push to the end of this project to put it to bed.

In the end, my goal was to create a game that worked and everything else was superfluous. In each new project I do try to pick up new things and to push my knowledge forward and this one had a number of things that did that without worrying about getting bogged down in the class aspect. Perhaps now that I have a working program I will pick it apart and work out a new approach, but first I needed a working program to do that on. I have a saying, "If I wanted patience I would have became a doctor.". So for me, making progress is the key to keep any interest, I can bang my head against a wall tomorrow.
Hellbent
Posts: 143
Joined: 23 Sep 2017, 13:34

Re: 2048 Game

16 May 2018, 14:12

SpeedMaster wrote:Not working on my win 7 64 bit Home Edition :? (Font error!, The font you have specified does not exist on the system)
the game works well after replacing the missing font with arial ;)
cheers,


lol it's so funny that you mentioned the font. When I was writing this out I was thinking about having it switch to another font rather than exiting the script, but I figured "well this font came with my computer so surely everyone must have it."

Did the arial fit without any adjustments being needed to the spacing etc?
If so, I can just edit the code to have it switch if the segoe Ui black font is not found.
OCP
Posts: 68
Joined: 28 Mar 2018, 19:28

Re: 2048 Game

16 May 2018, 17:10

impressive you can do shit like this

it wont work for me because of my weird dpi settings the gui does not form the way it should on my end

i also got the font thing you can get the font here btw https://www.dafontfree.net/freefonts-se ... f63033.htm
Last edited by OCP on 26 Jul 2018, 22:33, edited 1 time in total.
User avatar
SpeedMaster
Posts: 204
Joined: 12 Nov 2016, 16:09

Re: 2048 Game

16 May 2018, 17:49

Hellbent wrote:Did the arial fit without any adjustments being needed to the spacing etc?
If so, I can just edit the code to have it switch if the segoe Ui black font is not found.

Here's what i get with Arial without any adjustments: :roll:
Even if it's not perfect, switch security is a good idea :thumbup:

2048_arial.png
2048_arial.png (28.02 KiB) Viewed 667 times
burque505
Posts: 516
Joined: 22 Jan 2017, 19:37

Re: 2048 Game

16 May 2018, 17:53

Hi, wish I had Win10 to try it out, looks really nice. I tried it on Win7-64, both with Arial and the Segoe UI Black I downloaded, no luck (also tried on XP in a VM, but that was a shot in the dark).
I'm wondering if it might be my GDIP lib, since the tiles are not being drawn.
2048.PNG
2048.PNG (15.24 KiB) Viewed 664 times

Regards,
burque505
User avatar
kczx3
Posts: 586
Joined: 06 Oct 2015, 21:39

Re: 2048 Game

16 May 2018, 18:41

All the necessary gdip functions are in the OP
Hellbent
Posts: 143
Joined: 23 Sep 2017, 13:34

Re: 2048 Game

16 May 2018, 18:43

OCP wrote:
it wont work for me because of my weird dpi settings the gui does not form the way it should on my end


I only have one computer as my sample size so when things go off tilt on other peoples computers I don't have the means to even begin to understand what the underlying issues are.

That said, I do know that there is a gui option called +/-DPIScale.
I don't really know what it does but it could be a fix for you. The only thing I can remember about DPI is from back in the 1980's and early 1990's you could adjust the dpi of your printer. What your computer screen has to do with the number of "dots" per inch is beyond me.

Try running this


I get 96, if you get some other value, using the +/-DPIScale option might work?
Anyone familiar with this DPI stuff care to weigh in?

At any rate you can try adding -DPIScale to the options of the 3 Guis, I tried on my end but I see no change either way.

Out of curiosity, would you mind sharing a shot of what it looks like on your screen as it is now?
Hellbent
Posts: 143
Joined: 23 Sep 2017, 13:34

Re: 2048 Game

16 May 2018, 19:01

burque505 wrote:Hi, wish I had Win10 to try it out, looks really nice. I tried it on Win7-64, both with Arial and the Segoe UI Black I downloaded, no luck (also tried on XP in a VM, but that was a shot in the dark).
I'm wondering if it might be my GDIP lib, since the tiles are not being drawn.
burque505


As was mentioned by kczx3, all the GDIP functions that are required to run this are included at the bottom of the script.

Can you check to see if a subfolder called "2048 Assets" is being created?
Hellbent
Posts: 143
Joined: 23 Sep 2017, 13:34

Re: 2048 Game

16 May 2018, 19:15

SpeedMaster wrote:
Hellbent wrote:Did the arial fit without any adjustments being needed to the spacing etc?
If so, I can just edit the code to have it switch if the segoe Ui black font is not found.

Here's what i get with Arial without any adjustments: :roll:
Even if it's not perfect, switch security is a good idea :thumbup:


Thanks. I edited the OP with the switch added.
OCP
Posts: 68
Joined: 28 Mar 2018, 19:28

Re: 2048 Game

17 May 2018, 00:23

Hellbent wrote:Try running this


i get 120

adding -DPIScale fixed it tho
i added these 3 lines and that fixed it

Code: [Select all] [Download] GeSHi © Codebox Plus

Gui,1:-DPIScale
Gui,2:-DPIScale
Gui,3:-DPIScale


Hellbent wrote:Out of curiosity, would you mind sharing a shot of what it looks like on your screen as it is now?


my before looked as the image posted by burque505

cheers
OCP
Posts: 68
Joined: 28 Mar 2018, 19:28

Re: 2048 Game

17 May 2018, 00:38

i just realize the same thing will also fix that quick launcher you posted a while ago on tube to work for me :)
Last edited by OCP on 26 Jul 2018, 22:33, edited 1 time in total.
Hellbent
Posts: 143
Joined: 23 Sep 2017, 13:34

Re: 2048 Game

17 May 2018, 00:45

OCP wrote:i just realize the same thing will also fix that quick launcher you posted a while ago on tube to work for me :)


I was thinking the same thing, but in that case there is a fair bit more than just 3 guis lol. Not tons but def more than 3.
In my opinion it is well worth the 10-20 mins of editing.

Edit: Just did a quick look, and I count 11 windows.
OCP
Posts: 68
Joined: 28 Mar 2018, 19:28

Re: 2048 Game

17 May 2018, 01:06

Hellbent wrote:Just did a quick look, and I count 11 windows.


5 min work :) find and replace

edit: nice game tho i am impressed you can make things like this pretty cool cheers :bravo:
Last edited by OCP on 26 Jul 2018, 22:33, edited 1 time in total.
Hellbent
Posts: 143
Joined: 23 Sep 2017, 13:34

Re: 2048 Game

17 May 2018, 02:06

OCP wrote:
Hellbent wrote:Just did a quick look, and I count 11 windows.


5 min work :) find and replace

edit: nice game tho i am impressed you can make things like this pretty cool cheers :bravo:


I don't work on a computer so I don't have much use for the normal stuff that AHK can do.So in order for me to have a reason to keep learning this stuff I have to invent things to use it for, and in large part that is playing around with making little games etc.

In my opinion, this is the second most boring and lame game that I have made so far, but it was a quick game to work through. Most of the games I make, I only end up getting the core mechanics done before I get too bored and move on to the next project.

I think my favorite game so far would be my Space Invaders game. I never ended up finishing it, but the core is done. It has a beginning, middle and end. It's just missing some polish.



A close second would be my bots. While they are not a game per se, they are a training ground for creating the logic that could be used to create 100's of different games.

OCP
Posts: 68
Joined: 28 Mar 2018, 19:28

Re: 2048 Game

17 May 2018, 03:02

nice stuff i am not even close to understanding haha been watching some of your vids on this stuff

you sparked something i want to figure out now, a way to have my gui's auto adjust to the dpi of the system it runs on that way i could share my gui's and not have to worry about the need for people to adjust coordinates in the script

Return to “Scripts and Functions”

Who is online

Users browsing this forum: binghez, cocobanana and 17 guests