Stein.txt + enum Steintypen + Blockbuilder(Wie die steine generiert werden)+ stein constructor angepasst

This commit is contained in:
Newe666 2022-01-20 20:35:00 +01:00
parent 39d721462c
commit c5b6896038
13 changed files with 179 additions and 6 deletions

10
.idea/runConfigurations.xml generated Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

16
Steine/I.txt Normal file
View File

@ -0,0 +1,16 @@
0000
1111
0000
0000
0010
0010
0010
0010
0000
0000
1111
0000
0100
0100
0100
0100

12
Steine/J.txt Normal file
View File

@ -0,0 +1,12 @@
100
111
000
011
010
010
000
111
001
010
010
110

12
Steine/L.txt Normal file
View File

@ -0,0 +1,12 @@
001
111
000
010
010
011
000
111
100
110
010
010

8
Steine/O.txt Normal file
View File

@ -0,0 +1,8 @@
11
11
11
11
11
11
11
11

12
Steine/S.txt Normal file
View File

@ -0,0 +1,12 @@
011
110
000
010
011
001
000
011
110
100
110
010

12
Steine/T.txt Normal file
View File

@ -0,0 +1,12 @@
010
111
000
011
010
000
111
010
010
110
010

13
Steine/Z.txt Normal file
View File

@ -0,0 +1,13 @@
110
011
000
001
011
010
000
110
011
010
110
100

View File

@ -33,7 +33,7 @@ private Color[] colors ={Color.decode("#ff00bf"),Color.decode("#0000ff"),Color.d
public Board() { public Board() {
ran = new Random(); ran = new Random();
steine[0]= new Stein(new int[][]{ /*steine[0]= new Stein(new int[][]{
{1,1,1}, {1,1,1},
{0,1,0} {0,1,0}
@ -63,7 +63,7 @@ private Color[] colors ={Color.decode("#ff00bf"),Color.decode("#0000ff"),Color.d
{1,1,1,1} {1,1,1,1}
}, this,colors[6]); }, this,colors[6]);
currenStein= steine[0]; currenStein= steine[0];*/
loop = new Timer(delay, new ActionListener() { loop = new Timer(delay, new ActionListener() {
int n = 0; int n = 0;

View File

@ -1,15 +1,21 @@
package Tetris; package Tetris;
import java.awt.*; import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Stein { public class Stein {
private int x = 4, y = 0; SteineTyp Block;
private int x = 4, y = -2;
private int normal = 850; private int normal = 850;
private int fast = 50; private int fast = 50;
private int rotation;
private long beginTime; private long beginTime;
private int delayTime = normal; private int delayTime = normal;
private int deltax = 0; private int deltax = 0;
private boolean collision = false; private boolean collision = false;
private int size;
public static final int BOARD_WIDTH = 11; public static final int BOARD_WIDTH = 11;
public static final int BOARD_HEIGHT = 20; public static final int BOARD_HEIGHT = 20;
@ -19,10 +25,70 @@ public class Stein {
private Board board; private Board board;
private Color color; private Color color;
public Stein(int[][] coords, Board board, Color color) { public Stein() {
this.coords = coords; /* this.coords = coords;
this.board = board; this.board = board;
this.color = color; this.color = color;*/
//Ewen Kerbs still in progress
// Hier werden die verschiedene steine auf deren typ "analysiert" und dann ausgewertet wie viel platz die aufm spielbrett benötigen
Block = SteineTyp.randomSteine();
switch (Block)
{
case I:
size = 4;
break;
case O:
size =2;
break;
default:
size =3;
break;
}
}
//ewen Kerbs still in progress
public int[][][] BlockBuilder(SteineTyp type) throws FileNotFoundException {
int[][][] size;
switch(type)
{
case I:
/* 3 dimensionales array um die rotations zu erkennen + */
size = new int[4][4][4];
break;
case O:
size = new int[4][2][2];
break;
default:
size = new int[4][3][3];
break;
}
File file = new File("Steine/"+type+".txt");
Scanner leser = new Scanner(file);
//i= 4 verschiedene stein varianten (1=0° 2=90° 3=180°4=270°)
for (int varianten = 0; varianten < 4 ; varianten++) {
for (int j = 0; j < size[0].length; j++) {
if(leser.hasNext())
{
String[] srow = leser.next().split("");
int[] row = new int[size[0].length];
for (int k = 0; k <row.length; k++)
{
row[j]= Integer.valueOf(srow[j]);
size[varianten][j][k] =row[j];
}
}
}
}
return size;
}
public void rotate()
{
rotation++;
if(rotation==4)
{
rotation=0;
}
} }
public void setX(int x) { public void setX(int x) {
@ -40,6 +106,7 @@ public class Stein {
} }
//Kollisons abfrage
public void update() { public void update() {
if (collision) { if (collision) {
for (int row = 0; row < coords.length; row++) { for (int row = 0; row < coords.length; row++) {

11
src/Tetris/SteineTyp.java Normal file
View File

@ -0,0 +1,11 @@
package Tetris;
import java.util.concurrent.ThreadLocalRandom;
public enum SteineTyp {
I,O,T,L,J,Z,S;
public static SteineTyp randomSteine()
{
return values()[ThreadLocalRandom.current().nextInt(0,values().length)];
}
}