From c6ec39ebdb4ae92321361f9690ffe82f5e2a1faf Mon Sep 17 00:00:00 2001 From: Zachary Bonagura Date: Mon, 19 Aug 2024 12:58:04 -0400 Subject: [PATCH] Fixed Binary Cell merge conflict --- .../rpi/legup/puzzle/binary/BinaryCell.java | 68 ++++++++++++++++--- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/binary/BinaryCell.java b/src/main/java/edu/rpi/legup/puzzle/binary/BinaryCell.java index 56b37c03e..d09f7115e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/binary/BinaryCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/binary/BinaryCell.java @@ -1,30 +1,48 @@ package edu.rpi.legup.puzzle.binary; +import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.GridCell; - import java.awt.Point; +import java.awt.event.MouseEvent; + public class BinaryCell extends GridCell { - public BinaryCell(int valueInt, Point location) { - super(valueInt, location); + /** + * BinaryCell Constructor - creates a BinaryCell from the specified value and location + * + * @param value value of the BinaryCell + * @param location position of the BinaryCell + */ + public BinaryCell(int value, Point location) { + super(value, location); } + /** + * Gets the type of this BinaryCell + * + * @return type of BinaryCell + */ public BinaryType getType() { switch (data) { - case -2: - return BinaryType.UNKNOWN; - case -1: - return BinaryType.ZERO; case 0: + return BinaryType.ZERO; + case 1: return BinaryType.ONE; + case 2: + return BinaryType.UNKNOWN; default: - if (data > 0) { - return BinaryType.NUMBER; + if (data > 1) { + return BinaryType.UNKNOWN; } } return null; } + /** + * Performs a deep copy on the BinaryCell + * + * @return a new copy of the BinaryCell that is independent of this one + */ @Override public BinaryCell copy() { BinaryCell copy = new BinaryCell(data, (Point) location.clone()); @@ -33,4 +51,36 @@ public BinaryCell copy() { copy.setGiven(isGiven); return copy; } + + /** + * Sets the type of this BinaryCell + * + * @param e element to set the type of this binary cell to + */ + @Override + public void setType(Element e, MouseEvent m) { + if (e.getElementName().equals("Number Tile")) { + if (m.getButton() == MouseEvent.BUTTON1) { + if (this.data == 2) { + this.data = 0; + } + else { + this.data = this.data + 1; + } + } + else { + if (m.getButton() == MouseEvent.BUTTON3) { + if (this.data > 0) { + this.data = this.data - 1; + } + else { + this.data = 2; + } + } + } + } + else { // unknown tile + this.data = 2; + } + } } \ No newline at end of file