1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
public class Terrain extends JPanel
{
private ArrayList<Piece> array;
public int x=0, y=0;
public boolean fini = false;
public int[][] plateau;
public Color color = Color.BLUE;
public Terrain()
{
plateau = new int[6][7];
Jeu.initPlateau(plateau);
addMouseListener(new ColonneListener());
setBackground(Color.BLACK);
setPreferredSize(new Dimension(1401, 701));
}
public void paintComponent(Graphics page)
{
super.paintComponent(page);
page.setColor(Color.LIGHT_GRAY);
page.fillOval(300, 0, 200, 200);
page.fillOval(900, 0, 200, 200);
page.fillRect(300, 100, 800, 601);
page.fillRect(400, 0, 600, 100);
page.setColor(Color.WHITE);
// Menu
page.drawRect(0, 0, 200, 300);
page.setFont(new Font("Arial", Font.BOLD, 50));
page.drawString("Menu", 10, 50);
page.setFont(new Font("Arial", Font.BOLD, 20));
page.drawString("Regles", 10, 100);
page.drawString("Rejouer", 10, 150);
page.drawString("Quitter", 10, 200);
page.drawString("Joueur1", 10, 340);
// Bottom Left
page.drawRect(0, 350, 200, 350);
// Bottom Right
page.drawRect(1200, 350, 200, 350);
page.setColor(Color.BLUE);
page.fillRect(0, 325, 201, 24);
page.setColor(Color.RED);
page.fillRect(1200, 325, 201, 24);
page.setColor(Color.WHITE);
page.drawString("Jedi - Joueur1", 10, 345);
page.drawString("Sith - Joueur2", 1210, 345);
page.setColor(Color.YELLOW);
if(color==Color.BLUE)
{
page.fillOval(225, 325, 25, 25);
}
else
{
page.fillOval(1150, 325, 25, 25);
}
page.setColor(Color.BLACK);
for(int i=0; i<7; i++)
{
for(int j=0; j<6; j++)
{
page.fillOval(375+100*i, 75+100*j, 50, 50);
}
}
for(Piece piece : array)
{
piece.draw(page);
}
if(fini)
{
page.fillRect(0, 0, 1401, 701);
}
}
public void setArrayList(ArrayList<Piece> list)
{
array = list;
}
private class ColonneListener implements MouseListener
{
public void mousePressed (MouseEvent event)
{
int c = event.getX();
int l = event.getY();
for(int i = 0; i<6; i++)
{
for(int j = 0; j<7; j++)
{
if(50+100*i<l && l<150+100*i && c<450+100*j && 350+100*j<c && plateau[i][j]==0 && placable(i, j) && !fini)
{
array.add(new Piece(i, j, color));
for(int k=0; k<i+1; k++)
{
array.remove(array.size()-1);
array.add(new Piece(k, j, color));
setArrayList(array);
repaint();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if(color==Color.BLUE)
{
color = Color.RED;
plateau[i][j] = 1;
}
else
{
color = Color.BLUE;
plateau[i][j] = 2;
}
fini = Jeu.fini(plateau, new Piece(i, j, color));
}
}
}
}
public boolean placable (int i, int j)
{
boolean placable = true;
int c = i+1;
while(c<6 && placable)
{
if(plateau[c][j]==0)
{
placable = false;
}
c++;
}
return placable;
}
public void mouseClicked (MouseEvent event) {}
public void mouseReleased (MouseEvent event) {}
public void mouseEntered (MouseEvent event) {}
public void mouseExited (MouseEvent event) {}
}
} |
Partager