forked from dem08656775/newincrementalgame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
192 lines (167 loc) · 6.91 KB
/
game.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
const tweetbutton = document.getElementById("tweet");
console.log(tweetbutton);
var val = 0;
var version = 1;
var tickspeed = 1000;
var firstplayer = {
money: new Decimal(1),
generator1: new Decimal(0),
generator1bought: new Decimal(0),
generator1cost: new Decimal(1),
generator2: new Decimal(0),
generator2bought: new Decimal(0),
generator2cost: new Decimal('1e4'),
generator2mode: 1,
generator3: new Decimal(0),
generator3bought: new Decimal(0),
generator3cost: new Decimal('1e9'),
generator3mode: 2,
generator4: new Decimal(0),
generator4bought: new Decimal(0),
//generator4cost: 工事中,
generator5: new Decimal(0),
generator5bought: new Decimal(0),
//generator5cost: 工事中,
generator6: new Decimal(0),
generator6bought: new Decimal(0),
//generator6cost: 工事中,
generator7: new Decimal(0),
generator7bought: new Decimal(0),
//generator7cost: 工事中,
generator8: new Decimal(0),
generator8bought: new Decimal(0),
//generator8cost: 工事中,
accelerator1: new Decimal(0),
accelerator1bought: new Decimal(0),
accelerator1cost: new Decimal(10),
tickspeed: 1000,
saveversion: version
}
var player = $.extend(true,{},firstplayer)
function update(){
player.money = player.money.add(player.generator1)
if(player.generator2mode == 0)player.money = player.money.add(player.generator2.mul(1e2))
if(player.generator2mode == 1)player.generator1 = player.generator1.add(player.generator2)
if(player.generator3mode == 0)player.money = player.money.add(player.generator3.mul(1e6))
if(player.generator3mode == 1)player.generator1 = player.generator1.add(player.generator3.mul(1e3))
if(player.generator3mode == 2)player.generator2 = player.generator2.add(player.generator3)
player.generator3 = player.generator3.add(player.generator4)
player.generator4 = player.generator4.add(player.generator5)
player.generator5 = player.generator5.add(player.generator6)
player.generator6 = player.generator6.add(player.generator7)
player.generator7 = player.generator7.add(player.generator8)
tickspeed = 1000 / player.accelerator1.add(10).log10()
console.log(tickspeed)
updatetext()
setTimeout(update, tickspeed)
}
function updatetext(){
$("#coinamount").text('ポイント: '+ player.money.toExponential(3))
$("#tickspeed").text('間隙: ' + Math.round(tickspeed) + '毛秒')
$("#generator1").text('発生器1: ' + player.generator1)
$("#generator2").text('発生器2: ' + player.generator2)
$("#generator3").text('発生器3: ' + player.generator3)
$("#accelerator1").text('時間加速器1: ' + player.accelerator1)
$("#button1").text('購入 コスト: ' + player.generator1cost.toExponential(1))
$("#button2").text('購入 コスト: ' + player.generator2cost.toExponential(1))
$("#button3").text('購入 コスト: ' + player.generator3cost.toExponential(1))
$("#abutton1").text('購入 コスト: ' + player.accelerator1cost.toExponential(1))
$("#generator2mode").text('モード: '+player.generator2mode)
$("#generator3mode").text('モード: '+player.generator3mode)
if (!tweetbutton.firstChild){
const anchor = document.createElement('a');
anchor.className = 'twitter-hashtag-button';
anchor.innerText = 'Tweet #新しい放置ゲーム';
tweetbutton.appendChild(anchor);
}
tweetbutton.firstChild.setAttribute('href','https://twitter.com/intent/tweet?text=ポイント:'+player.money+'%0Adem08656775.github.io/newincrementalgame%0A&hashtags=新しい放置ゲーム');
}
function calcbought(){
var v = player.generator1cost.toNumber()
while(v>1){
v /= 10;
player.generator1bought = player.generator1bought.add(1)
}
}
function save(){
console.log(JSON.stringify(player))
localStorage.setItem("playerStored", JSON.stringify(player));
}
function load() {
$.extend(true, player, JSON.parse(localStorage.getItem("playerStored")));
player.money = new Decimal(player.money)
player.generator1 = new Decimal(player.generator1)
player.generator1bought = new Decimal(player.generator1bought)
player.generator1cost = new Decimal(player.generator1cost)
player.generator2 = new Decimal(player.generator2)
player.generator2bought = new Decimal(player.generator2bought)
player.generator2cost = new Decimal(player.generator2cost)
player.generator2mode = parseInt(player.generator2mode)
player.generator3 = new Decimal(player.generator3)
player.generator3bought = new Decimal(player.generator3bought)
player.generator3cost = new Decimal(player.generator3cost)
player.generator4 = new Decimal(player.generator4)
player.generator5 = new Decimal(player.generator5)
player.generator6 = new Decimal(player.generator6)
player.generator7 = new Decimal(player.generator7)
player.generator8 = new Decimal(player.generator8)
player.accelerator1 = new Decimal(player.accelerator1)
player.accelerator1bought = new Decimal(player.accelerator1bought)
player.accelerator1cost = new Decimal(10).pow(player.accelerator1bought.add(1).mul(player.accelerator1bought.add(2)).div(2))
player.saveversion = version
}
load()
$("#button1").on('click',function(){
if(player.money.greaterThanOrEqualTo(player.generator1cost)){
player.money = player.money.sub(player.generator1cost)
player.generator1 = player.generator1.add(1)
player.generator1bought = player.generator1bought.add(1)
player.generator1cost = player.generator1cost.mul(10)
updatetext()
}
})
$("#button2").on('click',function(){
if(player.money.greaterThanOrEqualTo(player.generator2cost)){
player.money = player.money.sub(player.generator2cost)
player.generator2 = player.generator2.add(1)
player.generator2bought = player.generator2bought.add(1)
player.generator2cost = player.generator2cost.mul(100)
updatetext()
}
})
$("#button3").on('click',function(){
if(player.money.greaterThanOrEqualTo(player.generator3cost)){
player.money = player.money.sub(player.generator3cost)
player.generator3 = player.generator3.add(1)
player.generator3bought = player.generator3bought.add(1)
player.generator3cost = player.generator3cost.mul(1000)
updatetext()
}
})
$("#abutton1").on('click',function(){
if(player.money.greaterThanOrEqualTo(player.accelerator1cost)){
player.money = player.money.sub(player.accelerator1cost)
player.accelerator1 = player.accelerator1.add(1)
player.accelerator1bought = player.accelerator1bought.add(1)
player.accelerator1cost = player.accelerator1cost.mul(player.accelerator1bought.add(1).pow_base(10))
updatetext()
}
})
$("#modebutton2").on('click',function(){
player.generator2mode += 1
if(player.generator2mode == 2) player.generator2mode = 0
updatetext()
})
$("#modebutton3").on('click',function(){
player.generator3mode += 1
if(player.generator3mode == 3) player.generator3mode = 0
updatetext()
})
$("#resetbutton").on('click',function(){
if(confirm('リセット?')){
player = $.extend(true,{},firstplayer)
updatetext()
}
})
setTimeout(update, tickspeed)
setInterval(save,2000)