old projects

This commit is contained in:
2022-10-12 19:59:56 +02:00
parent 3415a1383b
commit 199325ac33
75 changed files with 5172 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
------------------------------------------------------------------------
This is the project README file. Here, you should describe your project.
Tell the reader (someone who does not know anything about this project)
all they need to know. The comments should usually include at least:
------------------------------------------------------------------------
PROJECT TITLE:
PURPOSE OF PROJECT:
VERSION or DATE:
HOW TO START THIS PROJECT:
AUTHORS:
USER INSTRUCTIONS:

View File

@@ -0,0 +1,3 @@
#! /usr/bin/bash
javac rotation.java
java rotation

View File

@@ -0,0 +1,6 @@
5
#####
# 00#
#1 2#
#1 2#
## ##

View File

@@ -0,0 +1,9 @@
8
########
# 0#
# 0#
#112222#
#33 4#
#55 4#
#666 4#
### ####

View File

@@ -0,0 +1,11 @@
10
##########
# #
# #
# #
# 7775#
# 11 5#
# 2 888#
#990233 #
#44066666#
##### ####

View File

@@ -0,0 +1,13 @@
12
############
# #
# 01 #
# 01 #
# 01 #
# 222222#
# 34 5 #
# 34 5 #
# 634 5 #
# 63477775 #
# 63888885 #
###### #####

View File

@@ -0,0 +1,32 @@
#BlueJ package file
editor.fx.0.height=1396
editor.fx.0.width=2160
editor.fx.0.x=0
editor.fx.0.y=0
objectbench.height=94
objectbench.width=776
package.divider.horizontal=0.6
package.divider.vertical=0.8003952569169961
package.editor.height=398
package.editor.width=670
package.editor.x=125
package.editor.y=598
package.frame.height=600
package.frame.width=800
package.numDependencies=0
package.numTargets=1
package.showExtends=true
package.showUses=true
project.charset=UTF-8
readme.height=60
readme.name=@README
readme.width=49
readme.x=10
readme.y=10
target1.height=70
target1.name=rotation
target1.showInterface=false
target1.type=ClassTarget
target1.width=120
target1.x=134
target1.y=90

View File

@@ -0,0 +1,3 @@
#! /usr/bin/bash
javac rotation.java
java rotation

Binary file not shown.

View File

@@ -0,0 +1,39 @@
#BlueJ class context
comment0.target=rotation
comment1.params=
comment1.target=rotation()
comment10.params=pX\ pY\ block
comment10.target=void\ fallV(int,\ int,\ int)
comment11.params=input
comment11.target=void\ delete(int)
comment12.params=g
comment12.target=void\ paint(java.awt.Graphics)
comment13.params=
comment13.target=void\ neuzeichnen()
comment14.params=g
comment14.target=void\ anzeigen(java.awt.Graphics)
comment15.params=g
comment15.target=void\ feldAnzeigen(java.awt.Graphics)
comment16.params=
comment16.target=void\ anzeigenTxt()
comment17.params=milliseconds
comment17.target=void\ wait(int)
comment18.params=
comment18.target=void\ rotateClockwise()
comment2.params=
comment2.target=void\ rd()
comment3.params=
comment3.target=void\ ld()
comment4.params=
comment4.target=void\ richten()
comment5.params=
comment5.target=void\ checkFall()
comment6.params=px\ py
comment6.target=boolean\ movedBlocks(int,\ int)
comment7.params=pX\ pY\ block
comment7.target=void\ fall(int,\ int,\ int)
comment8.params=pX\ pY\ block
comment8.target=boolean\ horizontal(int,\ int,\ int)
comment9.params=pX\ pY\ block
comment9.target=void\ fallH(int,\ int,\ int)
numComments=19

View File

