Advertisement
alexarcan

game

Dec 5th, 2014
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. class Out extends Exception{
  4.     public Out(){
  5.         super("Out!!");
  6.     }
  7. }
  8.  
  9. class Goal extends Exception{
  10.     public Goal(){
  11.         super("Goal!!");
  12.     }
  13. }
  14.  
  15. class Corner extends Exception{
  16.     public Corner(){
  17.         super("Corner!!");
  18.     }
  19. }
  20.  
  21. public class Ball {
  22.    
  23.     private int x,y;
  24.     private Random aux = new Random();
  25.    
  26.     public Ball(int x, int y){
  27.         this.x = x;
  28.         this.y = y;
  29.     }
  30.    
  31.     public void play() throws Out, Goal, Corner{
  32.        
  33.         x = aux.nextInt(100);
  34.         y = aux.nextInt(50);
  35.        
  36.         if(y == 0 || y == 50)
  37.             throw new Out();
  38.        
  39.         if(x == 0 || x == 100){
  40.             if(y >= 20 && y<=30)
  41.                 throw new Goal();
  42.            
  43.             if((y > 0 && y < 20) || (y > 30 && y <50))
  44.                 throw new Corner();
  45.         }
  46.        
  47.     }
  48. }
  49.  
  50. class Game {
  51.    
  52.             //Ball ball = new Ball(50,25);
  53.            
  54.             private String Team1, Team2;
  55.             private int Score1, Score2, Outs, Corners;
  56.            
  57.             public Game(String Team1, String Team2){
  58.                 this.Team1 = Team1;
  59.                 this.Team2 = Team2;
  60.             }
  61.            
  62.             public String toString(){
  63.                 return Team1 + " " + Score1 + " " + Score2 + " " + Team2 + " outs: " + Outs + " corners " + Corners;
  64.             }
  65.            
  66.             /*
  67.             try {
  68.                 ball.play();
  69.                 ball.play();
  70.                 ball.play();ball.play();
  71.                 ball.play();
  72.                 ball.play();ball.play();
  73.                 ball.play();
  74.                
  75.                 ball.play();
  76.             }
  77.             catch(Exception e)
  78.             {  
  79.                 System.out.println(e);
  80.             }*/
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement