Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
public class BowlingMain {
public static void main(String[] args) {
System.out.println("*** Bowling-Turnier ***\n");
System.out.print("Wie viele Spieler spielen mit? ");
Tourney tourney = new Tourney(Integer.parseInt(readValue()));
for(int i=0; i<tourney.getPlayerCount(); i++) {
System.out.print("Name von Spieler "+ (i+1) +": ");
tourney.initPlayer(i, readValue());
}
tourney.startTourney();
System.out.println("\nErgebnisse:\n"+ tourney.getResults());
}
public static String readValue() {
try { return new BufferedReader(new InputStreamReader(System.in)).readLine(); }
catch(IOException ex) { return "-1"; }
}
}
public class Tourney {
private Player[] players = null;
private int playerCount = 0;
public Tourney(int playerCount) {
this.players = new Player[playerCount];
this.playerCount = playerCount;
}
public int getPlayerCount() {
return playerCount;
}
public void initPlayer(int idx, String name) {
players[idx] = new Player(name);
}
public void startTourney() {
for(int i=0; i<players.length; i++)
players[i].playTourney();
}
public String getResults() {
String results = "";
for(int i=0; i<players.length; i++)
results += players[i].getPlayerResult() +"\n";
return results.substring(0, results.length()-2);
}
}
public class Player {
static Random random = new Random();
private String name;
private int pointsResult;
private int[] pointsRounds;
public Player(String name) {
this.name = name;
this.pointsResult = 0;
this.pointsRounds = new int[20];
}
public void playTourney() {
int rounds = 10;
for(int i=0; i<rounds; i++) {
int hits = Player.random.nextInt(10) + 1;
if(hits == 10)
rounds++;
pointsResult += hits;
pointsRounds[i] = hits;
}
}
public String getPlayerResult() {
String player = "*** "+ name +" ***\n";
for(int i=0; i<pointsRounds.length; i++)
if(pointsRounds[i] > 0)
player += (i+1) +") Runde: "+ ((pointsRounds[i] == 10) ? "STRIKE " : pointsRounds[i]) +"\n";
player += "Ergebnis: "+ pointsResult;
return player + "\n";
}
}
Imports System.Console
Module Module1
Public spielerAnz As Integer = 0
Public namen As String(,)
Public wurf As Integer = 0
Public ergebnis As Integer = 0
Sub Main()
Randomize()
Do Until spielerAnz > 0 And spielerAnz <= 100
Write("Spieleranzahl: ")
spielerAnz = ReadLine()
Loop
WriteLine()
ReDim namen(1, spielerAnz - 1)
For x As Integer = 0 To spielerAnz - 1
Write("Namen für Spieler " & x + 1 & " eingeben: ")
namen(0, x) = ReadLine()
Next
WriteLine()
For x As Integer = 0 To spielerAnz - 1
For y As Integer = 0 To 9
wurf = CInt(Int((10 * Rnd()) + 1))
ergebnis += wurf
If wurf = 10 Then
wurf = CInt(Int((10 * Rnd()) + 1))
ergebnis += wurf
End If
Next
namen(1, x) = ergebnis.ToString
ergebnis = 0
Next
Sortieren(namen)
For x As Integer = 0 To spielerAnz - 1
WriteLine(namen(0, x).ToString & " hat " & namen(1, x).ToString & " Punkte erspielt.")
Next
ReadLine()
End Sub
Public Sub Sortieren(ByRef arr As Array)
Dim getauscht As Boolean
Do
getauscht = False
For x As Integer = 0 To spielerAnz - 2
If arr(1, x) < arr(1, x + 1) Then
Dim name, wert As String
name = arr(0, x)
wert = arr(1, x)
arr(0, x) = arr(0, x + 1)
arr(1, x) = arr(1, x + 1)
arr(0, x + 1) = name
arr(1, x + 1) = wert
getauscht = True
End If
Next
Loop While getauscht = True
End Sub
End Module