@@ -0,0 +1,404 @@
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.util.Random;
import java.util.ArrayList;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class rotation extends JFrame implements KeyListener {
int feldGroesse;
int[][] feld;
private int ppX, len; // laengen und tmp ints
public boolean cheggin, moved, canMove, solved;
public static String filename;
ArrayList<Integer> mBlocks = new ArrayList<Integer>();
ArrayList<Integer> arraylist = new ArrayList<Integer>();
public static void main(String[] args) {
if (args.length != 0) {
new rotation(args[0]);
} else {
new rotation("file1.txt");
}
}
public rotation(String pFilename) {
filename = pFilename;
einlesen();
setSize(800, 800);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
setBackground(new Color(0, 0, 0));
addKeyListener(this);
anzeigenTxt();
richten();
findZiel();
// i = feld.length;
// j = feld[0].length;
}
public void rd() {
rotateClockwise();
checkFall();
}
public void ld() {
// TODO: BS
rotateClockwise();
rotateClockwise();
rotateClockwise();
checkFall();
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Key: " + e.getKeyChar());
if (e.getKeyChar() == 'a') {
ld();
}
if (e.getKeyChar() == 'd') {
rd();
}
if (e.getKeyChar() == 's') {
solve();
}
}
@Override
public void keyReleased(KeyEvent e) {
}
public void findZiel() {
for (int i = 0; i < feld.length; i++)
if (feld[i][feld.length - 1] == 0) {
feld[i][feld.length - 1] = -2;
}
}
public void richten() {
rotateClockwise();
int[][] matrixNeu = new int[feld.length][feld.length];
for (int m = 0; m < feld.length; m++) {
for (int l = 0; l < feld.length; l++) {
matrixNeu[m][l] = feld[feld.length - 1 - m][l];
}
}
feld = matrixNeu;
repaint();
}
public void solve() {
solved = false;
while (!solved) {
if (Math.random() > 0.5) {
rd();
System.out.println("rechts");
} else {
ld();
System.out.println("links");
}
repaint();
wait(10);
}
}
public void checkFall() {
moved = false;
// while(moved == false){
mBlocks.clear();
for (int y = 0; y < feld.length; y++) {
for (int x = 0; x < feld.length; x++) {
if (feld[x][y] > 0 && movedBlocks(x, y) == false) {
mBlocks.add(feld[x][y]);
fall(x, y, feld[x][y]);
repaint();
// System.out.println("yeet");
}
}
}
// }
}
public boolean movedBlocks(int px, int py) {
// DONE check array-list, ob zahl schon abgefragt wurde
if (mBlocks.contains(feld[px][py])) {
return true;
} else {
return false;
}
}
public void fall(int pX, int pY, int block) {
if (horizontal(pX, pY, block) == true) {
fallH(pX, pY, block);
} else {
fallV(pX, pY, block);
}
}
public boolean horizontal(int pX, int pY, int block) {
if (feld[pX + 1][pY] == block) {
return true;
} else {
return false;
}
}
public void fallH(int pX, int pY, int block) {
ppX = pX;
len = 0;
while (feld[ppX][pY] == block) {
// System.out.println("ppX" + ppX + "py" + pY + "block" + block);
len++;
ppX++;
}
canMove = true;
for (int i = 0; i < len; i++) {
if (feld[pX + i][pY + 1] != 0) {
canMove = false;
}
}
if (canMove == true) {
moved = true;
for (int i = 0; i < len; i++) {
feld[pX + i][pY + 1] = block;
feld[pX + i][pY] = 0;
}
checkFall();
return;
}
}
public void fallV(int pX, int pY, int block) {
cheggin = true;
int i = 0;
int ppY = pY;
while (cheggin == true) {
if (feld[pX][ppY] != block) {
cheggin = false;
} else {
ppY++;
}
}
// TODO siegesabfrage
// System.out.println("ppy:" + ppY + "px:" + pX);
if (feld[pX][ppY] == -2) {
solved = true;
delete(block);
}
if (feld[pX][ppY] == 0) {
for (int j = ppY; j > pY; j--) {
feld[pX][j] = feld[pX][j - 1];
feld[pX][j - 1] = 0;
}
moved = true;
checkFall();
return;
} else {
return;
}
}
public void delete(int input) {
int[][] matrixNeu = new int[feld.length][feld.length];
matrixNeu = feld;
for (int m = 0; m < feld.length; m++) {
for (int l = 0; l < feld.length; l++) {
if (matrixNeu[m][l] == input) {
matrixNeu[m][l] = 0;
}
}
}
feld = matrixNeu;
repaint();
}
public void auslesen(String pString, int index) {
for (int i = 0; i < feldGroesse; i++) {
String pos = pString.substring(i, i + 1);
System.out.print(pos + ",");
// System.out.println("i: " + i + " index: " + index);
if (pos.equals("#")) {
feld[index][i] = -2;
} else if (pos.equals(" ")) {
feld[index][i] = -1;
} else
feld[index][i] = Integer.parseInt(pos);
feld[index][i]++;
}
// System.out.println();
}
public void einlesen() {
try {
ArrayList<Integer> arrayTxtDatei1 = new ArrayList<Integer>();
FileReader f = new FileReader(filename);
BufferedReader br = new BufferedReader(f);
String zeile = br.readLine();
System.out.println("Erste Zeile: " + zeile);
// Feld initialisieren
feldGroesse = Integer.parseInt(zeile);
feld = new int[feldGroesse][feldGroesse];
System.out.println("Feldgroesse ist: [" + feldGroesse + "][" + feldGroesse + "]");
int index = 0;
while (zeile != null && index < feldGroesse) {
// System.out.println("file1.txt " + zeile);
// arrayTxtDatei1.add(Integer.valueOf(zeile));
zeile = br.readLine();
auslesen(zeile, index);
index++;
}
br.close();
}
catch (IOException e) {
e.printStackTrace();
}
Integer array[] = new Integer[arraylist.size()];
array = arraylist.toArray(array);
}
public void paint(Graphics g) {
feldAnzeigen(g);
}
public void neuzeichnen() {
repaint();
}
public void anzeigen(Graphics g) {
feldAnzeigen(g);
}
public void feldAnzeigen(Graphics g) {
for (int j = 0; j < feld.length; j++) {
for (int i = 0; i < feld.length; i++) {
if (feld[j][i] == 0) {
g.setColor(new Color(255, 255, 255));
}
if (feld[j][i] == -1) {
g.setColor(new Color(100, 100, 100));
}
if (feld[j][i] == 1) {
g.setColor(new Color(255, 0, 0));
}
if (feld[j][i] == 2) {
g.setColor(new Color(0, 255, 0));
}
if (feld[j][i] == 3) {
g.setColor(new Color(0, 0, 255));
}
if (feld[j][i] == 4) {
g.setColor(new Color(255, 0, 255));
}
if (feld[j][i] == 5) {
g.setColor(new Color(0, 255, 255));
}
if (feld[j][i] == 6) {
g.setColor(new Color(138, 43, 226));
}
if (feld[j][i] == 7) {
g.setColor(new Color(147, 112, 219));
}
if (feld[j][i] == 8) {
g.setColor(new Color(255, 140, 0));
}
if (feld[j][i] == 9) {
g.setColor(new Color(0, 100, 0));
}
if (feld[j][i] == 10) {
g.setColor(new Color(151, 255, 255));
}
if (feld[j][i] == -2) {
g.setColor(new Color(255, 255, 0));
}
g.fillRect(100 + 21 * j, 100 + 21 * i, 20, 20);
}
}
}
public void anzeigenTxt() {
for (int xpos = 0; xpos < feld.length; xpos++) {
for (int ypos = 0; ypos < feld[0].length; ypos++) {
System.out.print(feld[ypos][xpos] + " \t");
}
System.out.println();
}
}
public void wait(int milliseconds) {
try {
Thread.sleep(milliseconds);
} catch (Exception e) {
// ignoring exception at the moment
}
}
void rotateClockwise() {
int[][] matrixNeu = new int[feld.length][feld.length];
for (int m = 0; m < feld.length; m++) {
for (int l = 0; l < feld.length; l++) {
// matrixNeu[k][i-l]=feld[i][j];
matrixNeu[feld.length - 1 - m][l] = feld[l][m];
}
}
feld = matrixNeu;
repaint();
}
}

