Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (12)
Showing
with 483 additions and 0 deletions
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="Obesenec/src"/>
<classpathentry kind="output" path="Obesenec/bin"/>
</classpath>
# This file is a template, and might need editing before it works on your project.
# This is a sample GitLab CI/CD configuration file that should run without any modifications.
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
# it uses echo commands to simulate the pipeline execution.
#
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
# Stages run in sequential order, but jobs within stages run in parallel.
#
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages
#
# You can copy and paste this template into a new `.gitlab-ci.yml` file.
# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword.
#
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml
stages: # List of stages for jobs, and their order of execution
- build
- test
- deploy
build-job: # This job runs in the build stage, which runs first.
stage: build
script:
- echo "Compiling the code..."
- whoami
- /home/gitlab-runner/.dotnet/dotnet
- mvn compile
- echo "Compile complete."
unit-test-job: # This job runs in the test stage.
stage: test # It only starts when the job in the build stage completes successfully.
script:
- echo "Running unit tests... This will take about 60 seconds."
- mvn test
- echo "Code coverage is 90%"
lint-test-job: # This job also runs in the test stage.
stage: test # It can run at the same time as unit-test-job (in parallel).
script:
- echo "Linting code... This will take about 10 seconds."
- echo "No lint issues found."
deploy-job: # This job runs in the deploy stage.
stage: deploy # It only runs when *both* jobs in the test stage complete successfully.
environment: production
script:
- echo "Deploying application..."
- mvn deploy
- echo "Application successfully deployed."
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>obesenec</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
/bin/
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cz.vsb.fei.kp</groupId>
<artifactId>obesenec</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>obesenec</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<pluginManagement><!-- lock down plugins versions to avoid using Maven
defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see
https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see
https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see
https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
package cz.vsb.krouzek;
import java.util.List;
public class Hraj {
private static OknoSibenice oknoSibenice;
private static String hadaneSlovo ="";
private static char[] tajenka = new char[0];
public static void main(String[] args) {
oknoSibenice = new OknoSibenice(Hraj::startHry, Hraj::konecHry, Hraj::zvolenoPismeno);
oknoSibenice.setWorldText("");
}
public static void startHry() {
hadaneSlovo = SibeniceZaklad.vyberNahodneSlovo().toUpperCase();
tajenka = new char[hadaneSlovo.length()];
for (int i = 0; i < tajenka.length; i++) {
tajenka[i] = '_';
}
oknoSibenice.setWorldText(new String(tajenka));
oknoSibenice.setInfoText("");
oknoSibenice.setMistakeCount(0);
}
public static void konecHry() {
oknoSibenice.setWorldText(new String(hadaneSlovo));
oknoSibenice.setInfoText("KONEC");
}
public static void zvolenoPismeno(List<Character> pismena) {
boolean uhodnuto = false;
for (Character character : pismena) {
for (int i = 0; i < hadaneSlovo.length(); i++) {
if(hadaneSlovo.charAt(i) == character) {
tajenka[i] = character;
uhodnuto = true;
}
}
}
if(!uhodnuto) {
oknoSibenice.setMistakeCount(oknoSibenice.getMistakeCount()+1);
} else {
oknoSibenice.setWorldText(new String(tajenka));
}
if(!new String(tajenka).contains("_")) {
oknoSibenice.setInfoText("VÝHRA");
}
if(oknoSibenice.getMistakeCount() >= 8) {
konecHry();
oknoSibenice.setInfoText("PROHRA");
}
}
}
package cz.vsb.krouzek;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
public class OknoSibenice extends JFrame {
private static final long serialVersionUID = -5182233956382753964L;
private static List<String> imageNames = Arrays.asList("sibenice-0.png", "sibenice-1.png", "sibenice-2.png",
"sibenice-3.png", "sibenice-4.png", "sibenice-5.png", "sibenice-6.png", "sibenice-7.png", "sibenice-8.png");
private JPanel letterPanel;
private JPanel gamePanel;
private JPanel midlePanel;
private JButton startButton;
private JButton endButton;
private JLabel wordLabel;
private JLabel infoLabel;
private JLabel imageLabel;
private List<JButton> charButtons = new ArrayList<JButton>();
private int mistakeCount = 0;
private Runnable startHry;
private Runnable konecHry;
private Consumer<List<Character>> vyberPismena;
public OknoSibenice(Runnable startHry, Runnable konecHry, Consumer<List<Character>> vyberPismena){
super("Hádání slov");
this.startHry = startHry;
this.konecHry = konecHry;
this.vyberPismena = vyberPismena;
initialize();
}
private void initialize() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(new BorderLayout());
// inicializace jednotlivých komponent přes getter metody
getContentPane().add(getLetterPanel(), BorderLayout.SOUTH);
getContentPane().add(getImageLabel(), BorderLayout.EAST);
getContentPane().add(getGamePanel(), BorderLayout.NORTH);
getContentPane().add(getMidlePanel(), BorderLayout.CENTER);
pack();
setVisible(true);
}
private JPanel getLetterPanel() {
if (letterPanel == null) {
letterPanel = new JPanel(new GridBagLayout());
int counter = 1;
for (Map.Entry<Character, List<Character>> entry : SibeniceZaklad.abeceda.entrySet()) {
JButton button = new JButton(
entry.getValue().stream().map(String::valueOf).collect(Collectors.joining(" ")));
button.setName(String.valueOf(entry.getKey()));
GridBagConstraints bagConstraints = new GridBagConstraints();
bagConstraints.insets = new Insets(2, 2, 2, 2);
if (counter % 9 == 0) {
bagConstraints.gridwidth = GridBagConstraints.REMAINDER;
}
charButtons.add(button);
button.addActionListener(e -> {
String name = ((JButton)e.getSource()).getName();
((JButton)e.getSource()).setEnabled(false);
vyberPismena.accept(SibeniceZaklad.abeceda.get(name.charAt(0)));
});
letterPanel.add(button, bagConstraints);
counter++;
}
}
return letterPanel;
}
private JLabel getWordLabel() {
if (wordLabel == null) {
wordLabel = new JLabel("");
wordLabel.setHorizontalAlignment(SwingConstants.CENTER);
Font font = new Font("Curier", Font.BOLD , 20);
wordLabel.setFont(font);
setWorldText("AB_H");
}
return wordLabel;
}
private JLabel getInfoLabel() {
if (infoLabel == null) {
infoLabel = new JLabel("");
infoLabel.setHorizontalAlignment(SwingConstants.CENTER);
Font font = new Font("Curier", Font.BOLD , 20);
infoLabel.setFont(font);
infoLabel.setForeground(Color.RED);
setWorldText("");
}
return infoLabel;
}
public void setInfoText(String text) {
infoLabel.setText(text);
}
public void setWorldText(String text) {
Pattern p = Pattern.compile("(.)");
Matcher matcher = p.matcher(text);
text = matcher.replaceAll("$1 ");
getWordLabel().setText(text);
}
private JLabel getImageLabel() {
if (imageLabel == null) {
imageLabel = new JLabel("");
updateImage();
}
return imageLabel;
}
public void setMistakeCount(int mistakeCount) {
this.mistakeCount = mistakeCount;
updateImage();
}
public int getMistakeCount() {
return mistakeCount;
}
private void updateImage() {
try {
if(mistakeCount >= imageNames.size()) {
mistakeCount = imageNames.size()-1;
}
BufferedImage image = ImageIO.read(this.getClass().getResourceAsStream("images/"+imageNames.get(mistakeCount)));
imageLabel.setIcon(new ImageIcon(image));
} catch (IOException e) {
e.printStackTrace();
}
}
private JButton getStartButton() {
if (startButton == null) {
startButton = new JButton("Start");
startButton.addActionListener(e -> {
charButtons.forEach(b -> b.setEnabled(true));
startHry.run();
});
}
return startButton;
}
private JButton getEndButton() {
if (endButton == null) {
endButton = new JButton("End");
endButton.addActionListener(e -> {
zakazTlacitkaPismenek(true);
konecHry.run();
});
}
return endButton;
}
public void zakazTlacitkaPismenek(boolean zakazat) {
charButtons.forEach(b -> b.setEnabled(!zakazat));
}
private JPanel getMidlePanel() {
if (midlePanel == null) {
// Horní panel s tlačítky start a end
midlePanel = new JPanel(new GridLayout(2,1));
midlePanel.add(getWordLabel());
midlePanel.add(getInfoLabel());
}
return midlePanel;
}
private JPanel getGamePanel() {
if (gamePanel == null) {
// Horní panel s tlačítky start a end
gamePanel = new JPanel(new FlowLayout());
gamePanel.add(getStartButton());
gamePanel.add(getEndButton());
}
return gamePanel;
}
}
package cz.vsb.krouzek;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
public class SibeniceZaklad {
private static List<String> slova = Arrays.asList("příroda", "telefon", "zahrada", "kytara", "knihovna", "banán",
"vlak", "internet", "obrazovka", "létání", "paprika", "jablko", "turistika", "boty", "slunce", "oheň",
"dálnice", "hokej", "kartáček", "jogurt");
private static Random random = new Random();
public static String vyberNahodneSlovo() {
int nahodneCislo = random.nextInt(slova.size());
return slova.get(nahodneCislo);
}
public static HashMap<Character, List<Character>> abeceda = new HashMap<>();
static {
// Vytvoření mapování písmen
abeceda.put('A', Arrays.asList('A', 'Á'));
abeceda.put('B', Arrays.asList('B'));
abeceda.put('C', Arrays.asList('C', 'Č'));
abeceda.put('D', Arrays.asList('D', 'Ď'));
abeceda.put('E', Arrays.asList('E', 'É', 'Ě'));
abeceda.put('F', Arrays.asList('F'));
abeceda.put('G', Arrays.asList('G', 'G'));
abeceda.put('H', Arrays.asList('H'));
abeceda.put('I', Arrays.asList('I', 'Í'));
abeceda.put('J', Arrays.asList('J'));
abeceda.put('K', Arrays.asList('K'));
abeceda.put('L', Arrays.asList('L', 'Ľ'));
abeceda.put('M', Arrays.asList('M'));
abeceda.put('N', Arrays.asList('N', 'Ň'));
abeceda.put('O', Arrays.asList('O', 'Ó'));
abeceda.put('P', Arrays.asList('P'));
abeceda.put('Q', Arrays.asList('Q'));
abeceda.put('R', Arrays.asList('R', 'Ř'));
abeceda.put('S', Arrays.asList('S', 'Š'));
abeceda.put('T', Arrays.asList('T', 'Ť'));
abeceda.put('U', Arrays.asList('U', 'Ú', 'Ů'));
abeceda.put('V', Arrays.asList('V'));
abeceda.put('W', Arrays.asList('W'));
abeceda.put('X', Arrays.asList('X'));
abeceda.put('Y', Arrays.asList('Y', 'Ý'));
abeceda.put('Z', Arrays.asList('Z', 'Ž'));
}
}
Obesenec/src/cz/vsb/krouzek/images/sibenice-0.png

1.87 KiB

Obesenec/src/cz/vsb/krouzek/images/sibenice-1.png

1.96 KiB

Obesenec/src/cz/vsb/krouzek/images/sibenice-2.png

2.05 KiB

Obesenec/src/cz/vsb/krouzek/images/sibenice-3.png

2.1 KiB

Obesenec/src/cz/vsb/krouzek/images/sibenice-4.png

2.65 KiB

Obesenec/src/cz/vsb/krouzek/images/sibenice-5.png

3.32 KiB

Obesenec/src/cz/vsb/krouzek/images/sibenice-6.png

4.2 KiB

Obesenec/src/cz/vsb/krouzek/images/sibenice-7.png

4.68 KiB

Obesenec/src/cz/vsb/krouzek/images/sibenice-8.png

4.98 KiB

/**
* @author jez04
*
*/
module Obesenec {
requires java.desktop;
}
\ No newline at end of file