Advertisement
Guest User

Untitled

a guest
May 28th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.23 KB | None | 0 0
  1. package com.example.gwynbleidd.verstkagame;
  2.  
  3.  
  4. import android.app.Dialog;
  5. import android.content.Context;
  6. import android.content.res.Resources;
  7. import android.graphics.Bitmap;
  8. import android.graphics.BitmapFactory;
  9. import android.graphics.Canvas;
  10. import android.graphics.Color;
  11. import android.graphics.Paint;
  12. import android.view.MotionEvent;
  13. import android.view.View;
  14. import android.widget.ImageView;
  15. import android.widget.Toast;
  16.  
  17. import com.example.gwynbleidd.verstkagame.UnitClasses.Humans.Archer;
  18. import com.example.gwynbleidd.verstkagame.UnitClasses.Humans.Mage;
  19. import com.example.gwynbleidd.verstkagame.UnitClasses.Unit;
  20.  
  21.  
  22. public class BattleField extends View {
  23. Resources resources;
  24. Context context;
  25. Integer cellWidth = 1;
  26. Integer cellHeight = 1;
  27. Integer indexOfCellY = 8;
  28. Integer indexOfCellX = 6;
  29. Integer deltaScreenX = 0;
  30. Integer deltaScreenY = 0;
  31. Integer indexOfCellOnClickY;
  32. Integer indexOfCellOnClickX;
  33. Integer width;
  34. Integer height;
  35. Integer previousIndexOfCellY = 8;
  36. Integer previousIndexOfCellX = 6;
  37. Integer befpreviousIndexOfCellX = 6;
  38. Integer befpreviousIndexOfCellY = 8;
  39. Integer[][] matrix = new Integer[7][9];
  40. Unit[][] unitMatrix = new Unit[7][9];
  41. Bitmap frame;
  42. Bitmap board1;
  43. Bitmap redImage;
  44. Bitmap blueImage;
  45. //Bitmap archImage;
  46. // Bitmap arch2Image;
  47. Bitmap red2Image;
  48. Bitmap armor;
  49. Bitmap turn;
  50. Bitmap turn2;
  51. Bitmap iconattack;
  52. Bitmap btnMenuImage;
  53. ImageView imageView;
  54. OurButton btnTurn;
  55. OurButton btnMenu;
  56. Boolean TurnOfSide;
  57. Canvas canvas;
  58. public long startTime1 = 0;
  59. public long elapsedTime1 = 0;
  60. MotionEvent previousEvent;
  61. Boolean DoubleClickCheck;
  62. Integer Unitx;
  63. Integer UnitY;
  64. Boolean DrawPermissed = false;
  65. Boolean UnitChosen = false;
  66.  
  67.  
  68.  
  69. Bitmap groundImage;
  70.  
  71. Bitmap blue2Image;
  72. Bitmap groundCellImage;
  73.  
  74.  
  75. public Integer getCellWidth() {
  76. return cellWidth;
  77. }
  78. public void setCellWidth(Integer cellWidth) {
  79. this.cellWidth = cellWidth;
  80. }
  81. public Integer getCellHeight() {
  82. return cellHeight;
  83. }
  84. public void setCellHeight(Integer cellHeight) {
  85. this.cellHeight = cellHeight;
  86. }
  87. public Integer getIndexOfCellY() {
  88. return indexOfCellY;
  89. }
  90. public void setIndexOfCellY(Integer indexOfCellY) {
  91. this.indexOfCellY = indexOfCellY;
  92. }
  93. public Integer getIndexOfCellX() {
  94. return indexOfCellX;
  95. }
  96. public void setIndexOfCellX(Integer indexOfCellX) {
  97. this.indexOfCellX = indexOfCellX;
  98. }
  99. public Integer getDeltaScreenX() {
  100. return deltaScreenX;
  101. }
  102. public void setDeltaScreenX(Integer deltaScreenX) {
  103. this.deltaScreenX = deltaScreenX;
  104. }
  105. public Integer getDeltaScreenY() {
  106. return deltaScreenY;
  107. }
  108. public void setDeltaScreenY(Integer deltaScreenY) {
  109. this.deltaScreenY = deltaScreenY;
  110. }
  111.  
  112. Paint p;
  113. Unit redUnit;
  114. Unit blueUnit;
  115. Archer archer;
  116. Paint pBlack;
  117. Paint pGreen;
  118. Paint pYellow;
  119. Paint pText;
  120. Paint pHealthBar;
  121. Paint pHealthBarBounds;
  122. Paint pRed;
  123.  
  124. Dialog menu;
  125.  
  126.  
  127. public BattleField(Context context, Integer width, Integer height, Integer[][] matrix1, Integer[][] matrix2, String[][] nameMatrix, Integer[][] HPMatrix, Boolean[][] canAttackMatrix, Boolean[][] OWNERmatrix, Integer[][] VALUABLEMOVEMatrix, Dialog menu) {
  128. super(context);
  129. this.context = context;
  130. this.menu = menu;
  131. this.cellWidth = width / 8;
  132. this.cellHeight = height / 12;
  133. this.deltaScreenX = width / 8;
  134. this.deltaScreenY = height / 6;
  135. this.width = width;
  136. this.height = height;
  137. this.resources = getResources();
  138. this.startTime1 = System.currentTimeMillis();
  139. turn = BitmapFactory.decodeResource(resources, R.drawable.turn);
  140. turn2 = BitmapFactory.decodeResource(resources, R.drawable.turn2);
  141. btnTurn = new OurButton(turn, turn2, resources, cellWidth * 2, cellHeight / 2);
  142. board1 = BitmapFactory.decodeResource(resources, R.drawable.board1);
  143.  
  144.  
  145. btnMenuImage = BitmapFactory.decodeResource(resources, R.drawable.gear);
  146.  
  147. btnMenu = new OurButton(btnMenuImage, btnMenuImage, resources , width / 17, height / 33);
  148.  
  149.  
  150. frame = BitmapFactory.decodeResource(resources, R.drawable.cutramka);
  151. frame = Bitmap.createScaledBitmap(frame, cellWidth, cellHeight, false);
  152. redImage = BitmapFactory.decodeResource(resources, R.drawable.mage);
  153. blueImage = BitmapFactory.decodeResource(resources, R.drawable.swordman);
  154. //archImage = BitmapFactory.decodeResource(resources, R.drawable.archer);
  155. blue2Image = BitmapFactory.decodeResource(resources, R.drawable.swordman2);
  156. //arch2Image = BitmapFactory.decodeResource(resources, R.drawable.archer2);
  157.  
  158.  
  159.  
  160. groundImage = BitmapFactory.decodeResource(resources, R.drawable.ground_test);
  161.  
  162. groundCellImage = Bitmap.createScaledBitmap(groundImage, cellWidth, cellHeight, false);
  163.  
  164.  
  165. red2Image = BitmapFactory.decodeResource(resources, R.drawable.mage2);
  166.  
  167.  
  168. armor = BitmapFactory.decodeResource(resources, R.drawable.armor);
  169. iconattack = BitmapFactory.decodeResource(resources, R.drawable.iconattack);
  170. // redUnit = new Unit("red", resources, cellWidth, cellHeight, redImage, groundCellImage, false, 10, 10, 0, 2, 1, 100);
  171. // blueUnit = new Unit("blue", resources, cellWidth, cellHeight, blueImage, groundCellImage, false, 20, 5, 0, 2, 1, 100);
  172. // archer = new Archer("blue", resources, cellWidth, cellHeight, groundCellImage, false, 10, 10, 0, 2, 1);
  173. DoubleClickCheck = false;
  174. TurnOfSide = true;
  175.  
  176.  
  177.  
  178.  
  179. /* for (int i = 0; i < 6; i++) {
  180.  
  181. this.matrix[i][0] = 1;
  182. this.unitMatrix[i][0] = new Archer("blarcher", getResources(),cellWidth, cellHeight, archImage, false,10,5,0,2,1);
  183.  
  184. }
  185. for (int i = 0; i < 6; i++) {
  186.  
  187. this.matrix[i][1] = 1;
  188. this.unitMatrix[i][1] = new Unit("blue", getResources(),cellWidth, cellHeight, blueImage, false,25,5,0,1,2);
  189.  
  190. }
  191. for (int i = 0; i < 6; i++) {
  192.  
  193. this.matrix[i][6] = 1;
  194. this.unitMatrix[i][6] = new Unit("red", getResources(),cellWidth, cellHeight, redImage, false,15,10,0,1,2);
  195.  
  196. }
  197. for (int i = 0; i < 6; i++) {
  198.  
  199. this.matrix[i][7] = 1;
  200. this.unitMatrix[i][7] = new Archer("rarcher", getResources(),cellWidth, cellHeight, archImage, false,10,5,0,2,1);
  201.  
  202. } */
  203.  
  204. if (VALUABLEMOVEMatrix == null || nameMatrix == null || OWNERmatrix == null || HPMatrix == null || canAttackMatrix == null) {
  205.  
  206. //Расстановка второго игрока
  207. for (int i = 0; i < 7; i++) {
  208. for (int j = 0; j < 4; j++) {
  209. if (matrix2[i][j] == 0) {
  210. this.unitMatrix[i][j] = new Unit("ground", resources, cellWidth, cellHeight, groundCellImage, true);
  211. } else if (matrix2[i][j] == 1) {
  212. this.unitMatrix[i][j] = new Mage("Mage", resources, cellWidth, cellHeight, red2Image, groundCellImage, false, 15, 10, 0, 2, 2);
  213. this.unitMatrix[i][j].Owner = false;
  214. } else if (matrix2[i][j] == 2) {
  215. this.unitMatrix[i][j] = new Unit("Swordman", resources, cellWidth, cellHeight, blue2Image, groundCellImage, false, 25, 5, 0, 1, 2, 100);
  216. this.unitMatrix[i][j].Owner = false;
  217. } else if (matrix2[i][j] == 3) {
  218. this.unitMatrix[i][j] = new Archer("Archer", resources, cellWidth, cellHeight, groundCellImage, false, 25, 5, 0, 2, 2);
  219. this.unitMatrix[i][j].Owner = false;
  220. }
  221. }
  222. }
  223.  
  224. //Расстановка первого игрока
  225. for (int i = 0; i < 7; i++) {
  226. for (int j = 4; j < 9; j++) {
  227. if (matrix1[i][j] == 0) {
  228. this.unitMatrix[i][j] = new Unit("ground", resources, cellWidth, cellHeight, groundCellImage, true);
  229. } else if (matrix1[i][j] == 1) {
  230. this.unitMatrix[i][j] = new Mage("Mage", resources, cellWidth, cellHeight, redImage, groundCellImage, false, 15, 10, 0, 2, 2);
  231. this.unitMatrix[i][j].Owner = true;
  232. } else if (matrix1[i][j] == 2) {
  233. this.unitMatrix[i][j] = new Unit("Swordman", resources, cellWidth, cellHeight, blueImage, groundCellImage, false, 25, 5, 0, 1, 2, 100);
  234. this.unitMatrix[i][j].Owner = true;
  235. } else if (matrix1[i][j] == 3) {
  236. this.unitMatrix[i][j] = new Archer("Archer", resources, cellWidth, cellHeight, groundCellImage, false, 25, 5, 0, 2, 2);
  237. this.unitMatrix[i][j].Owner = true;
  238. }
  239. }
  240. }
  241.  
  242. } else {
  243.  
  244. for (int i = 0; i < 7; i++) {
  245. for (int j = 0; j < 9; j++) {
  246. if (nameMatrix[i][j].equals("Archer")) {
  247. if (OWNERmatrix[i][j])
  248. this.unitMatrix[i][j] = new Archer("Archer", resources, cellWidth, cellHeight, groundCellImage, false, 25, 5, 0, 2, 2);
  249. else
  250. this.unitMatrix[i][j] = new Archer("Archer", resources, cellWidth, cellHeight, groundCellImage, false, 25, 5, 0, 2, 2);
  251. this.unitMatrix[i][j].HP = HPMatrix[i][j];
  252. this.unitMatrix[i][j].canAttack = canAttackMatrix[i][j];
  253. this.unitMatrix[i][j].Owner = OWNERmatrix[i][j];
  254. this.unitMatrix[i][j].VALUABLEMOVE = VALUABLEMOVEMatrix[i][j];
  255. } else if (nameMatrix[i][j].equals("Swordman")) {
  256. if (OWNERmatrix[i][j])
  257. this.unitMatrix[i][j] = new Unit("Swordman", resources, cellWidth, cellHeight, blueImage, groundCellImage, false, 25, 5, 0, 1, 2, 100);
  258. else
  259. this.unitMatrix[i][j] = new Unit("Swordman", resources, cellWidth, cellHeight, blue2Image, groundCellImage, false, 25, 5, 0, 1, 2, 100);
  260. this.unitMatrix[i][j].HP = HPMatrix[i][j];
  261. this.unitMatrix[i][j].canAttack = canAttackMatrix[i][j];
  262. this.unitMatrix[i][j].Owner = OWNERmatrix[i][j];
  263. this.unitMatrix[i][j].VALUABLEMOVE = VALUABLEMOVEMatrix[i][j];
  264. } else if (nameMatrix[i][j].equals("Mage")) {
  265. if (OWNERmatrix[i][j])
  266. this.unitMatrix[i][j] = new Mage("Mage", resources, cellWidth, cellHeight, redImage, groundCellImage, false, 15, 10, 0, 2, 2);
  267. else
  268. this.unitMatrix[i][j] = new Mage("Mage", resources, cellWidth, cellHeight, red2Image, groundCellImage, false, 15, 10, 0, 2, 2);
  269. this.unitMatrix[i][j].HP = HPMatrix[i][j];
  270. this.unitMatrix[i][j].canAttack = canAttackMatrix[i][j];
  271. this.unitMatrix[i][j].Owner = OWNERmatrix[i][j];
  272. this.unitMatrix[i][j].VALUABLEMOVE = VALUABLEMOVEMatrix[i][j];
  273. } else
  274. this.unitMatrix[i][j] = new Unit("ground", resources, cellWidth, cellHeight, groundCellImage, true);
  275. }
  276. }
  277.  
  278. }
  279.  
  280.  
  281. p = new Paint();
  282. Timer t = new Timer(this, Integer.MAX_VALUE, 100);
  283. t.start();
  284.  
  285.  
  286.  
  287.  
  288.  
  289. pBlack = new Paint();
  290. pBlack.setColor(Color.BLACK);
  291. pBlack.setStrokeWidth(width / 150);
  292. pYellow = new Paint();
  293. pYellow.setColor(Color.YELLOW);
  294. pYellow.setStrokeWidth(width / 150);
  295. pYellow.setStyle(Paint.Style.STROKE);
  296. pGreen = new Paint();
  297. pGreen.setColor(Color.GREEN);
  298. pGreen.setStrokeWidth(width / 150);
  299. pGreen.setStyle(Paint.Style.STROKE);
  300. pRed = new Paint();
  301. pRed.setColor(Color.RED);
  302. pRed.setStrokeWidth(width / 150);
  303. pRed.setStyle(Paint.Style.STROKE);
  304. pHealthBarBounds = new Paint();
  305. pHealthBarBounds.setColor(Color.BLACK);
  306. pHealthBarBounds.setStyle(Paint.Style.STROKE);
  307. pHealthBarBounds.setStrokeWidth(width / 170);
  308. pHealthBar = new Paint();
  309. pHealthBar.setColor(Color.RED);
  310. pHealthBar.setStyle(Paint.Style.FILL);
  311. pHealthBar.setStrokeWidth(width / 200);
  312. pText = new Paint();
  313. pText.setTextSize(cellHeight * 0.3f);
  314.  
  315. board1 = Bitmap.createScaledBitmap(board1, width, height, false);
  316. armor = Bitmap.createScaledBitmap(armor, cellWidth * 2 / 3, cellHeight * 2 / 3, false);
  317. iconattack = Bitmap.createScaledBitmap(iconattack, cellWidth * 2 / 3, cellHeight / 3, false);
  318.  
  319.  
  320. }
  321.  
  322.  
  323. @Override
  324. protected void onDraw(Canvas canvas) {
  325. canvas.drawBitmap(board1, 0f, 0f, p);
  326. btnMenu.draw(canvas, width * 16 / 17f, 0f);
  327. this.canvas = canvas;
  328. for (int i = 0; i < 9; i++) {
  329. canvas.drawLine(deltaScreenX, i * cellHeight + deltaScreenY, canvas.getWidth() - deltaScreenX, i * cellHeight + deltaScreenY, pBlack);
  330. }
  331.  
  332. for (int i = 0; i < 7; i++) {
  333. canvas.drawLine(i * cellWidth + deltaScreenX, deltaScreenY, i * cellWidth + deltaScreenX, canvas.getHeight() - deltaScreenY, pBlack);
  334. }
  335.  
  336.  
  337. for (int i = 0; i < 6; i++) {
  338. for (int j = 0; j < 8; j++) {
  339. unitMatrix[i][j].drawInCell(canvas, deltaScreenX + cellWidth * i * 1f, deltaScreenY + cellHeight * j * 1f);
  340. /* if (!unitMatrix[i][j].isGround()){
  341. if(!unitMatrix[i][j].Owner){
  342. canvas.drawBitmap(frame,deltaScreenX + cellWidth*i * 1f, deltaScreenY + cellHeight*j * 1f,p);
  343. }
  344. }*/
  345. }
  346.  
  347. }
  348.  
  349.  
  350.  
  351.  
  352. if (!unitMatrix[indexOfCellX][indexOfCellY].isGround()) {
  353. unitMatrix[indexOfCellX][indexOfCellY].drawOutCell(canvas, +cellWidth * 6, height - deltaScreenY);
  354. canvas.drawRect(cellWidth * 4.25f, cellHeight * 10.1f, cellWidth * 5.75f, cellHeight * 10.4f, pHealthBarBounds);
  355. canvas.drawRect(cellWidth * 4.25f, cellHeight * 10.1f, cellWidth * 5.75f - (1 - (float) unitMatrix[indexOfCellX][indexOfCellY].HP / (float) unitMatrix[indexOfCellX][indexOfCellY].MAXHP) * 1.5f * cellWidth, cellHeight * 10.4f, pHealthBar);
  356. canvas.drawText("Health Points : ", cellWidth * 1.5f, cellHeight * 10.35f, pText);
  357. canvas.drawBitmap(armor, cellWidth * 4.6f, cellHeight * 10.65f, p);
  358. canvas.drawBitmap(iconattack, cellWidth * 4.6f, cellHeight * 11.6f, p);
  359. canvas.drawText(unitMatrix[indexOfCellX][indexOfCellY].SHIELD.toString(), cellWidth * 4.85f, cellHeight * 11.1f, pText);
  360. canvas.drawText(unitMatrix[indexOfCellX][indexOfCellY].DMG.toString(), cellWidth * 4.85f, cellHeight * 11.85f, pText);
  361. if (unitMatrix[indexOfCellX][indexOfCellY].HP / 10 > 0)
  362. canvas.drawText(unitMatrix[indexOfCellX][indexOfCellY].HP.toString() + " / " + unitMatrix[indexOfCellX][indexOfCellY].MAXHP.toString(), cellWidth * 4.5f, cellHeight * 10.35f, pText);
  363. else
  364. canvas.drawText(" " + unitMatrix[indexOfCellX][indexOfCellY].HP.toString() + " / " + unitMatrix[indexOfCellX][indexOfCellY].MAXHP.toString(), cellWidth * 4.5f, cellHeight * 10.35f, pText);
  365.  
  366.  
  367.  
  368. }
  369.  
  370. btnTurn.draw(canvas, cellWidth * 3f, cellHeight * 1f);
  371.  
  372.  
  373. if (DrawPermissed) {
  374. if (TurnOfSide.equals(unitMatrix[indexOfCellX][indexOfCellY].Owner)) {
  375.  
  376.  
  377. for (int i = 0; i < 6; i++) {
  378. for (int j = 0; j < 8; j++) {
  379. if (!unitMatrix[indexOfCellX][indexOfCellY].isGround())
  380. if (unitMatrix[i][j].isGround()) {
  381. if (Math.abs(indexOfCellX - i) + Math.abs(indexOfCellY - j) <= unitMatrix[indexOfCellX][indexOfCellY].VALUABLEMOVE) {
  382. canvas.drawRect(i * cellWidth + deltaScreenX, j * cellHeight + deltaScreenY, (i + 1) * cellWidth + deltaScreenX, (j + 1) * cellHeight + deltaScreenY, pGreen);
  383. }
  384. } else {
  385. if ((Math.abs(indexOfCellX - i) + Math.abs(indexOfCellY - j) <= unitMatrix[indexOfCellX][indexOfCellY].RANGE) && (unitMatrix[indexOfCellX][indexOfCellY].Owner != unitMatrix[i][j].Owner) && unitMatrix[indexOfCellX][indexOfCellY].canAttack) {
  386. canvas.drawRect(i * cellWidth + deltaScreenX, j * cellHeight + deltaScreenY, (i + 1) * cellWidth + deltaScreenX, (j + 1) * cellHeight + deltaScreenY, pRed);
  387. }
  388. }
  389. }
  390. }
  391. }
  392. canvas.drawRect(indexOfCellX * cellWidth + deltaScreenX, indexOfCellY * cellHeight + deltaScreenY, (indexOfCellX + 1) * cellWidth + deltaScreenX, (indexOfCellY + 1) * cellHeight + deltaScreenY, pYellow);
  393. }
  394. }
  395.  
  396.  
  397. boolean firstTouch = false;
  398. long time = 0;
  399.  
  400. public boolean isDoubleClick(MotionEvent event) {
  401.  
  402. if (event.getAction() == event.ACTION_DOWN) {
  403. if (firstTouch && (System.currentTimeMillis() - time) <= 300 && (System.currentTimeMillis() - time) > 50) {
  404. //do stuff here for double tap
  405. Toast toast = Toast.makeText(context,
  406. befpreviousIndexOfCellX.toString() + befpreviousIndexOfCellY.toString(), Toast.LENGTH_SHORT);
  407. toast.show();
  408.  
  409. return true;
  410.  
  411. } else {
  412.  
  413.  
  414. firstTouch = true;
  415. time = System.currentTimeMillis();
  416. Toast toast = Toast.makeText(context,
  417. befpreviousIndexOfCellX.toString() + befpreviousIndexOfCellY.toString(), Toast.LENGTH_SHORT);
  418. toast.show();
  419.  
  420. }
  421. }
  422. return false;
  423. }
  424.  
  425.  
  426. @Override
  427. public boolean onTouchEvent(MotionEvent event) {
  428.  
  429. if (event.getX() >= (width * 16 / 17) && event.getY() <= height / 33) {
  430. btnMenu.isPressed = true;
  431. menu.show();
  432. }
  433.  
  434.  
  435. if (event.getX() > cellWidth * 3f && event.getY() >=cellHeight * 1f && event.getX() <= cellWidth * 3f + cellWidth*2 && event.getY() <=cellHeight * 1f + cellHeight/2 ){
  436. btnTurn.isPressed = !btnTurn.isPressed;
  437. for (int i = 0; i < 6; i++) {
  438. for (int j = 0; j < 8; j++) {
  439.  
  440. if (!unitMatrix[i][j].isGround()){
  441. if (unitMatrix[i][j].Owner.equals(TurnOfSide)){
  442. unitMatrix[i][j].VALUABLEMOVE = unitMatrix[i][j].MOVE;
  443. unitMatrix[i][j].canAttack = true;
  444. }
  445.  
  446. }
  447. }
  448.  
  449. }
  450. TurnOfSide = !TurnOfSide;
  451. }
  452.  
  453.  
  454. if ((event.getX() >= deltaScreenX) && (event.getX() <= cellWidth * 6 + deltaScreenX) && (event.getY() >= deltaScreenY) && (event.getY() <= cellHeight * 8 + deltaScreenY)) {
  455. DrawPermissed = true;
  456. for (int i = 1; i < 9; i++) {
  457. if (event.getY() > cellHeight * (i - 1) + deltaScreenY && event.getY() < cellHeight * i + deltaScreenY) {
  458. this.indexOfCellY = i - 1;
  459. }
  460. }
  461.  
  462. for (int i = 1; i < 7; i++) {
  463. if (event.getX() > cellWidth * (i - 1) + deltaScreenX && event.getX() < cellWidth * i + deltaScreenX) {
  464. this.indexOfCellX = i - 1;
  465. }
  466. }
  467.  
  468.  
  469.  
  470. if (!unitMatrix[indexOfCellX][indexOfCellY].isGround() && !isDoubleClick(event)) {
  471.  
  472.  
  473. }
  474. } else {
  475. indexOfCellX = 6;
  476. indexOfCellY = 8;
  477. DrawPermissed = false;
  478. }
  479.  
  480.  
  481. if ((event.getX() >= deltaScreenX) && (event.getX() <= cellWidth * 6 + deltaScreenX) && (event.getY() >= deltaScreenY) && (event.getY() <= cellHeight * 8 + deltaScreenY) && isDoubleClick(event)) {
  482. DrawPermissed = true;
  483.  
  484. for (int i = 1; i < 9; i++) {
  485. if (event.getY() > cellHeight * (i - 1) + deltaScreenY && event.getY() < cellHeight * i + deltaScreenY) {
  486. this.indexOfCellOnClickY = i - 1;
  487. }
  488. }
  489.  
  490. for (int i = 1; i < 7; i++) {
  491. if (event.getX() > cellWidth * (i - 1) + deltaScreenX && event.getX() < cellWidth * i + deltaScreenX) {
  492. this.indexOfCellOnClickX = i - 1;
  493. }
  494.  
  495. }
  496.  
  497.  
  498. //Передвижение и атака
  499. if(!unitMatrix[befpreviousIndexOfCellX][befpreviousIndexOfCellY].ground && unitMatrix[befpreviousIndexOfCellX][befpreviousIndexOfCellY].Owner.equals(TurnOfSide) ) {
  500. if ( unitMatrix[indexOfCellOnClickX][indexOfCellOnClickY].ground &&(Math.abs(indexOfCellOnClickX - befpreviousIndexOfCellX) + Math.abs(indexOfCellOnClickY - befpreviousIndexOfCellY)) <= unitMatrix[befpreviousIndexOfCellX][befpreviousIndexOfCellY].VALUABLEMOVE ){
  501. unitMatrix[befpreviousIndexOfCellX][befpreviousIndexOfCellY].VALUABLEMOVE -= Math.abs(indexOfCellOnClickX - befpreviousIndexOfCellX) + Math.abs(indexOfCellOnClickY - befpreviousIndexOfCellY);
  502. unitMatrix[befpreviousIndexOfCellX][befpreviousIndexOfCellY].move(indexOfCellOnClickX, indexOfCellOnClickY, befpreviousIndexOfCellX, befpreviousIndexOfCellY, unitMatrix, unitMatrix[indexOfCellOnClickX][indexOfCellOnClickY].isGround());
  503. indexOfCellX = indexOfCellOnClickX;
  504. indexOfCellY = indexOfCellOnClickY;
  505.  
  506. } else if ((Math.abs(indexOfCellOnClickX - befpreviousIndexOfCellX) + Math.abs(indexOfCellOnClickY - befpreviousIndexOfCellY)) <= unitMatrix[befpreviousIndexOfCellX][befpreviousIndexOfCellY].RANGE && !(unitMatrix[indexOfCellOnClickX][indexOfCellOnClickY].Owner.equals(unitMatrix[befpreviousIndexOfCellX][befpreviousIndexOfCellY].Owner)) && unitMatrix[befpreviousIndexOfCellX][befpreviousIndexOfCellY].canAttack) {
  507. unitMatrix[befpreviousIndexOfCellX][befpreviousIndexOfCellY].canAttack = false;
  508. unitMatrix[befpreviousIndexOfCellX][befpreviousIndexOfCellY].attack(indexOfCellOnClickX, indexOfCellOnClickY, befpreviousIndexOfCellX, befpreviousIndexOfCellY, unitMatrix, unitMatrix[indexOfCellOnClickX][indexOfCellOnClickY].isGround(), canvas);
  509. Toast toast = Toast.makeText(context,
  510. "Attacked", Toast.LENGTH_SHORT);
  511. toast.show();
  512.  
  513. }
  514.  
  515. }
  516. }
  517.  
  518.  
  519. befpreviousIndexOfCellX = previousIndexOfCellX;
  520. befpreviousIndexOfCellY = previousIndexOfCellY;
  521. previousIndexOfCellY = indexOfCellY;
  522. previousIndexOfCellX = indexOfCellX;
  523.  
  524. return false;
  525. }
  526.  
  527. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement