Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Logiikkaviidakko:
- //-----------------------------
- //Java:
- // Dead animals do not move
- if( ! animal.isAlive( ) || newLocation.equals( currLocation ) )
- return false;
- Room newRoom = rooms.get( newLocation );
- Room currRoom = rooms.get( currLocation );
- if( animal != newRoom.animal ) {
- if( newRoom.animal == null ) {
- newRoom.animal = animal;
- currRoom.animal = null;
- logEvent( animal + " moved from " + currLocation + " to " + newLocation );
- return true;
- }
- // Two non-predators cannot fit the same room, prevent movement
- if( ! newRoom.animal.isPredator( ) && ! animal.isPredator( ) )
- return false;
- // Both are predators, they annihilate each other
- if( newRoom.animal.isPredator( ) && animal.isPredator( ) ) {
- if( predatorsAnnihilateOnCollission ) {
- logEvent( animal + " moved from " + currLocation + " to " + newLocation );
- logEvent( animal + " and " + newRoom.animal + " annihilated each other at location " + newRoom.location );
- //...
- return true;
- }
- else
- return false;
- }
- // Only one of two is a predator
- else if( newRoom.animal.isPredator( ) || animal.isPredator( ) ) {
- logEvent( animal + " moved from " + currLocation + " to " + newLocation );
- if( animal.isPredator( ) ) {
- logEvent( newRoom.animal + " was killed by " + animal + " at location " + newRoom.location );
- //...
- currRoom.animal = null;
- newRoom.animal = animal;
- }
- else {
- logEvent( animal + " was killed by " + newRoom.animal + " at location " + newRoom.location );
- //...
- }
- return true;
- }
- return true;
- }
- return false;
- //-----------------------------
- //F#:
- match newRoom.animal, animal with
- | n,a when n=a -> false
- | n,a when n=null ->
- newRoom.animal <- animal
- currRoom.animal <- emptyanimal
- logEvent animal + " moved from " + currLocation + " to " + newLocation
- true
- // Two non-predators cannot fit the same room, prevent movement
- | n,a when not n.isPredator && not a.isPredator -> false
- | n,a when n.isPredator && a.isPredator ->
- match predatorsAnnihilateOnCollission with
- | true -> // Both are predators, they annihilate each other
- logEvent animal + " moved from " + currLocation + " to " + newLocation
- logEvent animal + " and " + newRoom.animal + " annihilated each other at location " + newRoom.location
- //...
- true
- | _ -> false
- | n,a ->
- logEvent animal + " moved from " + currLocation + " to " + newLocation
- if a.isPredator then
- logEvent newRoom.animal + " was killed by " + animal + " at location " + newRoom.location
- //...
- currRoom.animal = null
- newRoom.animal = animal
- else
- logEvent animal + " was killed by " + newRoom.animal + " at location " + newRoom.location
- //...
- true
- | _ -> true
- //-----------------------------
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement