Skip to content

Commit

Permalink
Improve compatibility with various 2048 clones
Browse files Browse the repository at this point in the history
  • Loading branch information
nneonneo committed Mar 31, 2014
1 parent cabfad0 commit 79fb9dd
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions gamectrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,19 @@ def setup(self):
# Obtain the GameManager instance by triggering a fake restart.
self.ctrl.execute(
'''
var _func_tmp = GameManager.prototype.setup;
GameManager.prototype.setup = function() {
var _func_tmp = GameManager.prototype.isGameTerminated;
GameManager.prototype.isGameTerminated = function() {
GameManager._instance = this;
return true;
};
''')

# 'R' for the official version
self.send_key_event('keydown', 82)
self.send_key_event('keydown', 38)
time.sleep(0.1)
self.send_key_event('keyup', 82)
# Space for other versions
self.send_key_event('keydown', 32)
time.sleep(0.1)
self.send_key_event('keyup', 32)
self.send_key_event('keyup', 38)

self.execute('GameManager.prototype.setup = _func_tmp;')
self.execute('GameManager.prototype.isGameTerminated = _func_tmp;')

def get_board(self):
grid = self.execute('GameManager._instance.grid')
Expand Down

0 comments on commit 79fb9dd

Please sign in to comment.