Skip to content

Commit

Permalink
Fixed Binary Cell merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharybonagura committed Aug 19, 2024
1 parent 80dc899 commit c6ec39e
Showing 1 changed file with 59 additions and 9 deletions.
68 changes: 59 additions & 9 deletions src/main/java/edu/rpi/legup/puzzle/binary/BinaryCell.java
Original file line number Diff line number Diff line change
@@ -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<Integer> {
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());
Expand All @@ -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;
}
}
}

0 comments on commit c6ec39e

Please sign in to comment.