Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. public class Battlefield : Adapter {
  2. public Cell[][] field;
  3. public Battlefield(int sizeX,int sizeY) {
  4. field = new Cell[sizeY][];
  5. for (int y = 0; y < sizeY; y++) {
  6. field[y] = new Cell[sizeX];
  7. for (int x = 0; x < sizeX; x++) {
  8. field[y][x] = new Cell(this);
  9. }
  10. }
  11. }
  12. public void muveUnit(int[] op,int[] np) {
  13. Unit u = field[op[1]][op[0]].getUnit();
  14. field[np[1]][np[0]].setUnit(u);
  15. field[op[1]][op[0]].setUnit(null);
  16. }
  17. public void AtacUnit(int[] p1,int[] p2) {
  18. Unit u1 = field[p1[1]][p1[0]].getUnit();
  19. Unit u2 = field[p2[1]][p2[0]].getUnit();
  20. u2.hels -= u1.atac;
  21. if (u2.hels <= 0) {
  22. u2.cell.setUnit(null);
  23. }
  24. }
  25. public void createUnit(Unit u, int x, int y) {
  26. field[y][x].setUnit(u);
  27. }
  28. string[] input(string[] data) {
  29. if (data[0] == "создать_юнит") {
  30. createUnit();
  31. }
  32. }
  33. }
  34.  
  35. public class Cell {
  36. Battlefield field;
  37. Unit unit;
  38. int[] p = new int[2];
  39. public Cell(Battlefield bf) {
  40. field = bf;
  41. }
  42. public void setUnit(Unit u) {
  43. unit = u;
  44. }
  45. public Unit getUnit() {
  46. return unit;
  47. }
  48. }
  49.  
  50.  
  51. using System;
  52. public class ConsoleAdapter
  53. {
  54. Adapter adapter;
  55. Battlefield b;
  56. public void start() {
  57. while (true) {
  58. Console.Clear();
  59. for (int y = 0; y < b.field.Length; y++) {
  60. for (int x = 0; x < b.field[y].Length; x++) {
  61. if (b.field[y][x].getUnit() != null)
  62. {
  63. Console.Write("U");
  64. }
  65. else {
  66. Console.Write(" ");
  67. }
  68. }
  69. Console.Write("\n");
  70. parseComand(Console.ReadLine());
  71. }
  72. }
  73. }
  74. public void parseComand(string comand) {
  75. string[] data = comand.Split(' ');
  76. adapter.input(data);
  77. }
  78. }
  79.  
  80.  
  81.  
  82. public interface Adapter {
  83. string[] input(string[] data);
  84. }
  85.  
  86. public class Unit {
  87. public Cell cell;
  88. public int atac;
  89. public int hels;
  90. public Unit(int h, int a) {
  91. hels = h;
  92. atac = a;
  93. }
  94. public void setPositeon(Cell cell) {
  95. this.cell = cell;
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement