diff --git a/AzulPanel.java b/AzulPanel.java index 2416903..2901416 100644 --- a/AzulPanel.java +++ b/AzulPanel.java @@ -8,10 +8,11 @@ public class AzulPanel extends JPanel{ - BufferedImage background, strtscrn; + BufferedImage background, strtscrn, gameSum; public static boolean strt; public BufferedImage []tileimage; public static int tilesize = 66; + public static int currentScore, currentRow, playerInc; public Factory[] allFactory = AzulWindow.allFactory; public static FactoryFloor factoryFloor = AzulWindow.factoryFloor; @@ -37,6 +38,7 @@ public AzulPanel(){ tileimage = new BufferedImage [6]; try{ strtscrn = ImageIO.read(getClass().getResource("/images/cover page.png")); + gameSum = ImageIO.read(getClass().getResource("/images/Finalscrn.png")); background = ImageIO.read(getClass().getResource("/images/FinalForMe.jpg")); tileimage[0] = ImageIO.read(getClass().getResource("/images/blue.png")); tileimage[1] = ImageIO.read(getClass().getResource("/images/yellow.png")); @@ -54,16 +56,17 @@ public void paint(Graphics g) { if(strt) { g.drawImage(strtscrn, 0, 0, getWidth(), getHeight(), null); + } if(!strt) { //1. BACKGROUND - FINAL g.drawImage(background, -10, -10, getWidth(), getHeight(), null); - + //2. CURRENT PLAYER TAG - FINAL g.setFont(new Font("Algerian", Font.PLAIN, 45)); int id = allPlayer[0].ID; - g.drawString("Player "+ id , 1500,985); + g.drawString("Player "+ id + " ", 1500,985); //3. FACTORY FLOOR NUMBER INDECATORS - FINAL int xinc = 85+10; @@ -106,6 +109,7 @@ else if (b==2) } } + //5. BUFFER ZONE BIG TILE + NUMBER INDECATOR - FINAL if (!allPlayer[0].BufferZone.isEmpty()) { g.setFont(new Font("Algerian", Font.PLAIN, 60)); @@ -127,40 +131,58 @@ else if(output.equals("1")) { g.drawString("the arrows near the pattern lines or the area in the floor line",1420,650+200+20-10); } else if(output.equals("3")) { - g.drawString("Scoring:",1420,650+200-10); + String str = "Scoring:"; + if (currentRow <5) + str += " Pattern Line "+ currentRow; + else if (currentRow == 5) + str += " Floor Line"; + else + str += " End Game Bonuses"; + g.drawString(str,1420,650+200-10); g.setFont(new Font("Dialog", Font.PLAIN, 15)); - g.drawString("Player Directions?",1420,650+200+20-10); + g.drawString("Click on the score button to score the next row",1420,650+200+20-10); + g.setFont(new Font("Algerian", Font.PLAIN, 60)); + if (currentScore>0) + g.drawString("+" + currentScore,1519,750); + else + g.drawString("" + currentScore,1519,750); } g.setFont(new Font("Algerian", Font.PLAIN, 45)); } g.setColor(Color.GRAY); g.setFont(new Font("Algerian", Font.PLAIN, 20)); - //g.drawString("Copyright 2022",1375,565+10); + g.drawString("Version 12-2",1375,565+10); + /*g.drawString("Verti "+allPlayer[0].scoreVerti(),1375,985-20); + g.drawString("Horiz "+allPlayer[0].scoreHoriz(),1375,1000-20); + g.drawString("Color "+allPlayer[0].scorecolor(),1375,1015-20);*/ g.setFont(new Font("Dialog", Font.PLAIN, 15)); - //g.drawString("Jess Luc Omar Josh",1375+220,565+10); + g.drawString("Jess Luc Omar Josh",1375+220,565+10); g.setFont(new Font("Algerian", Font.PLAIN, 45)); g.setColor(Color.BLACK); + //5.5 FINAL GAME VICTORS AND SCORE COMPARISON - if (endgame) { - g.setFont(new Font("Algerian", Font.ITALIC, 45)); - g.drawString("Game Summary ",1435,660); + if (endgame && playerInc ==4 && currentRow == 5) { + + g.drawImage(gameSum, -10, -10, getWidth(), getHeight(), null); + g.setFont(new Font("Algerian", Font.ITALIC, 50)); + g.drawString("Game Summary ",1427,165); g.setFont(new Font("Algerian", Font.PLAIN, 20)); - g.drawString("Player",1400+20+15,660+45); g.drawString("score.",1400+20+30+130-40,660+45); g.drawString("|hori|",1400+20+50+130+20,660+45); g.drawString("vert|",1400+15+120+130+15,660+45); g.drawString("colo.",1400+20+15+15+160+130,660+45); g.setFont(new Font("Algerian", Font.PLAIN, 25)); for (int b = 0; bcol = new ArrayList<>(); @@ -279,5 +301,10 @@ public void updateAll(Factory[] af, FactoryFloor f, ArrayList b, Player strt = start; output = out; } + public void updateScoring(int score, int row, int play) { + currentScore = score; + currentRow = row; + playerInc = play; + } } \ No newline at end of file diff --git a/AzulWindow.java b/AzulWindow.java index 4da5ad2..0d91499 100644 --- a/AzulWindow.java +++ b/AzulWindow.java @@ -6,13 +6,16 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.image.BufferedImage; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.TreeMap; import java.util.concurrent.TimeUnit; import javax.imageio.ImageIO; +import javax.swing.AbstractButton; import javax.swing.BorderFactory; +import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; @@ -28,6 +31,7 @@ public class AzulWindow extends JFrame implements ItemListener, ActionListener{ public static final int height = 1080; public static final int tilesize = 60; public BufferedImage []tileimage; + public BufferedImage score; public ImageIcon[] ruleBook; Container c; @@ -39,11 +43,13 @@ public class AzulWindow extends JFrame implements ItemListener, ActionListener{ static ArrayList victors; static PlainButton startB; static String output; + static int scoreRow, first, playerInc, maxRotation; //players ArrayList patternButton; PlainButton FloorButton; + JButton scoreButton ; static Player [] allPlayer; //animations @@ -66,6 +72,7 @@ public class AzulWindow extends JFrame implements ItemListener, ActionListener{ roundscore = false; endgame = false; + maxRotation = 5; //images tileimage = new BufferedImage [6]; @@ -94,6 +101,14 @@ public class AzulWindow extends JFrame implements ItemListener, ActionListener{ Collections.shuffle(bag); lid = new ArrayList(); + /* + + add button in the space right next to the current player tag for scoring + after each click, the panel is refreshed an a new row scores + remember to do the end game scoring too + + + */ //creating factories & its buttons allFactory = new Factory [9]; @@ -105,7 +120,7 @@ public class AzulWindow extends JFrame implements ItemListener, ActionListener{ PlainButton button = new PlainButton (b,i); setFactoryTileFunction(button); Buttonlist.add(button); - Collections.shuffle(bag); + //Collections.shuffle(bag); tile.add(bag.remove(0)); } Factory temp = new Factory(tile,i); @@ -143,10 +158,32 @@ public class AzulWindow extends JFrame implements ItemListener, ActionListener{ panel.setBounds(0,0,width, height); panel.setBorder(BorderFactory.createLineBorder(Color.black)); - //adding button + //adding start button + scoreButton = new JButton ("score"); + //scoreButton.setLabel("Score"); + scoreButton.setSize(80,75); + Icon score = null;; + try { + score = new ImageIcon(ImageIO.read(getClass().getResource("/images/arrow.png"))); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + scoreButton.setIcon(score); + scoreButton.setLabel("SCORE"); + scoreButton.setHorizontalTextPosition(AbstractButton.CENTER); + scoreButton.setLocation(1375,985-25-25); + setScoreFunction(scoreButton); + scoreButton.setEnabled(false); + + //adding start button startB = new PlainButton ("start"); startB.setSize(629-10,243-10); startB.setLocation(1021-10,686-10); + startB.setBorder(null); + startB.setBorderPainted(false); + startB.setContentAreaFilled(false); + startB.setOpaque(false); startB.addActionListener(new ActionListener() { @Override @@ -156,9 +193,9 @@ public void actionPerformed(ActionEvent e) { panel.updateAll(allFactory,factoryFloor,bag, allPlayer, roundscore,endgame,strt, output); c.validate(); c.repaint(); - + startB.setEnabled(false); c.add(panel); - System.out.println(strt); + c.add(scoreButton); }}); //adding button @@ -197,8 +234,105 @@ public void actionPerformed(ActionEvent e) { } + public void setScoreFunction(JButton scoreButton2) { + scoreButton2.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + //score + output = "3"; + panel.updateAll(allFactory,factoryFloor,bag, allPlayer, roundscore,endgame,strt, output); + //THE SPLIT SECOND OF ANIMATION - disable all buttons + for (Factory f: allFactory) + f.setEnabled(false); + setEnabledPlayer(false); + factoryFloor.setEnabled(false); + Player p = allPlayer[0]; + int i = scoreRow; + int score = 0; + + //scoring PATTERNLINES + if (i < 5) { + if (p.score(i) >-1) { + score = p.score(i); + int [] temp = p.patternLine[i]; + int col = p.idealwall.get(i).lastIndexOf(temp[0]); + ArrayList arr = p.wall.get(i); + arr.set(col, p.patternLine[i][0]); + p.wall.set(i,arr); + p.scoreWall.get(i).set(col, score); + p.clearPattern(i); + //System.out.println(); + } + } + //FLOOR LINES + else if (i == 5) { + i = 0; + while(i <7 && p.floorLine[i]!=-1 ) { + if (i == 0 || i==1) + score -=1; + if (i == 2 || i==3 || i == 4) + score -=2; + if (i == 6 || i==5) + score -=3; + i++; + } + + if (p.clearFloor()) + first = p.ID; + + endgame = endgame ||p.checkWall(); + + } + //checks end game conditions + if (endgame) { + victors = new ArrayList<>(); + + int horizontal = p.scoreHoriz(); + score += 2*horizontal; + + int vertical = p.scoreVerti(); + score += 7*vertical; + + int color = p.scorecolor(); + score += 10*color; + + } + p.score += score; + + if (p.score < 0) + p.score = 0; + if(p.score>100) + p.score = 100; + + panel.updateScoring(score,i, playerInc); + + c.validate(); + c.repaint(); + + if (scoreRow == 5 && playerInc == 4){ + rotateRound(first); + refillFactory(); + for (Factory f: allFactory) + f.setEnabled(true); + setEnabledPlayer(false); + factoryFloor.setEnabled(true); + scoreButton.setEnabled(false); + } + else if (scoreRow <= 5){ + if (scoreRow == 5) { + playerInc ++; + scoreRow =0; + rotateTurn(); + //doesn't recpgnize endgame situations + } + else + scoreRow++; + + } + + }});} public void setFactoryTileFunction(PlainButton temp) { temp.addActionListener(new ActionListener() { @@ -206,7 +340,6 @@ public void setFactoryTileFunction(PlainButton temp) { public void actionPerformed(ActionEvent e) { output = "1"; - System.out.println(output); panel.updateAll(allFactory,factoryFloor,bag, allPlayer, roundscore,endgame,strt, output); //REPAINT EVERYTHING c.validate(); @@ -295,11 +428,6 @@ public void actionPerformed(ActionEvent e) { //from: int x = temp.getBounds().x; int y = temp.getBounds().y; - //tile size: - //81 - //color of tile: color - //to: 1460,662 - //final size: 150 // NEXT ACTION //DISABLE ALL OF FACTORY AND ENABLE ALL OF CURRENT PLAYER PATTERNLINE & FLOOR @@ -330,7 +458,6 @@ public void actionPerformed(ActionEvent e) { c.repaint(); c.add(panel); //BUTTON FUNCTION - int first = -1; int row = temp.ID; while (!allPlayer[0].BufferZone.isEmpty()) { //adding to patternLine @@ -343,17 +470,7 @@ public void actionPerformed(ActionEvent e) { allPlayer[0].addFloorLine(); } - /*System.out.println("pattern line"); - for (int[] i: allPlayer[0].patternLine) { - for (int n: i) - System.out.print(n+" "); - System.out.println(); - } - System.out.println("Floorline"); - for (int n: allPlayer[0].floorLine) - System.out.print(n+" "); - System.out.println(); - System.out.println("wall");*/ + //THE SPLIT SECOND OF ANIMATION for (Factory f: allFactory) f.setEnabled(false); @@ -361,17 +478,8 @@ public void actionPerformed(ActionEvent e) { factoryFloor.setEnabled(false); // ANIMATE LUC - //from: 1460,662 - //size: 150 - //to: int x = temp.getBounds().x; int y = temp.getBounds().y; - /* - for (ArrayList d: allPlayer[0].wall) { - for (int n: d) - System.out.print(n+" "); - System.out.println(); - }*/ // NEXT ACTION //DISABLE ALL OF FACTORY AND ENABLE ALL OF CURRENT PLAYER PATTERNLINE & FLOOR @@ -383,111 +491,10 @@ public void actionPerformed(ActionEvent e) { //CHECKS END ROUND / GAME CONDITIONS if (!allFactoryEmpty()) { roundscore = true; - - c.validate(); - c.repaint(); - //THE SPLIT SECOND OF ANIMATION - disable all buttons - for (Factory f: allFactory) - f.setEnabled(false); - setEnabledPlayer(false); - factoryFloor.setEnabled(false); - - //scoring + ANIMATE LUC - for (Player p: allPlayer) { - for (int i = 0; i < 5; i++) { - int score = p.score(i); - if (score >-1) { - p.score += score; - int [] temp = p.patternLine[i]; - int col = p.idealwall.get(i).lastIndexOf(temp[0]); - ArrayList arr = p.wall.get(i); - arr.set(col, p.patternLine[i][0]); - p.wall.set(i,arr); - p.scoreWall.get(i).set(col, score); - } - try { - Thread.sleep(2000); - } catch (InterruptedException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - c.validate(); - c.repaint(); - - } - int i = 0; - while(i <7 && p.floorLine[i]!=-1 ) { - if (i == 0 || i==1) - p.score -=1; - if (i == 2 || i==3 || i == 4) - p.score -=2; - if (i == 6 || i==5) - p.score -=3; - i++; - } - if (p.score < 0) - p.score = 0; - if(p.score>100) - p.score = 100; - - if (p.clearFloor()) - first = p.ID; - p.clearPattern(); - if (p.checkWall()) { - endgame = true; - //roundscore = true; - } - } - //checks end game conditions - if (endgame) { - System.out.println("--------END GAME"); - victors = new ArrayList<>(); - //score - for (Player p: allPlayer) { - for (int i = 0; i < 5; i++) { - // number of horizontal, vertical, colors completed in the wall - int horizontal = p.scoreHoriz(); - p.score += 2*horizontal; - - int vertical = p.scoreVerti(); - p.score += 7*vertical; - - int color = p.scorecolor(); - p.score += 10*color; - - //determining ties - victors contain the final winners - if (victors.size()>0 && victors.get(0).score < p.score) { - victors = new ArrayList<>(); - victors.add(p); - } - else if (victors.size()>0 && victors.get(0).score == p.score) { - victors.add(p); - } - else - victors.add(p); - } - } - //if tied - if (victors.size()>2) { - ArrayList temp = new ArrayList<>(); - for(Player p: temp) { - if (temp.size()>0 && temp.get(0).score < p.score) { - temp = new ArrayList<>(); - temp.add(p); - } - else if (temp.size()>0 && temp.get(0).score == p.score) { - temp.add(p); - } - else - temp.add(p); - - } - victors = temp; - } - } - - roundscore = true; - } + scoreButton.setEnabled(true); + scoreRow = 0; + playerInc = 1; + } if (endgame) { for (Factory f: allFactory) f.setEnabled(false); @@ -499,8 +506,10 @@ else if (temp.size()>0 && temp.get(0).score == p.score) { } else{ if (roundscore) { - rotateRound(first); - refillFactory(); + for (Factory f: allFactory) + f.setEnabled(false); + setEnabledPlayer(false); + factoryFloor.setEnabled(false); } else rotateTurn(); @@ -582,46 +591,31 @@ public void actionPerformed(ActionEvent e) { factoryFloor.setEnabled(true); //if factories & factory floor runs out - if (!allFactoryEmpty()) { - //THE SPLIT SECOND OF ANIMATION - for (Factory f: allFactory) - f.setEnabled(false); - setEnabledPlayer(false); - factoryFloor.setEnabled(false); - //score - for (Player p: allPlayer) { - for (int i = 0; i < 5; i++) { - int score = p.score(i); - if (score >-1) { - p.score += score; - int [] temp = p.patternLine[i]; - int col = p.idealwall.get(i).lastIndexOf(temp[0]); - p.wall.get(i).set(col, p.patternLine[i][0]); - } - System.out.println("+++++++"+ score); - for (ArrayList d: p.wall) { - for (int n: d) - System.out.print(n+" "); - System.out.println(); - } - } - int i = 0; - while(i< 7&&p.floorLine[i]!=-1) { - if (i == 0 || i==1) - p.score -=1; - if (i == 2 || i==3 || i == 4) - p.score -=2; - if (i == 6 || i==5) - p.score -=3; - i++; - } - if (p.score < 0) - p.score = 0; - System.out.println("++++++++++++++++++++++++"+ p.score); - p.clearFloor(); - p.clearPattern(); - } - refillFactory(); + if (!allFactoryEmpty()) { + roundscore = true; + scoreButton.setEnabled(true); + scoreRow = 0; + playerInc = 1; + + } + if (endgame) { + for (Factory f: allFactory) + f.setEnabled(false); + setEnabledPlayer(false); + factoryFloor.setEnabled(false); + c.validate(); + c.repaint(); + c.add(panel); + } + else{ + if (roundscore) { + for (Factory f: allFactory) + f.setEnabled(false); + setEnabledPlayer(false); + factoryFloor.setEnabled(false); + } + else + rotateTurn(); for (Factory f: allFactory) f.setEnabled(true); diff --git a/Player.java b/Player.java index 1013e20..6549413 100644 --- a/Player.java +++ b/Player.java @@ -57,6 +57,27 @@ else if (i == 4 || i == -1) } idealwall.add(arr); } + + /*s + for (int r = 0; r< 5; r++) { + ArrayList arr = new ArrayList (); + for (int c = 0; c<5; c++) { + int i = (c-r)%5; + if (i == 0) + arr.add(i); + else if (i == 1 || i == -4) + arr.add(1); + else if (i == 2 || i ==-3 ) + arr.add(3); + /*else if (i == 3 || i ==-2) + arr.add(4); + //else if (i == 4 || i == -1) + //arr.add(2); + else + arr.add(-1); + } + wall.add(arr); + }*/ //miscellaneous BufferZone = new ArrayList<>(); score = 0; @@ -107,8 +128,8 @@ void addFloorLine () { //wall.set(row,BufferZone); } - void clearPattern() { - for(int r = 0; r< 5; r++) { + void clearPattern(int r) { + for (int c = 0; c=0) { - if (wall.get(row).get(col-c) == -1) + for (int c = col-1; c >= 0; c--) { + if (wall.get(row).get(c) == -1) break; else - p ++; - } + v ++; } - for (int c = 1; c < 5; c++) { - t = c+ row; - if (c+ row < 5) { - if (wall.get(c+ row).get(col) == -1) + for (int c = row+1; c < 5; c++) { + if (wall.get(c).get(col) == -1) break; else - p ++; - } + h ++; } - for (int c = 1; c < 5; c++) { - t = row-c; - if (row-c >=0) { - if (wall.get(row-c).get(col) == -1) + for (int c = row-1; c >=0; c--) { + if (wall.get(c).get(col) == -1) break; else - p ++; - } + h ++; } - + if (v> 0 && h > 0) + p+=1; + System.out.println("verti "+v+" horiz "+h); + p += v + h; } return p; } @@ -228,4 +242,4 @@ else if (c==4) -} +} \ No newline at end of file