Advertisement
KirillSamokhin

Field_Cell

Jul 4th, 2023
1,103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.47 KB | None | 0 0
  1. enum class Status {
  2.     NOTVIEWED,
  3.     VIEWED,
  4.     CHECK,
  5.     INPATH
  6. }
  7.  
  8. enum class Base{
  9.     GRASS,
  10.     WATER,
  11.     STONE
  12. }
  13.  
  14. enum class Edge {
  15.     START,
  16.     FINISH,
  17.     NONE
  18. }
  19.  
  20. class Cell(status: Status = Status.NOTVIEWED, base: Base = Base.GRASS, edge: Edge = Edge.NONE, var x: Int = 0, var y: Int = 0, var f: Int = 0, var g: Int = 0, var h: Int = 0){
  21.     private var status: Status = status
  22.         set(value){
  23.             field = value
  24.         }
  25.         get() = field
  26.     private var base: Base = base
  27.         set(value){
  28.             field = value
  29.         }
  30.         get() = field
  31.     private var edge: Edge = edge
  32.         set(value){
  33.             field = value
  34.         }
  35.         get() = field
  36.     fun setCoord(X: Int, Y: Int){
  37.         this.x = X
  38.         this.y = Y
  39.     }
  40.     fun getCoord(): Pair<Int, Int>{
  41.         return Pair(this.x, this.y)
  42.     }
  43.     fun setParams(g: Int, h: Int){
  44.         this.g = g
  45.         this.h = h
  46.         this.f = g+h
  47.     }
  48.     fun getParams(): IntArray{
  49.         var tmp = 0
  50.         when(this.base){
  51.             Base.GRASS -> tmp=10
  52.             Base.WATER -> tmp=30
  53.             Base.STONE -> tmp=-1
  54.         }
  55.         return intArrayOf(tmp, f, g, h)
  56.     }
  57. }
  58.  
  59. class Field(val x: Int, val y: Int){
  60.     val field = Array(this.y){Array<Cell>(this.x){Cell(x=0, y=0)}}
  61.     init{
  62.         for(i in 0 until y){
  63.             for(j in 0 until x){
  64.                 this.field[i][j].setCoord(j, i)
  65.             }
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement