@@ -40,15 +40,14 @@ class ProjectActivity : AppCompatActivity() {
4040 supportActionBar?.setDisplayHomeAsUpEnabled(true )
4141 supportActionBar?.title = " newProject"
4242 bindingClass.blocksRV.isDrawingCacheEnabled = true
43- bindingClass.blocksRV.setItemViewCacheSize(100 );
43+ bindingClass.blocksRV.setItemViewCacheSize(100 )
4444
4545 createConsoleView()
4646 createBlocksView()
4747
4848 init ()
4949
5050 mainHandler = Handler (Looper .getMainLooper())
51-
5251 }
5352 fun kicker () {
5453 listBlocks[0 ].kickRunning()
@@ -312,16 +311,16 @@ class ProjectActivity : AppCompatActivity() {
312311 override fun onSwiped (viewHolder : RecyclerView .ViewHolder , direction : Int ) {
313312 val position = viewHolder.adapterPosition
314313 if (viewHolder.adapterPosition == 0 ||
315- listBlocks[position].getBlockType() == " Begin" ||
316- listBlocks[position].getBlockType() == " End" ||
317- listBlocks[position].getBlockType() == " Else" ){
314+ listBlocks[position].type == " Begin" ||
315+ listBlocks[position].type == " End" ||
316+ listBlocks[position].type == " Else" ){
318317 blocksAdapter.notifyItemRemoved(position)
319318 return
320319 }
321- else if ( listBlocks[position].getBlockType() == " ConditionIf" ||
322- listBlocks[position].getBlockType() == " ConditionIfElse" ||
323- listBlocks[position].getBlockType() == " CycleWhile" ){
324- val type = listBlocks[position].getBlockType()
320+ else if ( listBlocks[position].type == " ConditionIf" ||
321+ listBlocks[position].type == " ConditionIfElse" ||
322+ listBlocks[position].type == " CycleWhile" ){
323+ val type = listBlocks[position].type
325324 listBlocks.remove(listBlocks[position])
326325 listBlocks.remove(listBlocks[position])
327326 blocksAdapter.notifyItemRemoved(position)
@@ -348,13 +347,13 @@ class ProjectActivity : AppCompatActivity() {
348347 }
349348 private fun findNearEnd (start : Int ) : Int {
350349 for (i in start until listBlocks.size)
351- if (listBlocks[i].getBlockType() == " End" )
350+ if (listBlocks[i].type == " End" )
352351 return i
353352 return - 1
354353 }
355354 private fun findNearElse (start : Int ) : Int {
356355 for (i in start until listBlocks.size)
357- if (listBlocks[i].getBlockType() == " Else" )
356+ if (listBlocks[i].type == " Else" )
358357 return i
359358 return - 1
360359 }
@@ -386,28 +385,27 @@ class ProjectActivity : AppCompatActivity() {
386385
387386 private fun check (index : Int ) : Pair <Int , Int >{
388387 var i = index
389- while (listBlocks[i+ 1 ].getBlockType() != " End" ){
388+ while (listBlocks[i+ 1 ].type != " End" ){
390389 if (i+ 1 == listBlocks.size) {
391390 consoleAdapter.addMessage(" В строке $i ожидался End" )
392391 return Pair (0 , 0 )
393392 }
394- if (listBlocks[i].getBlockType() == " ConditionIf" ||
395- listBlocks[i].getBlockType() == " ConditionIfElse" ||
396- listBlocks[i].getBlockType() == " CycleWhile" ){
397- val temp : Int
398- if (listBlocks[i].getBlockType() == " ConditionIfElse" )
399- temp = checkIfElse(i)
393+ if (listBlocks[i].type == " ConditionIf" ||
394+ listBlocks[i].type == " ConditionIfElse" ||
395+ listBlocks[i].type == " CycleWhile" ){
396+ val temp = if (listBlocks[i].type == " ConditionIfElse" )
397+ checkIfElse(i)
400398 else
401- temp = checkIf(i)
399+ checkIf(i)
402400
403401 if (temp == 0 )
404402 return Pair (0 , 0 )
405403 else {
406- if (temp < listBlocks.size && listBlocks[temp].getBlockType() != " End" ){
404+ if (temp < listBlocks.size && listBlocks[temp].type != " End" ){
407405 connectBlocks(listBlocks[i], listBlocks[temp])
408406 i = temp
409407 }
410- else if (temp < listBlocks.size && listBlocks[temp].getBlockType() == " End" ){
408+ else if (temp < listBlocks.size && listBlocks[temp].type == " End" ){
411409 return Pair (i, temp)
412410 }
413411 else if (temp >= listBlocks.size){
@@ -428,14 +426,14 @@ class ProjectActivity : AppCompatActivity() {
428426
429427 private fun checkIfElse (index : Int ): Int {
430428 var i = index + 1
431- if (listBlocks[i].getBlockType() == " Begin" ){
429+ if (listBlocks[i].type == " Begin" ){
432430 i + = 1
433- if (listBlocks[i].getBlockType() != " End" ){
431+ if (listBlocks[i].type != " End" ){
434432 connectBlocks(listBlocks[index].begin, listBlocks[i])
435433 val (j, temp) = check(i)
436434 if (j == 0 )
437435 return 0
438- else if (listBlocks[temp].getBlockType() == " End" ) {
436+ else if (listBlocks[temp].type == " End" ) {
439437 connectBlocks(listBlocks[j], listBlocks[index].end)
440438 i = temp + 1
441439 }
@@ -448,16 +446,16 @@ class ProjectActivity : AppCompatActivity() {
448446 connectBlocks(listBlocks[index].begin, listBlocks[index].end)
449447 i + = 1
450448 }
451- if (listBlocks[i].getBlockType() == " Else" ){
449+ if (listBlocks[i].type == " Else" ){
452450 i + = 1
453- if (listBlocks[i].getBlockType() == " Begin" ){
451+ if (listBlocks[i].type == " Begin" ){
454452 i + = 1
455- if (listBlocks[i].getBlockType() != " End" ){
453+ if (listBlocks[i].type != " End" ){
456454 connectBlocks(listBlocks[index].beginElse, listBlocks[i])
457455 val (i, temp) = check(i)
458456 if (i == 0 )
459457 return 0
460- else if (listBlocks[temp].getBlockType() == " End" ) {
458+ else if (listBlocks[temp].type == " End" ) {
461459 connectBlocks(listBlocks[i], listBlocks[index].end)
462460 return temp + 1
463461 }
@@ -486,17 +484,17 @@ class ProjectActivity : AppCompatActivity() {
486484
487485 private fun checkIf (index : Int ): Int {
488486 var i = index + 1
489- if (listBlocks[i].getBlockType() == " Begin" ){
487+ if (listBlocks[i].type == " Begin" ){
490488 i + = 1
491- if (listBlocks[i].getBlockType() == " End" ){
489+ if (listBlocks[i].type == " End" ){
492490 connectBlocks(listBlocks[index].begin, listBlocks[index].end)
493491 return i + 1
494492 }
495493 connectBlocks(listBlocks[index].begin, listBlocks[i])
496494 val (i, temp) = check(i)
497495 if (i == 0 )
498496 return 0
499- else if (listBlocks[temp].getBlockType() == " End" ) {
497+ else if (listBlocks[temp].type == " End" ) {
500498 connectBlocks(listBlocks[i], listBlocks[index].end)
501499 return temp + 1
502500 }
@@ -512,29 +510,28 @@ class ProjectActivity : AppCompatActivity() {
512510 private fun connectionBlocks () : Boolean {
513511 var i = 0
514512 while (i < listBlocks.size- 1 ) {
515- if (listBlocks[i].getBlockType() == " Begin" ){
513+ if (listBlocks[i].type == " Begin" ){
516514 consoleAdapter.addMessage(" Обнаружен не к месту Begin в строке $i " )
517515 return false
518516 }
519- else if (listBlocks[i].getBlockType() == " End" ){
517+ else if (listBlocks[i].type == " End" ){
520518 consoleAdapter.addMessage(" Обнаружен не к месту End в строке $i " )
521519 return false
522520 }
523- else if (listBlocks[i].getBlockType() == " Else" ){
521+ else if (listBlocks[i].type == " Else" ){
524522 consoleAdapter.addMessage(" Обнаружен не к месту Else в строке $i " )
525523 return false
526524 }
527- else if (listBlocks[i].getBlockType() == " ConditionIf" ||
528- listBlocks[i].getBlockType() == " ConditionIfElse" ||
529- listBlocks[i].getBlockType() == " CycleWhile" ) {
525+ else if (listBlocks[i].type == " ConditionIf" ||
526+ listBlocks[i].type == " ConditionIfElse" ||
527+ listBlocks[i].type == " CycleWhile" ) {
530528
531- val temp : Int
532- if (listBlocks[i].getBlockType() == " ConditionIfElse" )
533- temp = checkIfElse(i)
529+ val temp = if (listBlocks[i].type == " ConditionIfElse" )
530+ checkIfElse(i)
534531 else
535- temp = checkIf(i)
536- if (temp == 0 )
537- return false
532+ checkIf(i)
533+
534+ if (temp == 0 ) return false
538535 else {
539536 if (temp < listBlocks.size){
540537 connectBlocks(listBlocks[i], listBlocks[temp])
@@ -559,40 +556,38 @@ class ProjectActivity : AppCompatActivity() {
559556 for (i in 0 until listBlocks.size){
560557 listBlocks[i].indexListBlocks = i
561558 listBlocks[i].crutch = true
562- if (listBlocks[i].status != " OK " ){
563- listBlocks[i].status = " OK "
559+ if (listBlocks[i].status != ok() ){
560+ listBlocks[i].status = ok()
564561 blocksAdapter.notifyItemChanged(i)
565562 }
566- if (listBlocks[i].getBlockType() == " ConsoleInput" ){
563+ if (listBlocks[i].type == " ConsoleInput" ){
567564 listBlocks[i].activity = this
568565 }
569566
570567 }
571568 if (! connectionBlocks()) {
572- consoleAdapter.addMessage(" Program finished with status: Fail" )
569+ consoleAdapter.addMessage(programFinish( " Fail" ) )
573570 return
574571 }
575572 // printAllConnections()
576573 Block .isProgramRunning = true
577574 listBlocks[0 ].run ()
578575 // printAllConnections()
579576 // disconnectAllBlocks()
580-
581-
582577 }
583578
584579 private fun printAllConnections (){
585580 for (i in 0 until listBlocks.size){
586- consoleAdapter.addMessage(" $i " + (listBlocks[i].getPrevBlock()
587- ?.getBlockType() ? : " null" ) + " -" + listBlocks[i].getBlockType() + " -" +
588- (listBlocks[i].getNextBlock()?.getBlockType() ? : " null" ))
581+ consoleAdapter.addMessage(" $i " + (listBlocks[i].prevBlock
582+ ?.type ? : " null" ) + " -" + listBlocks[i].type + " -" +
583+ (listBlocks[i].nextBlock?.type ? : " null" ))
589584
590585 }
591586 }
592587 private fun disconnectAllBlocks (){
593588 for (i in 0 until listBlocks.size){
594- listBlocks[i].setPrevBlock( null )
595- listBlocks[i].setNextBlock( null )
589+ listBlocks[i].prevBlock = null
590+ listBlocks[i].nextBlock = null
596591 listBlocks[i].begin = Begin ()
597592 listBlocks[i].end = End ()
598593 listBlocks[i].beginElse = Begin ()
0 commit comments