Skip to content

Commit

Permalink
show number of squares moved
Browse files Browse the repository at this point in the history
  • Loading branch information
rubo77 committed May 25, 2019
1 parent baf748f commit f35aacf
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public GameOptionsGameScreen(GameManager gameManager){
@Override
public void create() {
int buttonSize=440;
// TODO: take the maximum out of a 1080x1920 square, lower ratio if the screen is not as long
float ratio = ((float)gameManager.getScreenWidth()) /((float)1080);
int relativeButtonWidth=(int)(ratio*(float)buttonSize);
int ws2 = (int)(((float)this.gameManager.getScreenWidth()-relativeButtonWidth)/2);
Expand Down
20 changes: 16 additions & 4 deletions app/src/main/java/roboyard/eclabs/GamePiece.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
* Created by Pierre on 25/02/2015.
*/
public class GamePiece implements IGameObject {



private int x = 0;
private int y = 0;
private int xObjective = 0;
Expand All @@ -24,6 +21,8 @@ public class GamePiece implements IGameObject {
private boolean inMovement = false;
private int deltaX = 0;
private int deltaY = 0;
private int curMoveSquares = 0;
private int numSquaresMoved = 0;
private int initialSpeed = 16;
private int extraSizeForRobotsAndTargets = 1; // robots and targets are 1px larger than the grid and may overlap 1 px
private int toleranceForInputManagerTouch = 1000; // virtual circle around robot to touch
Expand Down Expand Up @@ -84,6 +83,8 @@ public GamePiece(int x, int y, int color){
this.xObjective = x;
this.yObjective = y;
this.color = color;
this.curMoveSquares=0;
this.numSquaresMoved=0;

switch(color)
{
Expand All @@ -106,6 +107,10 @@ public GamePiece(int x, int y, int color){

}

public int getCurMoveSquares(){
return this.curMoveSquares;
}

public void setGridDimensions(int xGrid, int yGrid, float cellSize){
this.xGrid = xGrid;
this.yGrid = yGrid;
Expand Down Expand Up @@ -174,14 +179,21 @@ public void update(GameManager gameManager){

}else{ //sinon (si le pion doit bouger),
// TODO: reset if enlarging worked this.radius=32;
if(inMovement==false){
// before move
this.curMoveSquares=Math.abs(this.xObjective-this.x)+Math.abs(this.yObjective-this.y);
this.numSquaresMoved+=this.curMoveSquares;
System.out.println(" start move with "+this.curMoveSquares+" squares");
((GridGameScreen)(gameManager.getCurrentScreen())).setCurrentMovedSquares(this.curMoveSquares);
}
inMovement = true;
testIfWon = true;

deltaValue = initialSpeed; // initial speed of robots

if(this.x < this.xObjective) {
for(int i=deltaValue-1; i>0; i--){
if(this.x > this.xObjective-(i+1)) deltaValue=i; // slow down
if(this.x > this.xObjective - (i+1)) deltaValue = i; // slow down
}
deltaX += deltaValue;
} else if(this.x > this.xObjective) {
Expand Down
57 changes: 36 additions & 21 deletions app/src/main/java/roboyard/eclabs/GridGameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class GridGameScreen extends GameScreen {

private int timeCpt = 0;
private int nbCoups = 0;
private int numSquares = 0;
private int currentMovedSquares = 0;
private long prevTime;

private static String levelDifficulty="Advanced";
Expand Down Expand Up @@ -92,7 +94,7 @@ public GridGameScreen(GameManager gameManager){
preferences.setPreferences(gameManager.getActivity(),"difficulty", ld);
}
setDifficulty(ld);
gridSpace = (float)((16/(float)boardSizeX) * 67.3 * gameManager.getScreenWidth() /1080);
gridSpace = (float)gameManager.getScreenWidth() / (float)boardSizeX;
xGrid = 0;
yGrid = 1080/5;

Expand Down Expand Up @@ -216,18 +218,21 @@ public void draw(RenderManager renderManager)

//renderManager.setColor(Color.BLACK);
renderManager.setColor(Color.GRAY);
int lineHeight = yGrid/2-60; // 58
int lineHeightSmall = lineHeight-15;
float ratio = ((float)gameManager.getScreenWidth()) /((float)1080); // bei 720x1280:0.6667 bei 1440x2580:1.333
int lineHeight = (int)(ratio*55);
int lineHeightSmall = (int)(lineHeight*0.8);
int textPosY = lineHeight;
int textPosYSmall = 2*lineHeight-4;
int textPosYTime = yGrid/2+lineHeight;
int textPosYSmall = 2*lineHeight-(int)(ratio*4);
int textPosYTime = 2*lineHeight+lineHeightSmall+(int)(8/ratio);
renderManager.setTextSize(lineHeight);
if(gameManager.getScreenWidth() <=480){
renderManager.setTextSize(lineHeightSmall);
}
if(nbCoups>0){
// at least one move was made by hand or by AI
renderManager.drawText(10, textPosY, "Number of moves: " + nbCoups);
renderManager.drawText(10, textPosY, "Moves: " + nbCoups);
renderManager.setTextSize(lineHeightSmall);
renderManager.drawText(10, textPosYSmall, "Squares: " + numSquares);
} else if(isSolved && numSolutionClicks>0){
// show solution
if(numSolutionClicks-showSolutionAtHint >= 0) {
Expand Down Expand Up @@ -259,6 +264,7 @@ public void draw(RenderManager renderManager)
if(seconds < 10){
secondsS="0" + secondsS;
}
renderManager.setTextSize(lineHeightSmall);
renderManager.drawText(10, textPosYTime, "Time: " + timeCpt / 60 + ":" + secondsS);

if(timeCpt>=40 && autoSaved == false && mustStartNext==false){
Expand Down Expand Up @@ -292,6 +298,7 @@ public void update(GameManager gameManager){
if(mustStartNext) {

numSolutionClicks = 0;
currentMovedSquares = 0;

// show solution as the 2rd to 5th hint
showSolutionAtHint = 2 + (int)(Math.random() * ((5 - 2) + 1));
Expand Down Expand Up @@ -378,6 +385,12 @@ public ArrayList getGridElements() {
return gridElements;
}

public void setCurrentMovedSquares(int movedSquares){
currentMovedSquares=movedSquares;
System.out.println("store "+currentMovedSquares+" moved squares in last Move");
allMoves.get(allMoves.size()-1).setSquaresMoved(currentMovedSquares);
}

public void setSavedGame(String mapPath)
{
this.mapPath = "";
Expand Down Expand Up @@ -420,6 +433,7 @@ public void createGrid() {
isSolved = false;

nbCoups = 0;
numSquares = 0;
timeCpt = 0;
prevTime = System.currentTimeMillis();

Expand Down Expand Up @@ -601,8 +615,7 @@ public void editDestination(GamePiece p, int direction, Boolean moved)
}
}

if(canMove)
{
if(canMove){
switch(direction){
case 0: // haut
yDestination -= 1;
Expand All @@ -621,17 +634,13 @@ public void editDestination(GamePiece p, int direction, Boolean moved)
p.setyObjective(yDestination);

editDestination(p, direction, true);
numSquares++;
}else{
if(moved)
{
if(moved){
nbCoups++;
//boolean b = gagne(p);

}
else
{
} else {
allMoves.remove(allMoves.size()-1);

}
}
}
Expand Down Expand Up @@ -669,7 +678,7 @@ public void sayWon()
}
else
{
gameManager.requestToast("You won in "+nbCoups+" moves.", true);
gameManager.requestToast("You won in "+nbCoups+" moves, "+numSquares+" squares", true);
}
updatePlayedMaps();
}
Expand Down Expand Up @@ -706,10 +715,11 @@ public void addMapsPlayed()

public Boolean collision(GamePiece p, int x, int y, boolean canMove)
{
if(p.getxObjective() == x && p.getyObjective() == y && canMove == true)
if(p.getxObjective() == x && p.getyObjective() == y && canMove == true) {
return false;
else if(canMove == false)
} else if(canMove == false) {
return false;
}
return true;
}

Expand All @@ -722,6 +732,7 @@ public void execute(){
bb.execute();
}
nbCoups = 0;
numSquares = 0;
}
}

Expand Down Expand Up @@ -810,9 +821,13 @@ private class ButtonBack implements IExecutor{
public void execute(){
if(allMoves.size() > 0)
{
allMoves.get(allMoves.size()-1).goBack();

allMoves.remove(allMoves.size()-1);
int last=allMoves.size()-1;
Move lastMove=allMoves.get(last);
numSquares-=lastMove.getSquaresMoved();
System.out.println("substract "+lastMove.getSquaresMoved());
lastMove.goBack();
System.out.println("remove move nr. "+(allMoves.size()-1)+" "+lastMove._x+"/"+lastMove._y);
allMoves.remove(last);
nbCoups--;
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/roboyard/eclabs/InputManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/**
* Created by Pierre on 17/01/2015.
* TODO: add the possibility to send a chain of commands in one touch-and move event
*/
public class InputManager {

Expand Down
23 changes: 14 additions & 9 deletions app/src/main/java/roboyard/eclabs/Move.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@
* Created by Alain on 25/03/2015.
*/
public class Move {
public GamePiece _p;
public int _x;
public int _y;
private int squaresMoved;


private GamePiece _p;
private int _x;
private int _y;

public Move(GamePiece p, int x, int y)
{
public Move(GamePiece p, int x, int y){
_p = p;
_x = x;
_y = y;
}

public void goBack()
{
public void goBack(){
_p.setX(_x);
_p.setY(_y);
_p.setxObjective(_x);
_p.setyObjective(_y);
}

public int getSquaresMoved(){
return this.squaresMoved;
}

public void setSquaresMoved(int moved){
this.squaresMoved=moved;
}
}
Binary file added download/Roboyard_screenshot2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added download/Roboyard_screenshot3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f35aacf

Please sign in to comment.