package tetris;
import java.awt.Color;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.io.*;
import java.util.*;
public class Hra extends javax.swing.JFrame {
// Definice globálních věcí
public static final int VX=15,VY=30,VT=4; //rozměry hřiště, tvaru
public static final int velikostCtverecku=16;//velikost jednoho čtverečku hry
public static int hriste[][]=new int[VX][VY];
public static int hriste_Pom[][]=new int[VX][VY];//pomocná k hřišti - porovnávání při vykreslování
public static int uroven_Hry=0,rychlost_Hry=0,pocet_Bodu=0,pocet_Radku=0;
public static int tvar[][]=new int[VT][VT];
public static int tvar_DALSI[][]=new int[VT][VT];
public static int tvar_X,tvar_Y,CISLO_tvaru,ROTACE_tvaru;
public static int cislo_Dal_Tvaru,rotace_Dal_Tvaru;
public static boolean tvarY[][][]=new boolean[10][4][16];//DEFINICEtvarŮ
public static int tvar_K1,tvar_K2,tvar_H1,tvar_H2;//okraje tvaru
public static int pocet_tvaru;
public static boolean polozenTvar=false;
public static boolean hra_Bezi=false;//indikátor, zfa-li se hraje
public static String jmenoHrace=new String("");
//OBSAH POLE
/*
0 = prázdno
1 = políčko
2 = pohyblivé políčko - objekt jež padá
*/
//čaasovač
public Casovac TM=new Casovac(10);
public long UPLYNULO=0;
//
public Hra() {
initComponents();
startInit();
vypisStavHry();
vynulujDalsi();
};
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
jPanel3 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
cRychlost = new javax.swing.JLabel();
cUrovne = new javax.swing.JLabel();
pRadek = new javax.swing.JLabel();
pBodu = new javax.swing.JLabel();
jPanel4 = new javax.swing.JPanel();
plocha = new javax.swing.JPanel();
plocha=vyplnHriste(plocha);
jPanel5 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jPanel6 = new javax.swing.JPanel();
jPanel7 = new javax.swing.JPanel();
jPanel8 = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
jJED = new javax.swing.JLabel();
jULO = new javax.swing.JLabel();
jPOZ = new javax.swing.JLabel();
fil = new javax.swing.JButton();
jPanel9 = new javax.swing.JPanel();
jDalsi = new javax.swing.JPanel();
jDalsi=vyplnDalsi(jDalsi);
pBodu1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(51, 255, 255));
setName("Hra");
setResizable(false);
addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
formMouseClicked(evt);
}
});
jPanel3.setBackground(new java.awt.Color(0, 0, 0));
jPanel2.setBackground(new java.awt.Color(0, 153, 153));
cRychlost.setFont(new java.awt.Font("Arial", 0, 18));
cRychlost.setText("Rychlost:");
cUrovne.setFont(new java.awt.Font("Arial", 0, 18));
cUrovne.setText("\u00darove\u0148:");
pRadek.setFont(new java.awt.Font("Arial", 0, 18));
pRadek.setText("Po\u010det \u0159\u00e1dek:");
pBodu.setFont(new java.awt.Font("Arial", 0, 18));
pBodu.setText("Po\u010det bod\u016f: ");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(cRychlost, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
.addGap(31, 31, 31))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(pBodu, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cUrovne, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pRadek, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(pBodu)
.addComponent(pRadek))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cRychlost)
.addComponent(cUrovne))
.addContainerGap(6, Short.MAX_VALUE))
);
jPanel4.setBackground(new java.awt.Color(0, 153, 153));
plocha.setBackground(new java.awt.Color(0, 51, 51));
plocha.setAutoscrolls(true);
javax.swing.GroupLayout plochaLayout = new javax.swing.GroupLayout(plocha);
plocha.setLayout(plochaLayout);
plochaLayout.setHorizontalGroup(
plochaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 241, Short.MAX_VALUE)
);
plochaLayout.setVerticalGroup(
plochaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 481, Short.MAX_VALUE)
);
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(plocha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(plocha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel5.setBackground(new java.awt.Color(0, 0, 0));
jLabel2.setIcon(new javax.swing.ImageIcon("D:\\Skola\\Algoritmizace\\Ukoly\\Tetris\\mail.jpg"));
jLabel1.setIcon(new javax.swing.ImageIcon("D:\\Skola\\Algoritmizace\\Ukoly\\Tetris\\tetris.jpg"));
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 499, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel5Layout.createSequentialGroup()
.addGap(49, 49, 49)
.addComponent(jLabel2)))
.addContainerGap(84, Short.MAX_VALUE))
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel6.setBackground(new java.awt.Color(0, 153, 153));
jPanel7.setBackground(new java.awt.Color(0, 0, 0));
jPanel7.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jPanel7FocusLost(evt);
}
});
jPanel8.setBackground(new java.awt.Color(51, 51, 0));
jPanel1.setBackground(new java.awt.Color(51, 255, 51));
jJED.setIcon(new javax.swing.ImageIcon("D:\\Skola\\Algoritmizace\\Ukoly\\Tetris\\Jedouci.jpg"));
jULO.setIcon(new javax.swing.ImageIcon("D:\\Skola\\Algoritmizace\\Ukoly\\Tetris\\Ulozeny.jpg"));
jPOZ.setIcon(new javax.swing.ImageIcon("D:\\Skola\\Algoritmizace\\Ukoly\\Tetris\\Pozadi.jpg"));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jPOZ)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jJED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jULO))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jJED)
.addComponent(jULO)
.addComponent(jPOZ)
);
fil.setIcon(new javax.swing.ImageIcon("D:\\Skola\\Algoritmizace\\Ukoly\\Tetris\\ikona.jpg"));
fil.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
filActionPerformed(evt);
}
});
fil.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
filFocusLost(evt);
}
});
fil.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
filKeyPressed(evt);
}
});
javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
jPanel8.setLayout(jPanel8Layout);
jPanel8Layout.setHorizontalGroup(
jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel8Layout.createSequentialGroup()
.addComponent(fil, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(16, 16, 16)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel8Layout.setVerticalGroup(
jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
.addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(fil, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel8Layout.createSequentialGroup()
.addContainerGap(17, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
jPanel9.setBackground(new java.awt.Color(0, 153, 153));
jDalsi.setBackground(new java.awt.Color(0, 51, 51));
javax.swing.GroupLayout jDalsiLayout = new javax.swing.GroupLayout(jDalsi);
jDalsi.setLayout(jDalsiLayout);
jDalsiLayout.setHorizontalGroup(
jDalsiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 65, Short.MAX_VALUE)
);
jDalsiLayout.setVerticalGroup(
jDalsiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 65, Short.MAX_VALUE)
);
pBodu1.setFont(new java.awt.Font("Arial", 0, 18));
pBodu1.setText("< n\u00e1sleduj\u00edc\u00ed tvar");
pBodu1.getAccessibleContext().setAccessibleName("<- n\u00e1sleduj\u00edc\u00ed tvar");
javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
jPanel9.setLayout(jPanel9Layout);
jPanel9Layout.setHorizontalGroup(
jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel9Layout.createSequentialGroup()
.addComponent(jDalsi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(14, 14, 14)
.addComponent(pBodu1, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(160, Short.MAX_VALUE))
);
jPanel9Layout.setVerticalGroup(
jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDalsi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
.addContainerGap(22, Short.MAX_VALUE)
.addComponent(pBodu1)
.addGap(21, 21, 21))
);
jTextArea1.setBackground(new java.awt.Color(0, 0, 0));
jTextArea1.setColumns(20);
jTextArea1.setEditable(false);
jTextArea1.setFont(new java.awt.Font("Monospaced", 0, 18));
jTextArea1.setForeground(new java.awt.Color(0, 102, 102));
jTextArea1.setRows(5);
jTextArea1.setText("Ovl\u00e1d\u00e1n\u00ed:\n---------\nNov\u00e1 hra: F2 \nUko\u010dit hru/ Hight score: F4\nPohyb: \u0161ipka doleva, \n \u0161ipka doprava\nRotace: \u0161ipka nahoru, A, D\nZrychlit: \u0161ipka dol\u016f\nPolo\u017eit: mezern\u00edk");
jTextArea1.setBorder(null);
jTextArea1.setDisabledTextColor(new java.awt.Color(0, 102, 102));
jTextArea1.setFocusable(false);
jTextArea1.setSelectedTextColor(new java.awt.Color(0, 102, 102));
jTextArea1.setSelectionColor(new java.awt.Color(0, 0, 0));
jScrollPane1.setViewportView(jTextArea1);
javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
jPanel7.setLayout(jPanel7Layout);
jPanel7Layout.setHorizontalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel7Layout.setVerticalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(14, 14, 14)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
pack();
}// //GEN-END:initComponents
private void filFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_filFocusLost
}//GEN-LAST:event_filFocusLost
private void jPanel7FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jPanel7FocusLost
// TODO add your handling code here:
}//GEN-LAST:event_jPanel7FocusLost
private void filActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_filActionPerformed
private void filKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_filKeyPressed
//rozlišení ovládání klávesnicí - prvky obecné
switch(evt.getKeyCode())
{
case KeyEvent.VK_F12:vytvortvary();break;
case KeyEvent.VK_F4:konecHry();break;
//case KeyEvent.VK_F2:novaHra(uroven_Hry,rychlost_Hry);break;
case KeyEvent.VK_F2:nactiNovaHra();break;
}
if(!hra_Bezi)return;//ovládání za běhu hry
switch(evt.getKeyCode())
{
case KeyEvent.VK_LEFT: posuntvar(-1);break;
case KeyEvent.VK_RIGHT: posuntvar(1);break;
case KeyEvent.VK_DOWN: provedCykl();break;
case KeyEvent.VK_A:rotujtvar(-1);break;
case KeyEvent.VK_D:rotujtvar(1);break;
case KeyEvent.VK_UP:rotujtvar(1);break;
case KeyEvent.VK_SPACE:posuntvarDolu();break;
}
}//GEN-LAST:event_filKeyPressed
private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
}//GEN-LAST:event_formMouseClicked
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Hra().setVisible(true);
}
});
}
//************************Procedura Nová hra************************************************//
public void nactiNovaHra()
{
Main.zobrazNovaHra();
}
public void novaHra(int uroven,int rychlost)
{
//vstupní údaje
//vynulovani hriště
for(int i=0;i=1)vytvorUroven(uroven);
//
uroven_Hry=uroven;rychlost_Hry=rychlost;pocet_Bodu=0;pocet_Radku=0;
nactiNadhodnytvar();
//zaneseni tvaru do hřiště
tvar_Y=-tvar_H1;
zobraztvar(tvar_X,tvar_Y);
vypisStavHry();
hra_Bezi=true;
vykreslihriste();
nactiDalsitvar();
zobrazDalsi();
}
//*************************Procedura Vytvoř úroveň******************************************//
public void vytvorUroven(int x)
{
//Nahodne zaplni X spodnich řad policky
double a;
for(int o=VY-x;o3
tvar_X=(VX-VT)/2;tvar_Y=0;//vychozi postaveni
nactitvar(CISLO_tvaru,ROTACE_tvaru);
}
//**************************Procedura Nactitvar*********************************************//
public void nactitvar(int tvr,int rtc)
{
int i,o,in=0;
for(o=0;o3
cislo_Dal_Tvaru=x;rotace_Dal_Tvaru=y;
for(o=0;o-1 && tvar_Y+o-1)
{
if(hriste[x+i][y+o]==2)hriste[x+i][y+o]=0;
u=tvar[i][o];
if(u!=0)hriste[x+i][y+o]=2;//==1)?2:3;
}
}
}
//**************************Procedura Vytvořtvary*******************************************//
public void vytvortvary()
{ //Kostka 1, Lko 0, Z 2, opačný lko 3; čára 4; opačná Z 5
//načtení tvarů ze souboru tvary.txt. nadefinovány na jednom řádku. Počet znaku * 4*16 znaků nařádcích
pocet_tvaru=0;
try
{
FileReader XX=new FileReader("tvary.txt");
int i,o;boolean z=true;
char u[]=new char[1];
while(z)
{
XX.read(u);
if(u[0]=='Q')z=false;else
{
for(o=0;o<4;o++)
for(i=0;i<16;i++)
{
if(!(o==0 && i==0))XX.read(u);
tvarY[pocet_tvaru][o][i]=(u[0]=='1');
}
XX.read(u);XX.read(u);//odsaení na ddalší řádek v souboru
pocet_tvaru++;
}
}
XX.close();
}catch(Exception e){}
}
//****************************Procedura Proved cykl*****************************************//
public void provedCykl()
{
//tahy vrámci jednoho časového dílku
//posuneme aktuální tvar dolů a vykreslíme, vynulování řádku nad tvarem
kontrolaZapadnuti(1);
if(!hra_Bezi)return;//došlo k zaplnění hřiště, nevykreslíme nový tvar
if(polozenTvar){polozenTvar=false;return;}
tvar_Y++;
zobraztvar(tvar_X,tvar_Y);
for(int i=0;i3)ROTACE_tvaru=0;
nactitvar(CISLO_tvaru,ROTACE_tvaru);
zobraztvar(tvar_X,tvar_Y);
//kontrola jestli rotace nepřesahuje pole!
if(tvar_X-tvar_K2+VT>VX)jde=false;
if(tvar_X+tvar_K1<0)jde=false;
//kontrola jestli nerotujem do jiného prvku
int i,o;
if(jde)
{
for(o=0;o=0)hriste[i][o]=hriste_Pom[i][o];
rotujtvar(-smer);
}
}
//****************************Procedura Posuntvar*******************************************//
public void posuntvar(int smer)
{
//posune tvar v hřišti, kontrola jestli se dá osunout do boku,, přepsání hřiště a aktualizace obrazovky
int i,o,q;
switch(smer)
{
case 1:
//můžeme posunout? ->
if(tvar_X-tvar_K2+VT+1>VX)break;
//nebude kolize s jiným?
q=0;
for(o=0;o=0)if(hriste[tvar_X+tvar_K1][tvar_Y+i]==2) hriste[tvar_X+tvar_K1][tvar_Y+i]=0;
}catch(Exception exct){}
tvar_X++;
zobraztvar(tvar_X,tvar_Y);
vykreslihriste();
break;
case -1:
//můžeme posunout? <-
if(tvar_X+tvar_K1<1)break;
//nebude kolize s jiným?
q=0;
for(o=0;o=0)if(hriste[tvar_X+VT-tvar_K2-1][tvar_Y+i]==2) hriste[tvar_X+VT-tvar_K2-1][tvar_Y+i]=0;
}catch(Exception exct){}
tvar_X--;
zobraztvar(tvar_X,tvar_Y);
vykreslihriste();
break;
}
}
//*****************************Procedura KontrolaZapadnuti**********************************//
public void kontrolaZapadnuti(int typ)
{
//kontrola jestli nezapadne dilek, popř zobrazi nový
boolean ukotven=false;
if(tvar_Y>=VY-VT+tvar_H2 && typ==1)
{
//ukotví tvar
ukotvitvar();
ukotven=true;
}
else
{
int q;
for(int o=0;o0)
{
pocet_Radku+=pRad;
pocet_Bodu+=(pRad-1)*10+(int)(Math.sqrt((double)(pRad))*10);
vypisStavHry();
}
//vyber nového tvaru, po kontrole řádek
if(ukotven)
{
//konec?
for(p=0;p=1;o--)
for(int i=0;ii)provedCykl();
}
//*******************************Procedura VypisStavHry*************************************//
public void vypisStavHry()
{
//zvýšení úrovně a rychlosti
if(pocet_Bodu>(uroven_Hry+1)*500)zvysUroven(0);
if(pocet_Bodu>(rychlost_Hry+1)*500)zvysUroven(1);
//vypíše aktuální stav hry - body, řádky, ůroven, rychlsot
pBodu.setText("Počet bodů: "+pocet_Bodu);
pRadek.setText("Počet řádků: "+pocet_Radku);
cRychlost.setText("Rychlost: "+rychlost_Hry);
cUrovne.setText("Úroveň: "+uroven_Hry);
}
//*******************************Procedura KonecHry****************************************//
public void konecHry()
{
//konec hry - zastavení, zablokování
hra_Bezi=false;
vynulujDalsi();
Main.konecHry(jmenoHrace,pocet_Bodu,pocet_Radku,uroven_Hry,rychlost_Hry);
}
//*******************************Procedura Zvyš úroveń**************************************//
public void zvysUroven(int typ)
{
switch(typ)
{
case 0:
//0 - automatickíé navýšení úrovně, maximálně avšak do 2/3 hrací plochy
if(uroven_Hry>(VY/3*2))return;
uroven_Hry++;
for(int o=VY;o=(10-rychlost_Hry)*8){provedCykl();UPLYNULO=0;}
}else UPLYNULO=0;
}
},0,interval);
}
}
//******************************************************************************************//
}