From 08b3d8450e7dc8f0e540b22aea2e08181dea5f83 Mon Sep 17 00:00:00 2001 From: ilya201232 <44816360+ilya201232@users.noreply.github.com> Date: Fri, 8 Feb 2019 17:10:02 +0300 Subject: [PATCH 1/2] Moving to UTF-8 --- core/src/com/mygdx/game/Battle.java | 12 +++--- core/src/com/mygdx/game/ServerListener.java | 12 +++--- core/src/com/mygdx/game/SpaceBattle.java | 42 ++++++++++----------- core/src/model/EnergyPoint.java | 4 +- core/src/model/EnginePoint.java | 4 +- core/src/model/Modules/WeaponModule.java | 2 +- core/src/model/PhysicShip.java | 16 ++++---- core/src/model/WeaponPoint.java | 12 +++--- core/src/requests/PlayerActions.java | 2 +- 9 files changed, 53 insertions(+), 53 deletions(-) diff --git a/core/src/com/mygdx/game/Battle.java b/core/src/com/mygdx/game/Battle.java index f688932..a7c2c70 100644 --- a/core/src/com/mygdx/game/Battle.java +++ b/core/src/com/mygdx/game/Battle.java @@ -31,7 +31,7 @@ public class Battle { private Server server; private Array players; private Player enemy; - private long[] lastActTime;// . + private long[] lastActTime;//массив времени последних запросов игроков. Соответствует массиву игроков private AsteroidField asteroidField; @@ -71,8 +71,8 @@ public void received(Connection c, Object p) { players[0].getCurrentShip().setTransform(20, 20, 200); players[0].getCurrentShip().setTargetRotation(200); - enemy = new Player(); // enemy - enemy.setName("enemy");// + enemy = new Player(); //Искусственно создаем противника с именем enemy + enemy.setName("enemy");// и передаем игроку //PhysicShip tempShip=new Fury(55,30,0); //tempShip.create(world); enemy.setCurrentShip(new StarFighter(60, 30, 180)); @@ -80,7 +80,7 @@ public void received(Connection c, Object p) { // for (int i = 0; i < players.length; i++) { - players[i].getCurrentShip().setId(i + 1); // + players[i].getCurrentShip().setId(i + 1); //присваиваем идентификатор каждому кораблю System.out.println(players[i].getCurrentShip().getId()); } @@ -114,7 +114,7 @@ void update() { //} asteroidField.update(); - if (lrt + 5 < System.currentTimeMillis()) { + if (lrt + 20 < System.currentTimeMillis()) { System.out.println("x: " + players.get(0).getCurrentShip().getBody().getPosition().x + " y: " + players.get(0).getCurrentShip().getBody().getPosition().y + " r: " + Math.toDegrees(players.get(0).getCurrentShip().getBody().getAngle())); @@ -171,7 +171,7 @@ public void connect(ServPlayer player) { } void PlayerAct(PlayerActions acts) { - if (lastActTime[acts.getShipID() - 1] < acts.getTime())// + if (lastActTime[acts.getShipID() - 1] < acts.getTime())//проверяем является ли запрос новее предыдущего { players.get(acts.getShipID() - 1).getCurrentShip().setMovementPosition(acts.getMovementPosition()); players.get(acts.getShipID() - 1).getCurrentShip().setTargetRotation(acts.getTargetRotation()); diff --git a/core/src/com/mygdx/game/ServerListener.java b/core/src/com/mygdx/game/ServerListener.java index 18c5ead..7a31dff 100644 --- a/core/src/com/mygdx/game/ServerListener.java +++ b/core/src/com/mygdx/game/ServerListener.java @@ -9,24 +9,24 @@ public class ServerListener extends Listener { public void connected(Connection c) { - System.out.println(" " + c.getRemoteAddressTCP().getHostString()); + System.out.println("На сервер подключился " + c.getRemoteAddressTCP().getHostString()); BattleInfo info = new BattleInfo(); - info.setMessage(" : " + new Date().getHours() + ":" + new Date().getMinutes()); + info.setMessage("Сейчас время: " + new Date().getHours() + ":" + new Date().getMinutes()); c.sendTCP(info); } public void received(Connection c, Object p) { if (p instanceof Player) { Player player = (Player) p; - System.out.println(" :" + player.getName()); - System.out.println(":" + c.getReturnTripTime()); + System.out.println("Его имя:" + player.getName()); + System.out.println("Пинг:" + c.getReturnTripTime()); } } - // . + //Используется когда клиент покидает сервер. public void disconnected(Connection c) { - System.out.println(" !"); + System.out.println("Клиент покинул сервер!"); } } diff --git a/core/src/com/mygdx/game/SpaceBattle.java b/core/src/com/mygdx/game/SpaceBattle.java index bb14352..39bc9fd 100644 --- a/core/src/com/mygdx/game/SpaceBattle.java +++ b/core/src/com/mygdx/game/SpaceBattle.java @@ -57,15 +57,15 @@ public class SpaceBattle extends ApplicationAdapter { @Override public void create() { - // - server = new Server(32768, 32768);// + //создаем сервер + server = new Server(32768, 32768);//В скобочках размер буферов написания и объекта listener = new ServerListener(); players = new ArrayList(); waitQueue = new ArrayList(); World world = new World(new Vector2(0, 0), false); - // + //регистрируем класс kryo = server.getKryo(); kryo.register(BattleInfo.class); @@ -84,7 +84,7 @@ public void create() { kryo.register(PlayerActions.class); kryo.register(ServBattleInfo.class); - // + //регистрируем порт try { server.bind(tcpPort, udpPort); } catch (IOException e) { @@ -92,12 +92,12 @@ public void create() { e.printStackTrace(); } - // + //запускаем сервер server.start(); server.addListener(new Listener() { public void connected(Connection c) { - System.out.println(" " + c.getRemoteAddressTCP().getHostString()); + System.out.println("На сервер подключился " + c.getRemoteAddressTCP().getHostString()); } @@ -106,28 +106,28 @@ public void received(Connection c, Object p) { if (p instanceof BattleInfo) { BattleInfo info = (BattleInfo) p; if (info.getRequestType().equals(BattleInfo.RequestType.Adding)) { - System.out.println(" "); + System.out.println("Клиент просит добавления в очередь"); info.setConnectionID(c.getID()); info.setStatus("inQueue"); waitQueue.add(info); - System.out.println(" "); + System.out.println("Клиент добавлен в очередь"); info.setQueueTurn(waitQueue.size()); info.setQueueSize(waitQueue.size()); c.sendTCP(info); - System.out.println(" "); + System.out.println("Отправляем ответ"); } else if (info.getRequestType().equals(BattleInfo.RequestType.Info)) { - System.out.println(" "); + System.out.println("Клиент запрашивает информацию об очереди"); info.setQueueSize(waitQueue.size()); c.sendTCP(info); - System.out.println(" "); + System.out.println("Отправляем информацию"); } } else if (p instanceof HostStartInfo) { - System.out.println(" "); + System.out.println("Хост высылает начальные данные"); HostStartInfo hsi = (HostStartInfo) p; server.sendToTCP(hsi.getEnemyConID(), hsi); } else if (p instanceof ClientStartInfo) { - System.out.println(" "); + System.out.println("Клиент высылает начальные данные"); ClientStartInfo csi = (ClientStartInfo) p; server.sendToTCP(csi.getEnemyConID(), csi); } else if (p instanceof ServPlayer) { @@ -139,25 +139,25 @@ public void received(Connection c, Object p) { System.out.println("Id: " + player.getCurrentShip().getId()); battle = new Battle(battleID, server, players); - System.out.println(" " + player.getName()); + System.out.println("В бой вошел" + player.getName()); //System.out.println("Id: "+player.getConID()); } else if (p instanceof PlayerActions) { PlayerActions acts = (PlayerActions) p; - battle.PlayerAct(acts); + //battle.PlayerAct(acts); } } - // . + //Используется когда клиент покидает сервер. public void disconnected(Connection c) { - System.out.println(" !"); + System.out.println("Клиент покинул сервер!"); for (int i = 0; i < waitQueue.size(); i++) { if (waitQueue.get(i).getConnectionID() == c.getID()) { waitQueue.remove(i); } } - System.out.println(" "); + System.out.println("Клиент был удален из очереди"); } }); @@ -176,14 +176,14 @@ public void render() { waitQueue.get(1).setStatus("inBattle"); server.sendToTCP(waitQueue.get(0).getConnectionID(), waitQueue.get(0)); server.sendToTCP(waitQueue.get(1).getConnectionID(), waitQueue.get(1)); - System.out.println(" "); + System.out.println("Направвляем двух игроков в бой"); waitQueue.remove(1); waitQueue.remove(0); - System.out.println(" "); + System.out.println("Удаляем их из очереди"); } if (battle != null) { battle.update(); - //System.out.println(" "); + //System.out.println("Обновляем бои"); } } diff --git a/core/src/model/EnergyPoint.java b/core/src/model/EnergyPoint.java index ddbab51..5200099 100644 --- a/core/src/model/EnergyPoint.java +++ b/core/src/model/EnergyPoint.java @@ -82,8 +82,8 @@ void draw(SpriteBatch batch) { } } - void toShip(float x, float y, float rotation)// - {// + void toShip(float x, float y, float rotation)//телепортирует тело к кораблю на расстояние нормального смещения + {//на вход передаются координаты корабля energyModule.setTransform(x + localAnchor.x * (float) (Math.cos(Math.toRadians(rotation))) - localAnchor.y * (float) (Math.sin(Math.toRadians(rotation))), y + localAnchor.y * (float) (Math.cos(Math.toRadians(rotation))) + localAnchor.x * (float) (Math.sin(Math.toRadians(rotation))), rotation); } diff --git a/core/src/model/EnginePoint.java b/core/src/model/EnginePoint.java index 466eab4..f0bf543 100644 --- a/core/src/model/EnginePoint.java +++ b/core/src/model/EnginePoint.java @@ -94,8 +94,8 @@ void draw(SpriteBatch batch) { } } - void toShip(float x, float y, float rotation)// - {// + void toShip(float x, float y, float rotation)//телепортирует тело к кораблю на расстояние нормального смещения + {//на вход передаются координаты корабля engine.setTransform(x + localAnchor.x * (float) (Math.cos(Math.toRadians(rotation))) - localAnchor.y * (float) (Math.sin(Math.toRadians(rotation))), y + localAnchor.y * (float) (Math.cos(Math.toRadians(rotation))) + localAnchor.x * (float) (Math.sin(Math.toRadians(rotation))), rotation); } diff --git a/core/src/model/Modules/WeaponModule.java b/core/src/model/Modules/WeaponModule.java index c3a9b68..c26f6cc 100644 --- a/core/src/model/Modules/WeaponModule.java +++ b/core/src/model/Modules/WeaponModule.java @@ -46,7 +46,7 @@ public void create(World world) { this.world = world; } - public boolean shot(float l, Vector2 speedVector) //l - + public boolean shot(float l, Vector2 speedVector) //l - это расстояние от центра пушки до конца корабля { return false; } diff --git a/core/src/model/PhysicShip.java b/core/src/model/PhysicShip.java index c58e687..6883568 100644 --- a/core/src/model/PhysicShip.java +++ b/core/src/model/PhysicShip.java @@ -18,8 +18,8 @@ public class PhysicShip extends PhysicObject { private int movementPosition; private float rotationSpeed; private float targetRotation; - private float linearDamping;// 0.01 - private int rotationDirection;//-1- 1- 0- + private float linearDamping;//не ниже 0.01 + private int rotationDirection;//-1-влево 1-вправо 0-без вращения //private float enginePower; private WeaponPoint[] weapons; private EnginePoint[] engines; @@ -202,11 +202,11 @@ private void findRotDir() { while (shipRotation >= 360) { // shipRotation -= 360; // - } // 0 360 + } //Установление градусной меры корабля в рамки 0 до 360 while (shipRotation <= 0) { // shipRotation += 360; // } // - int spriteRotation = (int) targetRotation; // Int + int spriteRotation = (int) targetRotation; // Обрезаем значение до целого с помощью преобразование до Int while (spriteRotation >= 360) { spriteRotation -= 360; } @@ -215,8 +215,8 @@ private void findRotDir() { } //shipRotation=(Math.toDegrees(ship.getRotation())>360)?(float)Math.toDegrees(ship.getRotation())-360:(float)Math.toDegrees(ship.getRotation()); //spriteRotation=(sprite.getRotation()>360)?sprite.getRotation()-360:sprite.getRotation(); - int internalArc = Math.abs(shipRotation - spriteRotation); // - int externalArc = 360 - internalArc; // + int internalArc = Math.abs(shipRotation - spriteRotation); //Находим внешнее и внутренне растояние в градусах между + int externalArc = 360 - internalArc; // фазой корабля и штурвала /*if(internalArcexternalArc) ship.setRotationDirection(-1); } else ship.setRotationDirection(0);*/ - int tempShip = (shipRotation < 180) ? shipRotation + 360 : shipRotation;// 360 0 + int tempShip = (shipRotation < 180) ? shipRotation + 360 : shipRotation;// Увеличиваем половину градусной окружности на 360 для того чтобы избежать проблемы при вычитании перехода через 0 int tempSprite = (spriteRotation < 180) ? spriteRotation + 360 : spriteRotation; if (Math.abs(tempShip - tempSprite) > rotationSpeed) { @@ -458,7 +458,7 @@ public static PhysicShip fromServ(ServShip servShip) { } else if (servShip.getName().equals("StarFighter")) { ship = new StarFighter(servShip.getX(), servShip.getY(), servShip.getRotation()); } else { - System.out.println(" "); + System.out.println("Корабль с данным именем не существует"); return null; } diff --git a/core/src/model/WeaponPoint.java b/core/src/model/WeaponPoint.java index c80b50e..867ef10 100644 --- a/core/src/model/WeaponPoint.java +++ b/core/src/model/WeaponPoint.java @@ -30,8 +30,8 @@ public WeaponPoint(World world) { public WeaponPoint(WeaponModule weapon, Vector2 localAnchor) { this.weapon = weapon; - weapon.setTransform(weapon.getX() + localAnchor.x, weapon.getY() + localAnchor.y, (float) Math.toDegrees(weapon.getAngle()));// - // , + weapon.setTransform(weapon.getX() + localAnchor.x, weapon.getY() + localAnchor.y, (float) Math.toDegrees(weapon.getAngle()));//смещаем координату тела до нужного положения перед его созданием + //следует также учитывать, что при создании любого корабля мы передаем телу его координаты this.localAnchor = localAnchor; jointDef = new WeldJointDef(); jointDef.bodyA = shipBody; //_______________________________WATCH A MISTAKE______________________ @@ -45,12 +45,12 @@ public WeaponPoint(WeaponModule weapon, Vector2 localAnchor) { public boolean installModule(WeaponModule weapon, Body shipBody, Vector2 localAnchor) { if (weapon.getType().equals(ModuleType.Weapon)) { this.weapon = weapon; - weapon.setTransform(weapon.getX() + localAnchor.x, weapon.getY() + localAnchor.y, (float) Math.toDegrees(weapon.getAngle()));// + weapon.setTransform(weapon.getX() + localAnchor.x, weapon.getY() + localAnchor.y, (float) Math.toDegrees(weapon.getAngle()));//смещаем координату тела до нужного положения перед его созданием this.localAnchor = localAnchor; jointDef = new WeldJointDef(); jointDef.bodyA = shipBody; jointDef.bodyB = weapon.getBody(); - jointDef.localAnchorA.set(localAnchor.x, localAnchor.y);// + jointDef.localAnchorA.set(localAnchor.x, localAnchor.y);//указываем координату точки корабля к которому прекрепляем тело jointDef.collideConnected = false; joint = world.createJoint(jointDef); @@ -90,8 +90,8 @@ void destroy() { weapon.destroy(); } - void toShip(float x, float y, float rotation)// - {// + void toShip(float x, float y, float rotation)//телепортирует тело к кораблю на расстояние нормального смещения + {//на вход передаются координаты корабля weapon.setTransform(x + localAnchor.x * (float) (Math.cos(Math.toRadians(rotation))) - localAnchor.y * (float) (Math.sin(Math.toRadians(rotation))), y + localAnchor.y * (float) (Math.cos(Math.toRadians(rotation))) + localAnchor.x * (float) (Math.sin(Math.toRadians(rotation))), rotation); } diff --git a/core/src/requests/PlayerActions.java b/core/src/requests/PlayerActions.java index 8c1ae74..eceeadd 100644 --- a/core/src/requests/PlayerActions.java +++ b/core/src/requests/PlayerActions.java @@ -5,7 +5,7 @@ public class PlayerActions { private int shipID; private int movementPosition; private float targetRotation; - private long time;// + private long time;//время создания запроса public PlayerActions() { time = System.currentTimeMillis(); From ecbc8a1b92efdce5f9b0ac547aac7c5b9212f331 Mon Sep 17 00:00:00 2001 From: ilya201232 <44816360+ilya201232@users.noreply.github.com> Date: Fri, 8 Feb 2019 17:19:09 +0300 Subject: [PATCH 2/2] Moving to UTF-8 --- core/src/com/mygdx/game/SpaceBattle.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/com/mygdx/game/SpaceBattle.java b/core/src/com/mygdx/game/SpaceBattle.java index 39bc9fd..d93f2ab 100644 --- a/core/src/com/mygdx/game/SpaceBattle.java +++ b/core/src/com/mygdx/game/SpaceBattle.java @@ -143,7 +143,7 @@ public void received(Connection c, Object p) { //System.out.println("Id: "+player.getConID()); } else if (p instanceof PlayerActions) { PlayerActions acts = (PlayerActions) p; - //battle.PlayerAct(acts); + battle.PlayerAct(acts); }