-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshootingGame.js
More file actions
68 lines (59 loc) · 1.72 KB
/
Copy pathshootingGame.js
File metadata and controls
68 lines (59 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var axel = require("axel")
axel.clear();
var keypress = require("keypress");
var dartCordinate = {x:0,y:0,inc:0};
var arrowCordinate = {x:130,y:20,inc:0},score=0;
axel.bg(11,155,19);
axel.fg(0,0,0);
var createEnv = function (){
axel.clear();
process.stdout.cursorTo(130,2);
console.log("Score: ",score);
process.stdout.write(createArrow(arrowCordinate.x,arrowCordinate.y));
if(dartCordinate.y == 25){
dartCordinate.y=0,dartCordinate.inc=dartCordinate.inc+1;
if(dartCordinate.inc == 10) process.exit(0);
}
process.stdout.cursorTo(dartCordinate.x,dartCordinate.y);
var dart = new Array(10).join("**||\n");
return dart;
};
var createArrow = function(x,y){
if(arrowCordinate.y >= dartCordinate.y && arrowCordinate.y <= dartCordinate.y + 10 && x == 3){
score++;
};
var arrow = "<" + new Array(5).join("=");
process.stdout.cursorTo(x,y);
return arrow;
};
var moveDart = function(dart){
var moving = setInterval(function(){
var newDart = createEnv(dartCordinate.x,dartCordinate.y++);
process.stdout.write(newDart);
},100);
}
keypress(process.stdin);
var newArrow1 = function(x,y){
var a = setInterval(function(){
arrowCordinate.x--,arrowCordinate.y;
if(arrowCordinate.x == 2){
arrowCordinate = {x:130,y:20};
clearInterval(a);
}
process.stdout.write(createArrow(arrowCordinate.x,arrowCordinate.y));
},9);
}
var moveArrow = function(){
var newArrow = newArrow1(arrowCordinate.x--,arrowCordinate.y);
};
process.stdin.on("keypress",function(ch,key){
if(key.name == "up" && arrowCordinate.x == 130 && arrowCordinate.y == 20) moveArrow();
if(key.name == "c") process.exit();
});
var start = function(){
var dart = createEnv();
moveDart(dart);
};
start();
process.stdin.setRawMode(true);
process.stdin.resume();