martaczaska

Poziomy_RISKYSHIT_2

Jan 5th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.05 KB | None | 0 0
  1. package com.company;
  2. import javax.imageio.ImageIO;
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.awt.image.BufferedImage;
  8. import java.io.File;
  9. import java.io.FileNotFoundException;
  10. import java.io.IOException;
  11. import java.util.Scanner;
  12. import java.util.Random;
  13. import java.util.TimerTask;
  14. import java.util.Timer;
  15.  
  16.  
  17. public class Poziomy extends JPanel implements ActionListener {
  18.     public int czas = 1;
  19.     public BufferedImage tlo_lvl;
  20.  
  21.     JButton latwy;
  22.     JButton sredni;
  23.     JButton trudny;
  24.  
  25.     Timer timer = new Timer();
  26.     TimerTask odlicz = new odliczanie();
  27.     public int time = 0;
  28.  
  29.     boolean czy_wpisane = false;
  30.  
  31.     static List lista = new List();         //RISKY SHIT
  32.  
  33.  
  34.     public Poziomy(){
  35.         setLayout(null);
  36.  
  37.         File zdj_lvl = new File("zdjecia/tlo_menu.png");
  38.         try{ tlo_lvl = ImageIO.read(zdj_lvl); }
  39.         catch(IOException e){ System.err.println("Blad odczytu obrazków"); }
  40.  
  41.         latwy = new JButton("łatwy");
  42.         sredni = new JButton("średni");
  43.         trudny = new JButton("trudny");
  44.  
  45.         latwy.addActionListener(this);
  46.         sredni.addActionListener(this);
  47.         trudny.addActionListener(this);
  48.  
  49.         latwy.setBounds(320, 100, 300, 80 );
  50.         sredni.setBounds(320, 300, 300, 80);
  51.         trudny.setBounds(320, 500, 300, 80);
  52.  
  53.         add(latwy);
  54.         add(sredni);
  55.         add(trudny);
  56.  
  57.     }
  58.  
  59.     public void actionPerformed(ActionEvent f){
  60.  
  61.         Object poziom = f.getSource();
  62.         if(poziom == latwy){
  63.             czas = 30;
  64.  
  65.             Okno noweOkno_2 = new Okno(1024,768);
  66.             CardLayout CL_2 =(CardLayout)(noweOkno_2.karty.getLayout());
  67.             CL_2.show(noweOkno_2.karty, "etap_1");
  68.  
  69.             timer.schedule(odlicz, 0, 1000);
  70.         }
  71.  
  72.         else if(poziom == sredni){
  73.             czas = 20;
  74.  
  75.             Okno noweOkno_2 = new Okno(1024,768);
  76.             CardLayout CL_2 =(CardLayout)(noweOkno_2.karty.getLayout());
  77.             CL_2.show(noweOkno_2.karty, "etap_1");
  78.  
  79.             timer.schedule(odlicz, 0, 1000);
  80.         }
  81.  
  82.         else if(poziom == trudny){
  83.             czas = 10; //10
  84.  
  85.             timer.schedule(odlicz, 0, 1000);
  86.  
  87.         }
  88.     }
  89.  
  90.     public class odliczanie extends TimerTask{
  91.         //public int time = 0;
  92.  
  93.         public void run() {
  94.             //++time;
  95.             System.out.println("Timer ran" + ++time);    //sprawdzajka
  96.             Etap_1.label_timer.setText(String.valueOf(czas - time));
  97.  
  98.             przejscie(time);
  99.         }
  100.     }
  101.  
  102.     public void przejscie(int tiktak){
  103.         //Okno noweOkno_2 = new Okno(1024,768);
  104.  
  105.         CardLayout CL_risky =(CardLayout)(Projekt.noweOkno.karty.getLayout());        //RISKY SHIT
  106.         CL_risky.show(Projekt.noweOkno.karty, "etap_1");                        //RISKY SHIT
  107.         wpisywanie_liter();
  108.  
  109.         if(czy_wpisane == true){                                                  //RISKY SHIT
  110.             Okno noweOkno_1 = new Okno(1024,768);
  111.             CardLayout CL_2 = (CardLayout) (noweOkno_1.karty.getLayout());
  112.             CL_2.show(noweOkno_1.karty, "etap_1");
  113.         }
  114.         if(tiktak == czas){
  115.             timer.cancel();
  116.             //Okno noweOkno_3 = new Okno(1024,768);
  117.             CardLayout CL_3 =(CardLayout)(Projekt.noweOkno.karty.getLayout());
  118.             CL_3.show(Projekt.noweOkno.karty, "etap_3");
  119.         }
  120.     }
  121.  
  122.     public void wpisywanie_liter(){
  123.         Scanner scan = new Scanner(System.in);
  124.         System.out.println("Podaj literę?");
  125.         String wpisana = scan.nextLine();
  126.         Etap_1.jt.setText(wpisana);
  127.         if(wpisana == Etap_1.wybrana_zol){
  128.             lista.add(wpisana);
  129.             czy_wpisane = true;
  130.         }
  131.         else{
  132.             czy_wpisane = true;
  133.             System.out.println("Wpisałeś złą literę");
  134.         }
  135.  
  136.     }
  137.  
  138.  
  139.  
  140.     public void paintComponent(Graphics graphic) {
  141.         Graphics2D g2d = (Graphics2D) graphic;
  142.         g2d.drawImage(tlo_lvl, 0, 0, this);
  143.     }
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment