daily pastebin goal
73%
SHARE
TWEET

Untitled

a guest Jan 17th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import akka.actor._
  2. case class Ping(n:Int)
  3. case class Pong(n:Int)
  4.  
  5. class Player extends Actor {
  6.   def receive = {
  7.  
  8.     case Ping(n) =>
  9.       println("Ping")
  10.      
  11.       if(n == 1)
  12.       {
  13.         println("Kończymy grę")
  14.         context.system.terminate()
  15.       }
  16.       else
  17.         sender ! Pong(n - 1)
  18.        
  19.     case Pong(n) =>
  20.       println("Pong")
  21.       if(n == 1)
  22.       {
  23.         println("Kończymy grę")
  24.         context.system.terminate()
  25.       }
  26.       else
  27.         sender ! Ping(n - 1)
  28.        
  29.     case _ => new RuntimeException("Nieobsługiwany komunikat")
  30.   }
  31. }
  32.  
  33. object Zad1 {
  34.   def main(args:Array[String]) = {
  35.     val system = ActorSystem("System")
  36.     val player1 = system.actorOf(Props[Player])
  37.     val player2 = system.actorOf(Props[Player])
  38.     player1.tell(Ping(10),player2)
  39.   }
  40. }
RAW Paste Data
Top