<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=0">
<title>ARAGON | BATTLE</title>
<link rel="stylesheet" href="file:///android_asset/client/css/boss.css">
</head>
<body>
<div class="hp-border"></div>
<div class="box">
<div class="hp-line"></div>
</div>
<div class="boss-name">JUNGLER</div>
<div class="chat">
<div class="users-count"></div>
<div class="chat-box"></div>
<div class="user-data">
<input class="user-name" placeholder="nickname" disabled>
<button class="send-to-chat">Send</button>
<textarea class="chat-message" disabled></textarea>
</div>
</div>
<section>
<div class="boss"></div>
<div class="achivements">
<div class="armor"></div>
<div class="sword"></div>
<div class="heal"></div>
</div>
<div class="user-border"></div>
<div class="user-hp"></div>
</section>
<script src="file:///android_asset/client/lib/jquery.min.js"></script>
<script src="file:///android_asset/client/public/node_modules/socket.io/socket.io.js"></script>
<script src="file:///android_asset/client/scripts/boss.js"></script>
</body>
</html>
package com.example.caveshadows;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.view.View;
public class MainActivity extends Activity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.onStart();
setContentView(R.layout.activity_main);
webView = (WebView)findViewById(R.id.web);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
@TargetApi(Build.VERSION_CODES.N)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return false;
}
});
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.loadUrl("file:///android_asset/client/public/boss.html");
}
@Override
protected void onResume() {
//webView.getSettings().setAppVisible(true, this);
super.onResume();
if (Build.VERSION.SDK_INT >= 19) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (webView.canGoBack()) {
webView.goBack();
} else {
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
}
var host = 'http://localhost:3000/';
var socket = io(host, {
upgrade: false,
reconnection: true,
reconnectionDelay: 0,
reconnectionDelayMax : 500,
reconnectionAttempts: 99999
});
var hp,hp2,connections,x,message,msg,x2;
var boss_damage = Math.floor((Math.random() * 1000) + 500);
var user_damage = Math.floor((Math.random() * 31000) + 1000);
var bonus_sword_damage = 10000;
var max_user_hp = 30000,user_hp = max_user_hp,x2,lose,win,draw;
var heal=3000,youlose='Вы проиграли, следите за здоровьем!(Оно восстановится в течении 15 секунд.)';
$.getJSON('https://api.ipify.org?format=json', function(data){
socket.emit('banned',data.ip);
});
socket.emit('hp line for all');
var count=25200;
var counter=setInterval(timer, 1000);
function timer() {
count--;
if (count <= 0 || lose == 'lose' || win == 'win' || draw == 'draw') {
clearInterval(counter);
//localStorage.clear();
localStorage.setItem('hp', max_user_hp);
}
}
socket.on('connect', () => {
user_hp = localStorage.getItem('hp');
x2 = localStorage.getItem('w');
localStorage.clear();
socket.emit('user fight', user_hp,x2);
});
$('.user-name').click(function() {
$('.user-name').css({'top':'0px','position':'absolute','z-index':'9999'});
});
$('.chat').click(function() {
alert('На данный момент чат отключён - попробуйте позже.');
});
$('.boss').click(function() {
window.onfocus = function () {
socket.emit('new session');
};
user_hp = user_hp-boss_damage;
x2 = user_hp/max_user_hp*100;
/*if(user_hp <= 0 || user_hp >= max_user_hp) {
localStorage.setItem('hp', max_user_hp);
user_hp = max_user_hp;
x2 = 100;
}*/
if(user_hp >= max_user_hp) {
user_hp = max_user_hp;
x2 = 100;
}
localStorage.setItem('hp', user_hp);
localStorage.setItem('w', x2);
socket.emit('boss fight', user_damage);
socket.emit('user fight', user_hp,x2);
$('.hp-line').css("width", x+'%');
$('.user-hp').css("width", x2+'%');
});
$('.sword').click(function() {
user_hp = user_hp-boss_damage;
x2 = user_hp/max_user_hp*100;
/*if(user_hp <= 0 || user_hp >= max_user_hp) {
localStorage.setItem('hp', max_user_hp);
user_hp = max_user_hp;
x2 = 100;
}*/
if(user_hp >= max_user_hp) {
user_hp = max_user_hp;
x2 = 100;
}
localStorage.setItem('hp', user_hp);
localStorage.setItem('w', x2);
socket.emit('boss fight', user_damage+bonus_sword_damage);
socket.emit('user fight', user_hp,x2);
$('.hp-line').css("width", x+'%');
$('.user-hp').css("width", x2+'%');
});
$('.heal').click(function() {
user_hp = user_hp+heal;
x2 = user_hp/max_user_hp*100;
/*if(user_hp <= 0 || user_hp >= max_user_hp) {
localStorage.setItem('hp', max_user_hp);
user_hp = max_user_hp;
x2 = 100;
}*/
if(user_hp >= max_user_hp) {
user_hp = max_user_hp;
x2 = 100;
}
localStorage.setItem('hp', user_hp);
localStorage.setItem('w', x2);
socket.emit('user fight', user_hp+heal,x2);
$('.user-hp').css("width", x2+'%');
});
var healtimer = setInterval(timer2, 3000);
function timer2() {
user_hp = user_hp+heal;
x2 = user_hp/max_user_hp*100;
if(user_hp <= 0) {
//localStorage.setItem('hp', max_user_hp);
//user_hp = max_user_hp;
}
localStorage.setItem('hp', user_hp);
localStorage.setItem('w', x2);
socket.emit('user fight', user_hp,x2);
$('.user-hp').css("width", x2+'%');
/*if(user_hp >= max_user_hp || user_hp <= 0) {
user_hp = max_user_hp;
x2 = 100;
}*/
if(user_hp >= max_user_hp) {
user_hp = max_user_hp;
x2 = 100;
}
}
/*$('.send-to-chat').click(function() {
name = $(".user-name").val();
msg = $(".chat-message").val();
socket.emit('chat message', msg);
});*/
socket.on('realtime hp', function(data) {
hp = data;
$('.hp-border').html(hp);
});
$('.hp-border').html(hp);
$('.user-hp').css("width", x2+'%');
socket.on('disconnect', function(data) {
//alert('Вы отключены от сервера!');
//alert(data);
// window.location.replace(host + 'serverfull');
});
socket.on('connections', function(data) {
$('.users-count').html(data);
});
socket.on('hp line width', function(data) {
x = data;
$('.hp-line').css("width", x+'%');
$('.user-hp').css("width", x2+'%');
});
socket.on('w', function(data) {
x2 = data;
$('.user-hp').css("width", x2+'%');
});
socket.on('chat msg', function(data) {
message = data;
$(".chat-box").append("<li class='message'><div class='name'></div>" + message + "</li>");
});
socket.on('ban', function(data) {
alert(data);
});
socket.on('win', function(data) {
alert('You win this battle!');
win = 'win';
//window.location.replace("/");
});
socket.on('lose', function(data) {
$(".chat-box").append("<li class='message'><div class='name'></div>" + youlose + "</li>");
alert('You lose this battle!');
lose = 'lose';
hp = maxhp;
});
socket.on('server full', function(data) {
alert(data);
});
socket.on('draw', function(data) {
alert('DRAW!Revenge!');
draw = 'draw';
});
window.onbeforeunload = function() {
//return "Данные не сохранены. Точно перейти?";
};
<script src="file:///android_asset/client/public/node_modules/socket.io/socket.io.js"></script>