How to use setFrame method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

Run Appium Base Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

menu.js

Source: menu.js Github

copy
1import Phaser from 'phaser';
2import Play from './play';
3
4
5class Menu extends Phaser.Scene{
6    constructor(){
7       super({ key: 'Menu' });
8       this.state = {};
9   };
10
11   init(info){
12       console.log('game phase')
13       this.initSFX = info[0];
14       this.initMusic = info[1];
15   };
16
17
18    preload(){
19        this.load.image('bg', 'assets/barcounter.jpg');
20        this.load.image('machine', 'assets/machine.png');
21        this.load.spritesheet("default", "assets/defaultbutton.png",{ frameWidth: 200, frameHeight: 157 });
22        this.load.spritesheet("anime", "assets/animebutton.png",{ frameWidth: 200, frameHeight: 157 });
23        this.load.spritesheet("start", "assets/startbutton.png",{ frameWidth: 200, frameHeight: 157 });
24        this.load.spritesheet("easy", "assets/easybutton.png",{ frameWidth: 500, frameHeight: 431 });
25        this.load.spritesheet("normal", "assets/normalbutton.png",{ frameWidth: 500, frameHeight: 431 });
26        this.load.spritesheet("hard", "assets/hardbutton.png",{ frameWidth: 500, frameHeight: 431 });
27        this.load.spritesheet("sfx", "assets/sfxButton.png",{ frameWidth: 200, frameHeight: 200 });
28        this.load.spritesheet("musicButton", "assets/musicButton.png",{ frameWidth: 200, frameHeight: 200 });
29        this.load.audio('buttonClick', 'assets/audio/buttonclick.mp3'); 
30
31   };
32
33    create(){
34        let gameW = this.sys.game.config.width;
35        let gameH = this.sys.game.config.height;
36    
37        let background = this.add.sprite(0, 0 , 'bg');
38        background.setPosition(gameW/2, gameH/2).setDisplaySize(gameW, gameH);
39        let machine = this.add.sprite(gameW/2,gameH/2.2 , 'machine').setScale(1.9);
40
41        this.buttonClick = this.sound.add('buttonClick');
42        var mode = 'default';
43        var difficulty = 'normal';
44        this.pausetext = this.add.text(gameW * 0.02, gameH*0.7, "PRESS 'P' TO PAUSE", { font: "bold 25px Arial", fill: "#ffffff", stroke: '#000000', strokeThickness: 5 });
45        this.mutemusictext = this.add.text(gameW * 0.02, gameH*0.8, "PRESS 'M' TO STOP MUSIC", { font: "bold 25px Arial", fill: "#ffffff", stroke: '#000000', strokeThickness: 5 });
46        this.mutesfxtext = this.add.text(gameW * 0.02, gameH*0.9, "PRESS 'N' TO MUTE SOUND EFFECTS", { font: "bold 25px Arial", fill: "#ffffff", stroke: '#000000', strokeThickness: 5 });
47
48        this.im
49        
50        var sfxClick = false;
51        var musicClick = false;
52        this.sfxButton = this.add.sprite(gameW/ 1.45, gameH/1.5, 'sfx').setFrame(0).setScale(0.7).setInteractive().on('pointerover', function(){
53            
54        }).on('pointerdown', function(event){
55            
56            if(sfxClick == false){
57                this.sfxButton.setFrame(1);
58                this.buttonClick.setMute(true);
59                sfxClick = true;
60            }else{
61                this.sfxButton.setFrame(0);
62                this.buttonClick.setMute(false);
63                sfxClick = false;
64            }
65    
66            
67        }, this).on('pointerup', function(){
68            
69        }).on('pointerout', function(){
70            
71        });
72
73        this.input.keyboard.on('keydown-N', ()=>{
74
75            if(sfxClick == false){
76                this.sfxButton.setFrame(1);
77                this.buttonClick.setMute(true);
78                sfxClick = true;
79            }else{
80                this.sfxButton.setFrame(0);
81                this.buttonClick.setMute(false);
82                sfxClick = false;
83            }
84        }, this);
85
86        this.musicButton = this.add.sprite(gameW/ 1.45, gameH/2.1, 'musicButton').setFrame(0).setScale(0.7).setInteractive().on('pointerover', function(){
87            
88        }).on('pointerdown', function(event){
89            if(musicClick == false){
90                this.musicButton.setFrame(1);
91                // this.lobbymusic.setMute(true);
92                musicClick = true;
93            }else{
94                this.musicButton.setFrame(0);
95                // this.lobbymusic.setMute(false);
96                musicClick = false;
97            }
98            
99        }, this).on('pointerup', function(){
100            
101        }).on('pointerout', function(){
102            
103        });
104
105        this.input.keyboard.on('keydown-M', ()=>{
106
107            if(musicClick == false){
108                this.musicButton.setFrame(1);
109                // this.lobbymusic.setMute(true);
110                musicClick = true;
111            }else{
112                this.musicButton.setFrame(0);
113                // this.lobbymusic.setMute(false);
114                musicClick = false;
115            }
116
117        }, this);
118
119        console.log(this.initMusic, this.initSFX);
120
121        if(this.initSFX == true){
122            this.sfxButton.setFrame(1);
123            sfxClick = true;
124            this.buttonClick.setMute(this.initSFX);
125        };
126        if(this.initMusic == true){
127            this.musicButton.setFrame(1);
128            musicClick = true;
129            // this.lobbymusic.setMute(this.initMusic);
130        };
131        
132
133
134
135        this.default = this.add.sprite(gameW/2.2, gameH * 0.10, 'default').setScale(0.7).setInteractive().on('pointerover', function(){
136            this.setFrame(0);
137        }).on('pointerdown', function(event){
138            this.default.setFrame(0);
139            if(this.anime != null){
140                this.anime.setFrame(1);
141            }
142            mode = 'default';
143            if(this.buttonClick != null){
144                this.buttonClick.play();
145            };
146            
147            if(difficulty == 'easy'){
148                this.easy.setFrame(0);
149            }else{
150                this.easy.setFrame(1);
151            };
152
153            if(difficulty == 'normal'){
154                this.normal.setFrame(0);
155            }else{
156                this.normal.setFrame(1);
157            };
158
159            if(difficulty == 'hard'){
160                this.hard.setFrame(0);
161            }else{
162                this.hard.setFrame(1);
163            };
164
165            console.log(mode);
166        }, this).on('pointerup', function(){
167            this.setFrame(0);
168            if(this.buttonClick != null){
169                this.buttonClick.play();
170            };
171        }).on('pointerout', function(){
172            if(mode != 'default'){
173                this.setFrame(1);
174            }
175        });
176
177        this.anime = this.add.sprite(gameW/1.8, gameH * 0.10, 'anime').setScale(0.7).setFrame(1).setInteractive().on('pointerover', function(){
178            this.setFrame(0);
179        }).on('pointerdown', function(event){
180            this.anime.setFrame(0);
181            this.default.setFrame(1);
182            mode = 'anime';
183            if(this.buttonClick != null){
184                this.buttonClick.play();
185            };
186            if(difficulty == 'easy'){
187                this.easy.setFrame(2);
188            }else{
189                this.easy.setFrame(3);
190            };
191
192            if(difficulty == 'normal'){
193                this.normal.setFrame(2);
194            }else{
195                this.normal.setFrame(3);
196            };
197
198            if(difficulty == 'hard'){
199                this.hard.setFrame(2);
200            }else{
201                this.hard.setFrame(3);
202            };
203
204            console.log(mode);
205        }, this).on('pointerup', function(){
206            this.setFrame(0);
207            if(this.buttonClick != null){
208                this.buttonClick.play();
209            };
210        }).on('pointerout', function(){
211            if(mode != 'anime'){
212                this.setFrame(1);
213            }
214        });
215
216        this.easy = this.add.sprite(gameW/2.5, gameH*0.3, 'easy').setScale(0.3).setInteractive().on('pointerover', function(){
217            if(mode == 'default'){
218                this.setFrame(0);
219            }else{
220                this.setFrame(2);
221            };
222            
223        }).on('pointerdown', function(event){
224            if(mode == 'default'){
225                this.easy.setFrame(0);
226            }else{
227                this.easy.setFrame(2);
228            };
229            if(this.buttonClick != null){
230                this.buttonClick.play();
231            };
232            // if(this.anime != null){
233            //     this.anime.setFrame(1);
234            // }
235            difficulty = 'easy';
236
237            if(mode == 'default'){
238                this.normal.setFrame(1);
239            }else{
240                this.normal.setFrame(3);
241            };
242
243            if(mode == 'default'){
244                this.hard.setFrame(1);
245            }else{
246                this.hard.setFrame(3);
247            };
248
249            console.log(difficulty);
250        }, this).on('pointerup', function(){
251            if(this.buttonClick != null){
252                this.buttonClick.play();
253            };
254            if(mode == 'default'){
255                this.setFrame(0);
256            }else{
257                this.setFrame(2);
258            };
259        }).on('pointerout', function(){
260            if(difficulty != 'easy'){
261                if(mode == 'default'){
262                    this.setFrame(1);
263                }else{
264                    this.setFrame(3);
265                };
266            }
267        });
268
269        if(mode == 'default'){
270            this.easy.setFrame(1);
271        }else{
272            this.easy.setFrame(3);
273        };
274
275        this.normal = this.add.sprite(gameW/2, gameH*0.3, 'normal').setScale(0.3).setInteractive().on('pointerover', function(){
276            if(mode == 'default'){
277                this.setFrame(0);
278            }else{
279                this.setFrame(2);
280            };
281            
282        }).on('pointerdown', function(event){
283            if(this.buttonClick != null){
284                this.buttonClick.play();
285            };
286            if(mode == 'default'){
287                this.normal.setFrame(0);
288            }else{
289                this.normal.setFrame(2);
290            };
291            if(mode == 'default'){
292                this.easy.setFrame(1);
293            }else{
294                this.easy.setFrame(3);
295            };
296
297            if(mode == 'default'){
298                this.hard.setFrame(1);
299            }else{
300                this.hard.setFrame(3);
301            };
302
303            difficulty = 'normal';
304            console.log(difficulty);
305        }, this).on('pointerup', function(){
306            if(this.buttonClick != null){
307                this.buttonClick.play();
308            };
309            if(mode == 'default'){
310                this.setFrame(0);
311            }else{
312                this.setFrame(2);
313            };
314        }).on('pointerout', function(){
315            if(difficulty != 'normal'){
316                if(mode == 'default'){
317                    this.setFrame(1);
318                }else{
319                    this.setFrame(3);
320                };
321            }
322        });
323
324        if(mode == 'default'){
325            this.normal.setFrame(0);
326        }else{
327            this.normal.setFrame(2);
328        };
329
330        this.hard = this.add.sprite(gameW/ 1.665, gameH*0.3, 'hard').setScale(0.3).setInteractive().on('pointerover', function(){
331            if(mode == 'default'){
332                this.setFrame(0);
333            }else{
334                this.setFrame(2);
335            };
336            
337        }).on('pointerdown', function(event){
338            if(this.buttonClick != null){
339                this.buttonClick.play();
340            };
341            if(mode == 'default'){
342                this.hard.setFrame(0);
343            }else{
344                this.hard.setFrame(2);
345            };
346            // if(this.anime != null){
347            //     this.anime.setFrame(1);
348            // }
349            difficulty = 'hard';
350
351            if(mode == 'default'){
352                this.normal.setFrame(1);
353            }else{
354                this.normal.setFrame(3);
355            };
356
357            if(mode == 'default'){
358                this.easy.setFrame(1);
359            }else{
360                this.easy.setFrame(3);
361            };
362
363            console.log(difficulty);
364        }, this).on('pointerup', function(){
365            if(this.buttonClick != null){
366                this.buttonClick.play();
367            };
368            if(mode == 'default'){
369                this.setFrame(0);
370            }else{
371                this.setFrame(2);
372            };
373        }).on('pointerout', function(){
374            if(difficulty != 'hard'){
375                if(mode == 'default'){
376                    this.setFrame(1);
377                }else{
378                    this.setFrame(3);
379                };
380            }
381        });
382
383        if(mode == 'default'){
384            this.hard.setFrame(1);
385        }else{
386            this.hard.setFrame(3);
387        };
388
389        this.start = this.add.sprite(gameW/2, gameH * 0.9, 'start').setScale(0.7).setFrame(0).setInteractive().on('pointerover', function(){
390            this.setFrame(1);
391        }).on('pointerdown', function(event){
392            this.start.setFrame(1);
393           
394            // this.cache.audio.remove('lobby');
395            if(this.buttonClick != null){
396                this.buttonClick.play();
397            };
398     
399            let info = [mode,  difficulty, sfxClick, musicClick];
400            var timedEvent = this.time.delayedCall(1500, ()=>{
401                
402                this.scene.restart('Play');
403                
404                this.scene.start('Play', info);
405                // Play.textures.remove('board');
406        } , [], this);
407
408        }, this).on('pointerup', function(){
409            this.setFrame(0);
410        }).on('pointerout', function(){
411
412            this.setFrame(0);
413        });
414
415        
416   };
417
418   update(){
419
420       
421   };
422};
423
424
425var Pause = new Phaser.Class({
426
427    Extends: Phaser.Scene,
428
429    initialize:
430
431    function Pause ()
432    {
433        Phaser.Scene.call(this, { key: 'Pause' });
434    },
435
436    preload: function ()
437    {
438        
439    },
440
441    create: function ()
442    {
443        let gameW = this.sys.game.config.width;
444        let gameH = this.sys.game.config.height;
445        
446        this.pause = this.add.text(gameW/2, gameH/2.3, 'GAME IS PAUSED', { font: "bold 70px Arial", fill: "#ffffff", stroke: '#000000', strokeThickness: 5 }).setOrigin(0.5, 0.5);
447        this.pause2 = this.add.text(gameW/2, gameH/1.8, "PRESS 'P' TO RESUME", { font: "bold 70px Arial", fill: "#ffffff", stroke: '#000000', strokeThickness: 5 }).setOrigin(0.5, 0.5);
448
449        this.input.keyboard.on('keydown-P', ()=>{
450
451            this.scene.stop('Pause');
452            this.scene.resume('Play');
453
454        }, this);
455    }
456
457});
458
459
460
461
462let config = {
463    type: Phaser.AUTO,
464    width: window.innerWidth * window.devicePixelRatio,
465    height: window.innerHeight * window.devicePixelRatio,
466    scene: [ Menu, Play, Pause],
467    scale: {
468        mode: Phaser.Scale.FIT,
469    },
470    parent:'phaser-container',
471	dom: {
472        createContainer: true
473    },
474    physics: {
475        default: 'arcade',
476        arcade: {
477            gravity: { y: 0,
478                        x:0 },
479            debug: false
480        }
481    }
482};
483
484
485// create a new game , pass the configuration
486
487let game = new Phaser.Game(config); 
488
489export default game;
Full Screen

