33using System . Collections . Generic ;
44using UnityEngine ;
55using UnityEngine . UI ;
6+ using Assets . Scripts . GameObject . Interfaces ;
67
78public class GameController : MonoBehaviour {
89
@@ -165,7 +166,7 @@ void Update()
165166 positionMcPosition . z = 0 ;
166167 toBeAdded . transform . position = positionMcPosition ;
167168 toBeAdded . gameObject . SetActive ( true ) ;
168- selectedLink . setConnectingPlatform ( toBeAdded ) ; // connect the selected link to the new platform
169+ selectedLink . setConnectingEntity ( toBeAdded ) ; // connect the selected link to the new platform
169170 // end adding platform
170171 addingPlatforms = false ;
171172 // append code and log
@@ -293,7 +294,7 @@ void Update()
293294 //Debug.Log("millisecond diff: " + (DateTime.Now.Millisecond - lastTimeClickedMillis.Millisecond));
294295 if ( ( DateTime . Now . Millisecond - lastTimeClickedMillis . Millisecond ) < doubleClickDelay ) {
295296 codePanelBehavior . appendCodeText ( selectedLink . getCodeVariableString ( ) + " = null;" ) ; // still counds as setting it as null if it is already null;
296- if ( hoverLinkRef . connectingPlatform != null ) {
297+ if ( hoverLinkRef . connectingEntity != null ) {
297298 hoverLinkRef . removeLinkConnection ( ) ;
298299
299300 string actMsg = "the link block " + selectedLink . logId + " that was double clicked had an existing link so now it is deleted" ;
@@ -329,9 +330,9 @@ void Update()
329330 {
330331 selectedLink . removeLinkConnection ( ) ;
331332 }
332- if ( hoverLinkRef . connectingPlatform != null && hoverLinkRef . connectingPlatform != selectedLink . containerPlatform )
333+ if ( hoverLinkRef . connectingEntity != null && ( PlatformBehavior ) hoverLinkRef . connectingEntity != selectedLink . containerPlatform )
333334 {
334- selectedLink . setConnectingPlatform ( hoverLinkRef . connectingPlatform ) ;
335+ selectedLink . setConnectingEntity ( hoverLinkRef . connectingEntity ) ;
335336 }
336337 removeHoverArrow ( ) ;
337338 removeHoverLink ( ) ;
@@ -390,19 +391,20 @@ bool isWinConditonSatisfied()
390391 }
391392 //Debug.Log(debugFrameCount + " | WIN CONDITION: Number of platforms in the level: " + numberOfTotalPlatformsInLevel);
392393
393- if ( startingLink . connectingPlatform == null )
394+ if ( startingLink . connectingEntity == null )
394395 {
395396 return ( numberOfTotalPlatformsInLevel == 0 ) ; // if there are no platforms in the level
396397 }
397- else if ( startingLink . connectingPlatform . childLink . GetComponent < LinkBlockBehavior > ( ) . connectingPlatform == null )
398+ else if ( startingLink . connectingEntity is PlatformBehavior &&
399+ ( ( PlatformBehavior ) startingLink . connectingEntity ) . childLink . GetComponent < LinkBlockBehavior > ( ) . connectingEntity == null )
398400 {
399401 return ( numberOfTotalPlatformsInLevel == 1 ) ; // if there is only one platform in the level
400402 }
401403 sizeOfList = 1 ;
402- PlatformBehavior temp = startingLink . connectingPlatform . GetComponent < PlatformBehavior > ( ) ;
404+ ValueEntity temp = ( ( MonoBehaviour ) startingLink . connectingEntity ) . GetComponent < PlatformBehavior > ( ) ;
403405 while ( temp != null )
404406 {
405- PlatformBehavior next = temp . childLink . GetComponent < LinkBlockBehavior > ( ) . connectingPlatform ;
407+ ValueEntity next = ( ValueEntity ) ( ( PlatformBehavior ) temp ) . childLink . GetComponent < LinkBlockBehavior > ( ) . connectingEntity ;
406408 if ( next == null )
407409 {
408410 break ;
@@ -438,33 +440,34 @@ bool isWinConditonSatisfied()
438440 }
439441 }
440442
441- if ( startingLink . connectingPlatform == null )
443+ if ( startingLink . connectingEntity == null )
442444 {
443445 return ( listSize == 0 ) ; // if there are no platforms in the level
444446 }
445- else if ( startingLink . connectingPlatform . childLink . GetComponent < LinkBlockBehavior > ( ) . connectingPlatform == null )
447+ else if ( startingLink . connectingEntity is PlatformBehavior &&
448+ ( ( PlatformBehavior ) startingLink . connectingEntity ) . childLink . GetComponent < LinkBlockBehavior > ( ) . connectingEntity == null )
446449 {
447450 return ( listSize == 1 ) ; // if there is only one platform in the level
448451 }
449452 //start traversing the list and comparing the current and next platform's values
450- PlatformBehavior tempDupl = startingLink . connectingPlatform . GetComponent < PlatformBehavior > ( ) ;
453+ ValueEntity tempDupl = ( ( MonoBehaviour ) startingLink . connectingEntity ) . GetComponent < PlatformBehavior > ( ) ;
451454 //check student's list to make a dictionary...
452455 Dictionary < int , int > PlayersList = new Dictionary < int , int > ( ) ;
453456 while ( tempDupl != null )
454457 {
455- if ( PlayersList . ContainsKey ( tempDupl . getValue ( ) ) )
458+ if ( PlayersList . ContainsKey ( ( int ) tempDupl . getValue ( ) ) )
456459 {
457460 return false ;
458461 }
459- else if ( ! PlayersList . ContainsKey ( tempDupl . getValue ( ) ) && PlayersList . Count < listSize )
462+ else if ( ! PlayersList . ContainsKey ( ( int ) tempDupl . getValue ( ) ) && PlayersList . Count < listSize )
460463 {
461- PlayersList . Add ( tempDupl . getValue ( ) , 1 ) ;
464+ PlayersList . Add ( ( int ) tempDupl . getValue ( ) , 1 ) ;
462465 if ( ( PlayersList . Count == unique . Count ) && PlayersList . Count == listSize )
463466 {
464467 return true ;
465468 }
466469 }
467- PlatformBehavior next = tempDupl . childLink . GetComponent < LinkBlockBehavior > ( ) . connectingPlatform ;
470+ ValueEntity next = ( ValueEntity ) ( ( PlatformBehavior ) tempDupl ) . childLink . GetComponent < LinkBlockBehavior > ( ) . connectingEntity ;
468471 if ( next != null )
469472 {
470473 if ( next . getValue ( ) < tempDupl . getValue ( ) )
@@ -527,7 +530,7 @@ public void removeHoverLink()
527530 }
528531 // remove the "bridge" from the link we are no longer setting as the hover link.
529532 // so that its collision is now normal.
530- if ( hoverLinkRef . connectingPlatform != null )
533+ if ( hoverLinkRef . connectingEntity != null )
531534 {
532535 if ( enableLinkChaining )
533536 {
@@ -547,8 +550,8 @@ public void removeHoverLink()
547550 {
548551 previousNotNullHoverLinkRef . containerPlatform . updatePlatformValuesAndSprite ( ) ;
549552 }
550- if ( previousNotNullHoverLinkRef . connectingPlatform != null ) {
551- previousNotNullHoverLinkRef . connectingPlatform . updatePlatformValuesAndSprite ( ) ;
553+ if ( previousNotNullHoverLinkRef . connectingEntity != null && previousNotNullHoverLinkRef . connectingEntity is PlatformBehavior ) {
554+ ( ( PlatformBehavior ) previousNotNullHoverLinkRef . connectingEntity ) . updatePlatformValuesAndSprite ( ) ;
552555 }
553556 }
554557 }
@@ -570,7 +573,7 @@ public void setHoverLink(ref LinkBlockBehavior lb)
570573
571574 // Make a red X appear over the arrow of the selected link connection if the selected link connection will be removed
572575 // if the connection establishing action is complete.
573- if ( selectedLink != null && selectedLink . connectingPlatform != null && ( hoverLinkRef . connectingPlatform == null || selectedLink . connectingPlatform != hoverLinkRef . connectingPlatform ) )
576+ if ( selectedLink != null && selectedLink . connectingEntity != null && ( hoverLinkRef . connectingEntity == null || selectedLink . connectingEntity != hoverLinkRef . connectingEntity ) )
574577 {
575578 if ( deleteSpriteRef != null )
576579 {
@@ -582,23 +585,23 @@ public void setHoverLink(ref LinkBlockBehavior lb)
582585 }
583586
584587 // conditions for "bridging": there is a select link and a hover link, and they are not equal
585- if ( selectedLink != null && hoverLinkRef != null && selectedLink != hoverLinkRef && hoverLinkRef . connectingPlatform != null )
588+ if ( selectedLink != null && hoverLinkRef != null && selectedLink != hoverLinkRef && hoverLinkRef . connectingEntity != null )
586589 {
587590 hoverLinkRef . setDisplayMarker ( true ) ;
588591 // draw the faded arrow
589592 Color c = Color . gray ;
590593 c . a = 0.3f ;
591- Transform [ ] hoverArrowParts = createArrowInstanceBetweenLinkPlatform ( selectedLink , hoverLinkRef . connectingPlatform , c ) ;
594+ Transform [ ] hoverArrowParts = createArrowInstanceBetweenLinkPlatform ( selectedLink , hoverLinkRef . connectingEntity , c ) ;
592595 hoverArrowLine = hoverArrowParts [ 0 ] ;
593596 hoverArrowHead = hoverArrowParts [ 1 ] ;
594597
595598 // This is when the mouse is hovering over a link for establishing a link.
596599 // update and create a "bridge" from this link to the next for next->next->.. option.
597- if ( hoverLinkRef . connectingPlatform != null )
600+ if ( hoverLinkRef . connectingEntity != null && hoverLinkRef . connectingEntity is PlatformBehavior )
598601 {
599602 if ( enableLinkChaining ) {
600603 // Create a "bridge" from this link to the next link
601- Bounds otherBounds = hoverLinkRef . connectingPlatform . childLink . GetComponent < SpriteRenderer > ( ) . bounds ;
604+ Bounds otherBounds = ( ( PlatformBehavior ) hoverLinkRef . connectingEntity ) . childLink . GetComponent < SpriteRenderer > ( ) . bounds ;
602605 Bounds hoverBounds = hoverLinkRef . GetComponent < SpriteRenderer > ( ) . bounds ;
603606 Vector3 worldDiffNorm = ( otherBounds . center - hoverBounds . center ) . normalized ;
604607
@@ -630,7 +633,9 @@ public void setHoverLink(ref LinkBlockBehavior lb)
630633 hoverLinkRef . GetComponent < LineRenderer > ( ) . startWidth = scalePerpScale - 0.2f ; // make the path look a little smaller than it really is
631634 hoverLinkRef . GetComponent < LineRenderer > ( ) . endWidth = scalePerpScale - 0.2f ;
632635
633- hoverLinkRef . connectingPlatform . updatePlatformValuesAndSprite ( ) ;
636+ if ( hoverLinkRef . connectingEntity is PlatformBehavior ) {
637+ ( ( PlatformBehavior ) hoverLinkRef . connectingEntity ) . updatePlatformValuesAndSprite ( ) ;
638+ }
634639 }
635640 } // end creating the "bridge"
636641 }
@@ -730,11 +735,11 @@ public void clearReferenceLists()
730735 /**
731736 * Instantiate an arrow that goes from the given link block to the given platform using the given color.
732737 */
733- public Transform [ ] createArrowInstanceBetweenLinkPlatform ( LinkBlockBehavior lb , PlatformBehavior pb , Color color )
738+ public Transform [ ] createArrowInstanceBetweenLinkPlatform ( LinkBlockBehavior lb , ConnectableEntity ce , Color color )
734739 {
735740 // determine the start and end points of the arrow.
736741 Bounds linkBounds = lb . GetComponent < SpriteRenderer > ( ) . bounds ;
737- Bounds platBounds = pb . GetComponent < SpriteRenderer > ( ) . bounds ;
742+ Bounds platBounds = ( ( MonoBehaviour ) ce ) . GetComponent < SpriteRenderer > ( ) . bounds ;
738743
739744 // find the closest points on both bounding boxes to the center point to make the arrow.
740745 Vector3 betweenPoint = new Vector3 ( ( linkBounds . center . x + platBounds . center . x ) / 2 ,
0 commit comments