<commit_before>import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import java.util.Scanner;
import java.io.*;

/**
 * Created by bokense on 25-Mar-16.
 */


public class GameEngine extends JPanel implements MouseListener, MouseMotionListener, ActionListener, KeyListener {

    private int movementSpeed = 25;

    private Vector<Integer> rnglist;

    private int gameSpeed = 1;

    private int actionTick = 0;

    private final Timer timer = new Timer(gameSpeed, this);


    private Player player1;


    private Vector<Npc> npcList = new Vector<>();

    private boolean debugMenuVisible = true;

    private boolean inventoryMenuVisible = true;

    private Font font1 = new Font("Consola", Font.PLAIN, 8);
    private Font font2 = new Font("Consola", Font.BOLD, 16);
    private Font font3 = new Font("Consola", Font.BOLD,24);

    Tile[][] tilemap = new Tile[32][24];

    Tile[][] tilemaptest = new Tile[32][24];


    public GameEngine() {


        rnglist = rngSeeder();

        genereateWorldImproved();

        tilemaptest = writeWorld();

        System.out.println(printTileSet(tilemap));

        System.out.println(printTileSet(tilemaptest));


        generatePlayer();
        generateNpc(2,1,3,20,Color.BLUE);


        addMouseListener(this);
        addMouseMotionListener(this);
        addKeyListener(this); // Adds keyboard listener.

        setFocusable(true); // Setting required for keyboard listener.

        timer.start();


    }

