• R/O
  • SSH
  • HTTPS

simyukkuri: 提交


Commit MetaInfo

修订版259 (tree)
时间2015-09-04 20:28:16
作者mimisuke

Log Message

Cleaned up the code.

更改概述

差异

--- branches/test/MachinePress.java (revision 258)
+++ branches/test/MachinePress.java (revision 259)
@@ -20,9 +20,8 @@
2020
2121 public class MachinePress extends ObjEX implements java.io.Serializable {
2222 static final long serialVersionUID = 1L;
23- public int type = 0;
24- public static final int hitCheckObjType = 3;
25- public static final int size = 256;
23+
24+ private static final int size = 256;
2625 private static final int images_num = 8; // このクラスの総使用画像数
2726 private static int AnimeImagesNum[] = {8};// アニメごとに何枚使うか
2827 private static Image[] images = new Image[images_num];
@@ -47,7 +46,17 @@
4746 }
4847
4948 @Override
50- public int checkHitObj(Obj o) {
49+ public boolean isTargetObj(Obj o) {
50+ switch (o.getObjType()) {
51+ case YUKKURI:
52+ return true;
53+ default:
54+ }
55+ return false;
56+ }
57+
58+ @Override
59+ public boolean checkHitObj(Obj o) {
5160 int objX = o.getX();
5261 int objY = o.getY();
5362 int objZ = o.getZ();
@@ -60,11 +69,11 @@
6069 if ((platformX + offsetX + 15) <= (objX) && (objX) <= (platformX + offsetX + platformSize - 25)) { // X軸比較
6170 if ((platformY + offsetY + 50) <= (objY) && (objY) <= (platformY + offsetY + platformSize - 25)) { // Y軸比較
6271 objHitProcess(o);
63- return 1;
72+ return true;
6473 }
6574 }
6675 }
67- return 0;
76+ return false;
6877 }
6978
7079 public void objHitProcess(Obj o) {
--- branches/test/GarbageChute.java (revision 258)
+++ branches/test/GarbageChute.java (revision 259)
@@ -17,16 +17,14 @@
1717 import java.awt.Image;
1818 import java.io.IOException;
1919 import javax.imageio.ImageIO;
20-import java.util.Random;
2120
2221 public class GarbageChute extends ObjEX implements java.io.Serializable {
2322 static final long serialVersionUID = 1L;
24- public int type = 0;
25- public static final int hitCheckObjType = 31;
26- public static final int size = 128;
23+
24+ private static final int size = 128;
2725 private static final int images_num = 1; // このクラスの総使用画像数
2826 private static Image[] images = new Image[images_num];
29- protected Random rnd = new Random();
27+
3028 private static int value = 5000;
3129 private static int cost = 1;
3230
@@ -45,12 +43,21 @@
4543 }
4644
4745 @Override
48- public int getHitCheckObjType() {
49- return hitCheckObjType;
46+ public boolean isTargetObj(Obj o) {
47+ switch (o.getObjType()) {
48+ case YUKKURI:
49+ case SHIT:
50+ case FOOD:
51+ case TOILET:
52+ case TOY:
53+ return true;
54+ default:
55+ }
56+ return false;
5057 }
5158
5259 @Override
53- public int checkHitObj(Obj o) {
60+ public boolean checkHitObj(Obj o) {
5461 int objX = o.getX();
5562 int objY = o.getY();
5663 int objZ = o.getZ();
@@ -63,11 +70,11 @@
6370 if ((platformX + offsetX) <= (objX) && (objX) <= (platformX + offsetX + platformSize)) { // X軸比較
6471 if ((platformY + offsetY) <= (objY) && (objY) <= (platformY + offsetY + platformSize)) { // Y軸比較
6572 objHitProcess(o);
66- return 1;
73+ return true;
6774 }
6875 }
6976 }
70- return 0;
77+ return false;
7178 }
7279
7380 @Override
--- branches/test/Body.java (revision 258)
+++ branches/test/Body.java (revision 259)
@@ -65,7 +65,7 @@
6565 private int BABYLIMIT = 100*24*7;
6666 private int CHILDLIMIT = 100*24*21;
6767 private int LIFELIMIT = 100*24*365;
68- private int STEP[] = {1, 2, 4}; // This should be less than or equal MAXSTEP.
68+ private int STEP[] = {1, 2, 4}; // This should be less than or equal to MAXSTEP.
6969 private int RELAXPERIOD = 100*1;
7070 private int EXCITEPERIOD = 100*3;
7171 private int PREGPERIOD = 100*24;
@@ -1350,6 +1350,9 @@
13501350
13511351 public void setDirty(boolean flag) {
13521352 dirty = flag;
1353+ if (dead) {
1354+ return;
1355+ }
13531356 if (dirty) {
13541357 setHappiness(Happiness.SAD);
13551358 }
@@ -1411,7 +1414,7 @@
14111414 }
14121415
14131416 public boolean isSleepy() {
1414- if (wakeUpTime + ACTIVEPERIOD < age) {
1417+ if (!dead && (wakeUpTime + ACTIVEPERIOD < age)) {
14151418 return true;
14161419 }
14171420 return false;
@@ -1442,7 +1445,7 @@
14421445 }
14431446
14441447 public boolean isHappy() {
1445- return (happiness == Happiness.HAPPY || happiness == Happiness.VERY_HAPPY);
1448+ return (!dead && (happiness == Happiness.HAPPY || happiness == Happiness.VERY_HAPPY));
14461449 }
14471450
14481451 public boolean isFurifuri() {
@@ -1466,11 +1469,11 @@
14661469 }
14671470
14681471 public boolean isFeelPain() {
1469- return (checkPainState() == Pain.VERY || checkPainState() == Pain.SOME);
1472+ return (!dead && (checkPainState() == Pain.VERY || checkPainState() == Pain.SOME));
14701473 }
14711474
14721475 public boolean isFeelHardPain() {
1473- return (checkPainState() == Pain.VERY || checkPainState() == Pain.VERY);
1476+ return (!dead && (checkPainState() == Pain.VERY || checkPainState() == Pain.VERY));
14741477 }
14751478
14761479 public boolean isBirth() {
@@ -1820,9 +1823,8 @@
18201823 setHappiness(Happiness.HAPPY);
18211824 showEating();
18221825 rapidExcitingDiscipline();
1823- if ( superRapist == false && rnd.nextInt(10) == 0) {
1826+ if (rapist && (rnd.nextInt(10) == 0)) {
18241827 superRapist = true;
1825- rapist = true;
18261828 }
18271829 }
18281830 else if (foodType == Food.type.FUNGICIDE) {
--- branches/test/OrangePool.java (revision 258)
+++ branches/test/OrangePool.java (revision 259)
@@ -20,14 +20,15 @@
2020
2121 public class OrangePool extends ObjEX implements java.io.Serializable {
2222 static final long serialVersionUID = 1L;
23- public int type = 0;
24- public static final int hitCheckObjType = 1;
25- public static final int size = 128;
23+
24+ private static final int size = 128;
2625 private static final int images_num = 1; // このクラスの総使用画像数
2726 private static Image[] images = new Image[images_num];
27+
2828 private boolean rescue;
2929 private static int[] value = {500, 10000};
3030 private static int[] cost = {10, 200};
31+ private int type = 0;
3132
3233 public static void loadImages(ClassLoader loader, String path) throws IOException {
3334 images[0] = ImageIO.read(loader.getResourceAsStream(path + "orangepool.png"));
@@ -44,12 +45,17 @@
4445 }
4546
4647 @Override
47- public int getHitCheckObjType() {
48- return hitCheckObjType;
48+ public boolean isTargetObj(Obj o) {
49+ switch (o.getObjType()) {
50+ case YUKKURI:
51+ return true;
52+ default:
53+ }
54+ return false;
4955 }
50-
56+
5157 @Override
52- public int checkHitObj(Obj o) {
58+ public boolean checkHitObj(Obj o) {
5359 int objX = o.getX();
5460 int objY = o.getY();
5561 int objZ = o.getZ();
@@ -62,28 +68,35 @@
6268 if ((platformX + offsetX) <= (objX) && (objX) <= (platformX + offsetX + platformSize)) { // X軸比較
6369 if ((platformY + offsetY) <= (objY) && (objY) <= (platformY + offsetY + platformSize)) { // Y軸比較
6470 objHitProcess(o);
65- return 1;
71+ return true;
6672 }
6773 }
6874 }
69- return 0;
75+ return false;
7076 }
7177
7278 @Override
7379 public void objHitProcess(Obj o) {
80+ if (age % 10 != 0) {
81+ return;
82+ }
7483 if (o.objType == Obj.Type.YUKKURI) {
7584 Body b = (Body)o;
76- b.giveJuice();
77- if (b.isDirty() == true) {
78- b.setDirty(false);
79- }
8085 if (rescue) {
8186 if (b.isDead() && !b.isCrashed()) {
8287 b.revival();
88+ b.giveJuice();
89+ b.setDirty(false);
90+ Cash.delCash(getCost());
8391 }
84- b.setCantDie();
8592 }
86- Cash.delCash(getCost());
93+ else {
94+ if (!b.isDead()) {
95+ b.giveJuice();
96+ b.setDirty(false);
97+ Cash.delCash(getCost());
98+ }
99+ }
87100 }
88101 return;
89102 }
--- branches/test/FoodMaker.java (revision 258)
+++ branches/test/FoodMaker.java (revision 259)
@@ -21,17 +21,16 @@
2121
2222 public class FoodMaker extends ObjEX implements java.io.Serializable {
2323 static final long serialVersionUID = 1L;
24- public int type = 0;
25- public static final int hitCheckObjType = 7;
26- public static final int size = 128;
24+
25+ private static final int size = 128;
2726 private static final int images_num = 6; // このクラスの総使用画像数
2827 private static int AnimeImagesNum[] = {6};// アニメごとに何枚使うか
2928 private static Image[] images = new Image[images_num];
30- protected Random rnd = new Random();
3129
3230 protected boolean processReady = true;
3331 private static int value = 30000;
3432 private static int cost = 10;
33+ private Random rnd = new Random();
3534
3635 private int shitCount = 0;
3736
@@ -53,12 +52,19 @@
5352 }
5453
5554 @Override
56- public int getHitCheckObjType() {
57- return hitCheckObjType;
55+ public boolean isTargetObj(Obj o) {
56+ switch (o.getObjType()) {
57+ case YUKKURI:
58+ case SHIT:
59+ case FOOD:
60+ return true;
61+ default:
62+ }
63+ return false;
5864 }
5965
6066 @Override
61- public int checkHitObj(Obj o) {
67+ public boolean checkHitObj(Obj o) {
6268 int objX = o.getX();
6369 int objY = o.getY();
6470 int objZ = o.getZ();
@@ -71,11 +77,11 @@
7177 if ((platformX + offsetX) <= (objX) && (objX) <= (platformX + offsetX + platformSize)) { // X軸比較
7278 if ((platformY + offsetY) <= (objY) && (objY) <= (platformY + offsetY + platformSize)) { // Y軸比較
7379 objHitProcess(o);
74- return 1;
80+ return true;
7581 }
7682 }
7783 }
78- return 0;
84+ return false;
7985 }
8086
8187 @Override
--- branches/test/ObjEX.java (revision 258)
+++ branches/test/ObjEX.java (revision 259)
@@ -18,19 +18,9 @@
1818
1919 public class ObjEX extends Obj implements java.io.Serializable {
2020 static final long serialVersionUID = 1L;
21- public int type;
2221
2322 protected Image[] images;
2423
25- public static final int YUKKURI = 1;
26- public static final int SHIT = 2;
27- public static final int FOOD = 4;
28- public static final int TOILET = 8;
29- public static final int TOY = 16;
30- public static final int PLATFORM = 32;
31- public static final int FIX_OBJECT = 64;
32- public static final int hitCheckObjType = 0;
33-
3424 public static enum Direction {
3525 BACK, THISSIDE, RIGHT, LEFT
3626 };
@@ -51,11 +41,11 @@
5141 return direction;
5242 }
5343
54- public int getHitCheckObjType() {
55- return hitCheckObjType;
44+ public boolean isTargetObj(Obj o) {
45+ return false;
5646 }
5747
58- public int checkHitObj(Obj o) {
48+ public boolean checkHitObj(Obj o) {
5949 int objX = o.getX();
6050 int objY = o.getY();
6151 int objZ = o.getZ();
@@ -68,11 +58,11 @@
6858 if ((platformX + offsetX) <= (objX) && (objX) <= (platformX + offsetX + platformSize)) { // X軸比較
6959 if ((platformY + offsetY) <= (objY) && (objY) <= (platformY + offsetY + platformSize)) { // Y軸比較
7060 objHitProcess(o);
71- return 1;
61+ return true;
7262 }
7363 }
7464 }
75- return 0;
65+ return false;
7666 }
7767
7868 public void objHitProcess(Obj o) {
--- branches/test/BreedingPool.java (revision 258)
+++ branches/test/BreedingPool.java (revision 259)
@@ -21,17 +21,17 @@
2121
2222 public class BreedingPool extends ObjEX implements java.io.Serializable {
2323 static final long serialVersionUID = 1L;
24- public int type = 0;
25- public static final int hitCheckObjType = 1;
26- public static final int size = 128;
24+
25+ private static final int size = 128;
2726 private static final int images_num = 1; // このクラスの総使用画像数
2827 private static Image[] images = new Image[images_num];
29- protected Random rnd = new Random();
3028
3129 private boolean highDensity;
3230 private boolean rapidGrowth;
3331 private static int[] value = {1000, 4000, 4000, 10000};
3432 private static int[] cost = {5, 10, 10, 20};
33+ private int type = 0;
34+ private Random rnd = new Random();
3535
3636 public static void loadImages(ClassLoader loader, String path) throws IOException {
3737 images[0] = ImageIO.read(loader.getResourceAsStream(path + "breedingpool.png"));
@@ -48,8 +48,13 @@
4848 }
4949
5050 @Override
51- public int getHitCheckObjType() {
52- return hitCheckObjType;
51+ public boolean isTargetObj(Obj o) {
52+ switch (o.getObjType()) {
53+ case YUKKURI:
54+ return true;
55+ default:
56+ }
57+ return false;
5358 }
5459
5560 @Override
@@ -56,7 +61,7 @@
5661 public void objHitProcess(Obj o) {
5762 if (o.objType == Obj.Type.YUKKURI) {
5863 Body p = (Body) o;
59- if (!p.isDead() && (int) age % ((highDensity == true) ? 4 : 10) == 0) {
64+ if (!p.isDead() && ((int) age % ((highDensity == true) ? 4 : 10) == 0)) {
6065 int babyType;
6166 if (p.isSick() || p.isDamaged()) {
6267 babyType = InitLoader.getIdiotType();
--- branches/test/ProductChute.java (revision 258)
+++ branches/test/ProductChute.java (revision 259)
@@ -17,16 +17,14 @@
1717 import java.awt.Image;
1818 import java.io.IOException;
1919 import javax.imageio.ImageIO;
20-import java.util.Random;
2120
2221 public class ProductChute extends ObjEX implements java.io.Serializable {
2322 static final long serialVersionUID = 1L;
24- public static final int type = 0;
25- public static final int hitCheckObjType = 31;
26- public static final int size = 128;
23+
24+ private static final int size = 128;
2725 private static final int images_num = 1; // このクラスの総使用画像数
2826 private static Image[] images = new Image[images_num];
29- protected Random rnd = new Random();
27+
3028 private static int value = 5000;
3129 private static int cost = 10;
3230
@@ -45,12 +43,21 @@
4543 }
4644
4745 @Override
48- public int getHitCheckObjType() {
49- return hitCheckObjType;
46+ public boolean isTargetObj(Obj o) {
47+ switch (o.getObjType()) {
48+ case YUKKURI:
49+ case SHIT:
50+ case FOOD:
51+ case TOILET:
52+ case TOY:
53+ return true;
54+ default:
55+ }
56+ return false;
5057 }
5158
5259 @Override
53- public int checkHitObj(Obj o) {
60+ public boolean checkHitObj(Obj o) {
5461 int objX = o.getX();
5562 int objY = o.getY();
5663 int objZ = o.getZ();
@@ -63,11 +70,11 @@
6370 if ((platformX + offsetX) <= (objX) && (objX) <= (platformX + offsetX + platformSize)) { // X軸比較
6471 if ((platformY + offsetY) <= (objY) && (objY) <= (platformY + offsetY + platformSize)) { // Y軸比較
6572 objHitProcess(o);
66- return 1;
73+ return true;
6774 }
6875 }
6976 }
70- return 0;
77+ return false;
7178 }
7279
7380 @Override
--- branches/test/Terrarium.java (revision 258)
+++ branches/test/Terrarium.java (revision 259)
@@ -865,8 +865,7 @@
865865 i.remove();
866866 }
867867 }
868-
869- // Update Platform state. 床置き式の物を更新
868+ // Update Platform state. 床置き式の物を更新
870869 for (Iterator<ObjEX> i = objExList.iterator(); i.hasNext();) {
871870 ObjEX oex = i.next();
872871 ret = oex.clockTick();
@@ -874,42 +873,15 @@
874873 i.remove();
875874 continue;
876875 }
877- List <Obj>objList = getObjList();
876+ List<Obj> objList = getObjList();
878877 objList.addAll(Terrarium.toiletList);
879878 for (Obj o : objList) {
880- int objType = 0;
881- switch(o.getObjType()){
882- case YUKKURI:
883- objType = 1;
884- break;
885- case SHIT:
886- objType = 2;
887- break;
888- case FOOD:
889- objType = 4;
890- break;
891- case TOILET:
892- objType = 8;
893- break;
894- case TOY:
895- objType = 16;
896- break;
897- case PLATFORM:
898- objType = 32;
899- break;
900- case FIX_OBJECT:
901- objType = 64;
902- break;
903- default:
904- break;
879+ if (oex.isTargetObj(o)) {
880+ oex.checkHitObj(o);
905881 }
906- if ((objType & oex.getHitCheckObjType()) != 0){
907- oex.checkHitObj( o );
908- }
909882 }
910- }
911-
912- // Update FixObj state. 置物を更新
883+ }
884+ // Update FixObj state. 置物を更新
913885 for (Iterator<ObjEX> i = fixedObjExList.iterator(); i.hasNext();) {
914886 ObjEX oex = i.next();
915887 ret = oex.clockTick();
@@ -918,10 +890,11 @@
918890 continue;
919891 }
920892 for (Obj o : Terrarium.bodyList) {
921- oex.checkHitObj( o );
893+ if (oex.isTargetObj(o)) {
894+ oex.checkHitObj(o);
895+ }
922896 }
923897 }
924-
925898 // Update shit state.
926899 for (Iterator<Shit> i = shitList.iterator(); i.hasNext();) {
927900 Shit s = i.next();
@@ -949,22 +922,22 @@
949922 case STILLBIRTH:
950923 if (b.getBabyList().size() > 0) {
951924 int numOfBaby = b.getBabyList().size();
952- for (Body baby:b.getBabyList()) {
953- addBaby(b.getX(), b.getY(), b.getZ()+b.getSize()/20, rnd.nextInt(numOfBaby/4+1)-numOfBaby/8, rnd.nextInt(numOfBaby/4+1)-numOfBaby/8, rnd.nextInt(numOfBaby/4+1)-numOfBaby/8-2, baby);
925+ for (Body baby : b.getBabyList()) {
926+ addBaby(b.getX(), b.getY(), b.getZ() + b.getSize() / 20, rnd.nextInt(numOfBaby / 4 + 1) - numOfBaby / 8, rnd.nextInt(numOfBaby / 4 + 1) - numOfBaby / 8, rnd.nextInt(numOfBaby / 4 + 1) - numOfBaby / 8 - 2, baby);
954927 }
955928 b.getBabyList().clear();
956929 }
957930 continue;
958931 case BIRTHBABY:
959- if ( b.age % 10 == 0 ){
932+ if (b.age % 10 == 0) {
960933 Body baby = b.getBabyListDequeue();
961- if (baby != null){
962- addBaby(b.getX(), b.getY(), b.getZ()+b.getSize()/15, baby);
934+ if (baby != null) {
935+ addBaby(b.getX(), b.getY(), b.getZ() + b.getSize() / 15, baby);
963936 }
964937 }
965938 break;
966939 case DOSHIT:
967- addShit(b.getX(), b.getY(), b.getZ()+b.getSize()/15, b.getAgeState());
940+ addShit(b.getX(), b.getY(), b.getZ() + b.getSize() / 15, b.getAgeState());
968941 break;
969942 case REMOVED:
970943 i.remove();
@@ -995,7 +968,6 @@
995968 bodyList.addAll(babyList);
996969 babyList.clear();
997970 }
998-
999971 operationTime += TICK;
1000972 }
1001973 }
\ No newline at end of file
--- branches/test/Beltconveyor.java (revision 258)
+++ branches/test/Beltconveyor.java (revision 259)
@@ -20,9 +20,8 @@
2020
2121 public class Beltconveyor extends ObjEX implements java.io.Serializable {
2222 static final long serialVersionUID = 1L;
23- public int type = 0;
24- public static final int hitCheckObjType = 31;
25- public static final int size = 128;
23+
24+ private static final int size = 128;
2625 private static final int images_num = 10; // このクラスの総使用画像数
2726 private static int AnimeImagesNum[] = {5, 5};// アニメごとに何枚使うか
2827 private static Image[] images = new Image[images_num];
@@ -58,10 +57,19 @@
5857 public int getSize() {
5958 return size;
6059 }
61-
60+
6261 @Override
63- public int getHitCheckObjType() {
64- return hitCheckObjType;
62+ public boolean isTargetObj(Obj o) {
63+ switch (o.getObjType()) {
64+ case YUKKURI:
65+ case SHIT:
66+ case FOOD:
67+ case TOILET:
68+ case TOY:
69+ return true;
70+ default:
71+ }
72+ return false;
6573 }
6674
6775 @Override
--- branches/test/SimYukkuri.java (revision 258)
+++ branches/test/SimYukkuri.java (revision 259)
@@ -264,11 +264,11 @@
264264 int shit = 100 * b.getShit() / b.getShitLimit();
265265 String rapist = (b.isRaper() ? "Yes" : "No");
266266 String rude = (b.isRude() ? "Yes" : "No");
267- l4.setText(" "+InitLoader.getStatus(2)+": " + damage + "%");
268- l5.setText(" "+InitLoader.getStatus(3)+": " + hungry + "%");
269- l6.setText(" "+InitLoader.getStatus(4)+": " + shit + "%");
270- l7.setText(" "+InitLoader.getStatus(5)+": " + rapist);
271- l8.setText(" "+InitLoader.getStatus(6)+": " + rude);
267+ l4.setText(" " + InitLoader.getStatus(2) + ": " + damage + "%");
268+ l5.setText(" " + InitLoader.getStatus(3) + ": " + hungry + "%");
269+ l6.setText(" " + InitLoader.getStatus(4) + ": " + shit + "%");
270+ l7.setText(" " + InitLoader.getStatus(5) + ": " + rapist);
271+ l8.setText(" " + InitLoader.getStatus(6) + ": " + rude);
272272 }
273273
274274 public class MyItemListener implements ItemListener {
@@ -363,13 +363,15 @@
363363 }
364364
365365 public void doSave() {
366- synchronized(lock) {
366+ synchronized (lock) {
367367 int result = fc.showSaveDialog(SimYukkuri.this);
368- if(result != JFileChooser.APPROVE_OPTION) return;
368+ if (result != JFileChooser.APPROVE_OPTION)
369+ return;
369370 File file = fc.getSelectedFile();
370371 try {
371372 Terrarium.saveState(file);
372- } catch(IOException e) {
373+ }
374+ catch (IOException e) {
373375 e.printStackTrace();
374376 JOptionPane.showMessageDialog(SimYukkuri.this, e.getLocalizedMessage(), SimYukkuri.TITLE, JOptionPane.ERROR_MESSAGE);
375377 }
@@ -377,16 +379,19 @@
377379 }
378380
379381 public void doLoad() {
380- synchronized(lock) {
382+ synchronized (lock) {
381383 int result = fc.showOpenDialog(SimYukkuri.this);
382- if(result != JFileChooser.APPROVE_OPTION) return;
384+ if (result != JFileChooser.APPROVE_OPTION)
385+ return;
383386 File file = fc.getSelectedFile();
384387 try {
385388 Terrarium.loadState(file);
386- } catch(IOException e) {
389+ }
390+ catch (IOException e) {
387391 e.printStackTrace();
388392 JOptionPane.showMessageDialog(SimYukkuri.this, e.getLocalizedMessage(), SimYukkuri.TITLE, JOptionPane.ERROR_MESSAGE);
389- } catch(ClassNotFoundException e) {
393+ }
394+ catch (ClassNotFoundException e) {
390395 e.printStackTrace();
391396 JOptionPane.showMessageDialog(SimYukkuri.this, e.getLocalizedMessage(), SimYukkuri.TITLE, JOptionPane.ERROR_MESSAGE);
392397 }
@@ -412,12 +417,12 @@
412417 int w = size.width, h = size.height;
413418 Obj found = null;
414419 for (Obj o : list4sort) {
420+ int dx, dy;
415421 switch (o.objType) {
416422 case YUKKURI:
417- {
418423 Body b = (Body)o;
419- int dx = e.getX() - Translate.transX(b.getX(), b.getY(), b.getSize(), w);
420- int dy = e.getY() - Translate.transY(b.getX(), b.getY(), b.getSize(), h) + b.getZ() * h / Terrarium.MAX_Z;
424+ dx = e.getX() - Translate.transX(b.getX(), b.getY(), b.getSize(), w);
425+ dy = e.getY() - Translate.transY(b.getX(), b.getY(), b.getSize(), h) + b.getZ() * h / Terrarium.MAX_Z;
421426 if (dx >= 0 && dx <= b.getSize() && dy >= 0 && dy <= b.getSize()) {
422427 found = b;
423428 oX = dx;
@@ -424,12 +429,10 @@
424429 oY = dy;
425430 }
426431 break;
427- }
428432 case SHIT:
429- {
430433 Shit s = (Shit)o;
431- int dx = e.getX() - Translate.transX(s.getX(), s.getY(), s.getSize(), w);
432- int dy = e.getY() - Translate.transY(s.getX(), s.getY(), s.getSize(), h) + s.getZ() * h / Terrarium.MAX_Z;
434+ dx = e.getX() - Translate.transX(s.getX(), s.getY(), s.getSize(), w);
435+ dy = e.getY() - Translate.transY(s.getX(), s.getY(), s.getSize(), h) + s.getZ() * h / Terrarium.MAX_Z;
433436 if (dx >= 0 && dx <= s.getSize() && dy >= 0 && dy <= s.getSize()) {
434437 found = s;
435438 oX = dx;
@@ -436,12 +439,10 @@
436439 oY = dy;
437440 }
438441 break;
439- }
440442 case FOOD:
441- {
442443 Food f = (Food)o;
443- int dx = e.getX() - Translate.transX(f.getX(), f.getY(), f.getSize(), w);
444- int dy = e.getY() - Translate.transY(f.getX(), f.getY(), f.getSize()/2, h) + f.getZ() * h / Terrarium.MAX_Z;
444+ dx = e.getX() - Translate.transX(f.getX(), f.getY(), f.getSize(), w);
445+ dy = e.getY() - Translate.transY(f.getX(), f.getY(), f.getSize()/2, h) + f.getZ() * h / Terrarium.MAX_Z;
445446 if (dx >= 0 && dx <= f.getSize() && dy >= 0 && dy <= f.getSize()/2) {
446447 found = f;
447448 oX = dx;
@@ -448,12 +449,10 @@
448449 oY = dy;
449450 }
450451 break;
451- }
452452 case TOY:
453- {
454453 Toy t = (Toy)o;
455- int dx = e.getX() - Translate.transX(t.getX(), t.getY(), t.getSize(), w);
456- int dy = e.getY() - Translate.transY(t.getX(), t.getY(), t.getSize(), h) + t.getZ() * h / Terrarium.MAX_Z;
454+ dx = e.getX() - Translate.transX(t.getX(), t.getY(), t.getSize(), w);
455+ dy = e.getY() - Translate.transY(t.getX(), t.getY(), t.getSize(), h) + t.getZ() * h / Terrarium.MAX_Z;
457456 if (dx >= 0 && dx <= t.getSize() && dy >= 0 && dy <= t.getSize()) {
458457 found = t;
459458 oX = dx;
@@ -460,16 +459,13 @@
460459 oY = dy;
461460 }
462461 break;
463- }
464-
465462 case FIX_OBJECT:
466- {
467463 MachinePress fo = (MachinePress)o;
468464 if (fo.getZ() != 0) {
469465 continue;
470466 }
471- int dx = e.getX() - Translate.transX(fo.getX(), fo.getY(), fo.getSize(), w);
472- int dy = e.getY() - Translate.transY(fo.getX(), fo.getY(), fo.getSize()/2, h) + 128 + fo.getZ() * h / Terrarium.MAX_Z;
467+ dx = e.getX() - Translate.transX(fo.getX(), fo.getY(), fo.getSize(), w);
468+ dy = e.getY() - Translate.transY(fo.getX(), fo.getY(), fo.getSize()/2, h) + 128 + fo.getZ() * h / Terrarium.MAX_Z;
473469 if (dx >= 0 && dx <= fo.getSize() && dy >= 0 && dy <= fo.getSize()) {
474470 found = fo;
475471 oX = dx;
@@ -476,8 +472,6 @@
476472 oY = dy;
477473 }
478474 break;
479- }
480-
481475 default:
482476 break;
483477 }
@@ -509,21 +503,11 @@
509503 return found;
510504 }
511505
512- public void mouseClicked(MouseEvent e){
506+ public void mouseClicked(MouseEvent e) {
513507 if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0) {
514508 return;
515509 }
516- synchronized(lock) {
517- if ((s1.getSelectedIndex() == BARRIER) && (s2.getSelectedIndex() == DEL)) {
518- Dimension size = mypane.getSize();
519- int x = Translate.invX(e.getX(), e.getY(), 0, size.width, size.height);
520- int y = Translate.invY(e.getX(), e.getY(), 0, size.width, size.height);
521- Barrier found = Terrarium.getBarrier(x, y, 10);
522- if (found != null) {
523- Terrarium.clearBarrier(found);
524- }
525- return;
526- }
510+ synchronized (lock) {
527511 // If all is selected for clean, clean all shit, empty food and dead body.
528512 if ((s1.getSelectedIndex() == CLEAN) && (s2.getSelectedIndex() == ALL)) {
529513 Terrarium.cleanAll();
@@ -537,13 +521,13 @@
537521 case TOOL:
538522 switch (s2.getSelectedIndex()) {
539523 case PUNISH:
540- if (found instanceof Body) {
524+ if (found instanceof Body) {
541525 ((Body)found).strikeByPunish();
542526 Terrarium.setAlarm();
543527 }
544528 break;
545529 case HAMMER:
546- if (found instanceof Body) {
530+ if (found instanceof Body) {
547531 Body b = (Body)found;
548532 b.strikeByHammer();
549533 if (!b.hasPants() && !b.isDead()) {
@@ -554,12 +538,12 @@
554538 }
555539 break;
556540 case VIBRATOR:
557- if (found instanceof Body) {
541+ if (found instanceof Body) {
558542 ((Body)found).forceToSukkiri();
559543 }
560544 break;
561545 case JUICE:
562- if (found instanceof Body){
546+ if (found instanceof Body) {
563547 ((Body)found).giveJuice();
564548 }
565549 break;
@@ -582,7 +566,7 @@
582566 }
583567 break;
584568 case ACCESSORY:
585- if (found instanceof Body) {
569+ if (found instanceof Body) {
586570 if (((Body)found).hasAccessory())
587571 ((Body)found).takeAccessory();
588572 else
@@ -590,7 +574,7 @@
590574 }
591575 break;
592576 case PANTS:
593- if (found instanceof Body) {
577+ if (found instanceof Body) {
594578 if (((Body)found).hasPants())
595579 ((Body)found).takePants();
596580 else
@@ -597,7 +581,7 @@
597581 ((Body)found).givePants();
598582 }
599583 break;
600- default://Other tool
584+ default:// Other tool
601585 break;
602586 }
603587 if (found instanceof Body) {
@@ -607,10 +591,11 @@
607591 if (found == null) {
608592 Dimension size = mypane.getSize();
609593 int w = size.width, h = size.height;
594+ int x, y;
610595 switch (s1.getSelectedIndex()) {
611- case FOOD: {
612- int x = Translate.invX(e.getX(), e.getY(), Food.getSizeS(), w, h);
613- int y = Translate.invY(e.getX(), e.getY(), Food.getSizeS() / 2, w, h);
596+ case FOOD:
597+ x = Translate.invX(e.getX(), e.getY(), Food.getSizeS(), w, h);
598+ y = Translate.invY(e.getX(), e.getY(), Food.getSizeS() / 2, w, h);
614599 if (x >= 0 && x <= Terrarium.MAX_X && y >= 0 && y <= Terrarium.MAX_Y) {
615600 Food.type foodType;
616601 switch (s2.getSelectedIndex()) {
@@ -639,53 +624,47 @@
639624 }
640625 mypane.terrarium.buyFood(x, y, foodType);
641626 }
642- }
643- break;
644- case TOILET: {
645- int x = Translate.invX(e.getX(), e.getY(), Toilet.getSizeS(), w, h);
646- int y = Translate.invY(e.getX(), e.getY(), Toilet.getSizeS() * 2 / 3, w, h);
627+ break;
628+ case TOILET:
629+ x = Translate.invX(e.getX(), e.getY(), Toilet.getSizeS(), w, h);
630+ y = Translate.invY(e.getX(), e.getY(), Toilet.getSizeS() * 2 / 3, w, h);
647631 if (x >= 0 && x <= Terrarium.MAX_X && y >= 0 && y <= Terrarium.MAX_Y) {
648632 mypane.terrarium.buyToilet(x, y);
649633 }
650- }
651- break;
652- case TOYS: {
653- int x = Translate.invX(e.getX(), e.getY(), Toy.getSizeS(), w, h);
654- int y = Translate.invY(e.getX(), e.getY(), Toy.getSizeS(), w, h);
634+ break;
635+ case TOYS:
636+ x = Translate.invX(e.getX(), e.getY(), Toy.getSizeS(), w, h);
637+ y = Translate.invY(e.getX(), e.getY(), Toy.getSizeS(), w, h);
655638 if (x >= 0 && x <= Terrarium.MAX_X && y >= 0 && y <= Terrarium.MAX_Y) {
656639 mypane.terrarium.buyToy(x, y);
657- }
658- }
659- break;
660-
661- case BELTCONVEYOR: {
662- int x = Translate.invX(e.getX(), e.getY(), Beltconveyor.getSizeS(), w, h);
663- int y = Translate.invY(e.getX(), e.getY(), Beltconveyor.getSizeS() / 2, w, h);
640+ }
641+ break;
642+ case BELTCONVEYOR:
643+ x = Translate.invX(e.getX(), e.getY(), Beltconveyor.getSizeS(), w, h);
644+ y = Translate.invY(e.getX(), e.getY(), Beltconveyor.getSizeS() / 2, w, h);
664645 if (x >= 0 && x <= Terrarium.MAX_X && y >= 0 && y <= Terrarium.MAX_Y) {
665646 ObjEX.Direction dir;
666647 switch (s2.getSelectedIndex()) {
667- case BACK:
668- default:
669- dir = ObjEX.Direction.BACK;
670- break;
671- case THISSIDE:
672- dir = ObjEX.Direction.THISSIDE;
673- break;
674- case RIGHT:
675- dir = ObjEX.Direction.RIGHT;
676- break;
677- case LEFT:
678- dir = ObjEX.Direction.LEFT;
679- break;
648+ case BACK:
649+ default:
650+ dir = ObjEX.Direction.BACK;
651+ break;
652+ case THISSIDE:
653+ dir = ObjEX.Direction.THISSIDE;
654+ break;
655+ case RIGHT:
656+ dir = ObjEX.Direction.RIGHT;
657+ break;
658+ case LEFT:
659+ dir = ObjEX.Direction.LEFT;
660+ break;
680661 }
681- mypane.terrarium.buyObjEx(BELTCONVEYOR,x, y, dir);
662+ mypane.terrarium.buyObjEx(BELTCONVEYOR, x, y, dir);
682663 }
683- }
684- break;
685-
686- case BREEDINGPOOL: {
687- int x = Translate.invX(e.getX(), e.getY(), BreedingPool.getSizeS(), w, h);
688- int y = Translate.invY(e.getX(), e.getY(), BreedingPool.getSizeS() / 2, w, h);
664+ break;
665+ case BREEDINGPOOL:
666+ x = Translate.invX(e.getX(), e.getY(), BreedingPool.getSizeS(), w, h);
667+ y = Translate.invY(e.getX(), e.getY(), BreedingPool.getSizeS() / 2, w, h);
689668 if (x >= 0 && x <= Terrarium.MAX_X && y >= 0 && y <= Terrarium.MAX_Y) {
690669 ObjEX.Direction dir;
691670 switch (s2.getSelectedIndex()) {
@@ -705,72 +684,73 @@
705684 }
706685 mypane.terrarium.buyObjEx(BREEDINGPOOL, x, y, dir);
707686 }
708- }
709- break;
710-
711- case GARBAGECHUTE: {
712- int x = Translate.invX(e.getX(), e.getY(), GarbageChute.getSizeS(), w, h);
713- int y = Translate.invY(e.getX(), e.getY(), GarbageChute.getSizeS() / 2, w, h);
687+ break;
688+ case GARBAGECHUTE:
689+ x = Translate.invX(e.getX(), e.getY(), GarbageChute.getSizeS(), w, h);
690+ y = Translate.invY(e.getX(), e.getY(), GarbageChute.getSizeS() / 2, w, h);
714691 if (x >= 0 && x <= Terrarium.MAX_X && y >= 0 && y <= Terrarium.MAX_Y) {
715692 mypane.terrarium.buyObjEx(GARBAGECHUTE, x, y, ObjEX.Direction.BACK);
716693 }
717- }
718- break;
719-
720- case MACHINEPRESS: {
721- int x = Translate.invX(e.getX(), e.getY(), MachinePress.getSizeS(), w, h);
722- int y = Translate.invY(e.getX(), e.getY(), MachinePress.getSizeS() / 2, w, h);
694+ break;
695+ case MACHINEPRESS:
696+ x = Translate.invX(e.getX(), e.getY(), MachinePress.getSizeS(), w, h);
697+ y = Translate.invY(e.getX(), e.getY(), MachinePress.getSizeS() / 2, w, h);
723698 if (x >= 0 && x <= Terrarium.MAX_X && y >= 0 && y <= Terrarium.MAX_Y) {
724699 mypane.terrarium.buyObjEx(MACHINEPRESS, x, y, ObjEX.Direction.BACK);
725700 }
726- }
727- break;
728-
729- case FOODMAKER: {
730- int x = Translate.invX(e.getX(), e.getY(), FoodMaker.getSizeS(), w, h);
731- int y = Translate.invY(e.getX(), e.getY(), FoodMaker.getSizeS() / 2, w, h);
701+ break;
702+ case FOODMAKER:
703+ x = Translate.invX(e.getX(), e.getY(), FoodMaker.getSizeS(), w, h);
704+ y = Translate.invY(e.getX(), e.getY(), FoodMaker.getSizeS() / 2, w, h);
732705 if (x >= 0 && x <= Terrarium.MAX_X && y >= 0 && y <= Terrarium.MAX_Y) {
733706 mypane.terrarium.buyObjEx(FOODMAKER, x, y, ObjEX.Direction.BACK);
734707 }
735- }
736- break;
737-
738- case ORANGEPOOL: {
739- int x = Translate.invX(e.getX(), e.getY(), OrangePool.getSizeS(), w, h);
740- int y = Translate.invY(e.getX(), e.getY(), OrangePool.getSizeS() / 2, w, h);
708+ break;
709+ case ORANGEPOOL:
710+ x = Translate.invX(e.getX(), e.getY(), OrangePool.getSizeS(), w, h);
711+ y = Translate.invY(e.getX(), e.getY(), OrangePool.getSizeS() / 2, w, h);
741712 if (x >= 0 && x <= Terrarium.MAX_X && y >= 0 && y <= Terrarium.MAX_Y) {
742713 ObjEX.Direction dir;
743714 switch (s2.getSelectedIndex()) {
744- case BACK:
745- default:
746- dir = ObjEX.Direction.BACK;
747- break;
748- case THISSIDE:
749- dir = ObjEX.Direction.THISSIDE;
750- break;
751- case RIGHT:
752- dir = ObjEX.Direction.BACK;
753- break;
754- case LEFT:
755- dir = ObjEX.Direction.BACK;
756- break;
715+ case BACK:
716+ default:
717+ dir = ObjEX.Direction.BACK;
718+ break;
719+ case THISSIDE:
720+ dir = ObjEX.Direction.THISSIDE;
721+ break;
722+ case RIGHT:
723+ dir = ObjEX.Direction.BACK;
724+ break;
725+ case LEFT:
726+ dir = ObjEX.Direction.BACK;
727+ break;
757728 }
758729 mypane.terrarium.buyObjEx(ORANGEPOOL, x, y, dir);
759730 }
760- }
761- break;
762-
763- case PRODUCTCHUTE: {
764- int x = Translate.invX(e.getX(), e.getY(), ProductChute.getSizeS(), w, h);
765- int y = Translate.invY(e.getX(), e.getY(), ProductChute.getSizeS() / 2, w, h);
731+ break;
732+ case PRODUCTCHUTE:
733+ x = Translate.invX(e.getX(), e.getY(), ProductChute.getSizeS(), w, h);
734+ y = Translate.invY(e.getX(), e.getY(), ProductChute.getSizeS() / 2, w, h);
766735 if (x >= 0 && x <= Terrarium.MAX_X && y >= 0 && y <= Terrarium.MAX_Y) {
767736 mypane.terrarium.buyObjEx(PRODUCTCHUTE, x, y, ObjEX.Direction.BACK);
768737 }
769- }
770- break;
771-
772- default://Other tool
773738 break;
739+ case BARRIER:
740+ if (s2.getSelectedIndex() != DEL) {
741+ break;
742+ }
743+ // fall through
744+ case CLEAN:
745+ x = Translate.invX(e.getX(), e.getY(), 0, size.width, size.height);
746+ y = Translate.invY(e.getX(), e.getY(), 0, size.width, size.height);
747+ Barrier barrier = Terrarium.getBarrier(x, y, 10);
748+ if (barrier != null) {
749+ Terrarium.clearBarrier(barrier);
750+ }
751+ break;
752+ default:// Other tool
753+ break;
774754 }
775755 }
776756 }
@@ -1056,7 +1036,7 @@
10561036
10571037 // make initial bodies
10581038 initBodies();
1059- synchronized(SimYukkuri.lock) {
1039+ synchronized (SimYukkuri.lock) {
10601040 SimYukkuri.initialized = true;
10611041 }
10621042 // run animation
@@ -1766,14 +1746,14 @@
17661746
17671747 final class ObjComp implements Comparator<Obj> {
17681748 final static ObjComp INSTANCE = new ObjComp();
1769- //Painter's Algorithm / 画家のアルゴリズム
1770- @Override final public int compare(Obj o1, Obj o2) {
1749+ // Painter's Algorithm / 画家のアルゴリズム
1750+ @Override
1751+ final public int compare(Obj o1, Obj o2) {
17711752 int c = o1.y - o2.y;
1772- if(c == 0) {
1773- //Improve visibility: at the same y-coordinate, draw small
1774- //objects after large ones.
1775- c = (o2 instanceof Body ? ((Body)o2).getAgeState().ordinal() : 1) -
1776- (o1 instanceof Body ? ((Body)o1).getAgeState().ordinal() : 1);
1753+ if (c == 0) {
1754+ // Improve visibility: at the same y-coordinate, draw small
1755+ // objects after large ones.
1756+ c = (o2 instanceof Body ? ((Body)o2).getAgeState().ordinal() : 1) - (o1 instanceof Body ? ((Body)o1).getAgeState().ordinal() : 1);
17771757 }
17781758 return c;
17791759 }
Show on old repository browser