old projects
This commit is contained in:
5
TillsKakProjekt_noBlueJ/test3/file1.txt
Normal file
5
TillsKakProjekt_noBlueJ/test3/file1.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
#####
|
||||
# 00#
|
||||
#1 2#
|
||||
#1 2#
|
||||
## ##
|
||||
9
TillsKakProjekt_noBlueJ/test3/file2.txt
Normal file
9
TillsKakProjekt_noBlueJ/test3/file2.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
8
|
||||
########
|
||||
# 0#
|
||||
# 0#
|
||||
#112222#
|
||||
#33 4#
|
||||
#55 4#
|
||||
#666 4#
|
||||
### ####
|
||||
11
TillsKakProjekt_noBlueJ/test3/file3.txt
Normal file
11
TillsKakProjekt_noBlueJ/test3/file3.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
10
|
||||
##########
|
||||
# #
|
||||
# #
|
||||
# #
|
||||
# 7775#
|
||||
# 11 5#
|
||||
# 2 888#
|
||||
#990233 #
|
||||
#44066666#
|
||||
##### ####
|
||||
14
TillsKakProjekt_noBlueJ/test3/file4.txt
Normal file
14
TillsKakProjekt_noBlueJ/test3/file4.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
12
|
||||
############
|
||||
# #
|
||||
# 01 #
|
||||
# 01 #
|
||||
# 01 #
|
||||
# 222222#
|
||||
# 34 5 #
|
||||
# 34 5 #
|
||||
# 634 5 #
|
||||
# 63477775 #
|
||||
# 63888885 #
|
||||
###### #####
|
||||
BIN
TillsKakProjekt_noBlueJ/test3/rotation.class
Normal file
BIN
TillsKakProjekt_noBlueJ/test3/rotation.class
Normal file
Binary file not shown.
374
TillsKakProjekt_noBlueJ/test3/rotation.java
Normal file
374
TillsKakProjekt_noBlueJ/test3/rotation.java
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user