First things first! I am, yes, apart of the 2048 craze. It's just one of those games that make you want to punch the living everything out of it, yes?
After playing for WHO KNOWS
HOW LONG, I decided to play around with the Javascript.
Observations
One: This Is a JavaScript Job
Fiddling with the CSS, I made a 'Night' Theme (which I use, as it's preferable to the default). Anyone who has made a texture for 2048 would know that the JS 'pushes' (like you would do for an array item) a class to the tile upon it's creation. The CSS identifiers for this are:
- .tile-<value>
- <value> is either 2, 4, 8, 16...1024, or 2048
- .tile
- Describes the animation of the tile.
If one changes a two-tile (.tile-2) to a 2048 tile (.tile-2048), it will change upon moving the board, and will
not retain its style.
Two: The JavaScript code is Complicated
With 10 JS Game-related files, one may be overwhelmed. There are 7 non-pollyfil files, which are listed below:
- application.js
- game_manager.js
- grid.js
- html_actuator.js
- keyboard_input_manager.js
- local_storage.js
- tile.js
Three: All of the tiles are powers of two
..And, as a friend tells me, most are
Mojang's Most Popular Game's resolution for Resource/Texture packs.
2 = 2
1
4 = 2
2
8 = 2
3
16 = 2
4
32 = 2
5
64 = 2
6
128 = 2
7
256 = 2
8
256 = 2
8
512 = 2
9
1024 = 2
10
2048 = 2
11
What this does
This is a code that will add a tile whose value can be
anything, not limited to the powers of 2.
Under application.js, one finds (on line 3) the program making a GameManager (found under game_manager.js), which takes the parameters of a grid size (4), an InputManager (KeyboardInputManager), an Actuator (HTMLActuator), and a StorageManager (LocalStorageManager). A new one is presumably created with each iteration of the loop (as it's found under "window.requestAnimationFrame"), but you can create one by simply typing into the console/command line on your 2048 page a variable as found
here.
Of course, you have to create a prototype function (or a function that is applied to a certain object, like 'String.prototype.search = function(...' would be 'String.search(...')
Before doing what's stated above, you must do what is stated below (that is,
here.)
And enjoy!
Codes
The Tile Manager Prototype
GameManager.prototype.addTile = function (value) {
if (this.grid.cellsAvailable()) {
var tile = new Tile(this.grid.randomAvailableCell(), value);
this.grid.insertTile(tile);
}
};
The New Game Manager
var Gamer = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
Syntax and Usage
All possible (legitimate) tiles.
Gamer.addTile(2);
Gamer.addTile(4);
Gamer.addTile(8);
Gamer.addTile(16);
Gamer.addTile(32);
Gamer.addTile(64);
Gamer.addTile(128);
Gamer.addTile(256);
Gamer.addTile(512);
Gamer.addTile(1024);
Gamer.addTile(2048);
A final note
This is not a developers tactic--it has many glitches, and is not guaranteed to be cross-browser. Glitches can also occur due to the separate Game Managers trying to manage the same game, and can result in two
separate respective games going on at once.
Use with caution, and, by using this, you accept the Terms and Conditions of Service listed below.
Terms and Conditions of Service
Article I - Definitions
- The term 'Blog post' is defined herein as an article in which is written a paragraph or more.
- The term '2048 Game' or '2048 puzzle' or '2048' is defined herein as the original game hosted on the url "https://gabrielecirulli.github.io/2048/" (Link: here)
- The term 'Usage' is defined herein as taking the codes provided within this Blog Post and applying them to the 2048 game.
- The term 'Code' or 'Codes' refers to any of the Ordered List Item Groups (<ol>) that contain(s) a programming language (of which could be JavaScript, CSS, or HTML on this page).
- The term 'User' or 'The User' is defined as the person or persons using the Codes provided on this page.
Article II - Main Requirements
- Usage of the contents within the Blog Post can only be used for testing or for gratification of beating the game. You may not claim any results of using this code as anything besides that of which it is (which is the results of an edit of the JavaScripting). All screenshots of a game edited with the code provided in this blog post (or any alterations of said code) are strictly prohibited. The code can and will be taken down if multiple persons fail to comply to the Terms and Conditions of Service.
- These Terms of Service may and will be updated if necessary. Failure to comply with the alterations of the Terms of Service will be an infraction like any other. Ignorance of the Terms is the fault of the User
- All Content on the page is under a Creative Commons Attribution 4.0 international license.