    private Vector<Integer> rngSeeder(){


        FileReader file = null;
        try {
            file = new FileReader("Data/RNG.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        int rng;

        Vector<Integer> rnglist = new Vector<>();

        try {
            Scanner input = new Scanner(file);
            while(input.hasNext())
            {
                rng = input.nextInt();

                rnglist.add(rng);
            }

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
            return rnglist;
        }

    private int rotateRng(){

         int r = rnglist.firstElement();

        rnglist.remove(0);
        rnglist.addElement(r);

        return r;
    }





    private void genereateWorldImproved() {
        for (int i = 0; i < 32; i++) {
            for (int j = 0; j < 24; j++) {
                tilemap[i][j] = new Tile();
            }
        }

        for (int i = 0; i < 32; i++) {
            for (int j = 0; j < 24; j++) {

                //_________________________________WorldGen____________________________________________

               int r = rotateRng();
                

                if (r > 80) {                                     // Dirt spawn rate.
                    tilemap[i][j].type = "rakedDirt";
                }

                r = rotateRng();

                if (tilemap[i][j].type.equals("grass") && r > 96) {              // wood spawn rate/condition.
                    tilemap[i][j].type = "wood";
                } else if ((tilemap[i][j].type.equals("rakedDirt") && r > 95 )){ // sand spawn rate/condition.
                    tilemap[i][j].type = "sand";
                }

                //______________________________Resource Generation____________________________________

                r = rotateRng();



                if (r > 98)
                {
                    tilemap[i][j].type = "wall";
                }

                if (tilemap[i][j].type.equals("rakedDirt")) {                   // Makes all rakedDirt farmable
                    tilemap[i][j].farmable = true;}

                if (tilemap[i][j].type.equals("wall") || tilemap[i][j].type.equals("water") || tilemap[i][j].type.equals("wood")) {                   // Makes occupied terrain unwalkable
                    tilemap[i][j].occupied = true;}
            }
        }
        saveWorld();
    }

    private void saveWorld(){

        try {
            FileOutputStream fout = new FileOutputStream("Data/WORLD.txt");
            ObjectOutputStream oos = new ObjectOutputStream(fout);
            oos.writeObject(tilemap);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private Tile[][] writeWorld(){
        Tile[][] world;
        FileInputStream fis = null;
        try {
            fis = new FileInputStream("Data/WORLD.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(fis);
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            while (true) {
                try {
                    world = (Tile[][]) ois.readObject();
                    return world;
                } catch (IOException | ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        }  finally {
            try {
                ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private void generatePlayer() {

        player1 = new Player(0, 14, 9, 66, 100,Color.RED);

        System.out.println("Created new player1 - ID: " + player1.ID + " - X: " + player1.xPos + " - Y: " + player1.yPos + " Empty Inventory Slots: " + player1.playerInventory.itemArray.length);<commit_msg>Added files via upload<commit_after>import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import java.util.Scanner;
import java.io.*;

/**
 * Created by bokense on 25-Mar-16.
 */


public class GameEngine extends JPanel implements MouseListener, MouseMotionListener, ActionListener, KeyListener {

    private int movementSpeed = 25;

    private Vector<Integer> rnglist;

    private int gameSpeed = 1;

    private int actionTick = 0;

    private final Timer timer = new Timer(gameSpeed, this);


    private Player player1;


    private Vector<Npc> npcList = new Vector<>();

    private boolean debugMenuVisible = true;

    private boolean inventoryMenuVisible = true;

    private Font font1 = new Font("Consola", Font.PLAIN, 8);
    private Font font2 = new Font("Consola", Font.BOLD, 16);
    private Font font3 = new Font("Consola", Font.BOLD,24);

    Tile[][] tilemap = new Tile[32][24];

    Tile[][] tilemaptest = new Tile[32][24];


    public GameEngine() {


        rnglist = rngSeeder();

        genereateWorldImproved();

        tilemaptest = writeWorld();

        System.out.println(printTileSet(tilemap));

        System.out.println(printTileSet(tilemaptest));


        generatePlayer();
        generateNpc(2,1,3,20,Color.BLUE);


        addMouseListener(this);
        addMouseMotionListener(this);
        addKeyListener(this); // Adds keyboard listener.

        setFocusable(true); // Setting required for keyboard listener.

        timer.start();


    }

    private Vector<Integer> rngSeeder(){


        FileReader file = null;
        try {
            file = new FileReader("Data/RNG.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        int rng;

        Vector<Integer> rnglist = new Vector<>();

        try {
            Scanner input = new Scanner(file);
            while(input.hasNext())
            {
                rng = input.nextInt();

                rnglist.add(rng);
            }

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
            return rnglist;
        }

    private int rotateRng(){

         int r = rnglist.firstElement();

        rnglist.remove(0);
        rnglist.addElement(r);

        return r;
    }





    private void genereateWorldImproved() {
        for (int i = 0; i < 32; i++) {
            for (int j = 0; j < 24; j++) {
                tilemap[i][j] = new Tile();
            }
        }

        for (int i = 0; i < 32; i++) {
            for (int j = 0; j < 24; j++) {

                //_________________________________WorldGen____________________________________________

               int r = rotateRng();
                

                if (r > 80) {                                     // Dirt spawn rate.
                    tilemap[i][j].type = "rakedDirt";
                }

                r = rotateRng();

                if (tilemap[i][j].type.equals("grass") && r > 96) {              // wood spawn rate/condition.
                    tilemap[i][j].type = "wood";
                } else if ((tilemap[i][j].type.equals("rakedDirt") && r > 95 )){ // sand spawn rate/condition.
                    tilemap[i][j].type = "sand";
                }

                //______________________________Resource Generation____________________________________

                r = rotateRng();



                if (r > 98)
                {
                    tilemap[i][j].type = "wall";
                }

                if (tilemap[i][j].type.equals("rakedDirt")) {                   // Makes all rakedDirt farmable
                    tilemap[i][j].farmable = true;}

                if (tilemap[i][j].type.equals("wall") || tilemap[i][j].type.equals("water") || tilemap[i][j].type.equals("wood")) {                   // Makes occupied terrain unwalkable
                    tilemap[i][j].occupied = true;}
            }
        }
        saveWorld();
    }

    private void saveWorld(){

        try {
            FileOutputStream fout = new FileOutputStream("Data/WORLD.txt");
            ObjectOutputStream oos = new ObjectOutputStream(fout);
            oos.writeObject(tilemap);
            oos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private Tile[][] writeWorld(){
        Tile[][] world;
        FileInputStream fis = null;
        try {
            fis = new FileInputStream("Data/WORLD.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(fis);
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            while (true) {
                try {
                    world = (Tile[][]) ois.readObject();
                    ois.close();
                    return world;
                } catch (IOException | ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        }  finally {
            try {
                ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private void generatePlayer() {

        player1 = new Player(0, 14, 9, 66, 100,Color.RED);

        System.out.println("Created new player1 - ID: " + player1.ID + " - X: " + player1.xPos + " - Y: " + player1.yPos + " Empty Inventory Slots: " + player1.playerInventory.itemArray.length);
{'fraction_non_alphanumeric': 0.12089903933297082, 'fraction_numerical': 0.011963023382272975, 'mean_word_length': 1.5776687689792104, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3906968', 'n_tokens_mistral': 3244, 'n_tokens_neox': 2902, 'n_words': 692}