diff --git a/Answers/40230112013/QUIDDITCH/.vscode/settings.json b/Answers/40230112013/QUIDDITCH/.vscode/settings.json new file mode 100644 index 0000000..e112a70 --- /dev/null +++ b/Answers/40230112013/QUIDDITCH/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/Answers/40230112013/QUIDDITCH/README.md b/Answers/40230112013/QUIDDITCH/README.md new file mode 100644 index 0000000..7c03a53 --- /dev/null +++ b/Answers/40230112013/QUIDDITCH/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/Answers/40230112013/QUIDDITCH/src/Beater.java b/Answers/40230112013/QUIDDITCH/src/Beater.java new file mode 100644 index 0000000..6f73d1b --- /dev/null +++ b/Answers/40230112013/QUIDDITCH/src/Beater.java @@ -0,0 +1,13 @@ +import java.util.Random; +public class Beater extends Player{ + public Beater(){ + super(); + } + @Override + public boolean isSuccessful() { + Random r = new Random(); + int chance = r.nextInt(100); + return chance<=40; + } + } + diff --git a/Answers/40230112013/QUIDDITCH/src/Chaser.java b/Answers/40230112013/QUIDDITCH/src/Chaser.java new file mode 100644 index 0000000..ea15e8a --- /dev/null +++ b/Answers/40230112013/QUIDDITCH/src/Chaser.java @@ -0,0 +1,14 @@ +import java.util.Random; + +public class Chaser extends Player{ + public Chaser(){ + super(); + } + @Override + public boolean isSuccessful() { + Random r = new Random(); + int chance = r.nextInt(100); + return chance<=30; + } + } + diff --git a/Answers/40230112013/QUIDDITCH/src/Keeper.java b/Answers/40230112013/QUIDDITCH/src/Keeper.java new file mode 100644 index 0000000..6ed8c61 --- /dev/null +++ b/Answers/40230112013/QUIDDITCH/src/Keeper.java @@ -0,0 +1,14 @@ +import java.util.Random; + +public class Keeper extends Player{ + public Keeper(){ + super(); + } + @Override + public boolean isSuccessful() { + Random r = new Random(); + int chance = r.nextInt(100); + return chance<=70; + } + } + diff --git a/Answers/40230112013/QUIDDITCH/src/Match.java b/Answers/40230112013/QUIDDITCH/src/Match.java new file mode 100644 index 0000000..758f5c8 --- /dev/null +++ b/Answers/40230112013/QUIDDITCH/src/Match.java @@ -0,0 +1,41 @@ +public class Match { + public void Start() { + Team team1 = new Team(); + Team team2 = new Team(); + for (int i = 1; i < 100; i++) { + if (i % 2 == 0) { + team1.Play(); + team2.Play(); + } + if (i % 2 == 1) { + team2.Play(); + team1.Play(); + } + } + if (team1.seeker.isSuccessful()) { + System.out.println("The Snitch was found by team_1 and they won."); + return; + } + if (team2.seeker.isSuccessful()) { + System.out.println("The Snitch was found by team_2 and they won."); + return; + } + + System.out.println("--------------------------------"); + System.out.println(" team1 Goals : " + team1.Goal); + System.out.println(" team2 Goals : " + team2.Goal); + System.out.println("--------------------------------"); + if (team1.Goal > team2.Goal) { + System.out.println("team1 won"); + System.out.println("--------------------------------"); + } + if (team1.Goal < team2.Goal) { + System.out.println("team2 won"); + System.out.println("--------------------------------"); + } + if (team1.Goal == team2.Goal) { + System.out.println(" Result : draw"); + System.out.println("--------------------------------"); + } + } +} diff --git a/Answers/40230112013/QUIDDITCH/src/MyApp.java b/Answers/40230112013/QUIDDITCH/src/MyApp.java new file mode 100644 index 0000000..55aaf11 --- /dev/null +++ b/Answers/40230112013/QUIDDITCH/src/MyApp.java @@ -0,0 +1,17 @@ +import java.util.Scanner; + +public class MyApp { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int a=1; + while(a==1){ + Match match = new Match(); + match.Start(); + System.out.println("Do you want to continue?\n1.Yes 2.No"); + a = scanner.nextInt(); + if(a!=1)break; + } + scanner.close(); + } + +} diff --git a/Answers/40230112013/QUIDDITCH/src/Player.java b/Answers/40230112013/QUIDDITCH/src/Player.java new file mode 100644 index 0000000..f51f013 --- /dev/null +++ b/Answers/40230112013/QUIDDITCH/src/Player.java @@ -0,0 +1,6 @@ +public class Player implements Success{ + @Override + public boolean isSuccessful() { + return false; + } +} diff --git a/Answers/40230112013/QUIDDITCH/src/Seeker.java b/Answers/40230112013/QUIDDITCH/src/Seeker.java new file mode 100644 index 0000000..89db0f7 --- /dev/null +++ b/Answers/40230112013/QUIDDITCH/src/Seeker.java @@ -0,0 +1,14 @@ +import java.util.Random; + +public class Seeker extends Player{ + public Seeker(){ + super(); + } + @Override + public boolean isSuccessful() { + Random r = new Random(); + int chance = r.nextInt(100); + return chance<=5; + } + } + diff --git a/Answers/40230112013/QUIDDITCH/src/Success.java b/Answers/40230112013/QUIDDITCH/src/Success.java new file mode 100644 index 0000000..bd696f9 --- /dev/null +++ b/Answers/40230112013/QUIDDITCH/src/Success.java @@ -0,0 +1,5 @@ + +public interface Success { + public boolean isSuccessful(); + +} diff --git a/Answers/40230112013/QUIDDITCH/src/Team.java b/Answers/40230112013/QUIDDITCH/src/Team.java new file mode 100644 index 0000000..f57b9cc --- /dev/null +++ b/Answers/40230112013/QUIDDITCH/src/Team.java @@ -0,0 +1,26 @@ + +public class Team { + Beater beater1 = new Beater(); + Beater beater2 = new Beater(); + Keeper keeper = new Keeper(); + Seeker seeker = new Seeker(); + Chaser chaser1 = new Chaser(); + Chaser chaser2 = new Chaser(); + Chaser chaser3 = new Chaser(); + int Goal = 0; + + void setGoal() { + Goal++; + } + //طبق قوانین و اتفاق افتادن تمام حالات برای یک گل + void Play() { + boolean Beatersuccess = (beater1.isSuccessful() || beater2.isSuccessful()); + boolean chasersuccess = ((chaser1.isSuccessful() && chaser2.isSuccessful()) + || (chaser1.isSuccessful() && chaser3.isSuccessful()) + || (chaser2.isSuccessful() && chaser3.isSuccessful())); + if (keeper.isSuccessful() && Beatersuccess && chasersuccess) { + setGoal(); + } + } + +}