Sammlung
This commit is contained in:
47
Sammlung/Praktikum/3/ias_p2_a0.21/js/bot/bot.js
Normal file
47
Sammlung/Praktikum/3/ias_p2_a0.21/js/bot/bot.js
Normal file
@ -0,0 +1,47 @@
|
||||
var bot1ID = 0;
|
||||
var bot2ID = 0;
|
||||
|
||||
function randomizer(los_nr){
|
||||
return (Math.random() * (charge_data[los_nr]['startPreis'] - charge_data[los_nr]['minPreis']) + charge_data[los_nr]['minPreis']);
|
||||
};
|
||||
function buyBot(bot){
|
||||
los_nr = document.getElementById('los_nr').value;
|
||||
var bet = randomizer(los_nr);
|
||||
|
||||
if(charge_data[los_nr]['vkPreis'] < bet){
|
||||
setBotButtonStyle(bot, 'buyAction');
|
||||
var botname = 'Bot' + bot;
|
||||
kaufen(botname);
|
||||
|
||||
}
|
||||
};
|
||||
function botStart(bot){
|
||||
setBotButtonStyle(bot, 'active');
|
||||
|
||||
if(bot == 1){
|
||||
bot1ID = setInterval(function(){buyBot(1)}, 1000);
|
||||
}
|
||||
else if(bot == 2){
|
||||
bot2ID = setInterval(function(){buyBot(2)}, 1000);
|
||||
}
|
||||
else{
|
||||
alert("Fehler beim Aktivieren eines Bots");
|
||||
}
|
||||
|
||||
};
|
||||
function botStop(bot){
|
||||
setBotButtonStyle(bot, 'inactive');
|
||||
|
||||
if(bot == 1){
|
||||
clearInterval(bot1ID);
|
||||
bot1ID = 0;
|
||||
|
||||
}
|
||||
else if(bot == 2){
|
||||
clearInterval(bot2ID);
|
||||
bot2ID = 0;
|
||||
}
|
||||
else{
|
||||
alert("Fehler beim Aktivieren eines Bots");
|
||||
}
|
||||
};
|
56
Sammlung/Praktikum/3/ias_p2_a0.21/js/bot/botButtonStyle.js
Normal file
56
Sammlung/Praktikum/3/ias_p2_a0.21/js/bot/botButtonStyle.js
Normal file
@ -0,0 +1,56 @@
|
||||
function setBotButtonStyle(bot, style){
|
||||
var htmlID = 0;
|
||||
if(bot == 1){
|
||||
if(style == 'active'){
|
||||
document.getElementById('bot1Button').className = "botButtonActiveStyle";
|
||||
document.getElementById('bot1Button').onclick = function onclick(event){ botStop(1);};
|
||||
}
|
||||
else if(style == 'inactive'){
|
||||
document.getElementById('bot1Button').className = "botButtonInactiveStyle";
|
||||
document.getElementById('bot1Button').onclick = function onclick(event){ botStart(1);};
|
||||
}
|
||||
else if(style == 'buyAction'){
|
||||
document.getElementById('bot1Button').className = "botButtonBuyActionStyle";
|
||||
setTimeout(function(){ botButtonStyleCheck() }, 500);
|
||||
}
|
||||
else{
|
||||
alert("Fehler beim Stylen von Botbutton");
|
||||
}
|
||||
}
|
||||
|
||||
else if(bot == 2){
|
||||
if(style == 'active'){
|
||||
document.getElementById('bot2Button').className = "botButtonActiveStyle";
|
||||
document.getElementById('bot2Button').onclick = function onclick(event){ botStop(2);};
|
||||
}
|
||||
else if(style == 'inactive'){
|
||||
document.getElementById('bot2Button').className = "botButtonInactiveStyle";
|
||||
document.getElementById('bot2Button').onclick = function onclick(event){ botStart(2);};
|
||||
}
|
||||
else if(style == 'buyAction'){
|
||||
document.getElementById('bot2Button').className = "botButtonBuyActionStyle";
|
||||
setTimeout(function(){ botButtonStyleCheck() }, 500);
|
||||
}
|
||||
else{
|
||||
alert("Fehler beim Stylen von Botbutton");
|
||||
}
|
||||
}
|
||||
|
||||
else{
|
||||
alert("Fehler Auswahl eines Botbuttons f<>r Styling");
|
||||
}
|
||||
};
|
||||
function botButtonStyleCheck(){
|
||||
if(bot1ID != 0){
|
||||
setBotButtonStyle(1, 'active');
|
||||
}
|
||||
else{
|
||||
setBotButtonStyle(1, 'inactive');
|
||||
}
|
||||
if(bot2ID !=0){
|
||||
setBotButtonStyle(2, 'active');
|
||||
}
|
||||
else{
|
||||
setBotButtonStyle(2, 'inactive');
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user