From 7283153f442b2fd89f0a866eaa6f8888b70d6d77 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 2 Sep 2018 13:46:57 +0900 Subject: [PATCH] =?UTF-8?q?contraint=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/Constraint/Constraint.php | 42 +++++++++++++++------- hwe/sammo/Constraint/NoWanderingNation.php | 2 +- hwe/sammo/Constraint/OccupiedCity.php | 37 +++++++++++++++++++ hwe/sammo/Constraint/ReqGeneralGold.php | 32 +++++++++++++++++ hwe/sammo/Constraint/ReqGeneralRice.php | 32 +++++++++++++++++ hwe/sammo/Constraint/SuppliedCity.php | 32 +++++++++++++++++ 6 files changed, 164 insertions(+), 13 deletions(-) create mode 100644 hwe/sammo/Constraint/OccupiedCity.php create mode 100644 hwe/sammo/Constraint/ReqGeneralGold.php create mode 100644 hwe/sammo/Constraint/ReqGeneralRice.php create mode 100644 hwe/sammo/Constraint/SuppliedCity.php diff --git a/hwe/sammo/Constraint/Constraint.php b/hwe/sammo/Constraint/Constraint.php index d34095a0..9852b5f6 100644 --- a/hwe/sammo/Constraint/Constraint.php +++ b/hwe/sammo/Constraint/Constraint.php @@ -10,10 +10,13 @@ abstract class Constraint{ const REQ_CITY = 0x20; const REQ_NATION = 0x40; const REQ_ARG = 0x80; - const REQ_STRING_ARG = self::REQ_ARG | 0x100; - const REQ_INT_ARG = self::REQ_ARG | 0x200; - const REQ_NUMERIC_ARG = self::REQ_ARG | 0x400; - const REQ_ARRAY_ARG = self::REQ_ARG | 0x800; + const REQ_DEST_GENERAL = 0x100; + const REQ_DEST_CITY = 0x200; + const REQ_DEST_NATION = 0x400; + const REQ_STRING_ARG = self::REQ_ARG | 0x1000; + const REQ_INT_ARG = self::REQ_ARG | 0x2000; + const REQ_NUMERIC_ARG = self::REQ_ARG | 0x4000; + const REQ_ARRAY_ARG = self::REQ_ARG | 0x8000; const REQ_VALUES = 0; @@ -94,22 +97,37 @@ abstract class Constraint{ public function checkInputValues(bool $throwExeception=true):bool{ $valueType = static::requiredValueType(); - if(($valueType&REQ_GENERAL) && $this->general === null){ + if(($valueType&static::REQ_GENERAL) && $this->general === null){ if(!$throwExeception){return false; } throw new \InvalidArgumentException('require general'); } - if(($valueType&REQ_CITY) && $this->city === null){ + if(($valueType&static::REQ_CITY) && $this->city === null){ if(!$throwExeception){return false; } throw new \InvalidArgumentException('require city'); } - if(($valueType&REQ_NATION) && $this->nation === null){ + if(($valueType&static::REQ_NATION) && $this->nation === null){ if(!$throwExeception){return false; } throw new \InvalidArgumentException('require nation'); } - if (!($valueType&REQ_ARG)) { + if(($valueType&static::REQ_DEST_GENERAL) && $this->destGeneral === null){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException('require dest general'); + } + + if(($valueType&static::REQ_DEST_CITY) && $this->destCity === null){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException('require dest city'); + } + + if(($valueType&static::REQ_DEST_NATION) && $this->destNation === null){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException('require dest nation'); + } + + if (!($valueType&static::REQ_ARG)) { return true; } @@ -118,22 +136,22 @@ abstract class Constraint{ throw new \InvalidArgumentException('require arg'); } - if(($valueType&REQ_STRING_ARG) && !is_string($this->arg)){ + if(($valueType&static::REQ_STRING_ARG) && !is_string($this->arg)){ if(!$throwExeception){return false; } throw new \InvalidArgumentException('require string arg'); } - if(($valueType&REQ_INT_ARG) && !is_int($this->arg)){ + if(($valueType&static::REQ_INT_ARG) && !is_int($this->arg)){ if(!$throwExeception){return false; } throw new \InvalidArgumentException('require int arg'); } - if(($valueType&REQ_NUMERIC_ARG) && !is_numeric($this->arg)){ + if(($valueType&static::REQ_NUMERIC_ARG) && !is_numeric($this->arg)){ if(!$throwExeception){return false; } throw new \InvalidArgumentException('require numeric arg'); } - if(!($valueType&REQ_ARRAY_ARG) && !is_array($this->arg)){ + if(!($valueType&static::REQ_ARRAY_ARG) && !is_array($this->arg)){ if(!$throwExeception){return false; } throw new \InvalidArgumentException('require array arg'); } diff --git a/hwe/sammo/Constraint/NoWanderingNation.php b/hwe/sammo/Constraint/NoWanderingNation.php index 69628e17..6291b7b3 100644 --- a/hwe/sammo/Constraint/NoWanderingNation.php +++ b/hwe/sammo/Constraint/NoWanderingNation.php @@ -2,7 +2,7 @@ namespace sammo\Constraint; -class NoOpeningPart extends Constraint{ +class NoWanderingNation extends Constraint{ const REQ_VALUES = Constraint::REQ_NATION; public function checkInputValues(bool $throwExeception=true){ diff --git a/hwe/sammo/Constraint/OccupiedCity.php b/hwe/sammo/Constraint/OccupiedCity.php new file mode 100644 index 00000000..76953123 --- /dev/null +++ b/hwe/sammo/Constraint/OccupiedCity.php @@ -0,0 +1,37 @@ +general)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require nation in general"); + } + + if(!key_exists('nation', $this->city)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require nation in city"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->city['nation'] == $this->general['nation']){ + return true; + } + + $this->reason = "아국이 아닙니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/ReqGeneralGold.php b/hwe/sammo/Constraint/ReqGeneralGold.php new file mode 100644 index 00000000..2d33f0b9 --- /dev/null +++ b/hwe/sammo/Constraint/ReqGeneralGold.php @@ -0,0 +1,32 @@ +general)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require gold in general"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->general['gold'] < $this->arg){ + return true; + } + + $this->reason = "자금이 모자랍니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/ReqGeneralRice.php b/hwe/sammo/Constraint/ReqGeneralRice.php new file mode 100644 index 00000000..40d3246a --- /dev/null +++ b/hwe/sammo/Constraint/ReqGeneralRice.php @@ -0,0 +1,32 @@ +general)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require rice in general"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->general['rice'] < $this->arg){ + return true; + } + + $this->reason = "군량이 모자랍니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/SuppliedCity.php b/hwe/sammo/Constraint/SuppliedCity.php new file mode 100644 index 00000000..5530126f --- /dev/null +++ b/hwe/sammo/Constraint/SuppliedCity.php @@ -0,0 +1,32 @@ +city)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require supply in city"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->city['supply']){ + return true; + } + + $this->reason = "고립된 도시입니다."; + return false; + } +} \ No newline at end of file