Android Open Source - Sneik Game Play






From Project

Back to project page Sneik.

License

The source code is released under:

Apache License

If you think the Android project Sneik listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.plastboks.gameworld;
//  w  w  w .  j a  v a  2 s .  c  o  m
import net.plastboks.gameobjects.Autonomous;
import net.plastboks.gameobjects.Bird;
import net.plastboks.gameobjects.Mouse;
import net.plastboks.gameobjects.Snake;

import java.util.LinkedList;

/**
 * Created by alex on 12/22/14.
 */
public class GamePlay {

    private LinkedList<Autonomous> food;
    private Snake snake;
    private int inc = 0, maxFoodCount = 0;

    public GamePlay(Snake snake) {
        food = new LinkedList<Autonomous>();
        this.snake = snake;
        inc = 0;
        initFood();
    }

    private void initFood() {
        food.add(new Bird(inc));
        food.add(new Mouse(inc));
    }

    private LinkedList<Autonomous> getClone() {
        return (LinkedList<Autonomous>)food.clone();
    }

    private void addFood() {
        if (food.size() > maxFoodCount) { return; }

        LinkedList<Autonomous> tmp = getClone();
        if (inc % 5 == 0) { tmp.add(new Bird(inc)); }
        if (inc % 7 == 0) { tmp.add(new Mouse(inc)); }
        food = tmp;
    }

    private void removeRandomFood() {
        if (food.size() == 1) { return; }

        LinkedList<Autonomous> tmp = getClone();
        for (int i = 0; i < tmp.size(); i++) {
            if ((int)(Math.random() * 20) % 5 == 0) { tmp.remove(i); }
        }
        food = tmp;
    }

    public void increment(Autonomous a) {
        inc++;
        snake.incrementBodySizeBy(4);
        if (++inc % 5 == 0) { snake.incrementSpeed(); }
        addFood();
        removeRandomFood();
    }

    public LinkedList<Autonomous> getFood() { return food; }
}




Java Source Code List

net.plastboks.gameobjects.Artificial.java
net.plastboks.gameobjects.Autonomous.java
net.plastboks.gameobjects.Bird.java
net.plastboks.gameobjects.Creature.java
net.plastboks.gameobjects.Mouse.java
net.plastboks.gameobjects.Node.java
net.plastboks.gameobjects.Snake.java
net.plastboks.gameworld.GamePlay.java
net.plastboks.gameworld.GameRenderer.java
net.plastboks.gameworld.GameWorld.java
net.plastboks.screens.GameScreen.java
net.plastboks.shared.Directions.java
net.plastboks.sneik.IOSLauncher.java
net.plastboks.sneik.SneikGame.java
net.plastboks.sneik.android.AndroidLauncher.java
net.plastboks.sneik.client.HtmlLauncher.java
net.plastboks.sneik.desktop.DesktopLauncher.java
net.plastboks.sneikhelpers.AssetLoader.java
net.plastboks.sneikhelpers.InputHandler.java