View File

@@ -0,0 +1,347 @@
import javax.swing.*;
import java.awt.*;
import java.util.Random;
import java.util.ArrayList;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Scanner;
import java.io.*;
public class rotation extends JFrame implements KeyListener
{
private int feld[][]= //Feld... duh
{{-1, -1, -1, -1, -1 }, //-1=wand, 0=leeres feld, 1-3=bloecke, -2=ausgang
{ -1, 0, 1, 1, -1 },
{ -1, 2, 0, 3, -1 },
{ -1, 2, 0, 3, -1 },
{ -1, -1, -2, -1, -1 }};
private int fl=feld.length, ppX, len; //laengen und tmp ints
public boolean cheggin, moved, canMove;
Scanner scan;
public static String filename;
ArrayList<Integer> mBlocks = new ArrayList<Integer>();
public static void main(String[] args){
if(args.length!=0){
filename=args[0];
}
new rotation();
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Key: " + e.getKeyChar());
if(e.getKeyChar()=='a'){
ld();
}
if(e.getKeyChar()=='d'){
rd();
}
}
@Override
public void keyReleased(KeyEvent e) {
}
public void readFile(String filename){
try{
scan = new Scanner(new File(filename));
}
catch (FileNotFoundException e){
e.printStackTrace();
}
}
public rotation() {
setSize(800,800);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
anzeigenTxt();
setBackground(new Color(0,0,0));
addKeyListener(this);
richten();
}
public void rd() {
rotateClockwise();
checkFall();
}
public void ld() {
//TODO: BS
rotateClockwise();
rotateClockwise();
rotateClockwise();
checkFall();
}
public void richten(){
rotateClockwise();
int[][] matrixNeu= new int[feld.length][feld.length];
for(int m = 0;m < 5; m++)
{
for(int l = 0; l < 5;l++)
{
matrixNeu[m][l] = feld[fl-1-m][l];
}
}
feld=matrixNeu;
repaint();
}
public void checkFall(){
moved = false;
mBlocks.clear();
for(int y=0;y<fl;y++){
for(int x=0;x<fl;x++){
if(feld[x][y]>0 && movedBlocks(x,y)==false){
mBlocks.add(feld[x][y]);
fall(x,y,feld[x][y]);
repaint();
//System.out.println("yeet");
}
}
}
}
public boolean movedBlocks(int px, int py){
//DONE check array-list, ob zahl schon abgefragt wurde
if(mBlocks.contains(feld[px][py])){
return true;
}
else{
return false;
}
}
public void fall(int pX,int pY,int block){
if(horizontal(pX,pY,block)==true){
fallH(pX,pY,block);
}
else{
fallV(pX,pY,block);
}
}
public boolean horizontal(int pX,int pY,int block){
if(feld[pX+1][pY]==block){
return true;
}
else{
return false;
}
}
public void fallH(int pX,int pY,int block){
ppX = pX;
len = 0;
while(feld[ppX][pY]==block){
//System.out.println("ppX"+ppX+"py"+pY+"block"+block);
len++;
ppX++;
}
canMove = true;
for(int i = 0;i<len;i++){
if(feld[pX + i][pY + 1] != 0){
canMove=false;
}
}
if(canMove == true){
for(int i = 0;i<len;i++){
feld[pX + i][pY + 1] = block;
feld[pX + i][pY] = 0;
wait(100);
}
checkFall();
return;
}
}
public void fallV(int pX,int pY,int block){
cheggin = true;
int i = 0;
int ppY = pY;
while(cheggin==true){
if(feld[pX][ppY]!=block){
cheggin=false;
}
else{
ppY++;
}
}
//DONE siegesabfrage
//System.out.println("ppy:"+ppY+"px:"+pX);
if(feld[pX][ppY] == -2){
delete(block);
}
if(feld[pX][ppY]==0){
for(int j=ppY;j>pY;j--){
feld[pX][j]=feld[pX][j-1];
feld[pX][j-1]=0;
wait(100);
}
checkFall();
return;
}
else{
return;
}
}
public void delete(int input){
int[][] matrixNeu= new int[feld.length][feld.length];
matrixNeu = feld;
for(int m=0;m < fl; m++)
{
for(int l=0;l< fl;l++)
{
if(matrixNeu[m][l] == input){
matrixNeu[m][l] = 0;
wait(50);
}
}
}
feld=matrixNeu;
repaint();
}
public void paint(Graphics g)
{
feldAnzeigen(g);
}
public void neuzeichnen()
{
repaint();
}
public void anzeigen(Graphics g)
{
feldAnzeigen(g);
}
public void feldAnzeigen(Graphics g)
{
for(int j=0;j < 5; j++)
{
for(int i=0;i< 5;i++)
{
if(feld[j][i] == 0){
g.setColor(new Color(255,255,255));
}
if(feld[j][i] == -1){
g.setColor(new Color(100,100,100));
}
if(feld[j][i] == 1){
g.setColor(new Color(255,0,0));
}
if(feld[j][i] == 2){
g.setColor(new Color(0,255,0));
}
if(feld[j][i] == 3){
g.setColor(new Color(0,0,255));
}
if(feld[j][i] == -2){
g.setColor(new Color(255,215,0));
}
g.fillRect(100+42*j ,100+42*i ,40, 40);
}
}
}
public void anzeigenTxt()
{
for (int xpos=0;xpos<feld.length;xpos++)
{
for (int ypos=0;ypos<feld[0].length;ypos++)
{
//System.out.println(feld[xpos][ypos]+" x:"+xpos+" y:"+ypos);
}
}
}
public void wait(int milliseconds)
{
try
{
Thread.sleep(milliseconds);
}
catch (Exception e)
{
// ignoring exception at the moment
}
}
void rotateClockwise()
{
int[][] matrixNeu= new int[feld.length][feld.length];
for(int m=0;m < 5; m++)
{
for(int l=0;l< 5;l++)
{
matrixNeu[feld.length-1-m][l]=feld[l][m];
}
}
feld=matrixNeu;
repaint();
}
}

