Skip to content

Commit 7c706fb

Browse files
committed
changes in structure programming/lab3
1 parent 4c2ef1a commit 7c706fb

30 files changed

+432
-217
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package src.Character.Actions;
2+
3+
public class BecomeTired {
4+
public void becomeTired() {
5+
System.out.print("В какой-то момент он окончательно выбился из сил, сел посреди поля и стал ожидать чего-то, сам не зная чего. ");
6+
}
7+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package src.Character.Actions;
2+
3+
import src.Character.BasicCharacter;
4+
import src.Random.RandomWrapper;
5+
6+
public class BitePotato {
7+
private final RandomWrapper rnd;
8+
public BitePotato(RandomWrapper rnd) {
9+
this.rnd = rnd;
10+
}
11+
12+
public boolean bite(){
13+
System.out.print("Скуперфильд откусил кусочек и попробовал его разжевать.");
14+
final boolean isDelicious = this.rnd.randomizePotato().isDelicious();
15+
16+
if (isDelicious) {
17+
System.out.print("Сырой картофель оказался весьма сносным");
18+
} else {
19+
System.out.print("Сырой картофель показался ему страшно невкусным, даже противным. ");
20+
}
21+
return isDelicious;
22+
}
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package src.Character.Actions;
2+
3+
import src.Character.BasicCharacter;
4+
import src.Character.CharacterMethods.CharacterCloth;
5+
6+
public class CheckIfClothBroken {
7+
private final CharacterCloth cloth;
8+
public CheckIfClothBroken(CharacterCloth cloth) {
9+
this.cloth = cloth;
10+
}
11+
// check if cloth broken
12+
public void checkIfClothBroken(){
13+
if (this.cloth.getCloth().getStepIncrement() != 0) {
14+
System.out.print("Однако он оказался дырявым и при каждом шаге вываливалось " + this.cloth.getCloth().getStepIncrement() + " клубней. ");
15+
}
16+
}
17+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package src.Character.Actions;
2+
3+
import src.Character.Actions.Exceptons.NegativePotatoesException;
4+
import src.Character.CharacterMethods.CharacterCloth;
5+
import src.Character.CharacterMethods.CharacterName;
6+
import src.Locations.LocationsEnums.GroundType;
7+
8+
public class ClaimPotatoes {
9+
private final CharacterCloth cloth;
10+
private final CharacterName name;
11+
public ClaimPotatoes(CharacterCloth cloth, CharacterName name) {
12+
this.cloth = cloth;
13+
this.name = name;
14+
}
15+
16+
public void claimPotatoes(int potatoesCnt, GroundType groundType) {
17+
try {
18+
this.cloth.getCloth().setPotatoes(potatoesCnt);
19+
System.out.print(name.getName() +
20+
" достаёт " +
21+
potatoesCnt +
22+
" клубней из " +
23+
groundType +
24+
". "
25+
);
26+
}
27+
catch (NegativePotatoesException e){
28+
System.out.println(name.getName() + " не подобрал ни одной картофелины.");
29+
}
30+
}
31+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package src.Character.Actions;
2+
3+
public class EnjoyGrass {
4+
public void enjoyGrass() {
5+
System.out.print(". Он ещё никогда не был так рад ощущать траву под ногами.");
6+
}
7+
}

programming/sem1/lab3/src/Character/Exceptons/NegativeEnergyException.java renamed to programming/sem1/lab3/src/Character/Actions/Exceptons/NegativeEnergyException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package src.Character.Exceptons;
1+
package src.Character.Actions.Exceptons;
22

33
public class NegativeEnergyException extends Exception {
44
public NegativeEnergyException() {

programming/sem1/lab3/src/Character/Exceptons/NegativePotatoesException.java renamed to programming/sem1/lab3/src/Character/Actions/Exceptons/NegativePotatoesException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package src.Character.Exceptons;
1+
package src.Character.Actions.Exceptons;
22

33
public class NegativePotatoesException extends Exception {
44
public NegativePotatoesException() {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package src.Character.Actions;
2+
3+
public class GoFurther {
4+
public void goFurther() {
5+
System.out.print("он решил не подбирать картофель и пойти дальше. ");
6+
}
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package src.Character.Actions;
2+
3+
import src.Character.CharacterMethods.CharacterName;
4+
5+
public class LeaveField {
6+
CharacterName characterName;
7+
public LeaveField(CharacterName characterName) {
8+
this.characterName = characterName;
9+
}
10+
public void leaveField(){
11+
System.out.print("Как и следовало ожидать, ему все же удалось в конце концов добраться до края картофельного поля. " +
12+
"Выбравшись на твердую почву," +
13+
characterName.getName() +
14+
"облегченно вздохнул "
15+
);
16+
}
17+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package src.Character.Actions;
2+
3+
import src.Character.BasicCharacter;
4+
import src.Character.Actions.Exceptons.NegativeEnergyException;
5+
import src.Character.Actions.Exceptons.NegativePotatoesException;
6+
import src.Character.Actions.StepsEnums.StepStatus;
7+
import src.Character.CharacterMethods.CharacterEnergy;
8+
import src.Character.CharacterMethods.CharacterName;
9+
import src.Clothes.Cloth;
10+
11+
public class MakeSteps {
12+
private final CharacterEnergy energy;
13+
private final CharacterName name;
14+
public MakeSteps(CharacterEnergy energy, CharacterName name) {
15+
this.energy = energy;
16+
this.name = name;
17+
}
18+
19+
// make step (potatoes + energy)
20+
private StepStatus makePotatoStep(Cloth cloth) {
21+
try { cloth.makeStep(); }
22+
catch (NegativePotatoesException e){
23+
System.out.print("В какой-то момент " +
24+
name.getName() +
25+
" ощутил необычайную лёгкость и решил проверить карманы. Он обнаружил, что из прорех вывалился весь картофель, "
26+
);
27+
return StepStatus.NOT_ENOUGH_POTATOES;
28+
}
29+
return StepStatus.OK;
30+
}
31+
private StepStatus makeEnergyStep() {
32+
try { energy.energyStepIncriment(); }
33+
catch (NegativeEnergyException e){
34+
System.out.print("В какой-то момент он окончательно выбился из сил, сел посреди поля и стал ожидать чего-то, сам не зная чего. ");
35+
return StepStatus.NOT_ENOUGH_ENERGY;
36+
}
37+
38+
return StepStatus.OK;
39+
}
40+
public StepStatus makeStep(Cloth cloth) {
41+
StepStatus potatoStepStatus = this.makePotatoStep(cloth);
42+
if (potatoStepStatus != StepStatus.OK){ return potatoStepStatus; }
43+
44+
return this.makeEnergyStep();
45+
}
46+
// make step (energy)
47+
public StepStatus makeStepAfterReclaim(){
48+
StepStatus energyStepStatus = this.makeEnergyStep();
49+
if (energyStepStatus != StepStatus.OK){ return energyStepStatus; }
50+
51+
if (energy.getEnergy() == 0) return StepStatus.LAST_STEP;
52+
return StepStatus.OK;
53+
}
54+
}

0 commit comments

Comments
 (0)