8000 mta-15341 Lecture 1 by kaas- · Pull Request #1 · mraau/pcss · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

mta-15341 Lecture 1 #1

8000 New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
65 changes: 41 additions & 24 deletions Lecture1/FriendlySoccerMatch.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import java.util.Random;
import java.util.Scanner;

public class FriendlySoccerMatch implements FriendlyMatch {
private String nameHomeTeam;
Expand Down Expand Up @@ -36,12 +37,24 @@ public int getGuestPoints() {
public String getResultText() {
return "The friendly game ends with \n\n"+nameHomeTeam+" - "+nameGuestTeam +" "+pointsHome+":"+pointsGuest+".";
}

public boolean shotEvent (Player p, Keeper k, int time){
int shot = p.shootsOnGoal();
// check if shot is saved
boolean goal = !k.saveShot(shot);
System.out.println();
System.out.println(time+".Minute: ");
System.out.println(" Chance for "+p.getName()+" ...");
System.out.println(" "+p.getName()+" shoots");
return goal;
}

public void startGame(Team t1, Team t2){
nameHomeTeam = t1.getName();
nameGuestTeam = t2.getName();
pointsHome = 0;
pointsGuest = 0;
Scanner input = new Scanner(System.in);

// now the game can begin; we have to create for the
// 90 minutes + extra time the different actions
Expand Down Expand Up @@ -82,44 +95,48 @@ public void startGame(Team t1, Team t2){
if ((r.nextInt(Math.round(strength_1+strength_2))-strength_1)<=0){
Player p = t1.getPlayers()[shooter];
Keeper k = t2.getKeeper();
int shot = p.shootsOnGoal();
// check if shot is saved
boolean goal = !k.saveShot(shot);
System.out.println();
System.out.println(time+".Minute: ");
System.out.println(" Chance for "+t1.getName()+" ...");
System.out.println(" "+p.getName()+" shoots");
if (goal) {
if (shotEvent(p, k, time)) {
pointsHome++;
p.addGoal();
System.out.println(" Goal!!! "+pointsHome+":"+
pointsGuest+" "+p.getName()+"("+p.getGoals()+")");
}
pointsGuest+" "+p.getName()+"("+p.getGoals()+")");
}
else {
System.out.println(" "+t2.getKeeper().getName()
+" saves briliantly.");
System.out.println(" "+k.getName()
+" saves briliantly.");
}
} // IF
else{
Player p = t2.getPlayers()[shooter];
Keeper k = t1.getKeeper();
int shot = p.shootsOnGoal();
boolean goal = !k.saveShot(shot);
System.out.println();
System.out.println(time+".Minute: ");
System.out.println(" Chance for "+t2.getName()+" ...");
System.out.println(" "+p.getName()+" shoots");

if (goal) {
if (shotEvent(p, k, time)) {
pointsGuest++;
p.addGoal();
System.out.println(" GOAL!!! "+pointsHome+":"+ pointsGuest+" "+p.getName()+"("+p.getGoals()+")");
}
System.out.println(" Goal!!! "+pointsHome+":"+
pointsGuest+" "+p.getName()+"("+p.getGoals()+")");
}
else {
System.out.println(" "+t1.getKeeper().getName()
+" saves brilliantly.");
System.out.println(" "+k.getName()
+" saves briliantly.");
}
} // else
//ask user if player should be switched
System.out.println("Do you wish to switch out a player? (y/n)");
String yn = input.next().toLowerCase();
if (yn.equals("y")) {
System.out.println("Which player should be recalled? Enter their number:");
for (int i = 0; i > 10; i ++){
System.out.println((i + 1) + t1.getPlayers()[i].getName());
}
Player switchOut = t1.getPlayers()[input.nextInt()];
System.out.println("u picked: " + switchOut.getName());
}
else if (yn.equals("n")) {
break;
}
else {
System.out.println("u don goofd m8");
}
} //WHILE
}
}
0