Skip to content
Open

done #25

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
File renamed without changes.
10 changes: 10 additions & 0 deletions 40230112057/src/example/Beater.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package example;

public class Beater extends Player implements Success{

private int chance=40;
@Override
public boolean isSuccessful() {
return random.getrand()<=chance;
}
}
12 changes: 12 additions & 0 deletions 40230112057/src/example/Chaser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package example;

public class Chaser extends Player implements Success{
private int chance=30;

@Override
public boolean isSuccessful() {
return random.getrand()<=chance;
}

}
//sdaadasdasd
14 changes: 14 additions & 0 deletions 40230112057/src/example/Keeper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package example;

public class Keeper extends Player implements Success{

private int chance=70;
@Override
public boolean isSuccessful() {
return random.getrand()<=chance;
}
public Keeper(String name,String number){
super.name=name;
super.number=number;
}
}
94 changes: 94 additions & 0 deletions 40230112057/src/example/Match.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package example;

public class Match {
Team team1;
Team team2=new Team();
public void Start1(){
if(team1.seeker.isSuccessful()){
System.out.println("**************************************");
System.out.println("team 1 won by finding the golden snitch.");
System.out.println("**************************************");
System.out.println("The Scores:");

System.out.println("team1: "+(team1.goals+150)+" team2: "+team2.goals);
System.out.println("**************************************");
return;
}

if(team2.seeker.isSuccessful()){
System.out.println("**************************************");
System.out.println("team 2 won by finding the golden snitch.");
System.out.println("**************************************");
System.out.println("The Scores:");

System.out.println("team1: "+team1.goals+" team2: "+(team2.goals+150));
System.out.println("**************************************");
return;

}

for(int i=0;i<100;i++){
team1.Play();
team2.Play();
}
if(team1.goals>team2.goals){
System.out.println("**************************************");
System.out.println("team 1 won by having more goals.");
System.out.println("**************************************");
System.out.println("The Scores:");

System.out.println("team1: "+team1.goals+" team2: "+team2.goals);
System.out.println("**************************************");
}
else if(team1.goals<team2.goals){
System.out.println("**************************************");
System.out.println("team 2 won by having more goals.");
System.out.println("**************************************");
System.out.println("The Scores:");

System.out.println("team1: "+team1.goals+" team2: "+team2.goals);
System.out.println("**************************************");
}
else{
System.out.println("**************************************");
System.out.println("draw.");
System.out.println("**************************************");
System.out.println("The Scores:");

System.out.println("team1: "+team1.goals+" team2: "+team2.goals);
System.out.println("**************************************");
}


}
public void Start2(){
for(int i=0;i<100;i++){
team1.Play();
team2.Play();
if(team1.seeker.isSuccessful()){
System.out.println("**************************************");
System.out.println("team 1 won by finding the golden snitch.");
System.out.println("**************************************");
System.out.println("The Scores:");

System.out.println("team1: "+(team1.goals+150)+" team2: "+team2.goals);
System.out.println("**************************************");
return;
}
if(team2.seeker.isSuccessful()){
System.out.println("**************************************");
System.out.println("team 2 won by finding the golden snitch.");
System.out.println("**************************************");
System.out.println("The Scores:");

System.out.println("team1: "+team1.goals+" team2: "+(team2.goals+150));
System.out.println("**************************************");
return;
}
}
}
public Match(Team team){
this.team1=team;
}

}
45 changes: 45 additions & 0 deletions 40230112057/src/example/MyApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package example;
import java.util.Objects;
import java.util.Scanner;

public class MyApp {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("please enter the name of keeper:");
String name=input.next();
System.out.println("please enter the number of keeper:");
String number=input.next();
Keeper keeper=new Keeper(name,number);
System.out.println("please enter the name of seeker:");
name=input.next();
System.out.println("please enter the number of seeker:");
number=input.next();
Seeker seeker=new Seeker(name,number);
Team team=new Team();
team.seeker=seeker;
team.keeper=keeper;
Match match=new Match(team);
boolean done=true;
while(done){
System.out.println("which one do you want? 1 or 2");
int n=input.nextInt();
switch (n){
case 1:
match.Start1();
break;
case 2:
match.Start2();
break;
}
System.out.println("again? ");
String again=input.next();
if(Objects.equals(again,"Y") || Objects.equals(again,"y")){
team.reset();
match.team2.reset();
}
else
break;
}

}
}
8 changes: 8 additions & 0 deletions 40230112057/src/example/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package example;

public class Player {
public String name;
public String number;
public int chance;

}
16 changes: 16 additions & 0 deletions 40230112057/src/example/Seeker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package example;