index.test.js

Source: index.test.js Github

copy
1// @flow
2//
3//  Copyright (c) 2018-present, Cruise LLC
4//
5//  This source code is licensed under the Apache License, Version 2.0,
6//  found in the LICENSE file in the root directory of this source tree.
7//  You may not use this file except in compliance with the License.
8import SceneBuilder from "webviz-core/src/panels/ThreeDimensionalViz/SceneBuilder";
9
10describe("SceneBuilder", () => {
11  it("on setFrame, modified topics rendered", () => {
12    const builder = new SceneBuilder();
13    builder.setTopics([{ name: "a", datatype: "A" }]);
14
15    builder.setFrame({ a: [] });
16
17    expect(builder.topicsToRender).toContain("a");
18  });
19
20  it("on setFrame, only specified topics rendered", () => {
21    const builder = new SceneBuilder();
22    builder.setTopics([{ name: "a", datatype: "A" }]);
23
24    builder.setFrame({ b: [] });
25
26    expect(builder.topicsToRender.size).toBe(0);
27  });
28
29  it("on setFrame, same instance, nothing rendered", () => {
30    const builder = new SceneBuilder();
31    builder.setTopics([{ name: "a", datatype: "A" }]);
32    const frame = { a: [] };
33    builder.setFrame(frame);
34    // check that we're set up properly with one topic rendered
35    expect(builder.topicsToRender.size).toBe(1);
36    builder.render();
37
38    builder.setFrame(frame);
39
40    expect(builder.topicsToRender.size).toBe(0);
41  });
42
43  it("on setFrame, same value different instance, topics rendered", () => {
44    const builder = new SceneBuilder();
45    builder.setTopics([{ name: "a", datatype: "A" }]);
46    const frame1 = { a: [] };
47    const frame2 = { a: [] };
48    builder.setFrame(frame1);
49    builder.render();
50
51    builder.setFrame(frame2);
52
53    expect(builder.topicsToRender.size).toBe(1);
54  });
55
56  it("on setFrame, latest value saved", () => {
57    const builder = new SceneBuilder();
58    builder.setTopics([{ name: "a", datatype: "A" }]);
59    const messages1 = [];
60    const messages2 = [];
61    builder.setFrame({ a: messages1 });
62    builder.setFrame({ a: messages2 });
63
64    expect(builder.lastSeenMessages.a).not.toBe(messages1);
65    expect(builder.lastSeenMessages.a).toBe(messages2);
66  });
67
68  it("on setFrame, messages are saved", () => {
69    const builder = new SceneBuilder();
70    const messagesValue = [];
71    builder.setTopics([{ name: "a", datatype: "A" }]);
72
73    builder.setFrame({ a: messagesValue });
74
75    expect(builder.lastSeenMessages.a).toBe(messagesValue);
76  });
77
78  it("on setFrame, old messages not clobbered", () => {
79    const builder = new SceneBuilder();
80    const messagesValue = [];
81    builder.setTopics([{ name: "a", datatype: "A" }, { name: "b", datatype: "B" }]);
82    builder.setFrame({ a: messagesValue });
83
84    builder.setFrame({ b: messagesValue });
85
86    // a survives even though it's only included in the first setFrame
87    expect(builder.lastSeenMessages.a).toBe(messagesValue);
88  });
89
90  it("on setFrame, unrendered messages saved", () => {
91    const builder = new SceneBuilder();
92    const messagesValue = [];
93    builder.setTopics([{ name: "a", datatype: "A" }]);
94
95    builder.setFrame({ b: messagesValue });
96
97    expect("b" in builder.lastSeenMessages).toBe(true);
98  });
99
100  it("on render, topics to render cleared", () => {
101    const builder = new SceneBuilder();
102    builder.setTopics([{ name: "a", datatype: "A" }]);
103    builder.setFrame({ a: [] });
104    // to make sure we're set up right, check that one topic should be rendered
105    expect(builder.topicsToRender.size).toBe(1);
106
107    builder.render();
108
109    expect(builder.topicsToRender.size).toBe(0);
110  });
111});
112
Full Screen