View File

@@ -0,0 +1,5 @@
#####
# 00#
#1 2#
#1 2#
## ##

Binary file not shown.

View File

@@ -0,0 +1,403 @@
import javax.swing.*;
import java.awt.*;
import java.util.Random;
import java.util.ArrayList;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Scanner;
import java.io.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Scanner;
public class rotation extends JFrame implements KeyListener {
private int feld[][] = // Feld... duh
{ { -1, -1, -1, -1, -1 }, // -1=wand, 0=leeres feld, 1-3=bloecke, -2=ausgang
{ -1, 0, 1, 1, -1 },
{ -1, 2, 0, 3, -1 },
{ -1, 2, 0, 3, -1 },
{ -1, -1, -2, -1, -1 } };
private int fl, ppX, len; // laengen und tmp ints
public boolean cheggin, moved, canMove;
Scanner scan;
public static String filename;
public String[] array, tmpArray;
public String[][] sArray;
ArrayList<Integer> mBlocks = new ArrayList<Integer>();
public static void main(String[] args) {
if (args.length != 0) {
filename = args[0];
}
new rotation();
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Key: " + e.getKeyChar());
if (e.getKeyChar() == 'a') {
ld();
}
if (e.getKeyChar() == 'd') {
rd();
}
}
@Override
public void keyReleased(KeyEvent e) {
}
public void readFile() {
try {
scan = new Scanner(new File(filename));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public void createString() {
List<String> listOfStrings = new ArrayList<String>();
// load the data from file
try {
listOfStrings = Files.readAllLines(Paths.get(filename));
} catch (IOException e) {
}
// convert arraylist to array
array = listOfStrings.toArray(new String[0]);
for (int i = 0; i < array.length; i++) {
array[i] = array[i].replace(' ', 'a');
}
System.out.println(array[3]);
}
public void dimension() {
tmpArray = new String[array.length];
sArray = new String[array.length][array.length];
for (int i = 0; i < array.length; i++) {
scan = new Scanner(array[i]).useDelimiter("\\s*\\s*");
int j = 0;
while (scan.hasNext()) {
tmpArray[j] = scan.next();
// tmpArray[j] = tmpArray[j].replace("#","-1");
tmpArray[j] = tmpArray[j].replace("a", "99");
System.out.println(tmpArray[j]);
j++;
for (int k = 0; k < tmpArray.length; k++) {
System.out.println(tmpArray[k]);
}
}
sArray[i] = tmpArray;
}
System.out.println(sArray[0][0]);
System.out.println(sArray[4][4]);
for (int x = 0; x < sArray.length; x++) {
for (int y = 0; y < sArray.length; y++) {
if (sArray[y][x] == "#") {
sArray[y][x] = "-1";
}
}
}
}
public void fill() {
feld = new int[sArray.length][sArray.length];
for (int x = 0; x < sArray.length; x++) {
for (int y = 0; y < sArray.length; y++) {
feld[y][x] = Integer.parseInt(sArray[y][x]);
System.out.println(feld[y][x]);
if (feld[y][x] == 99) {
feld[y][x] = 0;
} else if (feld[y][x] >= 0) {
feld[y][x]++;
}
System.out.println(feld[y][x]);
}
}
printNew();
}
public void printNew() {
for (int x = 0; x < sArray.length; x++) {
for (int y = 0; y < sArray.length; y++) {
System.out.print(sArray[x][y] + " \t");
}
System.out.println();
}
}
public rotation() {
setSize(800, 800);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
// anzeigenTxt();
setBackground(new Color(0, 0, 0));
addKeyListener(this);
if (filename != null) {
readFile();
createString();
dimension();
fill();
}
richten();
fl = feld.length;
}
public void rd() {
rotateClockwise();
checkFall();
}
public void ld() {
// TODO: BS
rotateClockwise();
rotateClockwise();
rotateClockwise();
checkFall();
}
public void richten() {
rotateClockwise();
fl = feld.length;
int[][] matrixNeu = new int[feld.length][feld.length];
for (int m = 0; m < 5; m++) {
for (int l = 0; l < 5; l++) {
matrixNeu[m][l] = feld[fl - 1 - m][l];
}
}
feld = matrixNeu;
repaint();
}
public void checkFall() {
moved = false;
mBlocks.clear();
for (int y = 0; y < fl; y++) {
for (int x = 0; x < fl; x++) {
if (feld[x][y] > 0 && movedBlocks(x, y) == false) {
mBlocks.add(feld[x][y]);
fall(x, y, feld[x][y]);
repaint();
// System.out.println("yeet");
}
}
}
}
public boolean movedBlocks(int px, int py) {
// DONE check array-list, ob zahl schon abgefragt wurde
if (mBlocks.contains(feld[px][py])) {
return true;
} else {
return false;
}
}
public void fall(int pX, int pY, int block) {
if (horizontal(pX, pY, block) == true) {
fallH(pX, pY, block);
} else {
fallV(pX, pY, block);
}
}
public boolean horizontal(int pX, int pY, int block) {
if (feld[pX + 1][pY] == block) {
return true;
} else {
return false;
}
}
public void fallH(int pX, int pY, int block) {
ppX = pX;
len = 0;
while (feld[ppX][pY] == block) {
// System.out.println("ppX"+ppX+"py"+pY+"block"+block);
len++;
ppX++;
}
canMove = true;
for (int i = 0; i < len; i++) {
if (feld[pX + i][pY + 1] != 0) {
canMove = false;
}
}
if (canMove == true) {
for (int i = 0; i < len; i++) {
feld[pX + i][pY + 1] = block;
feld[pX + i][pY] = 0;
wait(100);
repaint();
}
checkFall();
return;
}
}
public void fallV(int pX, int pY, int block) {
cheggin = true;
int i = 0;
int ppY = pY;
while (cheggin == true) {
if (feld[pX][ppY] != block) {
cheggin = false;
} else {
ppY++;
}
}
// DONE siegesabfrage
// System.out.println("ppy:"+ppY+"px:"+pX);
if (feld[pX][ppY] == -2) {
delete(block);
}
if (feld[pX][ppY] == 0) {
for (int j = ppY; j > pY; j--) {
feld[pX][j] = feld[pX][j - 1];
feld[pX][j - 1] = 0;
wait(100);
repaint();
}
checkFall();
return;
} else {
return;
}
}
public void delete(int input) {
int[][] matrixNeu = new int[feld.length][feld.length];
matrixNeu = feld;
for (int m = 0; m < fl; m++) {
for (int l = 0; l < fl; l++) {
if (matrixNeu[m][l] == input) {
matrixNeu[m][l] = 0;
wait(50);
}
}
}
feld = matrixNeu;
repaint();
}
public void paint(Graphics g) {
feldAnzeigen(g);
}
public void neuzeichnen() {
repaint();
}
public void anzeigen(Graphics g) {
feldAnzeigen(g);
}
public void feldAnzeigen(Graphics g) {
for (int j = 0; j < 5; j++) {
for (int i = 0; i < 5; i++) {
if (feld[j][i] == 0) {
g.setColor(new Color(255, 255, 255));
}
if (feld[j][i] == -1) {
g.setColor(new Color(100, 100, 100));
}
if (feld[j][i] == 1) {
g.setColor(new Color(255, 0, 0));
}
if (feld[j][i] == 2) {
g.setColor(new Color(0, 255, 0));
}
if (feld[j][i] == 3) {
g.setColor(new Color(0, 0, 255));
}
if (feld[j][i] == -2) {
g.setColor(new Color(255, 215, 0));
}
g.fillRect(100 + 42 * j, 100 + 42 * i, 40, 40);
}
}
}
public void anzeigenTxt() {
for (int xpos = 0; xpos < feld.length; xpos++) {
for (int ypos = 0; ypos < feld[0].length; ypos++) {
System.out.println(feld[xpos][ypos] + " x:" + xpos + " y:" + ypos);
}
}
}
public void wait(int milliseconds) {
try {
Thread.sleep(milliseconds);
} catch (Exception e) {
// ignoring exception at the moment
}
}
void rotateClockwise() {
int[][] matrixNeu = new int[feld.length][feld.length];
for (int m = 0; m < 5; m++) {
for (int l = 0; l < 5; l++) {
matrixNeu[feld.length - 1 - m][l] = feld[l][m];
}
}
feld = matrixNeu;
repaint();
}
}

View File

@@ -0,0 +1,5 @@
#####
# 00#
#1 2#
#1 2#
## ##

View File

@@ -0,0 +1,8 @@
########
# 0#
# 0#
#112222#
#33 4#
#55 4#
#666 4#
### ####

View File

@@ -0,0 +1,10 @@
##########
# #
# #
# #
# 7775#
# 11 5#
# 2 888#
#990233 #
#44066666#
##### ####

View File

@@ -0,0 +1,12 @@
############
# #
# 01 #
# 01 #
# 01 #
# 222222#
# 34 5 #
# 34 5 #
# 634 5 #
# 63477775 #
# 63888885 #
###### #####

Binary file not shown.

View File

@@ -0,0 +1,371 @@
import javax.swing.*;
import java.awt.*;
import java.util.Random;
import java.util.ArrayList;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Scanner;
import java.io.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class rotation extends JFrame implements KeyListener {
public int feld[][];
/*
* private int feld[][] = // Feld... duh
*
* { { -1, -1, -1, -1, -1 }, // -1=wand, 0=leeres feld, 1-3=bloecke, -2=ausgang
* { -1, 0, 1, 1, -1 },
* { -1, 2, 0, 3, -1 },
* { -1, 2, 0, 3, -1 },
* { -1, -1, -2, -1, -1 } };
*/
private int ppX, len; // laengen und tmp ints
public boolean cheggin, moved, canMove;
Scanner scan;
public static String filename = "file2.txt";
public int[][] feld2;
int feldGroesse;
ArrayList<Integer> arraylist = new ArrayList<Integer>();
ArrayList<Integer> mBlocks = new ArrayList<Integer>();
public static void main(String[] args) {
if (args.length != 0) {
filename = args[0];
}
new rotation();
}
public rotation() {
setSize(800, 800);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
// anzeigenTxt();
setBackground(new Color(0, 0, 0));
addKeyListener(this);
if (filename != null) {
System.out.print("einlesen");
einlesen();
System.out.print("auslesen");
}
richten();
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Key: " + e.getKeyChar());
if (e.getKeyChar() == 'a') {
ld();
}
if (e.getKeyChar() == 'd') {
rd();
}
}
@Override
public void keyReleased(KeyEvent e) {
}
public void auslesen(String pString, int index) {
for (int i = 0; i < feldGroesse; i++) {
String pos = pString.substring(i, i + 1);
System.out.print(pos + ",");
System.out.println("i: " + i + " index: " + index);
if (pos.equals("#")) {
feld[index][i] = -2;
} else if (pos.equals(" ")) {
feld[index][i] = -1;
} else
feld[index][i] = Integer.parseInt(pos);
}
System.out.println();
}
public void einlesen() {
try {
ArrayList<Integer> arrayTxtDatei1 = new ArrayList<Integer>();
FileReader f = new FileReader(filename);
BufferedReader br = new BufferedReader(f);
String zeile = br.readLine();
System.out.println("Erste Zeile: " + zeile);
// Feld initialisieren
feldGroesse = Integer.parseInt(zeile);
feld = new int[feldGroesse][feldGroesse];
System.out.println("Feldgroesse ist: [" + feldGroesse + "][" + feldGroesse + "]");
int index = 0;
while (zeile != null && index < feldGroesse) {
// System.out.println("file1.txt " + zeile);
// arrayTxtDatei1.add(Integer.valueOf(zeile));
zeile = br.readLine();
auslesen(zeile, index);
index++;
}
br.close();
}
catch (IOException e) {
e.printStackTrace();
}
Integer array[] = new Integer[arraylist.size()];
array = arraylist.toArray(array);
}
public void rd() {
rotateClockwise();
checkFall();
}
public void ld() {
// TODO: BS
rotateClockwise();
rotateClockwise();
rotateClockwise();
checkFall();
}
public void richten() {
rotateClockwise();
int[][] matrixNeu = new int[feld.length][feld.length];
for (int m = 0; m < 5; m++) {
for (int l = 0; l < 5; l++) {
matrixNeu[m][l] = feld[feld.length - 1 - m][l];
}
}
feld = matrixNeu;
repaint();
}
public void checkFall() {
moved = false;
mBlocks.clear();
for (int y = 0; y < feld.length; y++) {
for (int x = 0; x < feld.length; x++) {
if (feld[x][y] > 0 && movedBlocks(x, y) == false) {
mBlocks.add(feld[x][y]);
fall(x, y, feld[x][y]);
repaint();
// System.out.println("yeet");
}
}
}
}
public boolean movedBlocks(int px, int py) {
// DONE check array-list, ob zahl schon abgefragt wurde
if (mBlocks.contains(feld[px][py])) {
return true;
} else {
return false;
}
}
public void fall(int pX, int pY, int block) {
if (horizontal(pX, pY, block) == true) {
fallH(pX, pY, block);
} else {
fallV(pX, pY, block);
}
}
public boolean horizontal(int pX, int pY, int block) {
if (feld[pX + 1][pY] == block) {
return true;
} else {
return false;
}
}
public void fallH(int pX, int pY, int block) {
ppX = pX;
len = 0;
while (feld[ppX][pY] == block) {
// System.out.println("ppX"+ppX+"py"+pY+"block"+block);
len++;
ppX++;
}
canMove = true;
for (int i = 0; i < len; i++) {
if (feld[pX + i][pY + 1] != 0) {
canMove = false;
}
}
if (canMove == true) {
for (int i = 0; i < len; i++) {
feld[pX + i][pY + 1] = block;
feld[pX + i][pY] = 0;
wait(100);
}
checkFall();
return;
}
}
public void fallV(int pX, int pY, int block) {
cheggin = true;
int i = 0;
int ppY = pY;
while (cheggin == true) {
if (feld[pX][ppY] != block) {
cheggin = false;
} else {
ppY++;
}
}
// DONE siegesabfrage
// System.out.println("ppy:"+ppY+"px:"+pX);
if (feld[pX][ppY] == -2) {
delete(block);
}
if (feld[pX][ppY] == 0) {
for (int j = ppY; j > pY; j--) {
feld[pX][j] = feld[pX][j - 1];
feld[pX][j - 1] = 0;
wait(100);
}
checkFall();
return;
} else {
return;
}
}
public void delete(int input) {
int[][] matrixNeu = new int[feld.length][feld.length];
matrixNeu = feld;
for (int m = 0; m < feld.length; m++) {
for (int l = 0; l < feld.length; l++) {
if (matrixNeu[m][l] == input) {
matrixNeu[m][l] = 0;
wait(50);
}
}
}
feld = matrixNeu;
repaint();
}
public void paint(Graphics g) {
feldAnzeigen(g);
}
public void neuzeichnen() {
repaint();
}
public void anzeigen(Graphics g) {
feldAnzeigen(g);
}
public void feldAnzeigen(Graphics g) {
for (int j = 0; j < 5; j++) {
for (int i = 0; i < 5; i++) {
if (feld[j][i] == 0) {
g.setColor(new Color(255, 255, 255));
}
if (feld[j][i] == -1) {
g.setColor(new Color(100, 100, 100));
}
if (feld[j][i] == 1) {
g.setColor(new Color(255, 0, 0));
}
if (feld[j][i] == 2) {
g.setColor(new Color(0, 255, 0));
}
if (feld[j][i] == 3) {
g.setColor(new Color(0, 0, 255));
}
if (feld[j][i] == -2) {
g.setColor(new Color(255, 215, 0));
}
g.fillRect(100 + 42 * j, 100 + 42 * i, 40, 40);
}
}
}
public void anzeigenTxt() {
for (int xpos = 0; xpos < feld2.length; xpos++) {
for (int ypos = 0; ypos < feld2[0].length; ypos++) {
System.out.print(feld2[xpos][ypos] + " \t");
}
System.out.println();
}
}
public void wait(int milliseconds) {
try {
Thread.sleep(milliseconds);
} catch (Exception e) {
// ignoring exception at the moment
}
}
void rotateClockwise() {
int[][] matrixNeu = new int[feld.length][feld.length];
for (int m = 0; m < 5; m++) {
for (int l = 0; l < 5; l++) {
matrixNeu[feld.length - 1 - m][l] = feld[l][m];
}
}
feld = matrixNeu;
repaint();
}
}

View File

@@ -0,0 +1,5 @@
#####
# 00#
#1 2#
#1 2#
## ##

View File

@@ -0,0 +1,9 @@
8
########
# 0#
# 0#
#112222#
#33 4#
#55 4#
#666 4#
### ####

View File

@@ -0,0 +1,11 @@
10
##########
# #
# #
# #
# 7775#
# 11 5#
# 2 888#
#990233 #
#44066666#
##### ####

View File

@@ -0,0 +1,14 @@
12
############
# #
# 01 #
# 01 #
# 01 #
# 222222#
# 34 5 #
# 34 5 #
# 634 5 #
# 63477775 #
# 63888885 #
###### #####

Binary file not shown.

View File

@@ -0,0 +1,374 @@
import javax.swing.*;
import java.awt.*;
import java.util.Random;
import java.util.ArrayList;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class rotation extends JFrame implements KeyListener {
int feldGroesse;
int[][] feld;
private int ppX, len; // laengen und tmp ints
public boolean cheggin, moved, canMove;
public static String filename;
ArrayList<Integer> mBlocks = new ArrayList<Integer>();
ArrayList<Integer> arraylist = new ArrayList<Integer>();
public static void main(String[] args) {
if (args.length != 0) {
filename = args[0];
}
new rotation();
}
public rotation() {
if (filename == null) {
filename = "file1.txt";
}
einlesen();
setSize(800, 800);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
setBackground(new Color(0, 0, 0));
addKeyListener(this);
anzeigenTxt();
richten();
findZiel();
// i = feld.length;
// j = feld[0].length;
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Key: " + e.getKeyChar());
if (e.getKeyChar() == 'a') {
ld();
}
if (e.getKeyChar() == 'd') {
rd();
}
}
@Override
public void keyReleased(KeyEvent e) {
}
public void rd() {
rotateClockwise();
checkFall();
}
public void ld() {
// TODO: BS
rotateClockwise();
rotateClockwise();
rotateClockwise();
checkFall();
}
public void findZiel() {
for (int i = 0; i < feld.length; i++)
if (feld[i][feld.length - 1] == 0) {
feld[i][feld.length - 1] = -2;
}
}
public void richten() {
rotateClockwise();
int[][] matrixNeu = new int[feld.length][feld.length];
for (int m = 0; m < feld.length; m++) {
for (int l = 0; l < feld.length; l++) {
matrixNeu[m][l] = feld[feld.length - 1 - m][l];
}
}
feld = matrixNeu;
repaint();
}
public void checkFall() {
moved = false;
// while(moved == false){
mBlocks.clear();
for (int y = 0; y < feld.length; y++) {
for (int x = 0; x < feld.length; x++) {
if (feld[x][y] > 0 && movedBlocks(x, y) == false) {
mBlocks.add(feld[x][y]);
fall(x, y, feld[x][y]);
repaint();
System.out.println("yeet");
}
}
}
// }
}
public boolean movedBlocks(int px, int py) {
// DONE check array-list, ob zahl schon abgefragt wurde
if (mBlocks.contains(feld[px][py])) {
return true;
} else {
return false;
}
}
public void fall(int pX, int pY, int block) {
if (horizontal(pX, pY, block) == true) {
fallH(pX, pY, block);
} else {
fallV(pX, pY, block);
}
}
public boolean horizontal(int pX, int pY, int block) {
if (feld[pX + 1][pY] == block) {
return true;
} else {
return false;
}
}
public void fallH(int pX, int pY, int block) {
ppX = pX;
len = 0;
while (feld[ppX][pY] == block) {
System.out.println("ppX" + ppX + "py" + pY + "block" + block);
len++;
ppX++;
}
canMove = true;
for (int i = 0; i < len; i++) {
if (feld[pX + i][pY + 1] != 0) {
canMove = false;
}
}
if (canMove == true) {
moved = true;
for (int i = 0; i < len; i++) {
feld[pX + i][pY + 1] = block;
feld[pX + i][pY] = 0;
}
checkFall();
return;
}
}
public void fallV(int pX, int pY, int block) {
cheggin = true;
int i = 0;
int ppY = pY;
while (cheggin == true) {
if (feld[pX][ppY] != block) {
cheggin = false;
} else {
ppY++;
}
}
// TODO siegesabfrage
System.out.println("ppy:" + ppY + "px:" + pX);
if (feld[pX][ppY] == -2) {
delete(block);
}
if (feld[pX][ppY] == 0) {
for (int j = ppY; j > pY; j--) {
feld[pX][j] = feld[pX][j - 1];
feld[pX][j - 1] = 0;
}
moved = true;
checkFall();
return;
} else {
return;
}
}
public void delete(int input) {
int[][] matrixNeu = new int[feld.length][feld.length];
matrixNeu = feld;
for (int m = 0; m < feld.length; m++) {
for (int l = 0; l < feld.length; l++) {
if (matrixNeu[m][l] == input) {
matrixNeu[m][l] = 0;
}
}
}
feld = matrixNeu;
repaint();
}
public void auslesen(String pString, int index) {
for (int i = 0; i < feldGroesse; i++) {
String pos = pString.substring(i, i + 1);
System.out.print(pos + ",");
System.out.println("i: " + i + " index: " + index);
if (pos.equals("#")) {
feld[index][i] = -2;
} else if (pos.equals(" ")) {
feld[index][i] = -1;
} else
feld[index][i] = Integer.parseInt(pos);
feld[index][i]++;
}
System.out.println();
}
public void einlesen() {
try {
ArrayList<Integer> arrayTxtDatei1 = new ArrayList<Integer>();
FileReader f = new FileReader(filename);
BufferedReader br = new BufferedReader(f);
String zeile = br.readLine();
System.out.println("Erste Zeile: " + zeile);
// Feld initialisieren
feldGroesse = Integer.parseInt(zeile);
feld = new int[feldGroesse][feldGroesse];
System.out.println("Feldgroesse ist: [" + feldGroesse + "][" + feldGroesse + "]");
int index = 0;
while (zeile != null && index < feldGroesse) {
// System.out.println("file1.txt " + zeile);
// arrayTxtDatei1.add(Integer.valueOf(zeile));
zeile = br.readLine();
auslesen(zeile, index);
index++;
}
br.close();
}
catch (IOException e) {
e.printStackTrace();
}
Integer array[] = new Integer[arraylist.size()];
array = arraylist.toArray(array);
}
public void paint(Graphics g) {
feldAnzeigen(g);
}
public void neuzeichnen() {
repaint();
}
public void anzeigen(Graphics g) {
feldAnzeigen(g);
}
public void feldAnzeigen(Graphics g) {
for (int j = 0; j < feld.length; j++) {
for (int i = 0; i < feld.length; i++) {
if (feld[j][i] == 0) {
g.setColor(new Color(255, 255, 255));
}
if (feld[j][i] == -1) {
g.setColor(new Color(100, 100, 100));
}
if (feld[j][i] == 1) {
g.setColor(new Color(255, 0, 0));
}
if (feld[j][i] == 2) {
g.setColor(new Color(0, 255, 0));
}
if (feld[j][i] == 3) {
g.setColor(new Color(0, 0, 255));
}
if (feld[j][i] == 4) {
g.setColor(new Color(255, 0, 255));
}
if (feld[j][i] == 5) {
g.setColor(new Color(0, 255, 255));
}
if (feld[j][i] == 6) {
g.setColor(new Color(138, 43, 226));
}
if (feld[j][i] == 7) {
g.setColor(new Color(147, 112, 219));
}
if (feld[j][i] == -2) {
g.setColor(new Color(255, 255, 0));
}
g.fillRect(100 + 21 * j, 100 + 21 * i, 20, 20);
}
}
}
public void anzeigenTxt() {
for (int xpos = 0; xpos < feld.length; xpos++) {
for (int ypos = 0; ypos < feld[0].length; ypos++) {
System.out.print(feld[xpos][ypos] + " \t");
}
System.out.println();
}
}
public void wait(int milliseconds) {
try {
Thread.sleep(milliseconds);
} catch (Exception e) {
// ignoring exception at the moment
}
}
void rotateClockwise() {
int[][] matrixNeu = new int[feld.length][feld.length];
for (int m = 0; m < feld.length; m++) {
for (int l = 0; l < feld.length; l++) {
// matrixNeu[k][i-l]=feld[i][j];
matrixNeu[feld.length - 1 - m][l] = feld[l][m];
}
}
feld = matrixNeu;
repaint();
}
}