Guest User

Untitled

a guest
May 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. //logiikkaviidakko
  2.  
  3. //-----------------------------
  4. //Java:
  5. // Dead animals do not move
  6. if( ! animal.isAlive( ) || newLocation.equals( currLocation ) )
  7. return false;
  8.  
  9. Room newRoom = rooms.get( newLocation );
  10. Room currRoom = rooms.get( currLocation );
  11.  
  12. if( animal != newRoom.animal ) {
  13. if( newRoom.animal == null ) {
  14. newRoom.animal = animal;
  15. currRoom.animal = null;
  16. logEvent( animal + " moved from " + currLocation + " to " + newLocation );
  17. return true;
  18. }
  19. // Two non-predators cannot fit the same room, prevent movement
  20. if( ! newRoom.animal.isPredator( ) && ! animal.isPredator( ) )
  21. return false;
  22.  
  23. // Both are predators, they annihilate each other
  24. if( newRoom.animal.isPredator( ) && animal.isPredator( ) ) {
  25. if( predatorsAnnihilateOnCollission ) {
  26. logEvent( animal + " moved from " + currLocation + " to " + newLocation );
  27. logEvent( animal + " and " + newRoom.animal + " annihilated each other at location " + newRoom.location );
  28. //...
  29. return true;
  30. }
  31. else
  32. return false;
  33. }
  34. // Only one of two is a predator
  35. else if( newRoom.animal.isPredator( ) || animal.isPredator( ) ) {
  36. logEvent( animal + " moved from " + currLocation + " to " + newLocation );
  37. if( animal.isPredator( ) ) {
  38. logEvent( newRoom.animal + " was killed by " + animal + " at location " + newRoom.location );
  39. //...
  40. currRoom.animal = null;
  41. newRoom.animal = animal;
  42. }
  43. else {
  44. logEvent( animal + " was killed by " + newRoom.animal + " at location " + newRoom.location );
  45. //...
  46. }
  47. return true;
  48. }
  49.  
  50. return true;
  51. }
  52.  
  53. return false;
  54.  
  55.  
  56.  
  57. //-----------------------------
  58. //F#:
  59.  
  60. match newRoom.animal, animal with
  61. | n,a when n=a -> false
  62. | n,a when n=null ->
  63. newRoom.animal <- animal
  64. currRoom.animal <- emptyanimal
  65. logEvent animal + " moved from " + currLocation + " to " + newLocation
  66. true
  67. // Two non-predators cannot fit the same room, prevent movement
  68. | n,a when not n.isPredator && not a.isPredator -> false
  69. | n,a when n.isPredator && a.isPredator ->
  70. match predatorsAnnihilateOnCollission with
  71. | true -> // Both are predators, they annihilate each other
  72. logEvent animal + " moved from " + currLocation + " to " + newLocation
  73. logEvent animal + " and " + newRoom.animal + " annihilated each other at location " + newRoom.location
  74. //...
  75. true
  76. | _ -> false
  77. | n,a ->
  78. logEvent animal + " moved from " + currLocation + " to " + newLocation
  79. if a.isPredator then
  80. logEvent newRoom.animal + " was killed by " + animal + " at location " + newRoom.location
  81. //...
  82. currRoom.animal = null
  83. newRoom.animal = animal
  84. else
  85. logEvent animal + " was killed by " + newRoom.animal + " at location " + newRoom.location
  86. //...
  87. true
  88. | _ -> true
  89.  
  90. //-----------------------------
Add Comment
Please, Sign In to add comment