Player.js

Source: Player.js Github

copy
1import Phaser from 'phaser'
2
3let timeOne, timeTwo, timeThree
4
5export default class Player extends Phaser.Physics.Arcade.Sprite {
6
7    constructor(config) {
8        super(config.scene, config.x, config.y, config.type)
9
10        this.setData({
11			speed: 200,
12			jumpSpeed: 590,
13			gravity: 800
14		})
15
16        // set Anims Player
17        config.scene.dataAnim = config.scene.cache.json.get('astronaut_anim')
18        config.scene.anims.fromJSON(config.scene.dataAnim)
19
20        // Add Sprite 
21        config.scene.add.existing(this)
22        config.scene.physics.add.existing(this)
23        this.create(config)
24
25    }
26
27    create(config) {
28
29        // set Properties
30        this.setScale(config.scale)
31        this.setOrigin(0.5)
32        this.setCollideWorldBounds(true)
33        this.setGravityY(this.data.values.gravity)
34        this.body.setSize(40, 110)
35        this.body.setOffset(50,10)
36
37        // set anim
38        this.anims.play('idle')
39
40    }
41
42    move(direction) {
43        if (direction == 'STOP') {
44            this.setVelocityX(0)
45            this.data.values.speed = 200
46            this.data.values.jumpSpeed = 590 
47            this.anims.play('idle')
48        }
49        
50        if (direction == 'LEFT') {
51            this.setVelocityX(-this.data.values.speed)
52            this.setFlipX(true)
53            this.anims.play('walk')
54        }
55        else if (direction == 'RIGHT') {
56            this.setVelocityX(this.data.values.speed)
57            this.setFlipX(false)
58            this.anims.play('walk')
59        } else if (direction == 'RIGHT_SHORT') {
60            this.setVelocityX(this.data.values.speed)
61            this.setFlipX(false)
62        } else if (direction == 'LEFT_SHORT') {
63            this.setVelocityX(-this.data.values.speed)
64            this.anims.play('walk')
65        }
66
67        if (direction == 'JUMP') {
68            this.setVelocityY(-this.data.values.jumpSpeed)
69            this.anims.play('jump')
70        } else if (direction == 'JUMP_SHORT') {
71            this.setVelocityY(-this.data.values.jumpSpeed)
72            this.anims.play('jump_short')
73        }
74    }
75
76    movePlayer(game) {
77
78        let moves = game.dropZones[0].data.get('action') + game.dropZones[1].data.get('action') + game.dropZones[2].data.get('action')
79
80        switch(moves) {
81            case 'RSS':
82            case 'LSS':
83                // Move Player
84                this.move(game.dropZones[0].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
85                // Turn on indicators
86                game.instructions[game.dropZones[0].data.get('action') === 'R' ? 0: 1].setFrame(1)
87                // Stop player and turn off indicators
88                timeOne = setTimeout(() => { 
89                    game.instructions[game.dropZones[0].data.get('action') === 'R' ? 0: 1].setFrame(0); 
90                    game.lights[1].setFrame(1) 
91                    this.move('STOP')
92                }, 500)
93                timeTwo = setTimeout(() => { 
94                    game.lights[1].setFrame(0)
95                    game.lights[2].setFrame(1)
96                }, 1500)
97                timeThree = setTimeout(() => { game.lights[2].setFrame(0) }, 2500)
98                break
99            
100            case 'SSR':
101            case 'SSL':
102                game.lights[0].setFrame(1)
103                timeOne = setTimeout(() => { 
104                    game.lights[0].setFrame(0); 
105                    game.lights[1].setFrame(1)
106                }, 1000)
107                timeTwo = setTimeout(() => { 
108                    this.move(game.dropZones[2].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
109                    game.instructions[game.dropZones[2].data.get('action') === 'R' ? 0: 1].setFrame(1)
110                    game.lights[1].setFrame(0) 
111                }, 2000)
112                timeThree = setTimeout(() => { 
113                    game.instructions[game.dropZones[2].data.get('action') === 'R' ? 0: 1].setFrame(0) 
114                    this.move('STOP')
115                }, 2500)
116                break
117
118            case 'SRS':
119            case 'SLS':
120                game.lights[0].setFrame(1)
121                timeOne = setTimeout(() => { 
122                    game.lights[0].setFrame(0) 
123                    game.instructions[game.dropZones[1].data.get('action') === 'R' ? 0: 1].setFrame(1)
124                    this.move(game.dropZones[1].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
125                }, 1000)
126                timeTwo = setTimeout(() => { 
127                    game.instructions[game.dropZones[1].data.get('action') === 'R' ? 0: 1].setFrame(0)
128                    game.lights[2].setFrame(1) 
129                    this.move('STOP')
130                }, 1500)
131                timeThree = setTimeout(() => { game.lights[2].setFrame(0) }, 2500)
132                break
133
134            case 'LRS':
135            case 'RLS':
136                // Move Player
137                this.move(game.dropZones[0].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
138                // Turn on indicators
139                game.instructions[game.dropZones[0].data.get('action') === 'R' ? 0: 1].setFrame(1)
140                // Stop player and turn off indicators
141                timeOne = setTimeout(() => { 
142                    game.instructions[game.dropZones[0].data.get('action') === 'R' ? 0: 1].setFrame(0)
143                    game.instructions[game.dropZones[1].data.get('action') === 'R' ? 0: 1].setFrame(1) 
144                    this.move(game.dropZones[1].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
145                }, 500)
146                timeTwo = setTimeout(() => { 
147                    game.instructions[game.dropZones[1].data.get('action') === 'R' ? 0: 1].setFrame(0)
148                    game.lights[2].setFrame(1) 
149                    this.move('STOP')
150                }, 1000)
151                timeThree = setTimeout(() => { game.lights[2].setFrame(0) }, 2500)
152                break
153
154            case 'SLR':
155            case 'SRL':
156                game.lights[0].setFrame(1)
157                timeOne = setTimeout(() => { 
158                    game.lights[0].setFrame(0) 
159                    game.instructions[game.dropZones[1].data.get('action') === 'R' ? 0: 1].setFrame(1)
160                    this.move(game.dropZones[1].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
161                }, 1500)
162                timeTwo = setTimeout(() => { 
163                    game.instructions[game.dropZones[1].data.get('action') === 'R' ? 0: 1].setFrame(0)
164                    game.instructions[game.dropZones[2].data.get('action') === 'R' ? 0: 1].setFrame(1) 
165                    this.move(game.dropZones[2].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
166                }, 2000)
167                timeThree = setTimeout(() => { 
168                    game.instructions[game.dropZones[2].data.get('action') === 'R' ? 0: 1].setFrame(0) 
169                    this.move('STOP')
170                }, 2500)
171                break
172
173            case 'LSR':
174            case 'RSL':
175                // Move Player
176                this.move(game.dropZones[0].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
177                // Turn on indicators
178                game.instructions[game.dropZones[0].data.get('action') === 'R' ? 0: 1].setFrame(1)
179                // Stop player and turn off indicators
180                timeOne = setTimeout(() => { 
181                    game.instructions[game.dropZones[0].data.get('action') === 'R' ? 0: 1].setFrame(0)
182                    game.lights[1].setFrame(1) 
183                    this.move('STOP')
184                }, 500)
185                timeTwo = setTimeout(() => { 
186                    game.lights[1].setFrame(0) 
187                    game.instructions[game.dropZones[2].data.get('action') === 'R' ? 0: 1].setFrame(1)
188                    this.move(game.dropZones[2].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
189                }, 1500)
190                timeThree = setTimeout(() => { 
191                    game.instructions[game.dropZones[2].data.get('action') === 'R' ? 0: 1].setFrame(0) 
192                    this.move('STOP')
193                }, 2000)
194                break
195
196            case 'RJS':
197            case 'LJS':
198                // Move Player
199                this.data.values.speed = 350
200                this.data.values.jumpSpeed = 620
201                this.move(game.dropZones[0].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
202                this.move('JUMP')
203                // Turn on indicators
204                game.instructions[game.dropZones[0].data.get('action') === 'R' ? 0: 1].setFrame(1)
205                game.instructions[2].setFrame(1)
206                // Stop player and turn off indicators
207                timeOne = setTimeout(() => { game.instructions[game.dropZones[0].data.get('action') === 'R' ? 0: 1].setFrame(0) }, 500)
208                timeTwo = setTimeout(() => { this.move('STOP') ; game.instructions[2].setFrame(0) ; game.lights[2].setFrame(1) }, 1000)
209                timeThree = setTimeout(() => { game.lights[2].setFrame(0) }, 2000)
210                break
211
212            case 'SRJ':
213            case 'SLJ':
214                this.data.values.speed = 350
215                this.data.values.jumpSpeed = 620
216                game.lights[0].setFrame(1)
217                timeOne = setTimeout(() => { 
218                    game.lights[0].setFrame(0)
219                    game.instructions[game.dropZones[1].data.get('action') === 'R' ? 0: 1].setFrame(1)
220                    game.instructions[2].setFrame(1) 
221                    this.move(game.dropZones[1].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
222                    this.move('JUMP')
223                }, 1000)
224                timeTwo = setTimeout(() => { game.instructions[game.dropZones[1].data.get('action') === 'R' ? 0: 1].setFrame(0) }, 1500)
225                timeThree = setTimeout(() => { this.move('STOP') ; game.instructions[2].setFrame(0) }, 2000)
226                break
227
228            case 'JSS':
229                // Move Player
230                this.move('JUMP')
231                // Turn on indicators
232                game.instructions[2].setFrame(1)
233                // Stop player and turn off indicators
234                timeOne = setTimeout(() => { this.move('STOP'); game.instructions[2].setFrame(0); game.lights[1].setFrame(1) }, 1000)
235                timeTwo = setTimeout(() => { game.lights[1].setFrame(0); game.lights[2].setFrame(1) }, 1800)
236                timeThree = setTimeout(() => { game.lights[2].setFrame(0) }, 2300)
237                break
238
239            case 'SJS':
240                game.lights[0].setFrame(1)
241                timeOne = setTimeout(() => { this.move('JUMP'); game.instructions[2].setFrame(1); game.lights[0].setFrame(0) }, 1000)
242                timeTwo = setTimeout(() => { this.move('STOP'); game.instructions[2].setFrame(0); game.lights[2].setFrame(1) }, 2000)
243                timeThree = setTimeout(() => { game.lights[2].setFrame(0) }, 3000)
244                break
245            case 'SSJ':
246                game.lights[0].setFrame(1)
247                timeOne = setTimeout(() => { game.lights[0].setFrame(0); game.lights[1].setFrame(0) }, 1000)
248                timeTwo = setTimeout(() => { this.move('JUMP'); game.instructions[2].setFrame(1); game.lights[2].setFrame(0) }, 2000)
249                timeThree = setTimeout(() => { this.move('STOP'); game.instructions[2].setFrame(0) }, 3000)
250                break
251            
252            case 'JLS':
253            case 'JRS':
254                // Move Player
255                this.move('JUMP_SHORT')
256                // Turn on indicators
257                game.instructions[2].setFrame(1)
258                // Stop player and turn off indicators
259                timeOne = setTimeout(() => { 
260                    game.instructions[game.dropZones[1].data.get('action') === 'R' ? 0: 1].setFrame(1) 
261                    this.move((game.dropZones[1].data.get('action') === 'R' ? 'RIGHT': 'LEFT') + '_SHORT') 
262                }, 500)
263                timeTwo = setTimeout(() => { 
264                    game.instructions[2].setFrame(0)
265                    game.instructions[game.dropZones[1].data.get('action') === 'R' ? 0: 1].setFrame(0)
266                    game.lights[2].setFrame(1) 
267                    this.move('STOP')
268                }, 1000)
269                timeThree = setTimeout(() => { game.lights[2].setFrame(0) }, 2000)
270                break
271
272            case 'SJL':
273            case 'SJR':
274                game.lights[0].setFrame(1)
275                timeOne = setTimeout(() => { 
276                    game.instructions[2].setFrame(1)
277                    game.lights[0].setFrame(0) 
278                    this.move('JUMP_SHORT')
279                }, 1000)
280                timeTwo = setTimeout(() => { 
281                    game.instructions[game.dropZones[2].data.get('action') === 'R' ? 0: 1].setFrame(1) 
282                    this.move((game.dropZones[2].data.get('action') === 'R' ? 'RIGHT': 'LEFT') + '_SHORT')
283                }, 1500)
284                timeThree = setTimeout(() => { 
285                    game.instructions[2].setFrame(0)
286                    game.instructions[game.dropZones[2].data.get('action') === 'R' ? 0: 1].setFrame(0) 
287                    this.move('STOP')
288                }, 2000)
289                break
290
291            case 'JSL':
292            case 'JSR':
293                // Move Player
294                this.move('JUMP')
295                // Turn on indicators
296                game.instructions[2].setFrame(1)
297                // Stop player and turn off indicators
298                timeOne = setTimeout(() => { 
299                    game.instructions[2].setFrame(0); 
300                    game.lights[1].setFrame(1) 
301                    this.move('STOP')
302                }, 1000)
303                timeTwo = setTimeout(() => { 
304                    game.lights[1].setFrame(0)
305                    game.lights[2].setFrame(1)
306                    game.instructions[game.dropZones[2].data.get('action') === 'R' ? 0: 1].setFrame(1) 
307                    this.move(game.dropZones[2].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
308                }, 2000)
309                timeThree = setTimeout(() => { 
310                    game.instructions[game.dropZones[2].data.get('action') === 'R' ? 0: 1].setFrame(0) 
311                    this.move('STOP')
312                }, 2500)
313                break
314
315            case 'JLR':
316            case 'JRL':
317                // Move Player
318                this.move('JUMP_SHORT')
319                // Turn on indicators
320                game.instructions[2].setFrame(1)
321                // Stop player and turn off indicators
322                timeOne = setTimeout(() => { 
323                    game.instructions[game.dropZones[1].data.get('action') === 'R' ? 0: 1].setFrame(1) 
324                    this.move((game.dropZones[1].data.get('action') === 'R' ? 'RIGHT': 'LEFT') + '_SHORT') 
325                }, 500)
326                timeTwo = setTimeout(() => { 
327                    game.instructions[2].setFrame(0)
328                    game.instructions[game.dropZones[1].data.get('action') === 'R' ? 0: 1].setFrame(0)
329                    game.instructions[game.dropZones[2].data.get('action') === 'R' ? 0: 1].setFrame(1) 
330                    this.move(game.dropZones[2].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
331                }, 1000)
332                timeThree = setTimeout(() => { 
333                    game.instructions[game.dropZones[2].data.get('action') === 'R' ? 0: 1].setFrame(0) 
334                    this.move('STOP')
335                }, 1500)
336                break
337
338            case 'LRJ':
339            case 'RLJ':
340                // Move Player
341                this.move(game.dropZones[0].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
342                // Turn on indicators
343                game.instructions[game.dropZones[0].data.get('action') === 'R' ? 0: 1].setFrame(1)
344                // Stop player and turn off indicators
345                timeOne = setTimeout(() => { 
346                    game.instructions[game.dropZones[0].data.get('action') === 'R' ? 0: 1].setFrame(0)
347                    game.instructions[game.dropZones[1].data.get('action') === 'R' ? 0: 1].setFrame(1) 
348                    game.instructions[2].setFrame(1)
349                    // Move Player
350                    this.data.values.speed = 350
351                    this.data.values.jumpSpeed = 620
352                    this.move(game.dropZones[1].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
353                    this.move('JUMP')                    
354                }, 500)
355                timeTwo = setTimeout(() => { 
356                    game.instructions[game.dropZones[1].data.get('action') === 'R' ? 0: 1].setFrame(0)
357                    game.instructions[2].setFrame(0)
358                    this.move('STOP')
359                }, 1500)
360                break
361
362            case 'LJR':
363            case 'RJL':
364                // Move Player
365                this.data.values.speed = 350
366                this.data.values.jumpSpeed = 620
367                this.move(game.dropZones[0].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
368                this.move('JUMP')
369                // Turn on indicators
370                game.instructions[game.dropZones[0].data.get('action') === 'R' ? 0: 1].setFrame(1)
371                game.instructions[2].setFrame(1)
372                // Stop player and turn off indicators
373                timeOne = setTimeout(() => { 
374                    game.instructions[game.dropZones[0].data.get('action') === 'R' ? 0: 1].setFrame(0) 
375                }, 500)
376                timeTwo = setTimeout(() => { 
377                    game.instructions[2].setFrame(0)
378                    game.instructions[game.dropZones[2].data.get('action') === 'R' ? 0: 1].setFrame(1)
379                    this.move(game.dropZones[2].data.get('action') === 'R' ? 'RIGHT': 'LEFT')
380                }, 1000)
381                timeThree = setTimeout(() => { 
382                    game.instructions[game.dropZones[2].data.get('action') === 'R' ? 0: 1].setFrame(1)
383                    this.move('STOP')
384                }, 1500)
385                break
386
387        }
388
389    }
390
391    stopTimerPlayer(){
392        clearTimeout(timeOne)
393        clearTimeout(timeTwo)
394        clearTimeout(timeThree)
395    }
396}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Base Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)