Advertisement
Guest User

Untitled

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