import example.Player;
import example.random;

public class Seeker extends Player implements Success{
private int chance=5;
@Override
public boolean isSuccessful() {
return random.getrand()<=chance;
}
public Seeker(String name,String number){
super.name=name;
super.number=number;
}
}
5 changes: 5 additions & 0 deletions 40230112057/src/example/Success.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package example;

public interface Success {
public boolean isSuccessful();
}
42 changes: 42 additions & 0 deletions 40230112057/src/example/Team.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package example;

import example.Seeker;

public class Team {
public int goals=0;
Keeper keeper;
Seeker seeker;
Beater beater1,beater2;
Chaser chaser1,chaser2,chaser3;
private void setGoal(){
goals++;
}
public void Play(){
if(keeper.isSuccessful() && (beater1.isSuccessful() || beater2.isSuccessful()) && (chaser1.isSuccessful()
&&chaser2.isSuccessful())||(chaser3.isSuccessful() && chaser2.isSuccessful())||(chaser3.isSuccessful()&&chaser1.isSuccessful()) ){
setGoal();
}
}
public Team(Beater[] beaters, Chaser[] chasers, Seeker seeker, Keeper keeper){
this.beater1=beaters[0];
this.beater2=beaters[1];
this.seeker=seeker;
this.chaser1=chasers[0];
this.chaser2=chasers[1];
this.chaser3=chasers[2];
this.keeper=keeper;
}
public Team(){
this.beater1=new Beater();
this.beater2=new Beater();
this.seeker=new Seeker("abol","09394242609");
this.chaser1=new Chaser();
this.chaser2=new Chaser();
this.chaser3=new Chaser();
this.keeper=new Keeper("sadra","091231");
}
public void reset(){
goals=0;

}
}
9 changes: 9 additions & 0 deletions 40230112057/src/example/random.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package example;

import java.util.Random;
public class random {

public static int getrand(){
Random rand=new Random();
return rand.nextInt(100)+1;}
}
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ Your assignment is a bit different from the real game. You won't need to impleme

We have two teams. Each team has a keeper, a seeker, 3 chasers, and 2 beaters. You can read about each role's responsibilities in the above link, so let's talk about implementing the project. Each of these roles has a name, number, and each one has a method called `isSuccessful`. The chance of success varies for each one. Let's start with the keeper.

### Keeper
### example.Keeper
The keeper has a 70% chance to save a hanging goal.

### Seeker
### example.Seeker
The seeker has a 5% chance to find the golden snitch.

### Chaser
### example.Chaser
The chaser has a 30% chance to score a goal.

### Beater
### example.Beater
The beater has a 40% chance to stop chasers.

## How to Implement

### Classes
- Create a class for each role (Keeper, Seeker, etc.).
- Create a class called `Player` and make all roles inherit this class.
- Create an interface called `Success` and put the method `isSuccessful` inside it. Don't forget to implement this interface with all of your roles. What's next?
- Create a class for each role (example.Keeper, example.Seeker, etc.).
- Create a class called `example.Player` and make all roles inherit this class.
- Create an interface called `example.Success` and put the method `isSuccessful` inside it. Don't forget to implement this interface with all of your roles. What's next?

#### Team
- Create a class for `Team`. This class contains players of your team (1 Keeper, 1 Seeker, 3 Chasers, and 2 Beaters) and the number of goals, which is zero at the beginning of the game.
#### example.Team
- Create a class for `example.Team`. This class contains players of your team (1 example.Keeper, 1 example.Seeker, 3 Chasers, and 2 Beaters) and the number of goals, which is zero at the beginning of the game.
- It has a method called `setGoal`, and after calling it, the number of goals increases by one. However, this method is private.
- Also, we have another method called `play`. After calling this method, the team will start playing the game, and if the conditions are met, then the `setGoal` method will be called.

Expand All @@ -36,8 +36,8 @@ When the keeper of the team is successful in saving the goal, at least one beate
##### Winning Conditions:
When a seeker of a team finds the golden snitch, the team will get 150 scores and will win the match. Otherwise, the team with the most goals will win the match.

#### Match
After you've created the `Team` class, it's time for the `Match` class. In this class, you will need to create two teams initially. Then, you create a method called `start`. This method will start the game.
#### example.Match
After you've created the `example.Team` class, it's time for the `example.Match` class. In this class, you will need to create two teams initially. Then, you create a method called `start`. This method will start the game.

##### Game Starting:
The game consists of 100 rounds. In each round, both teams will play, and after finishing the game, the scores of both teams will be shown, and also the winning team will be shown as the winner. Don't forget that the game can also end in a draw.
Expand Down