Clipboard.

  • FTB will be shutting down this forum by the end of July. To participate in our community discussions, please join our Discord! https://ftb.team/discord

VikeStep

New Member
Jul 29, 2019
1,117
0
0
$$\log_{6}(\frac{3\cdot(18^x+3\cdot2^x)}{28})=x$$

oh its nothing, just learning mathjax/latex for math.stackexchange :)

also lol lawbroken :)
 

frederikam

New Member
Jul 29, 2019
836
0
1
One of my first Java classes, good times.
Code:
import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)
 
import java.util.List;
import java.util.ArrayList;
 
/**
* Wombat. A Wombat moves forward until it can't do so anymore, at
* which point it turns left. If a wombat finds a leaf, it eats it.
*
* @version 1.0.1
*/
public class Wombat extends Actor
{
    private static final int EAST = 0;
    private static final int WEST = 1;
    private static final int NORTH = 2;
    private static final int SOUTH = 3;
 
    private int direction;
    private int leavesEaten;
    private int steps;
    private int health;
    private boolean dead;
    private int rocks;
    private int lookY = 0;
    private int lookX = 0;
    private boolean stoneInTheWay = false;
    private boolean wait = false;
 
    public Wombat()
    {
        setDirection(EAST);
        leavesEaten = 0;
        health = 50;
    }
 
    /**
    * Do whatever the wombat likes to to just now.
    */
    public void act()
    {
        getLookingDirection();
        eatRock();
        if(foundLeaf()) {
            eatLeaf();
            health = health + 25;
        }
        else if(wait == true){wait = false;}
        else if(canMove()) {
            move();
            health = health - 1;
            steps = steps + 1;
        }
        else {
            turnLeft();
            steps = steps + 1;
            health = health - 1;
        }
        if(health == 0){
            getWorld().removeObject(this);
            dead = true;
        }
    }
 
    /**
    * Check whether there is a leaf in the same cell as we are.
    */
    public boolean foundLeaf()
    {
        Actor leaf = getOneObjectAtOffset(0, 0, Leaf.class);
        if(leaf != null) {
            return true;
        }
        else {
            return false;
        }
    }
 
 
    public void eatLeaf()
    {
        Actor leaf = getOneObjectAtOffset(0, 0, Leaf.class);
        if(leaf != null) {
            // eat the leaf...
            getWorld().removeObject(leaf);
            leavesEaten = leavesEaten + 1;
        }
    }
 
        public void eatRock()
    {
        Actor rock = getOneObjectAtOffset(0, 0, rock.class);
        if(rock != null) {
            // eat the leaf...
            getWorld().removeObject(rock);
            leavesEaten = leavesEaten - 5;
            wait = true;
        }
    }
    public void getLookingDirection()
    {
        switch(direction) {
            case SOUTH :
                lookY = 1;
                lookX = 0;
                /*Actor rock = getOneObjectAtOffset(0, 1, rock.class); */
                break;
            case EAST :
                lookX = 1;
                lookY = 0;
                /*Actor rock = getOneObjectAtOffset(1, 0, rock.class); */
                break;
            case NORTH :
                lookY = -1;
                lookX = 0;
                /*Actor rock = getOneObjectAtOffset(0, -1, rock.class); */
                break;
            case WEST :
                lookX = -1;
                lookY = 0;
                /*Actor rock = getOneObjectAtOffset(-1, 0, rock.class); */
                break;
        }
    }
 
    public boolean foundRock()
    {
        Actor rock = getOneObjectAtOffset(lookX, lookY, rock.class);
        if(rock != null)
        {
            return true;
        }
        return false;
    }
 
    /**
    * Move one cell forward in the current direction.
    */
    public void move()
    {
        if (!canMove()) {
            return;
        }
        switch(direction) {
            case SOUTH :
                setLocation(getX(), getY() + 1);
                break;
            case EAST :
                setLocation(getX() + 1, getY());
                break;
            case NORTH :
                setLocation(getX(), getY() - 1);
                break;
            case WEST :
                setLocation(getX() - 1, getY());
                break;
        }
    }
 
    /**
    * Test if we can move forward. Return true if we can, false otherwise.
    */
    public boolean canMove()
    {
        World myWorld = getWorld();
        int x = getX();
        int y = getY();
        switch(direction) {
            case SOUTH :
                y++;
                break;
            case EAST :
                x++;
                break;
            case NORTH :
                y--;
                break;
            case WEST :
                x--;
                break;
        }
        // test for outside border
        if (x >= myWorld.getWidth() || y >= myWorld.getHeight()) {
            return false;
        }
        else if (x < 0 || y < 0) {
            return false;
        }
        if(foundRock() == true)
        {
            if(leavesEaten <= 4)
            {
                return false;
            }
        }
     
        return true;
    }
 
    /**
    * Turns towards the left.
    */
    public void turnLeft()
    {
        switch(direction) {
            case SOUTH :
                setDirection(EAST);
                break;
            case EAST :
                setDirection(NORTH);
                break;
            case NORTH :
                setDirection(WEST);
                break;
            case WEST :
                setDirection(SOUTH);
                break;
        }
    }
 
    /**
    * Sets the direction we're facing.
    */
    public void setDirection(int direction)
    {
        this.direction = direction;
        switch(direction) {
            case SOUTH :
                setRotation(90);
                break;
            case EAST :
                setRotation(0);
                break;
            case NORTH :
                setRotation(270);
                break;
            case WEST :
                setRotation(180);
                break;
            default :
                break;
        }
    }
 
    /**
    * Tell how many leaves we have eaten.
    */
    public int getLeavesEaten()
    {
        return leavesEaten;
    }
}
 

Vauthil

New Member
Jul 29, 2019
1,491
-14
1
photo.jpg


Headboop.
 
  • Like
Reactions: ApSciLiara