Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
Merge branch 'Maren' into experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
marenandrea committed Apr 30, 2019
2 parents bf77478 + 3c2e98e commit c848b68
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 45 deletions.
9 changes: 9 additions & 0 deletions assets/Boards/pusherBoardTest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "check mate",
"length": "short",
"players": "5-8",
"width": "12",
"height": "12",
"grid": "f_wN f_pSO f f f f_wN f f f f_pSP f_bNW1 f f_pEO f f f_bSE0 f f_pSP f f f f_pWP f f f f f f f f f f f f f f f_pWP f f f f f f f_pWP f f f f f f f f_wN f f f f f f f_pWP f f f f f f f f f f f_bSEN0 f f_bSEN1 f f_bSEW0 f_bSEW1 f f_pWO f f_pWP f f_pWP f f_pWO f f_pWP f f_pWP f f f f_pWO f_pEP f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f"

}
22 changes: 22 additions & 0 deletions src/main/java/sky7/Client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.HashMap;

import sky7.board.BoardGenerator;
import sky7.board.IBoard;
import sky7.board.IBoardGenerator;
import sky7.board.cellContents.Inactive.Flag;
import sky7.card.ICard;
import sky7.card.IProgramCard;
import sky7.game.Game;
Expand All @@ -22,6 +24,7 @@ public class Client implements IClient {
private IPlayer player;
private STATE state;
private String boardName;
private HashSet<Integer> flagVisited;
private Game game;
private boolean localClient, readyToRender = false; // True if this user is also running Host, false if remotely connected to Host.
private ClientNetHandler netHandler;
Expand All @@ -32,6 +35,7 @@ public Client() {
//board = new Board(10,8);
this.player = new Player();
state = STATE.LOADING;
this.flagVisited = new HashSet<>();
localClient = true;
}

Expand Down Expand Up @@ -144,6 +148,24 @@ public void activateBoardElements() {
public void activateLasers() {
//TODO should call board.activateLasers


}
public void setFlagVisited(Flag visitedFlag){
int flagNumber = visitedFlag.getFlagNumber();
boolean canVisit= true;
//check if the player has visited every previous flag
for(int i=1; i<flagNumber; i++){
if(!hasVisitedFlag(i)){
canVisit = false;
}
}
if(canVisit){//if the player has visited every previous
this.flagVisited.add(flagNumber);
}
}

public boolean hasVisitedFlag(int flag){
return this.flagVisited.contains(flag);
}

@Override
Expand Down
71 changes: 62 additions & 9 deletions src/main/java/sky7/board/Board.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package sky7.board;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.TreeSet;

import com.badlogic.gdx.math.Vector2;

import sky7.board.cellContents.DIRECTION;
import sky7.board.cellContents.Active.CogWheel;
import sky7.board.cellContents.Active.IConveyorBelt;
import sky7.board.cellContents.Inactive.*;
import sky7.board.cellContents.Active.Laser;
import sky7.board.cellContents.Active.Pusher;
import sky7.board.cellContents.DIRECTION;
import sky7.board.cellContents.Inactive.Flag;
import sky7.board.cellContents.Inactive.FloorTile;
import sky7.board.cellContents.Inactive.Hole;
import sky7.board.cellContents.Inactive.Wall;
import sky7.board.cellContents.robots.RobotTile;

import java.util.*;

public class Board implements IBoard {
private TreeSet<ICell>[][] grid;
private int width, height, nPlayers, maxMove;
Expand All @@ -38,7 +38,6 @@ public class Board implements IBoard {
private List<Vector2> flagPositions;
private List<Wrench> wrenches;
private List<Vector2> wrenchPositions;

public Board(int width, int height) {
this.width = width;
this.height = height;
Expand Down Expand Up @@ -84,11 +83,12 @@ public Board(TreeSet<ICell>[][] grid, int height, int width) {
this.pusherPos = new ArrayList<>();
this.startPositions = new ArrayList<>();
this.startCells = new ArrayList<>();
this.flagPositions = new ArrayList<>();
this.flags = new ArrayList<>();
this.flagPositions = new ArrayList<>();
this.wrenchPositions = new ArrayList<>();
this.wrenches = new ArrayList<>();


// find and store locations of cogwheels, conveyor belts
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[0].length; j++) {
Expand Down Expand Up @@ -410,6 +410,49 @@ public void rotateRobot(int currentPlayer, int rotate) {
public void moveConveyors() {
// TODO Auto-generated method stub
}
@Override
public List<Vector2> getPusherPos(){
return pusherPos;
}
@Override
public List<Pusher> getPushers(){
return pushers;
}



/*
private boolean canPusherPush(Vector2 pos, DIRECTION dirToPush) {
if(wallInCurrentTile(pos,dirToPush)){
return false;
}
Vector2 newPos = getDestination(pos, dirToPush, 1);
if(!containsPosition(newPos)){//if the pusher push to outside of the board
return true;
}
if(wallInCurrentTileMadeByMaren(pos,dirToPush)){
return false;
}
return true;
//TODO hva om to roboter vil til samme felt samtidig?
}
/* @Override
public Map<Integer, Flag> robotVisitFlag(){
Map<Integer,Flag> robotWhoVisitedFlag = new HashMap<>();
for(int i=0; i<flags.size(); i++){
for(int j=0; j<robots.length; j++){
if(flagsPos.get(i).equals(robotPos[j])){
int idOfRobot = robots[j].getId();
robotWhoVisitedFlag.put(idOfRobot,flags.get(i));
}
}
}
return robotWhoVisitedFlag;
}*/

@Override
public TreeSet<ICell> getCell(Vector2 a) {
Expand All @@ -420,4 +463,14 @@ public TreeSet<ICell> getCell(Vector2 a) {
public RobotTile[] getRobots() {
return robots;
}
/* private boolean wallInCurrentTileMadeByMaren(Vector2 robotPos, DIRECTION dir) {
for (ICell item : grid[(int) robotPos.x][(int) robotPos.y]) {
if (item instanceof Wall) {
return (((Wall) item).getDirection() == dir.reverse());
}
}
return false;
}*/


}
7 changes: 7 additions & 0 deletions src/main/java/sky7/board/IBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.badlogic.gdx.math.Vector2;
import sky7.board.cellContents.Active.Laser;
import sky7.board.cellContents.Active.Pusher;
import sky7.board.cellContents.DIRECTION;
import sky7.board.cellContents.Inactive.Flag;
import sky7.board.cellContents.Inactive.StartPosition;
Expand Down Expand Up @@ -68,6 +69,12 @@ public interface IBoard {

void moveConveyors();

List<Vector2> getPusherPos();

List<Pusher> getPushers();

//Map<Integer, Flag> robotVisitFlag();

TreeSet<ICell> getCell(Vector2 a);

Vector2[] getRobotPos();
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/sky7/board/cellContents/Active/Laser.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Texture getStartLaserTexture() {
} else if (numberOfLasers == 2) {
texture = new Texture("assets/laser/LaserDStartU.png");
} else {
throw new IllegalArgumentException("the number og laser has invalid value. Should be 1 or 2, was " + numberOfLasers);
throw new IllegalArgumentException("The number of laser has invalid value. Should be 1 or 2, was " + numberOfLasers);
}
break;
case SOUTH:
Expand All @@ -58,7 +58,7 @@ public Texture getStartLaserTexture() {
} else if (numberOfLasers == 2) {
texture = new Texture("assets/laser/LaserDStartD.png");
} else {
throw new IllegalArgumentException("the number og laser has invalid value. Should be 1 or 2, was " + numberOfLasers);
throw new IllegalArgumentException("The number of laser has invalid value. Should be 1 or 2, was " + numberOfLasers);
}
break;
case WEST:
Expand All @@ -67,7 +67,7 @@ public Texture getStartLaserTexture() {
} else if (numberOfLasers == 2) {
texture = new Texture("assets/laser/LaserDStartL.png");
} else {
throw new IllegalArgumentException("the number og laser has invalid value. Should be 1 or 2, was " + numberOfLasers);
throw new IllegalArgumentException("The number of laser has invalid value. Should be 1 or 2, was " + numberOfLasers);
}
break;
case EAST:
Expand All @@ -76,7 +76,7 @@ public Texture getStartLaserTexture() {
} else if (numberOfLasers == 2) {
texture = new Texture("assets/laser/LaserDStartR.png");
} else {
throw new IllegalArgumentException("the number og laser has invalid value. Should be 1 or 2, was " + numberOfLasers);
throw new IllegalArgumentException("The number of laser has invalid value. Should be 1 or 2, was " + numberOfLasers);
}
break;
default:
Expand All @@ -97,18 +97,18 @@ public Texture getLaserTexture() {
} else if (numberOfLasers == 2) {
texture = new Texture("assets/laser/LaserDVert.png");
} else {
throw new IllegalArgumentException("The number og laser has invalid value. Should be 1 or 2, was " + numberOfLasers);
throw new IllegalArgumentException("The number of laser has invalid value. Should be 1 or 2, was " + numberOfLasers);
}
} else if (direction == DIRECTION.EAST || direction == DIRECTION.WEST) {
if (numberOfLasers == 1) {
texture = new Texture("assets/laser/LaserHor.png");
} else if (numberOfLasers == 2) {
texture = new Texture("assets/laser/LaserDHor.png");
} else {
throw new IllegalArgumentException("The number og laser has invalid value. Should be 1 or 2, was " + numberOfLasers);
throw new IllegalArgumentException("The number of laser has invalid value. Should be 1 or 2, was " + numberOfLasers);
}
} else {
throw new IllegalArgumentException("The number og laser has invalid value. Should be 1 or 2, was " + numberOfLasers);
throw new IllegalArgumentException("The number of laser has invalid value. Should be 1 or 2, was " + numberOfLasers);
}
return texture;
}
Expand Down Expand Up @@ -142,7 +142,6 @@ public DIRECTION getDirection() {

public static List<AbstractMap.SimpleEntry<String, Supplier<ICell>>> getSuppliers() {
List<AbstractMap.SimpleEntry<String, Supplier<ICell>>> suppliers = new ArrayList<>();
// TODO add laser supplier

char[] bools = {'T', 'F'};
int maxNrOfLaserEyes = 2;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/sky7/board/cellContents/Active/Pusher.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import sky7.board.ICell;
import sky7.board.cellContents.DIRECTION;
import sky7.board.cellContents.IActive;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.function.Supplier;

Expand All @@ -20,23 +18,25 @@ public class Pusher implements IActive {

public Pusher(DIRECTION direction, boolean oddPhased) {
this.direction = direction;
this.oddPhased = oddPhased; //oddPhased is 1 if it is oddPhased else 0
this.oddPhased = oddPhased; //oddPhased is true if it is oddPhased else false

}

/**
* Check if the pusher activates in the current phase.
*
* @param phase the current phase
* @return true if the pusher activates in phase, false otherwise.
* @return true if pusher is oddPhased and phase is odd, or if pusher is not oddPhased and phase is equal,
* false otherwise.
*/
boolean doActivate(int phase) {

public boolean doActivate(int phase) {
assert phase > 0 && phase < 5;
return phase % 2 == 1 && oddPhased;
return (phase % 2 == 1 && oddPhased) || (phase % 2 == 0 && !oddPhased);
}

@Override
public Texture getTexture() {//TODO change image 8.png , this is the same as 1.png
public Texture getTexture() {
if (texture == null) {
if (!oddPhased) {
switch (direction) {
Expand Down Expand Up @@ -94,7 +94,7 @@ public int compareTo(ICell other) {
}

/**
* return the direction of this pusher
* return the direction of where the pusher push into
*
* @return
*/
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/sky7/board/cellContents/Inactive/Flag.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ public static List<AbstractMap.SimpleEntry<String,Supplier<ICell>>> getSuppliers
return suppliers;

}
public int getFlagNumber(){
return this.flagNumber;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ public class StartPosition implements IInactive {
private int startNumber;
private static final int PRIORITY = 3;
private Texture texture;
private DIRECTION direction;

public StartPosition(int startNumber) {
this.startNumber = startNumber;

}


Expand Down
Loading

0 comments on commit c848b68

Please sign in to comment.