commit f335297065dcbd0869875ce2ad0a499f0e817278 Author: Sobottasgithub Date: Mon Jan 12 16:17:14 2026 +0100 Init diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..a5dbbcb --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake . diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..524f096 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..2ab9f2e --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,12 @@ +JAVA_FMT = google-java-format +JAVA_FILES = $(shell find . -name '*.java') +XML_FMT = xmlindent +XML_FILES = $(shell find . -name '*.xml') + +.PHONY: fmt +fmt: + @echo "Formatting all Java files..." + @for f in $(JAVA_FILES); do \ + echo " $$f"; \ + $(JAVA_FMT) -i $$f; \ + done diff --git a/Hero.java b/Hero.java new file mode 100644 index 0000000..be914ff --- /dev/null +++ b/Hero.java @@ -0,0 +1,29 @@ +public class Hero { + private String name; + private int strength; + private LinkedList weaponInventory; + private Weapon currentWeapon; + + public Hero(String name, int strength) { + this.name = name; + this.strength = strength; + } + + public LinkedList getWeaponInventory() { + return weaponInventory; + } + + public void addWeapon(Weapon weapon) { + weaponInventory.append(weapon); + } + + public void chooseWeapon(weapon) { + weaponInventory.toFirst(); + while(weaponInventory.hasAccess() && weaponInventory.getCurrentContent() != weapon) { + weaponInventory.toNext(); + } + if (weaponInventory.hasAccess()) { + currentWeapon = weaponInventory.getCurrentContent(); + } + } +} diff --git a/LinkedList.java b/LinkedList.java new file mode 100644 index 0000000..0d1858e --- /dev/null +++ b/LinkedList.java @@ -0,0 +1,108 @@ +public class LinkedList { + private Node first; + private Node last; + private Node current; + private int size; + + public LinkedList() {} + + public void toFirst() { + current = first; + } + + public void toLast() { + current = last; + } + + public Node getFirst() { + return first; + } + + public Node getLast() { + return last; + } + + public void toNext() { + if (hasAccess()) { + current = current.nextNode(); + } + } + + public boolean isEmpty() { + if (first == null && last == null) { + return true; + } + return false; + } + + public boolean hasAccess() { + if (current == null) { + return false; + } + return true; + } + + public void append(Object content) { + Node newNode = new Node(content); + if (isEmpty()) { + first = newNode; + last = newNode; + } else { + last.setNext(newNode); + last = newNode; + } + size++; + } + + public int getSize() { + return size; + } + + public void insert(Object content) { + if (hasAccess()) { + Node newNode = new Node(content); + + Node nextNode = current.getNextNode(); + current.setNextNode(newNode); + newNode.setNextNode(newNode); + } + size++; + } + + public void remove() { + if (hasAccess()) { + if (head == tail) { + head = null; + tail = null; + current = null; + return; + } + + Node newCurrent = current.getNextNode(); + Node pointer = head; + while(pointer.getNextNode() != current) { + pointer = pointer.getNextNode(); + } + current = newCurrent; + pointer.setNextNode(current); + } + size--; + } + + public void concat(LinkedList weaponList) { + if (!isEmpty()) { + last.setNextNode(weaponList.getFirst()); + last = weaponList.getLast(); + size = weaponList.getSize(); + return; + } + head = weaponList.getFirst(); + last = weaponList.getFirst(); + current = head; + size += weaponList.getSize(); + } + + public Object getCurrentContent() { + return current.getContent(); + } +} diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..9c885bf --- /dev/null +++ b/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} diff --git a/Node.java b/Node.java new file mode 100644 index 0000000..f19ca92 --- /dev/null +++ b/Node.java @@ -0,0 +1,25 @@ +public class Node { + private T content = null; + private Node nextNode = null; + + public Node(T content) { + setContent(content); + } + + private void setContent(T content) { + this.content = content; + } + + private T getContent() { + return this.content; + } + + private void setNextNode(Node nextNode) { + this.nextNode = nextNode; + } + + private Node getNextNode() { + return this.nextNode; + } +} + diff --git a/Weapon.java b/Weapon.java new file mode 100644 index 0000000..a082c83 --- /dev/null +++ b/Weapon.java @@ -0,0 +1,27 @@ +public class Weapon { + public String name; + public int damage; + + public Weapon() {} + + public Weapon(String name, int damage) { + setName(name); + setDamage(damage); + } + + public void setName(String name) { + this.name = name; + } + + public void setDamage(int damage) { + this.damage = damage; + } + + public int getDamage() { + return damage; + } + + public String getName() { + return name; + } +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..c344998 --- /dev/null +++ b/flake.nix @@ -0,0 +1,57 @@ +{ + description = "Linked-List"; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + ]; + systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; + perSystem = { config, self', inputs', pkgs, system, ... }: let + + jdk = pkgs.jdk21.override { + }; + + buildInputs = [ + jdk + ]; + + devTools = [ + pkgs.google-java-format + ]; + + in { + devShells.default = pkgs.mkShell { + buildInputs = buildInputs ++ devTools; + }; + + packages = { + default = pkgs.stdenv.mkDerivation { + pname = "linked-list"; + version = "1.0.0"; + + src = ./.; + + nativeBuildInputs = buildInputs ++ [ pkgs.makeWrapper ]; + + buildPhase = '' + javac -Werror -g:none -deprecation -verbose Main.java + ''; + + installPhase = '' + mkdir -p $out/{bin,lib} + cp *.class $out/lib + + makeWrapper ${pkgs.lib.getExe jdk} $out/bin/linked-list --add-flags "-cp $out/lib/ Main" + ''; + }; + }; + }; + flake = { + }; + }; +}