コード例 #1
0
ファイル: GamePanel.java プロジェクト: smittal13/Assignment-3
 // Update the tile based on its properties
 protected void update() {
   if (mTile == null) return;
   if (mTile.isOccupied() && !pawnDisplayed) {
     pawnDisplayed = true;
     components.push(pawn);
   }
   if (mTile.isOccupied() && pawnDisplayed) {
     pawn.setBackground(mTile.getPawnColor());
   }
   if (!mTile.isOccupied() && pawnDisplayed) {
     pawnDisplayed = false;
     components.pop();
   }
   removeAll();
   if (!components.isEmpty()) add(components.peek());
 }
コード例 #2
0
ファイル: GamePanel.java プロジェクト: smittal13/Assignment-3
    TilePanel(Tile tile) {
      mTile = tile;
      setOpaque(false);
      // Used to keep track what component should be displayed
      components = new Stack<Component>();

      if (mTile != null) {
        if (mTile.isHome()) {
          try {
            JLabel j = new JLabel("Home");
            Font f =
                Font.createFont(
                    Font.TRUETYPE_FONT, new FileInputStream("src/fonts/kenvector_future.ttf"));
            f = f.deriveFont(7f);
            j.setFont(f);
            components.push(j);
          } catch (FontFormatException | IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
        if (mTile.isStart()) {
          try {
            JLabel j = new JLabel("Start");
            Font f =
                Font.createFont(
                    Font.TRUETYPE_FONT, new FileInputStream("src/fonts/kenvector_future.ttf"));
            f = f.deriveFont(7f);
            j.setFont(f);
            components.push(j);
          } catch (FontFormatException | IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }

      // If the tile is clicked by the user...
      addMouseListener(
          new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent me) {
              // Update this in the action manager
              mGameManager.tileClicked(mTile, mGameManager.getMainPlayer());
            }
          });
    }
コード例 #3
0
ファイル: Node.java プロジェクト: ConcoMB/TP-EDA
 public int extraHV() {
   int heurVal = board.getPossiblePositions(myTile).size() * 3;
   if (heurVal == 0 && board.getPossiblePositions(myTile.getOpposite()).isEmpty()) {
     int myCount = 0, otherCount = 0;
     for (int row = 0; row < Board.SIZE; row++) {
       for (int col = 0; col < Board.SIZE; col++) {
         if (board.getField()[row][col] == myTile) {
           myCount++;
         } else if (board.getField()[row][col] == myTile.getOpposite()) {
           otherCount++;
         }
       }
       if (myCount - otherCount < 0) {
         return -10000;
       } else if (myCount - otherCount > 0) {
         return 10000;
       }
     }
   }
   heurVal += controlCorners(heurVal) + controlBorders(heurVal);
   return heurVal;
 }
コード例 #4
0
ファイル: Node.java プロジェクト: ConcoMB/TP-EDA
 public void setChilds() {
   int myRow, myCol;
   for (int row = 0; row < Board.SIZE; row++) {
     for (int col = 0; col < Board.SIZE; col++) {
       if (board.getTile(row, col) == myTile.getOpposite()) {
         for (Direction dir : Direction.values()) {
           myRow = row + dir.getRow();
           myCol = col + dir.getCol();
           if (!(myRow < 0 || myCol < 0 || myRow >= Board.SIZE || myCol >= Board.SIZE)
               && board.getTile(myRow, myCol) == Tile.EMPTY) {
             if (board.possibleChange(myRow, myCol, myTile, dir.getOpposite())) {
               childs.add(
                   getNewChild(
                       board.putTile(myRow, myCol, myTile.getOpposite()),
                       new Position(myRow, myCol),
                       myTile.getOpposite()));
             }
           }
         }
       }
     }
   }
 }
コード例 #5
0
ファイル: GamePanel.java プロジェクト: smittal13/Assignment-3
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);
      // If we are a meaningful tile in the game
      if (mTile != null) {
        if (mTile.getColor() == Color.RED) {
          fileString = "src/images/tiles/red_tile.png";
        } else if (mTile.getColor() == Color.BLUE) {
          fileString = "src/images/tiles/blue_tile.png";
        } else if (mTile.getColor() == Color.GREEN) {
          fileString = "src/images/tiles/green_tile.png";
        } else if (mTile.getColor() == Color.YELLOW) {
          fileString = "src/images/tiles/yellow_tile.png";
        } else {
          fileString = "src/images/tiles/grey_tile.png";
        }

        // Set any special looks based on the tiles properties
        if (mTile.doesSlide()) {
          if (mTile.getColor() == Color.RED) {
            slideString = "src/images/sliders/red_slide.png";
            backString = "src/images/tiles/red_tile.png";
          } else if (mTile.getColor() == Color.BLUE) {
            slideString = "src/images/sliders/blue_slide.png";
            backString = "src/images/tiles/blue_tile.png";
          } else if (mTile.getColor() == Color.GREEN) {
            slideString = "src/images/sliders/green_slide.png";
            backString = "src/images/tiles/green_tile.png";
          } else if (mTile.getColor() == Color.YELLOW) {
            slideString = "src/images/s)liders/yellow_slide.png";
            backString = "src/images/tiles/yellow_tile.png";
          }
        }
        if (mTile.isStart()) {
          if (mTile.getColor() == Color.RED) {
            backString = "src/images/panels/red_panel.png";
          } else if (mTile.getColor() == Color.BLUE) {
            backString = "src/images/panels/blue_panel.png";
          } else if (mTile.getColor() == Color.GREEN) {
            backString = "src/images/panels/green_panel.png";
          } else if (mTile.getColor() == Color.YELLOW) {
            backString = "src/images/panels/yellow_panel.png";
          }
        }
        if (mTile.isHome()) {
          if (mTile.getColor() == Color.RED) {
            backString = "src/images/panels/red_panel.png";
          } else if (mTile.getColor() == Color.BLUE) {
            backString = "src/images/panels/blue_panel.png";
          } else if (mTile.getColor() == Color.GREEN) {
            backString = "src/images/panels/green_panel.png";
          } else if (mTile.getColor() == Color.YELLOW) {
            backString = "src/images/panels/yellow_panel.png";
          }
        }
        try {
          i = ImageIO.read(new File(fileString));
          j = ImageIO.read(new File(backString));
          k = ImageIO.read(new File(slideString));
        } catch (IOException e) {
          e.getMessage();
        }
        g.drawImage(j, 0, 0, getWidth(), getHeight(), null);
        g.drawImage(i, 0, 0, getWidth(), getHeight(), null);
        g.drawImage(k, 9, 5, getWidth() / 2, getHeight() / 2, null);
      }
    }