import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class twoplayergamebomb extends JApplet implements KeyListener{
int P1x=4;
int P1y=4;
int P1xc=4;
int P1yc=4;
int P2x=564;
int P2y=564;
int P2xc=564;
int P2yc=564;
int B1=0;
int B2=0;
int R1=0;
int R2=0;
double bombNorthg=Math.random();
double bombSouthg=Math.random();
double bombWestg=Math.random();
double bombEastg=Math.random();
int bombNorth;
int bombSouth;
int bombEast;
int bombWest;
int PowerUp=1;
Color darkRed=new Color(178,32,32);
Color lightRed=new Color(225,32,32);
Color darkBlue=new Color(0,0,128);
Color lightBlue=new Color(0,0,200);
boolean RedPlace=false;
boolean BluePlace=false;
boolean[][] broken=new boolean[15][15];
int background = 0;
public void init(){
setSize(600,600);
addKeyListener(this);
}
public void background(Graphics g){
int y=40;
int x=40;
while(x<601){
g.drawLine(x, 0, x, 600);
g.drawLine(0, y, 600, y);
x+=40;
y+=40;
}
int x1=4;
int y1=4;
int addative=40;
int counter=0;
while(counter<225){
g.fillRect(x1, y1, 32, 32);
if(x1>=564 || x1<=0){
y1+=40;
addative=-addative;
g.fillRect(x1, y1, 32, 32);
}
if(y1>-123){
x1+=addative;
}
counter++;
}
g.setColor(Color.white);
g.fillRect(44, 4, 32, 32);
g.fillRect(4, 44, 32, 32);
g.fillRect(524, 564, 32, 32);
g.fillRect(564, 524, 32, 32);
counter=0;
addative=1;
while(counter<15){
broken[0][B2]=false;
broken[1][B2]=false;
broken[2][B2]=false;
broken[3][B2]=false;
broken[4][B2]=false;
broken[5][B2]=false;
broken[6][B2]=false;
broken[7][B2]=false;
broken[8][B2]=false;
broken[9][B2]=false;
broken[10][B2]=false;
broken[11][B2]=false;
broken[12][B2]=false;
broken[13][B2]=false;
broken[14][B2]=false;
broken[0][R2]=false;
broken[1][R2]=false;
broken[2][R2]=false;
broken[3][R2]=false;
broken[4][R2]=false;
broken[5][R2]=false;
broken[6][R2]=false;
broken[7][R2]=false;
broken[8][R2]=false;
broken[9][R2]=false;
broken[10][R2]=false;
broken[11][R2]=false;
broken[12][R2]=false;
broken[13][R2]=false;
broken[14][R2]=false;
B2++;
counter++;
}
broken[0][0]=true;
broken[1][0]=true;
broken[0][1]=true;
broken[14][14]=true;
broken[14][13]=true;
broken[13][14]=true;
B1=14;
B2=14;
R1=0;
R2=0;
}
public void players(Graphics g){
g.setColor(Color.white);
g.fillRect(P2xc, P2yc, 32, 32);
g.fillRect(P1xc, P1yc, 32, 32);
g.setColor(Color.red);
g.fillRect(P1x, P1y, 32, 32);
g.setColor(Color.blue);
g.fillRect(P2x, P2y, 32, 32);
}
public void paint(Graphics g){
if(background==0){
background++;
background(g);
}
players(g);
BombPlace(g);
RedBomb r= new RedBomb();
r.init();
r.input(P1x, P1y, darkRed, lightRed);
r.repaint();
}
public void generator(){
bombNorthg=Math.random();
bombSouthg=Math.random();
bombWestg=Math.random();
bombEastg=Math.random();
bombNorth=(int) bombNorthg;
bombSouth=(int) bombSouthg;
bombWest=(int) bombWestg;
bombEast=(int) bombEastg;
}
public void BombPlace(Graphics g){
if(RedPlace==true){
g.setColor(darkRed);
g.fillRect(P1x+5,P1y+5,22,22);
repaint();
RedPlace=false;
}else if(BluePlace==true){
g.setColor(darkBlue);
g.fillRect(P2x+5, P2y+5, 22, 22);
repaint();
BluePlace=false;
}
}
public void BombExplode(Graphics g){
generator();
if(PowerUp==1){
if(bombSouth<3){
bombSouth+=3;
}else if(bombNorth<3){
bombNorth+=3;
}else if(bombEast<3){
bombEast+=3;
}else if(bombWest<3){
bombWest+=3;
}else{
bombNorth=bombNorth/5;
bombSouth=bombSouth/5;
bombEast=bombEast/5;
bombWest=bombWest/5;
}
}else if(PowerUp==2){
bombNorth=bombNorth/3;
bombSouth=bombSouth/3;
bombEast=bombEast/3;
bombWest=bombWest/3;
}else if(PowerUp==3){
}else if(PowerUp==4){
}else if(PowerUp==5){
}
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_W:
P1yc=P1y;
P1xc=P1x;
if(R1!=0){
R1--;
}
if(P1y==4 ){
}else if(broken[R1][R2]==true){
P1y-=40;
}if(broken[R1][R2]==false){
R1++;
}
repaint();
break;
case KeyEvent.VK_S:
P1yc=P1y;
P1xc=P1x;
if(R1!=14){
R1++;
}
if(P1y==564){
}else if(broken[R1][R2]==true){
P1y+=40;
}
if(broken[R1][R2]==false){
R1--;
}
repaint();
break;
case KeyEvent.VK_D:
P1xc=P1x;
P1yc=P1y;
if(R2!=14){
R2++;
}
if(P1x==564){
}else if(broken[R1][R2]==true){
P1x+=40;
}
if(broken[R1][R2]==false){
R2--;
}
repaint();
break;
case KeyEvent.VK_A:
P1xc=P1x;
P1yc=P1y;
if(R2!=0){
R2--;
}
if(P1x==4){
}else if(broken[R1][R2]==true){
P1x-=40;
}
if(broken[R1][R2]==false){
R2++;
}
repaint();
break;
case KeyEvent.VK_F:
RedPlace=true;
repaint();
break;
}
switch (e.getKeyCode()) {
case KeyEvent.VK_I:
P2yc=P2y;
P2xc=P2x;
if(B1!=0){
B1--;
}
if(P2y==4){
}else if(broken[B1][B2]==true){
P2y-=40;
}
if(broken[B1][B2]==false){
B1++;
}
repaint();
break;
case KeyEvent.VK_K:
P2yc=P2y;
P2xc=P2x;
if(B1!=14){
B1++;
}
if(P2y==564){
}else if(broken[B1][B2]==true){
P2y+=40;
}
if(broken[B1][B2]==false){
B1--;
}
repaint();
break;
case KeyEvent.VK_L:
P2xc=P2x;
P2yc=P2y;
if(B2!=14){
B2++;
}
if(P2x==564){
}else if(broken[B1][B2]==true){
P2x+=40;
}
if(broken[B1][B2]==false){
B2--;
}
repaint();
break;
case KeyEvent.VK_J:
P2xc=P2x;
P2yc=P2y;
if(B2!=0){
B2--;
}
if(P2x==4){
}else if(broken[B1][B2]==true){
P2x-=40;
}
if(broken[B1][B2]==false){
B2++;
}
repaint();
break;
case KeyEvent.VK_H:
BluePlace=true;
repaint();
break;
}
}
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
}