daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static List<TOPlayableGame> getPlayableGames(){
  2.        
  3.         String error = "";
  4.         if (!(Block223Application.getCurrentUserRole() instanceof Player)) {
  5.             error = "Player privileges are required to play a game.";
  6.         }
  7.        
  8.         Block223 block223 = Block223Application.getBlock223();
  9.         UserRole player = Block223Application.getCurrentUserRole();
  10.        
  11.         List<TOPlayableGame> result = new ArrayList<>();  //  --> creates List <TOPlayableGame>
  12.        
  13.         List<Game> games = block223.getGames();
  14.        
  15.         for(Game agame: games) {
  16.            
  17.             if(agame.isPublished()) {
  18.                 TOPlayableGame to = new TOPlayableGame(agame.getName(),-1,0);
  19.                 result.add(to);
  20.             }
  21.         }
  22.        
  23.         player.getPlayedGames();
  24.        
  25.         for(Game agame: games) {
  26.             TOPlayableGame to = new TOPlayableGame(agame.getGame().getName(), agame.getId(), agame.getCurrentLevel());
  27.             result.add(to);
  28.         }
  29.        
  30.         return result;
  31.     }
  32.    
  33.     public static void selectPlayableGame(String name, int id) throws InvalidInputException {
  34.        
  35.         String error = "";
  36.         if (!(Block223Application.getCurrentUserRole() instanceof Player)) {
  37.             error = "Player privileges are required to play a game.";
  38.         }
  39.  
  40.         Game agame = Game.getWithName(name);
  41.         Block223 block223 = Block223Application.getBlock223();
  42.         PlayedGame pgame;
  43.        
  44.         if(agame == null) {
  45.             throw new InvalidInputException("The game does not exist.");
  46.         }
  47.        
  48.         else if(agame != null) {
  49.            
  50.             UserRole player = Block223Application.getCurrentUserRole();
  51.             String username = User.findUsername(player); // LOOK INTO
  52.            
  53.             if(username == null) {
  54.                 throw new InvalidInputException("The game does not exist.");
  55.             }
  56.            
  57.             pgame = new PlayedGame(username, agame, block223);
  58.             pgame.setPlayer((Player)player); // Player cast <----
  59.            
  60.            
  61.         }else pgame = block223.findPlayableGame(id);
  62.        
  63.         Block223Application.setCurrentPlayableGame(pgame);
  64.     }
  65.    
  66.     public static void startGame(Block223PlayModeInterface ui) {
  67.        
  68.         Game game = Block223Application.getCurrentPlayableGame();
  69.         game.play(); // game: PlayedGame
  70.        
  71.         ui.takeInputs();
  72.        
  73.         while(game.getPlaystatus() == PlayStatus.Moving) {
  74.             String userinputs = ui.takeInputs();
  75.            
  76.             Block223Controller.updatePaddlePosition(userinputs);
  77.            
  78.             game.move();
  79.            
  80.             if(userinputs == " ") {
  81.                 game.pause();
  82.             }
  83.             game.getWaitTime();
  84.             ui.refresh();
  85.         }
  86.        
  87.         if(game.getPlayStatus() == PlayStatus.GameOver) {
  88.             Block223Application.setCurrentPlayableGame(null);
  89.         }
  90.         else if(game.getPlayer()!= null) {
  91.             Block223 block223 = Block223Application.getBlock223();
  92.             Block223Persistence.save(block223);
  93.         }
  94.     }
  95.    
  96.     public static TOCurrentlyPlayedGame getCurrentPlayableGame() {
  97.        
  98.         PlayedGame pgame = Block223Application.getCurrentPlayableGame();
  99.        
  100.         boolean paused = pgame.getPlayStatus() == PlayStatus.Ready || pgame.getPlayStatus() == PlayStatus.Paused;
  101.        
  102.         TOCurrentlyPlayedGame result = new TOCurrentlyPlayedGame(pgame.getGame().getName(), paused,
  103.                 pgame.getScore(), pgame.getLives(),pgame.getCurrentLevel(), pgame.getPlayername(),
  104.                 (int)pgame.getCurrentBallX(), (int)pgame.getCurrentBallY(), (int)pgame.getCurrentPaddleLength(), (int)pgame.getCurrentPaddleX());
  105.        
  106.         List<PlayedBlockAssignment> blocks = pgame.getBlocks();
  107.        
  108.         for(PlayedBlockAssignment pblock: blocks) {
  109.             TOCurrentBlock to = new TOCurrentBlock(pblock.getBlock().getRed(),pblock.getBlock().getGreen(),
  110.                     pblock.getBlock().getBlue(),pblock.getBlock().getPoints(),pblock.getX(),pblock.getY(), result);
  111.         }
  112.         return result;
  113.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top