Advertisement
Guest User

twoplayergamebomb

a guest
Mar 19th, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.81 KB | None | 0 0
  1. import java.awt.*;
  2.  
  3. import javax.swing.*;
  4. import java.awt.event.*;
  5. public class twoplayergamebomb extends JApplet implements KeyListener{
  6.     int P1x=4;
  7.     int P1y=4;
  8.     int P1xc=4;
  9.     int P1yc=4;
  10.    
  11.     int P2x=564;
  12.     int P2y=564;
  13.     int P2xc=564;
  14.     int P2yc=564;
  15.    
  16.     int B1=0;
  17.     int B2=0;
  18.    
  19.     int R1=0;
  20.     int R2=0;
  21.    
  22.     double bombNorthg=Math.random();
  23.     double bombSouthg=Math.random();
  24.     double bombWestg=Math.random();
  25.     double bombEastg=Math.random();
  26.    
  27.     int bombNorth;
  28.     int bombSouth;
  29.     int bombEast;
  30.     int bombWest;
  31.    
  32.     int PowerUp=1;
  33.    
  34.     Color darkRed=new Color(178,32,32);
  35.     Color lightRed=new Color(225,32,32);
  36.     Color darkBlue=new Color(0,0,128);
  37.     Color lightBlue=new Color(0,0,200);
  38.     boolean RedPlace=false;
  39.     boolean BluePlace=false;
  40.    
  41.     boolean[][] broken=new boolean[15][15];
  42.    
  43.     int background = 0;
  44.    
  45.     public void init(){
  46.         setSize(600,600);
  47.         addKeyListener(this);
  48.     }
  49.    
  50.     public void background(Graphics g){
  51.         int y=40;
  52.         int x=40;
  53.         while(x<601){
  54.             g.drawLine(x, 0, x, 600);
  55.             g.drawLine(0, y, 600, y);
  56.             x+=40;
  57.             y+=40;
  58.         }
  59.         int x1=4;
  60.         int y1=4;
  61.         int addative=40;
  62.         int counter=0;
  63.         while(counter<225){
  64.             g.fillRect(x1, y1, 32, 32);
  65.             if(x1>=564 || x1<=0){
  66.                 y1+=40;
  67.                 addative=-addative;
  68.                 g.fillRect(x1, y1, 32, 32);
  69.             }
  70.             if(y1>-123){
  71.                 x1+=addative;
  72.             }
  73.             counter++;
  74.         }
  75.         g.setColor(Color.white);
  76.         g.fillRect(44, 4, 32, 32);
  77.         g.fillRect(4, 44, 32, 32);
  78.         g.fillRect(524, 564, 32, 32);
  79.         g.fillRect(564, 524, 32, 32);
  80.         counter=0;
  81.         addative=1;
  82.         while(counter<15){
  83.             broken[0][B2]=false;
  84.             broken[1][B2]=false;
  85.             broken[2][B2]=false;
  86.             broken[3][B2]=false;
  87.             broken[4][B2]=false;
  88.             broken[5][B2]=false;
  89.             broken[6][B2]=false;
  90.             broken[7][B2]=false;
  91.             broken[8][B2]=false;
  92.             broken[9][B2]=false;
  93.             broken[10][B2]=false;
  94.             broken[11][B2]=false;
  95.             broken[12][B2]=false;
  96.             broken[13][B2]=false;
  97.             broken[14][B2]=false;
  98.             broken[0][R2]=false;
  99.             broken[1][R2]=false;
  100.             broken[2][R2]=false;
  101.             broken[3][R2]=false;
  102.             broken[4][R2]=false;
  103.             broken[5][R2]=false;
  104.             broken[6][R2]=false;
  105.             broken[7][R2]=false;
  106.             broken[8][R2]=false;
  107.             broken[9][R2]=false;
  108.             broken[10][R2]=false;
  109.             broken[11][R2]=false;
  110.             broken[12][R2]=false;
  111.             broken[13][R2]=false;
  112.             broken[14][R2]=false;
  113.             B2++;
  114.             counter++;
  115.         }
  116.         broken[0][0]=true;
  117.         broken[1][0]=true;
  118.         broken[0][1]=true;
  119.        
  120.         broken[14][14]=true;
  121.         broken[14][13]=true;
  122.         broken[13][14]=true;
  123.         B1=14;
  124.         B2=14;
  125.         R1=0;
  126.         R2=0;
  127.     }
  128.    
  129.     public void players(Graphics g){
  130.         g.setColor(Color.white);
  131.         g.fillRect(P2xc, P2yc, 32, 32);
  132.         g.fillRect(P1xc, P1yc, 32, 32);
  133.         g.setColor(Color.red);
  134.         g.fillRect(P1x, P1y, 32, 32);
  135.         g.setColor(Color.blue);
  136.         g.fillRect(P2x, P2y, 32, 32);
  137.     }
  138.    
  139.     public void paint(Graphics g){
  140.         if(background==0){
  141.             background++;
  142.             background(g);
  143.         }
  144.         players(g);
  145.         BombPlace(g);
  146.         RedBomb r= new RedBomb();
  147.         r.init();
  148.         r.input(P1x, P1y, darkRed, lightRed);
  149.         r.repaint();
  150.     }
  151.    
  152.     public void generator(){
  153.             bombNorthg=Math.random();
  154.             bombSouthg=Math.random();
  155.             bombWestg=Math.random();
  156.             bombEastg=Math.random();
  157.             bombNorth=(int) bombNorthg;
  158.             bombSouth=(int) bombSouthg;
  159.             bombWest=(int) bombWestg;
  160.             bombEast=(int) bombEastg;
  161.     }
  162.    
  163.     public void BombPlace(Graphics g){
  164.        
  165.         if(RedPlace==true){
  166.         g.setColor(darkRed);
  167.         g.fillRect(P1x+5,P1y+5,22,22);
  168.         repaint();
  169.         RedPlace=false;
  170.         }else if(BluePlace==true){
  171.         g.setColor(darkBlue);
  172.         g.fillRect(P2x+5, P2y+5, 22, 22);
  173.         repaint();
  174.         BluePlace=false;
  175.         }  
  176.     }
  177.    
  178.     public void BombExplode(Graphics g){
  179.         generator();
  180.         if(PowerUp==1){
  181.             if(bombSouth<3){
  182.                 bombSouth+=3;
  183.             }else if(bombNorth<3){
  184.                 bombNorth+=3;
  185.             }else if(bombEast<3){
  186.                 bombEast+=3;
  187.             }else if(bombWest<3){
  188.                 bombWest+=3;
  189.             }else{
  190.                 bombNorth=bombNorth/5;
  191.                 bombSouth=bombSouth/5;
  192.                 bombEast=bombEast/5;
  193.                 bombWest=bombWest/5;
  194.             }
  195.            
  196.            
  197.         }else if(PowerUp==2){
  198.             bombNorth=bombNorth/3;
  199.             bombSouth=bombSouth/3;
  200.             bombEast=bombEast/3;
  201.             bombWest=bombWest/3;
  202.         }else if(PowerUp==3){
  203.            
  204.         }else if(PowerUp==4){
  205.            
  206.         }else if(PowerUp==5){
  207.            
  208.         }
  209.        
  210.     }
  211.    
  212.     public void keyPressed(KeyEvent e) {
  213.     }
  214.  
  215.     public void keyReleased(KeyEvent e) {
  216.        
  217.          switch (e.getKeyCode()) {        
  218.          case KeyEvent.VK_W:
  219.              P1yc=P1y;
  220.              P1xc=P1x;
  221.              if(R1!=0){
  222.                 R1--;
  223.              }
  224.              if(P1y==4 ){
  225.              }else if(broken[R1][R2]==true){
  226.                  P1y-=40;
  227.              }if(broken[R1][R2]==false){
  228.                  R1++;
  229.              }
  230.              repaint();
  231.              break;        
  232.              case KeyEvent.VK_S:
  233.                  P1yc=P1y;
  234.                  P1xc=P1x;
  235.                  if(R1!=14){
  236.                     R1++;
  237.                  }
  238.                  if(P1y==564){
  239.                      
  240.                  }else if(broken[R1][R2]==true){
  241.                      P1y+=40;
  242.                  }    
  243.                  if(broken[R1][R2]==false){
  244.                      R1--;
  245.                  }
  246.                  repaint();
  247.                  break;        
  248.                  case KeyEvent.VK_D:
  249.                      P1xc=P1x;
  250.                      P1yc=P1y;
  251.                      if(R2!=14){
  252.                          R2++;
  253.                      }
  254.                      if(P1x==564){
  255.                      }else if(broken[R1][R2]==true){
  256.                          P1x+=40;
  257.                      }  
  258.                      if(broken[R1][R2]==false){
  259.                          R2--;
  260.                      }  
  261.                      repaint();
  262.                      break;
  263.                      case KeyEvent.VK_A:
  264.                          P1xc=P1x;
  265.                          P1yc=P1y;
  266.                          if(R2!=0){
  267.                              R2--;
  268.                          }
  269.                          if(P1x==4){
  270.                              
  271.                          }else if(broken[R1][R2]==true){
  272.                              P1x-=40;
  273.                          }
  274.                          if(broken[R1][R2]==false){
  275.                              R2++;
  276.                          }
  277.                          repaint();
  278.                          break;
  279.                      case KeyEvent.VK_F:
  280.                          RedPlace=true;
  281.                          
  282.                          repaint();
  283.                          break;
  284.          }
  285.          
  286.          switch (e.getKeyCode()) {        
  287.          case KeyEvent.VK_I:            
  288.              P2yc=P2y;
  289.              P2xc=P2x;
  290.              if(B1!=0){
  291.                 B1--;
  292.              }
  293.              if(P2y==4){
  294.              }else if(broken[B1][B2]==true){
  295.                  P2y-=40;
  296.              }
  297.              if(broken[B1][B2]==false){
  298.                  B1++;
  299.              }
  300.              repaint();            
  301.              break;        
  302.              case KeyEvent.VK_K:            
  303.                  P2yc=P2y;
  304.                  P2xc=P2x;
  305.                  if(B1!=14){
  306.                      B1++;
  307.                  }
  308.                  if(P2y==564){
  309.                      
  310.                  }else if(broken[B1][B2]==true){
  311.                      P2y+=40;
  312.                  }    
  313.                  if(broken[B1][B2]==false){
  314.                      B1--;
  315.                  }    
  316.                  repaint();          
  317.                  break;        
  318.                  case KeyEvent.VK_L:            
  319.                      P2xc=P2x;
  320.                      P2yc=P2y;
  321.                      if(B2!=14){
  322.                         B2++;
  323.                      }
  324.                      if(P2x==564){
  325.                      }else if(broken[B1][B2]==true){
  326.                          P2x+=40;
  327.                      }  
  328.                      if(broken[B1][B2]==false){
  329.                          B2--;
  330.                      }  
  331.                      repaint();
  332.                      break;
  333.                      case KeyEvent.VK_J:
  334.                          P2xc=P2x;
  335.                          P2yc=P2y;
  336.                          if(B2!=0){
  337.                             B2--;
  338.                          }
  339.                          if(P2x==4){
  340.                          }else if(broken[B1][B2]==true){
  341.                              P2x-=40;
  342.                          }
  343.                          if(broken[B1][B2]==false){
  344.                              B2++;
  345.                          }
  346.                          repaint();
  347.                          break;
  348.                      case KeyEvent.VK_H:
  349.                          BluePlace=true;
  350.                          
  351.                          repaint();
  352.                          break;
  353.          }
  354.        
  355.     }
  356.  
  357.     public void keyTyped(KeyEvent e) {
  358.         // TODO Auto-generated method stub
  359.        
  360.     }
  361.  
  362. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement