package GUI;
import Game.Game;
import GamePlay.Player;
import Map.MakeMapOne;
import Node.Node;
import java.awt.Graphics;
import Map.Map;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
/**
*
*
*/
public class gameGUI extends javax.swing.JPanel {
private Game game;
private boolean lfcard;//boolean for if they are looking for turn
private boolean lfnode;
private int columnnum;
private int nodenum;
/** Creates new form GameInterface */
public gameGUI(Game g) {
game=g;
node=new nodeGUI[22];
cardb=new cardButton[7];
initComponents();
setBackgroundTranslucent();
setNodes(game.getMap());
jLabel1.setText(game.getPlayers()[0].getUserName());
jLabel2.setText(game.getPlayers()[1].getUserName());
lfcard=false;
lfnode=true;
addActionListeners();
setCards();
repaint();
//repaint();
}
public void addActionListeners(){
for(int i=0;i<7;i++){
final int ifinal=i;
cardb[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if(lfcard==false){
System.out.println("not looking for card nigga "+ifinal);
}
else{
if(game.getTurn()==1||game.getTurn()==3){
if(game.verifyCard(game.getMap().getColumn(columnnum)[nodenum], ifinal)){
game.move(game.getMap().getColumn(columnnum)[nodenum], ifinal);
setNodes(game.getMap());
setCards();
repaint();
lfnode=true;//looking for node
lfcard=false;//not looking for card;
}
}
else{
game.block(game.getMap().getColumn(columnnum)[nodenum], ifinal);
setNodes(game.getMap());
setCards();
repaint();
lfnode=true;//looking for node
lfcard=false;//not looking for card;
}
}
}
});
}
StartButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
}
});
for(int i=0;i<22;i++){
final int ifinal=i;
node[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
int column=(int)(ifinal/3);
int node=ifinal%3;
if(lfnode==false){
System.out.println("not looking for node nigga "+ifinal);
}
else{
//turn = 1 or 3
if(game.getTurn()==3||game.getTurn()==1){
if(game.checkMove(game.getMap().getColumn(column)[node])){
//prompt for card
columnnum=column;//saving the column number for access later
nodenum=node;//saving the node number for acces later
lfnode=false;//not looking for node
lfcard=true;//looking for card;
}
}
else{
if(game.isBlockable(game.getMap().getColumn(column)[node])){
//prompt for card
columnnum=column;//saving the column number for access later
nodenum=node;//saving the node number for acces later
lfnode=false;//not looking for node
lfcard=true;//looking for card;
}
}
//turn = 2 or 4
}
}
});
}
}
public void setCards(){
int player;
System.out.println(game.getTurn());
if(game.getTurn()<3)player=0;
else player=1;
int cards=game.getPlayers()[player].cardCount();
Player p=game.getPlayers()[player];
for(int i=0;i<7;i++){
if(i<cards){
cardb[i].setsIcon(p.getCard(i).getGraphic());
}
else{
cardb[i].setsIcon("Graphics/emptyCard.jpg");
}
}
}
public void setNodes(Map m){
Node test;
Player[] ps;
test=m.getStart();
ps=game.getPlayers();
if(ps[0].getPosition().equals(test)){
if(ps[1].getPosition().equals(test)){
StartButton.setsIcon(test.getValue(),3);
}
else{
StartButton.setsIcon(test.getValue(),1);
}
}
else{
if(ps[1].getPosition().equals(test)){
StartButton.setsIcon(test.getValue(),2);
}
else{
StartButton.setsIcon(test.getValue());
}
}
for(int i =0;i<7;i++){
for(int j=0;j<3;j++){
test=m.getColumn(i)[j];
ps=game.getPlayers();
if(ps[0].getPosition().equals(test)){
if(ps[1].getPosition().equals(test)){
node[i*3+j].setsIcon(test.getValue(),3);
}
else{
node[i*3+j].setsIcon(test.getValue(),1);
}
}
else{
if(ps[1].getPosition().equals(test)){
node[i*3+j].setsIcon(test.getValue(),2);
}
else{
node[i*3+j].setsIcon(test.getValue());
}
}
}
}
test=m.getColumn(7)[0];
ps=game.getPlayers();
if(ps[0].getPosition().equals(test)){
if(ps[1].getPosition().equals(test)){
node[21].setsIcon(test.getValue(),3);
}
else{
node[21].setsIcon(test.getValue(),1);
}
}
else{
if(ps[1].getPosition().equals(test)){
node[21].setsIcon(test.getValue(),2);
}
else{
node[21].setsIcon(test.getValue());
}
}
}
public void setBackgroundTranslucent(){
jPanel1.setOpaque(false);
//jPanel1.setBackground(Color.red);
}
public Node[] forwardNodes(List l){
Node[] n=new Node[3];
for(int i=0;i<l.size();i++){
n[i]=(Node)l.get(i);
}
return n;
}
public Graphics drawLines(Map m, Graphics g){
Node[] first;
Node[] second;
int spot=0;
int y=0;
int y1=0;
int x;
for(int i=0;i<6;i++){
x=75+i*150;
first=m.getColumn(i);
second=m.getColumn(i+1);
for(int n=0;n<3;n++){
if(n==0)y1=167;
if(n==1)y1=285;
if(n==2)y1=390;
Node at=first[n];
List l=at.getForwardPaths();
for(int lines=0;lines<l.size();lines++){
for(int s=0;s<3;s++){
if(((Node)l.get(lines)).equals(second[s])){
spot=s;
}
}
if(spot==0)y=167;
if(spot==1)y=285;
if(spot==2)y=390;
g.drawLine(x+150, y1, x+300, y);
}
}
}
return g;
}
public void paintComponent(Graphics page){
super.paintComponent(page);
page=drawLines(game.getMap(),page);
page.drawLine(75, 285, 225,167 );
page.drawLine(75, 285, 225, 285);
page.drawLine(75, 285, 225, 390);
page.drawLine(1125,167 , 1275, 285);
page.drawLine(1125, 285, 1275,285);
page.drawLine(1125,390 , 1275, 285);
//page.fillRect(5,5,50,5);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
public void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
jPanel1 = new javax.swing.JPanel();
StartButton = new nodeGUI(1);
node[0] = new nodeGUI(1);
node[1] = new nodeGUI(1);
node[2] = new nodeGUI(1);
node[3] = new nodeGUI(1);
node[4] = new nodeGUI(1);
node[5] = new nodeGUI(1);
node[6] = new nodeGUI(4);
node[7] = new nodeGUI(4);
node[8] = new nodeGUI(4);
node[9] = new nodeGUI(1);
node[10] = new nodeGUI(1);
node[11] = new nodeGUI(4);
node[12] = new nodeGUI(4);
node[13] = new nodeGUI(4);
node[14] = new nodeGUI(4);
node[15] = new nodeGUI(4);
node[16] = new nodeGUI(4);
node[17] = new nodeGUI(4);
node[18] = new nodeGUI(4);
node[19] = new nodeGUI(4);
node[20] = new nodeGUI(4);
node[21] = new nodeGUI(4);
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
cardb[0] = new cardButton(game.getPlayers()[0].getCard(0).getGraphic());
cardb[1] = new cardButton(game.getPlayers()[0].getCard(1).getGraphic());
cardb[2] = new cardButton(game.getPlayers()[0].getCard(2).getGraphic());
cardb[3] = new cardButton(game.getPlayers()[0].getCard(3).getGraphic());
cardb[4] = new cardButton(game.getPlayers()[0].getCard(4).getGraphic());
cardb[5] = new cardButton(game.getPlayers()[0].getCard(5).getGraphic());
cardb[6] = new cardButton(game.getPlayers()[0].getCard(6).getGraphic());
jButton1 = new javax.swing.JButton();
jPanel1.setLayout(new java.awt.GridBagLayout());
StartButton.setText(null);
StartButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
StartButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
jPanel1.add(StartButton, gridBagConstraints);
node[0].setText(null);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 0;
jPanel1.add(node[0], gridBagConstraints);
node[1].setText(null);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 2;
gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
jPanel1.add(node[1], gridBagConstraints);
node[2].setText(null);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 4;
jPanel1.add(node[2], gridBagConstraints);
node[3].setText(null);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 0;
jPanel1.add(node[3], gridBagConstraints);
node[4].setText(null);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 2;
gridBagConstraints.ipady = 5;
gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
jPanel1.add(node[4], gridBagConstraints);
node[5].setText(null);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 4;
jPanel1.add(node[5], gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 6;
gridBagConstraints.gridy = 0;
jPanel1.add(node[6], gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 6;
gridBagConstraints.gridy = 2;
gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
jPanel1.add(node[7], gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 6;
gridBagConstraints.gridy = 4;
jPanel1.add(node[8], gridBagConstraints);
node[9].setText(null);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 8;
gridBagConstraints.gridy = 0;
jPanel1.add(node[9], gridBagConstraints);
node[10].setText(null);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 8;
gridBagConstraints.gridy = 2;
gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
jPanel1.add(node[10], gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 8;
gridBagConstraints.gridy = 4;
jPanel1.add(node[11], gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 10;
gridBagConstraints.gridy = 0;
jPanel1.add(node[12], gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 10;
gridBagConstraints.gridy = 2;
gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
jPanel1.add(node[13], gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 10;
gridBagConstraints.gridy = 4;
jPanel1.add(node[14], gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 12;
gridBagConstraints.gridy = 0;
jPanel1.add(node[15], gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 12;
gridBagConstraints.gridy = 2;
gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
jPanel1.add(node[16], gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 12;
gridBagConstraints.gridy = 4;
jPanel1.add(node[17], gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 14;
gridBagConstraints.gridy = 0;
jPanel1.add(node[18], gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 14;
gridBagConstraints.gridy = 2;
gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
jPanel1.add(node[19], gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 14;
gridBagConstraints.gridy = 4;
jPanel1.add(node[20], gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 16;
gridBagConstraints.gridy = 2;
gridBagConstraints.insets = new java.awt.Insets(50, 50, 50, 50);
jPanel1.add(node[21], gridBagConstraints);
jLabel3.setText("Start Point");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
jPanel1.add(jLabel3, gridBagConstraints);
jLabel4.setText("Switch Point");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 16;
gridBagConstraints.gridy = 1;
jPanel1.add(jLabel4, gridBagConstraints);
jLabel1.setText("Player 1");//Player[0].getUserName());
jLabel2.setText("Player2");//Player[1].getUserName());
jPanel2.setLayout(new java.awt.GridBagLayout());
cardb[0].setText("");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
jPanel2.add(cardb[0], gridBagConstraints);
cardb[1].setText("");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
jPanel2.add(cardb[1], gridBagConstraints);
cardb[2].setText("");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
jPanel2.add(cardb[2], gridBagConstraints);
cardb[3].setText("");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
jPanel2.add(cardb[3], gridBagConstraints);
cardb[4].setText("");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
jPanel2.add(cardb[4], gridBagConstraints);
cardb[5].setText("");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 5;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
jPanel2.add(cardb[5], gridBagConstraints);
cardb[6].setText("");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 6;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
jPanel2.add(cardb[6], gridBagConstraints);
jButton1.setText("jButton1");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.insets = new java.awt.Insets(0, 75, 0, 0);
jPanel2.add(jButton1, gridBagConstraints);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1773, Short.MAX_VALUE)
.addComponent(jLabel2)
.addGap(58, 58, 58))
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(1102, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(182, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(115, 115, 115)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
);
}// </editor-fold>
public void StartButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
public nodeGUI[] node;
public nodeGUI StartButton;
public cardButton[] cardb;
public javax.swing.JButton jButton1;
public javax.swing.JLabel jLabel1;
public javax.swing.JLabel jLabel2;
public javax.swing.JLabel jLabel3;
public javax.swing.JLabel jLabel4;
public javax.swing.JPanel jPanel1;
public javax.swing.JPanel jPanel2;
// End of variables declaration
}