Würfelklassen

Die Klassen für den Würfelvorgang. Die Klassen nehmen die Variable für
die Anzahl eines vorher gewählten Feldes .
master
SariusRu 9 years ago
parent 2a041a3cd2
commit e7145a710b

@ -1,7 +1,8 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import greenfoot.*;
import java.util.Arrays; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/** /**
* Write a description of class Dice_Defender here. * Write a description of class Dice_Offender here.
* *
* @author (your name) * @author (your name)
* @version (a version number or a date) * @version (a version number or a date)
@ -9,21 +10,63 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Dice_Defender extends Dice public class Dice_Defender extends Dice
{ {
/** /**
* Act - do whatever the Dice_Defender wants to do. This method is called whenever * Act - do whatever the Dice_Offender wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment. * the 'Act' or 'Run' button gets pressed in the environment.
*/ */
int[] diceEyesDefender = new int[2];
public void act() public void act()
{ {
// Add your action code here. // Add your action code here.
} }
/** /**
* @param Troups Anzahl der Truppen auf dem gewählten Feld * Die Methode für das Würfeln mit bis zu drei Würfeln des Angreifers, es wird ein Array mit den drei Zahlen zurückgegeben, höchster Wert befindet sich immer an dritter Stelle.
* //@param cheat optional: Die Kleinstmöglichste Anzahl des Würfels, standardmäßig 1 * @param troupNumberDefender Anzahl der Truppen auf dem ausgewählten Feld
*
*/ */
public int dice(int Troups) public int[] dice_offender(int troupNumberDefender)
{
if(troupNumberDefender == 1)
{
diceEyesDefender[0] = (int) (Math.random() * 6 +1);
return diceEyesDefender;
}
if(troupNumberDefender >=2 )
{
diceEyesDefender[0] = (int) (Math.random() * 6 +1);
diceEyesDefender[1] = (int) (Math.random()* 6 +1);
System.out.println(diceEyesDefender[0]);
System.out.println(diceEyesDefender[1]);
return diceEyesDefender;
}
Arrays.sort(diceEyesDefender);
return diceEyesDefender;
}
public int[] max(int troupNumberDefender)
{ {
int dice_eyes = 0; if(troupNumberDefender == 1)
return dice_eyes; {
diceEyesDefender[0] = (int) (Math.random() * 2 +4);
return diceEyesDefender;
}
if(troupNumberDefender >=2 )
{
diceEyesDefender[0] = (int) (Math.random() * 2 +4);
diceEyesDefender[1] = (int) (Math.random()* 2 +4);
System.out.println(diceEyesDefender[0]);
System.out.println(diceEyesDefender[1]);
return diceEyesDefender;
}
Arrays.sort(diceEyesDefender);
return diceEyesDefender;
} }
} }

@ -1,4 +1,5 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import greenfoot.*;
import java.util.Arrays; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/** /**
* Write a description of class Dice_Offender here. * Write a description of class Dice_Offender here.
@ -12,8 +13,92 @@ public class Dice_Offender extends Dice
* Act - do whatever the Dice_Offender wants to do. This method is called whenever * Act - do whatever the Dice_Offender wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment. * the 'Act' or 'Run' button gets pressed in the environment.
*/ */
int[] diceEyesOffender = new int[3];
public void act() public void act()
{ {
// Add your action code here. // Add your action code here.
} }
/**
* Die Methode für das Würfeln mit bis zu drei Würfeln des Angreifers, es wird ein Array mit den drei Zahlen zurückgegeben, höchster Wert befindet sich immer an dritter Stelle.
* @param troupNumberOffender Anzahl der Truppen auf dem ausgewählten Feld
*/
public int[] dice_offender(int troupNumberOffender)
{
if(troupNumberOffender == 1)
{
System.out.println("Mit einer verbleibenden Truppe auff dem Feld kann man nicht angreifen!");
}
if(troupNumberOffender == 2)
{
diceEyesOffender[0] = (int) (Math.random()*6+1);
System.out.println(diceEyesOffender[0]);
return diceEyesOffender;
}
if(troupNumberOffender == 3)
{
diceEyesOffender[0] = (int) (Math.random() * 6 +1);
diceEyesOffender[1] = (int) (Math.random()* 6 +1);
System.out.println(diceEyesOffender[0]);
System.out.println(diceEyesOffender[1]);
return diceEyesOffender;
}
if(troupNumberOffender > 3)
{
diceEyesOffender[0] = (int) (Math.random() * 6 +1);
diceEyesOffender[1] = (int) (Math.random()* 6 +1);
diceEyesOffender[2] = (int) (Math.random()* 6 + 1);
System.out.println(diceEyesOffender[0]);
System.out.println(diceEyesOffender[1]);
System.out.println(diceEyesOffender[2]);
return diceEyesOffender;
}
Arrays.sort(diceEyesOffender);
return diceEyesOffender;
}
public int[] max(int troupNumberOffender)
{
if(troupNumberOffender == 1)
{
System.out.println("Mit einer verbleibenden Truppe auff dem Feld kann man nicht angreifen!");
}
if(troupNumberOffender == 2)
{
diceEyesOffender[0] = (int) (Math.random()*2+5);
System.out.println(diceEyesOffender[0]);
return diceEyesOffender;
}
if(troupNumberOffender == 3)
{
diceEyesOffender[0] = (int) (Math.random() * 2 +5);
diceEyesOffender[1] = (int) (Math.random()* 2 +5);
System.out.println(diceEyesOffender[0]);
System.out.println(diceEyesOffender[1]);
return diceEyesOffender;
}
if(troupNumberOffender > 3)
{
diceEyesOffender[0] = (int) (Math.random() * 2 +5);
diceEyesOffender[1] = (int) (Math.random()* 2 +5);
diceEyesOffender[2] = (int) (Math.random()* 2 + 5);
System.out.println(diceEyesOffender[0]);
System.out.println(diceEyesOffender[1]);
System.out.println(diceEyesOffender[2]);
return diceEyesOffender;
}
Arrays.sort(diceEyesOffender);
return diceEyesOffender;
}
} }

Loading…
Cancel
Save