Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Answers/40230112013/QUIDDITCH/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
18 changes: 18 additions & 0 deletions Answers/40230112013/QUIDDITCH/README.md
Original file line number Diff line number Diff line change
@@ -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).
13 changes: 13 additions & 0 deletions Answers/40230112013/QUIDDITCH/src/Beater.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

14 changes: 14 additions & 0 deletions Answers/40230112013/QUIDDITCH/src/Chaser.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

14 changes: 14 additions & 0 deletions Answers/40230112013/QUIDDITCH/src/Keeper.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

41 changes: 41 additions & 0 deletions Answers/40230112013/QUIDDITCH/src/Match.java
Original file line number Diff line number Diff line change
@@ -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("--------------------------------");
}
}
}
17 changes: 17 additions & 0 deletions Answers/40230112013/QUIDDITCH/src/MyApp.java
Original file line number Diff line number Diff line change
@@ -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();
}

}
6 changes: 6 additions & 0 deletions Answers/40230112013/QUIDDITCH/src/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class Player implements Success{
@Override
public boolean isSuccessful() {
return false;
}
}
14 changes: 14 additions & 0 deletions Answers/40230112013/QUIDDITCH/src/Seeker.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

5 changes: 5 additions & 0 deletions Answers/40230112013/QUIDDITCH/src/Success.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

public interface Success {
public boolean isSuccessful();

}
26 changes: 26 additions & 0 deletions Answers/40230112013/QUIDDITCH/src/Team.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

}