您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

60 行
1.5 KiB

  1. package controllers;
  2. import javax.inject.Inject;
  3. import actors.GameActor;
  4. import akka.actor.ActorRef;
  5. import akka.actor.ActorSystem;
  6. import akka.actor.Props;
  7. import akka.stream.Materializer;
  8. import play.data.Form;
  9. import play.data.FormFactory;
  10. import play.libs.streams.ActorFlow;
  11. import play.mvc.Controller;
  12. import play.mvc.Http;
  13. import play.mvc.Result;
  14. import play.mvc.WebSocket;
  15. import structures.User;
  16. /**
  17. * This is the Controller class for the game.
  18. * @author Dr. Richard McCreadie
  19. *
  20. */
  21. public class GameScreenController extends Controller {
  22. private final ActorSystem actorSystem;
  23. private final Materializer materializer;
  24. Form<User> userForm = null;
  25. @Inject
  26. public GameScreenController(FormFactory formFactory, ActorSystem actorSystem, Materializer materializer) {
  27. this.actorSystem = actorSystem;
  28. this.materializer = materializer;
  29. userForm = formFactory.form(User.class);
  30. }
  31. /**
  32. * This responds to the request for creation of the Websocket
  33. * @return
  34. */
  35. public WebSocket socket() {
  36. return WebSocket.Json.accept(
  37. request -> ActorFlow.actorRef(this::createGameActor, actorSystem, materializer));
  38. }
  39. /**
  40. * This method responds to the original request for the /game screen
  41. * @param request
  42. * @return
  43. */
  44. public Result index(Http.Request request) {
  45. return ok(views.html.gamescreen.render(request, null));
  46. }
  47. public Props createGameActor(ActorRef out) {
  48. return Props.create(GameActor.class, out); // calls the constructor for Game Actor
  49. }
  50. }