From 261156f6f01f7a219bd2501837c07a8c8dfb2eca Mon Sep 17 00:00:00 2001 From: Sachit1137 <55988870+Sachit1137@users.noreply.github.com> Date: Sat, 11 Jul 2020 20:47:34 -0400 Subject: [PATCH] Added my code --- ch-1(Guitar_Shop)/FindGuitarTester.py | 49 +++++++++++ .../__pycache__/guitar.cpython-37.pyc | Bin 0 -> 473 bytes .../__pycache__/guitarSpec.cpython-37.pyc | Bin 0 -> 1001 bytes .../__pycache__/inventory.cpython-37.pyc | Bin 0 -> 1619 bytes ch-1(Guitar_Shop)/guitar.py | 5 ++ ch-1(Guitar_Shop)/guitarSpec.py | 25 ++++++ ch-1(Guitar_Shop)/inventory.py | 32 ++++++++ ch-2,3,4(Dog_Door)/Bark.py | 10 +++ ch-2,3,4(Dog_Door)/BarkRecognizer.py | 16 ++++ ch-2,3,4(Dog_Door)/DogDoor.py | 29 +++++++ ch-2,3,4(Dog_Door)/DogDoorSimulator.py | 35 ++++++++ ch-2,3,4(Dog_Door)/Remote.py | 11 +++ .../__pycache__/Bark.cpython-37.pyc | Bin 0 -> 703 bytes .../__pycache__/BarkRecognizer.cpython-37.pyc | Bin 0 -> 788 bytes .../__pycache__/DogDoor.cpython-37.pyc | Bin 0 -> 1286 bytes .../__pycache__/Remote.cpython-37.pyc | Bin 0 -> 679 bytes .../FindGuitarTester.py | 76 ++++++++++++++++++ .../Instrument.py | 9 +++ .../InstrumentSpec.py | 17 ++++ .../__pycache__/Instrument.cpython-37.pyc | Bin 0 -> 648 bytes .../__pycache__/InstrumentSpec.cpython-37.pyc | Bin 0 -> 1010 bytes .../__pycache__/Mandolin.cpython-37.pyc | Bin 0 -> 694 bytes .../__pycache__/MandolinSpec.cpython-37.pyc | Bin 0 -> 866 bytes .../__pycache__/guitar.cpython-37.pyc | Bin 0 -> 693 bytes .../__pycache__/guitarSpec.cpython-37.pyc | Bin 0 -> 845 bytes .../__pycache__/inventory.cpython-37.pyc | Bin 0 -> 1047 bytes .../inventory.py | 19 +++++ ch-7(Game System Framework)/Board/Board.py | 27 +++++++ ch-7(Game System Framework)/Board/Tile.py | 18 +++++ ch-7(Game System Framework)/Units/Units.py | 6 ++ 30 files changed, 384 insertions(+) create mode 100644 ch-1(Guitar_Shop)/FindGuitarTester.py create mode 100644 ch-1(Guitar_Shop)/__pycache__/guitar.cpython-37.pyc create mode 100644 ch-1(Guitar_Shop)/__pycache__/guitarSpec.cpython-37.pyc create mode 100644 ch-1(Guitar_Shop)/__pycache__/inventory.cpython-37.pyc create mode 100644 ch-1(Guitar_Shop)/guitar.py create mode 100644 ch-1(Guitar_Shop)/guitarSpec.py create mode 100644 ch-1(Guitar_Shop)/inventory.py create mode 100644 ch-2,3,4(Dog_Door)/Bark.py create mode 100644 ch-2,3,4(Dog_Door)/BarkRecognizer.py create mode 100644 ch-2,3,4(Dog_Door)/DogDoor.py create mode 100644 ch-2,3,4(Dog_Door)/DogDoorSimulator.py create mode 100644 ch-2,3,4(Dog_Door)/Remote.py create mode 100644 ch-2,3,4(Dog_Door)/__pycache__/Bark.cpython-37.pyc create mode 100644 ch-2,3,4(Dog_Door)/__pycache__/BarkRecognizer.cpython-37.pyc create mode 100644 ch-2,3,4(Dog_Door)/__pycache__/DogDoor.cpython-37.pyc create mode 100644 ch-2,3,4(Dog_Door)/__pycache__/Remote.cpython-37.pyc create mode 100644 ch-5(added_support_for_other instruments_in_guitar_shop)/FindGuitarTester.py create mode 100644 ch-5(added_support_for_other instruments_in_guitar_shop)/Instrument.py create mode 100644 ch-5(added_support_for_other instruments_in_guitar_shop)/InstrumentSpec.py create mode 100644 ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/Instrument.cpython-37.pyc create mode 100644 ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/InstrumentSpec.cpython-37.pyc create mode 100644 ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/Mandolin.cpython-37.pyc create mode 100644 ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/MandolinSpec.cpython-37.pyc create mode 100644 ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/guitar.cpython-37.pyc create mode 100644 ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/guitarSpec.cpython-37.pyc create mode 100644 ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/inventory.cpython-37.pyc create mode 100644 ch-5(added_support_for_other instruments_in_guitar_shop)/inventory.py create mode 100644 ch-7(Game System Framework)/Board/Board.py create mode 100644 ch-7(Game System Framework)/Board/Tile.py create mode 100644 ch-7(Game System Framework)/Units/Units.py diff --git a/ch-1(Guitar_Shop)/FindGuitarTester.py b/ch-1(Guitar_Shop)/FindGuitarTester.py new file mode 100644 index 0000000..755c79f --- /dev/null +++ b/ch-1(Guitar_Shop)/FindGuitarTester.py @@ -0,0 +1,49 @@ +import inventory +import guitar +import guitarSpec +import enum + + +class Type(enum.Enum): + ACOUSTIC = "ACOUSTIC" + ELECTRIC = "ELECTRIC" + + +class Builder(enum.Enum): + FENDER = "FENDER" + MARTIN = "MARTIN" + GIBSON = "GIBSON" + + +class Wood(enum.Enum): + CEDAR = "CEDAR" + MAPLE = "MAPLE" + COCOBOLO = "COCOBOLO" + ALDER = "ALDER" + + +class FindGuitarTester(): + def main(self): + num_of_strings = 12 + self.inv = inventory.Inventory() + + customer_guitar = guitarSpec.GuitarSpec( + Builder.FENDER, "Sratocastor", Type.ELECTRIC, Wood.ALDER, Wood.ALDER, num_of_strings) + self.initialize_inventory() + + gtrs_found = self.inv.search(customer_guitar) + print("Not found") if not gtrs_found else self.inv.display_guitar(gtrs_found) + + def initialize_inventory(self): + guitar_spec1 = guitarSpec.GuitarSpec(Builder.FENDER, + "abc", Type.ELECTRIC, Wood.ALDER, Wood.ALDER,12) + guitar_spec2 = guitarSpec.GuitarSpec(Builder.FENDER, + "sratocastor", Type.ELECTRIC, Wood.ALDER, Wood.ALDER,12) + self.inv.add_guitar("V95693", 1499.95, guitar_spec1) + self.inv.add_guitar("V95123", 1543.95, guitar_spec2) + self.inv.add_guitar("V54312", 1249.95, guitar_spec2) + + + +obj = FindGuitarTester() +obj.main() diff --git a/ch-1(Guitar_Shop)/__pycache__/guitar.cpython-37.pyc b/ch-1(Guitar_Shop)/__pycache__/guitar.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..235a37091df0856a5b43bf873ba78643d59e2bce GIT binary patch literal 473 zcmYjM%}T>S5T4!CHdc!u;@OkXg9Wczq}oDHrb2HaIK=F>T}aZp+Z>eK?91po_#%7t z5d;sOoK2{7mhYR{*>8UKuG47)+4axo;|KXKciEap!GK_niN+v6unpmjhamVAx?V#0 zf8!Jl2V8#H{p)xd5tU zLD#cwBejZC%!|zKt+Yy{J(ySh(5z%a?Hfj>Gutw{5^1-;b|cIuEoi}evzuGWZdW78x8)}-@# zRR5~CeGh0A66bLy5p5eWTZ$re@gd@K5vTQw-lq=LVmsu!9CNJ+#!d2Bbq~6=-_g21 QX;)zVem&yGReclS4_SU{zyJUM literal 0 HcmV?d00001 diff --git a/ch-1(Guitar_Shop)/__pycache__/guitarSpec.cpython-37.pyc b/ch-1(Guitar_Shop)/__pycache__/guitarSpec.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..985d0d94d3a4b3d670ab8960c7d7a51533972d12 GIT binary patch literal 1001 zcmZvbzi-n(6vyw*Kby2mkr)s{r~|?Sl~@r%fmUi4QlxB_#mVuxiBl&|-#JvRywS0L z1dJ^G3-}9|IxyYJ)R~Qm_s&Vkz*+D6-km@9&Uf$pZfB>%u-*Om{&Cl1>=$)b&B36D zrgu?}m|}`wqkR@JQ)0j(C&Te|6BzZ-^kbBq#ayviD6Ygciyh@C7rm=IoadX)(W0nR z7|io53lOJ9o^l+Z>E|d7ZKcmKNJoKjbzYtVEe^EjxI40+XA{K!(9Vhd zy7dmu{l;Jm!9P9qDtSLh4l0G2lEYjVquJ9BPz}p`s*`b^DtTIfuI0(e+h>PKHh%Fk zX>-%o_ve=;l(Lu=wUo55-bP{EUq4q5{vFi*ip&V5Mt*%_Ke5w@34=XS#m}5JYWRdt z81<-T_)fqvsU>Xm#rcY7jg&y@cuBc1LCUq1jV$3JFW}nQ?s0LYAQs*gTV_VHu=yx#PXKeFI&4$}9BL8A_{lOhLopa5((tkI%NZLjvR7KY#!3d4&9n zi}i4Uc?!SY10sl^IfN25V1qaS(`Z@d> zy+}z#H~@qL^l(D!LAuOLtazSj14~!S{PZuPz)kYs6R|)2$vv0ngW@`wK7MFFvc~)eGbBvNk9E7fh9m+@R?F9F6 z;M{}X!uV~lpyfK3~)|f{d%o~NoIs{q>0t04I{|U^+J3|bu=rw!? zno$BP>(4_nbK13w{=wRvd9B3jBz`OLJ4vsV^g2nZ`b`! zBSgvh&T$jH@NgA0VH)qh$0}LvXsNO|A48;0q}pE%PnKCOq#D1LN@ry;{&BqOnahPl zW^fWGul^`Yfs4?Ti{q9LY>ZL*F&G+`r(c-Lxh!lt3KNCRy_g}j z1wf)+dvWBa9Pf+zcp1mrq5!V4oEo6&01ol?f{A0(9raVAw5{iwX7}^EBQm|nCr+V86J87xwA#V)?L zl}X?=YHD-u%Bcu+7f34SA*tvsQ=^LAxN8aa+xh62pcnXLc}NYIl>0M(J=8 z;Nw!nbIExfay~D`GDm)k^Ydk#H#-V@SZyQu1jz`=10)!jI|O@QVLPKo_V$1V4t#^a qw{q~Q4_n}beOivd**a|c2YIV=$DTEBAC%yS2HIonF^xF^%k+PX{B>6V literal 0 HcmV?d00001 diff --git a/ch-1(Guitar_Shop)/guitar.py b/ch-1(Guitar_Shop)/guitar.py new file mode 100644 index 0000000..8db93e6 --- /dev/null +++ b/ch-1(Guitar_Shop)/guitar.py @@ -0,0 +1,5 @@ +class Guitar: + def __init__(self, srl_num, price, guitar_spec): + self.serial_num = srl_num + self.price = price + self.guitar_spec = guitar_spec \ No newline at end of file diff --git a/ch-1(Guitar_Shop)/guitarSpec.py b/ch-1(Guitar_Shop)/guitarSpec.py new file mode 100644 index 0000000..6d5a54b --- /dev/null +++ b/ch-1(Guitar_Shop)/guitarSpec.py @@ -0,0 +1,25 @@ +class GuitarSpec: + + def __init__(self, builder, model, guitar_type, b_wood, t_wood, num): + self.builder = builder + self.model = model + self.g_type = guitar_type + self.back_wood = b_wood + self.top_wood = t_wood + self.num_strings = num + + def match_specs(self,guitar_inv,gtr_to_search): + if gtr_to_search.builder and gtr_to_search.builder != "" and gtr_to_search.builder != guitar_inv.guitar_spec.builder: + return 0 + if gtr_to_search.model and gtr_to_search.model != "" and gtr_to_search.model.lower() != guitar_inv.guitar_spec.model: + return 0 + if gtr_to_search.g_type and gtr_to_search.g_type != "" and gtr_to_search.g_type != guitar_inv.guitar_spec.g_type: + return 0 + if gtr_to_search.back_wood and gtr_to_search.back_wood != "" and gtr_to_search.back_wood != guitar_inv.guitar_spec.back_wood: + return 0 + if gtr_to_search.top_wood and gtr_to_search.top_wood != "" and gtr_to_search.top_wood != guitar_inv.guitar_spec.top_wood: + return 0 + if gtr_to_search.num_strings and gtr_to_search.num_strings != 0 and gtr_to_search.num_strings != guitar_inv.guitar_spec.num_strings: + return 0 + + return 1 \ No newline at end of file diff --git a/ch-1(Guitar_Shop)/inventory.py b/ch-1(Guitar_Shop)/inventory.py new file mode 100644 index 0000000..0b4d717 --- /dev/null +++ b/ch-1(Guitar_Shop)/inventory.py @@ -0,0 +1,32 @@ +import guitar +import guitarSpec +class Inventory(guitarSpec.GuitarSpec): + def __init__(self): + self.guitar_list = [] + + def add_guitar(self, srl_num, price, guitar_spec): + self.guitar_list.append(guitar.Guitar(srl_num, price, guitar_spec)) + + def display_guitar(self, gtrs_list): + for i in range(len(gtrs_list)): + print("Guitar :", i+1) + print("serial number:", gtrs_list[i].serial_num) + print("builder version = ", gtrs_list[i].guitar_spec.builder) + print("type = ", gtrs_list[i].guitar_spec.g_type) + print("backwood = ", gtrs_list[i].guitar_spec.back_wood) + print("topWood = ", gtrs_list[i].guitar_spec.top_wood) + print("price = ", gtrs_list[i].price) + print("num of strings = ", gtrs_list[i].guitar_spec.num_strings) + + def get_guitar(self, srl_num): + for gtr in self.guitar_list: + if gtr.srl_num == srl_num: + return gtr + return None + + def search(self, gtr_to_search): + gtrs_found = [] + for i in range(len(self.guitar_list)): + if self.match_specs(self.guitar_list[i], gtr_to_search): + gtrs_found.append(self.guitar_list[i]) + return gtrs_found diff --git a/ch-2,3,4(Dog_Door)/Bark.py b/ch-2,3,4(Dog_Door)/Bark.py new file mode 100644 index 0000000..1d6b5e9 --- /dev/null +++ b/ch-2,3,4(Dog_Door)/Bark.py @@ -0,0 +1,10 @@ +class Bark: + def __init__(self,bark_sound): + self.bark_sound = bark_sound + + def get_sound(self): + return self.bark_sound + + #compares 2 bark objects + def equals(self,stored_bark): + return True if self.get_sound().lower().__eq__(stored_bark.get_sound().lower()) else False \ No newline at end of file diff --git a/ch-2,3,4(Dog_Door)/BarkRecognizer.py b/ch-2,3,4(Dog_Door)/BarkRecognizer.py new file mode 100644 index 0000000..ca0aef3 --- /dev/null +++ b/ch-2,3,4(Dog_Door)/BarkRecognizer.py @@ -0,0 +1,16 @@ +import DogDoor +import Bark +class BarkRecognizer: + def __init__(self,dog_door): + self.dog_door = dog_door + + # Listens to the barking and sends the request to the DogDoor class to open the door + def recognize(self,bark_heard,time): + # check if bark_heard is stored in the dog door + for bark in self.dog_door.bark: + if bark_heard.equals(bark): + print("Door opens after hearing Bruce bark") + self.dog_door.open(time) + return + + print("Bark not recognized") \ No newline at end of file diff --git a/ch-2,3,4(Dog_Door)/DogDoor.py b/ch-2,3,4(Dog_Door)/DogDoor.py new file mode 100644 index 0000000..7742e75 --- /dev/null +++ b/ch-2,3,4(Dog_Door)/DogDoor.py @@ -0,0 +1,29 @@ +import time +class DogDoor: + def __init__(self): + self.door_open = False + self.bark = [] + + #store the owner's dog's bark + def store_bark(self,bark): + self.bark = [brk for brk in bark] + + #open the door + def open(self,t): + self.door_open = True + self.wait(t) + self.close() + + #close the door + def close(self): + self.door_open = False + + #check if the door is open + def is_open(self): + return self.door_open + + # wait for 5 seconds and then close the door + def wait(self,t): + for i in range(t): + time.sleep(1) + \ No newline at end of file diff --git a/ch-2,3,4(Dog_Door)/DogDoorSimulator.py b/ch-2,3,4(Dog_Door)/DogDoorSimulator.py new file mode 100644 index 0000000..3a38121 --- /dev/null +++ b/ch-2,3,4(Dog_Door)/DogDoorSimulator.py @@ -0,0 +1,35 @@ +import DogDoor +# import Remote +import BarkRecognizer +import Bark +class DogDoorSimulator: + + def main(self): + no_of_barks = 3 + dog_door = DogDoor.DogDoor() + # store multiple barks in the dog door + barks = [] + for i in range(no_of_barks): + barks.append(Bark.Bark("bark"+str(i+1))) + dog_door.store_bark(barks) + print("Bruce starts barking") + #call bark recognizer to recognize the sound + bark_recognizer = BarkRecognizer.BarkRecognizer(dog_door) + bark_recognizer.recognize(Bark.Bark("bark2"),3) + print("Bruce has gone outside...") + print("Bruce's all done ...") + print("... but he is stuck outside") + + #Simulate a bark of neighbor's dog + print("Neighbor's dog start barking") + bark_recognizer.recognize(Bark.Bark("yip"),3) + + #Simulate hardware hearing another bark + print("Bruce starts barking") + bark_recognizer.recognize(Bark.Bark("bark1"),3) + print("Bruce is back inside") + # print("Check if door is closed") + # print("Door is open") if dog_door.is_open() else print("Door is closed") + +obj = DogDoorSimulator() +obj.main() \ No newline at end of file diff --git a/ch-2,3,4(Dog_Door)/Remote.py b/ch-2,3,4(Dog_Door)/Remote.py new file mode 100644 index 0000000..37e4e19 --- /dev/null +++ b/ch-2,3,4(Dog_Door)/Remote.py @@ -0,0 +1,11 @@ +class Remote: + def __init__(self,dog_door): + self.dog_door = dog_door + + def press_button(self,time): + if self.dog_door.is_open(): + print("Closing the door...") + self.dog_door.close() + else: + print("Opening the door...") + self.dog_door.open(time) \ No newline at end of file diff --git a/ch-2,3,4(Dog_Door)/__pycache__/Bark.cpython-37.pyc b/ch-2,3,4(Dog_Door)/__pycache__/Bark.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6d8c2b9069c1bf72033ed6687c46946cfe024533 GIT binary patch literal 703 zcmZuu!A{&j4D}@05EizFen3?rR4IpY;D}JQ1yoL5DlMldsL4<0i;} zf-$7wjPIW%U~kB<+pIKXiXaO}QE&@cNFhaRBkEDiwnuB6pSb8?VlHQrDI!*I$go1I zQ4Jv1<+o~-D%YR#bF}rUqBL-k)#aIygr8s{HV=EWmwz7Thcy+|JU`O5m{)JVn0i|3 zh0V|Pgz&5|c8Mn^AKxA2v-9`6xiHxI_T43jMO7>jhaO7&-JpUFUPLPD_`U}^w&6~Enj7eod)jU9_|z)XjJFlEAxib z_-Q4h(@$w=)}&gmtgp3kF`~XgOao6T+px>pXu>J?{V%^*U#%vkU4KDt!;@?8M`z!pDhZRw-|?2c{a=zx_S=FV JB>N8o9s#dfkCgxb literal 0 HcmV?d00001 diff --git a/ch-2,3,4(Dog_Door)/__pycache__/BarkRecognizer.cpython-37.pyc b/ch-2,3,4(Dog_Door)/__pycache__/BarkRecognizer.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a1def8d711129adfe7593a8480c16e83c48104b4 GIT binary patch literal 788 zcmZuuv2N5r5Zzg?FUGp0p&$i?1yUpzq)3Sn3KvUMTo5UcEW^t2?l}%V`?B^)U^!Lt zAxX(+@Ea>SDt>{A8Cw?uVx-xb-I;mwW_Gr{?K6~b;`_&lGxmcn8*$J%L~Wknp_qb_ z#iNB7UNgm&bIp`<#bd7EgoWZK=COH3=SC27#CVL3W-%y6*@|DY*inuWXoYgIdSZ8G zsrmFyXLVi`oi-WOl8_}mLT!j{4?UB}1gl^kg7s9LOI6n<Wy(r1fo*g8AGudB#v7VGgRkTtH zVlhyI?$JMao1BdLlTb40K>ZM%&j&p_XXg;H4||tR4>!DbZo&Aiqu>gFQS?Ui{1$y0 z@WOx3Fvcl14D8IirxA`C)GJ*zLAq$Q32+F5!v!<5&UA2!YwR8pwV{Es$SY<_9EVc3QdD!Q8Oz>(S+(A>cnc~6t4*1}~ z6g=MT5{Ew@x__5G4_#Vll`gfE)|YZwt942KR7zqsM$8rh8iKvonf}yJdqbZt<8 literal 0 HcmV?d00001 diff --git a/ch-2,3,4(Dog_Door)/__pycache__/DogDoor.cpython-37.pyc b/ch-2,3,4(Dog_Door)/__pycache__/DogDoor.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cb03ef7e44b3bd67bee257df74497c79ae96fb5d GIT binary patch literal 1286 zcmZux&2AGh5VrRx*=&=vDu_eHp{GiFph6r`S^69=sARr+TI60lS zk)vxIyjVUKBkdi=@+6|#QzAS1MPvoMZg%*~{`+o!FX!oK&~FQs4n~_FWPX^5q3R!t zn6sl)s)FtBzus#1ljCPE`tw@0$KQ3pSUO4z#*irGfgrR(Cu{bKJx;JzT&NdyKZcKz zkST4G3xmMa?sgVH@iGSQ!Ztt=;z4jur}T$&>UB#T1`NP;wx9RhLwRDpOHl>Ko3NFo zsz~zTc(;auFlvQNwrriM$faON&~_`!lQ>hmU|5%kN`w|U(g$VidkJ)S8zHa>2%W6| zpWqG^h|IL`DHvr7r(_1$t|$eZGv|s>m^;(XkC7|!zV^PxX`%fj%axedq-k-#A`hEh z$6Bz_*p`q^>b4#{TyT76nD8-_l`O`Hn!Lb*fsf&Csg(`*T!(Eq1;`DX!qj&s2j($o zF~pR7L0q&0aS_(T;dM1tW_+J4rC7Bo=4T5^F%EXhB-sSx+eSgA^a7^qpn2{TbOsL) zsXYxpSz52Ls>s#8j7I~Zy&@fop06??#z441+=LsNruP_@NG|>t=5ya%q8B^ViE8*h zM)6QErbEVtIX}zLt}}Le7H8#&#Cee`C{|G*pAuiRiNBQ7@Q%|g?ITiHK|ljP@PZ0# Y&z!(WJhHbQa@RqttYjCFo3;h?A2et4-2eap literal 0 HcmV?d00001 diff --git a/ch-2,3,4(Dog_Door)/__pycache__/Remote.cpython-37.pyc b/ch-2,3,4(Dog_Door)/__pycache__/Remote.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f066cf90af73ee522e8a799990ec79e0e516a3bb GIT binary patch literal 679 zcmZ8fy>1gh5T4n)GbhUt5~f7R719;BprD8%6mTRe?1)fVCsvMkV;{P^HM{2`mb>IZ zaLI#E({GzcNSBJ4JscTEnxFgTfA&5c9d&`|*YWSKUl8DqKlT)naZ2o-k@yG-6y6fw zh$$#>0a-LB{E-A%r^N0B2@O+JFck`wxP@t?A{CR4RYG|k-}$U7)95+pFtKJH5j!4e zi(8P?k)m;&p-+`rNM(%8gpZvruPlfE1RIljI8n#>r;B`KR8cSTGwq5+Jvg`KvecE! zmwKk;RbgEtCzJQD&hq*4^_#q%V7R*Wsgy-sG*WU&#{zKk^sj&K`)5=>Oc?bo8C&=U zKX3>3Wkc)UAht-f1BCiHVd4>sx40vJSSuQD`lHe~nt0GG^?;Wf4u_lmWTor>z$^*t z`X_~xhTJ|`*`jWIGN%IC$Bbpd@>o7@ib{vGv?5`!x3bzfdAV*HQ!^5d4A{jKdm_b6 ze}9gHxN(;7ZR%O2rSx4XE2GvW+dV12uV-cJu^p;sdo1`d4g@!{^i$Cxs3SX5OrwC% Vn+AOl9g@Se=}Ft^9p~K>!yne5m;3+# literal 0 HcmV?d00001 diff --git a/ch-5(added_support_for_other instruments_in_guitar_shop)/FindGuitarTester.py b/ch-5(added_support_for_other instruments_in_guitar_shop)/FindGuitarTester.py new file mode 100644 index 0000000..be4b148 --- /dev/null +++ b/ch-5(added_support_for_other instruments_in_guitar_shop)/FindGuitarTester.py @@ -0,0 +1,76 @@ +import inventory +import InstrumentSpec +import Instrument +import enum + +class Type(enum.Enum): + ACOUSTIC = "ACOUSTIC" + ELECTRIC = "ELECTRIC" + +class Builder(enum.Enum): + FENDER = "FENDER" + MARTIN = "MARTIN" + GIBSON = "GIBSON" + +class InstrumentCategory(enum.Enum): + GUITAR = "GUITAR" + MANDOLIN = "MANDOLIN" + BANJO = "BANJO" + DOBROS = "DOBROS" + FIDDLES = "FIDDLES" + +class Wood(enum.Enum): + CEDAR = "CEDAR" + MAPLE = "MAPLE" + COCOBOLO = "COCOBOLO" + ALDER = "ALDER" + +class Style(enum.Enum): + STYLE1 = "BOLLYWOOD" + STYLE2 = "HOLLYWOOD" + +class FindGuitarTester(): + def main(self): + self.num_of_strings = 12 + self.inv = inventory.Inventory() + + customer_specs = {"model":"abc"} + instr_spec = InstrumentSpec.InstrumentSpec(customer_specs) + self.initialize_inventory() + + instruments_found = self.inv.search(instr_spec) + + print("Instrument Not found") if not instruments_found else [print(i.srl_num) for i in instruments_found] + + def initialize_inventory(self): + specs1 = {"instrument":InstrumentCategory.GUITAR,"strings":12,"builder":Builder.FENDER, "type":Type.ELECTRIC, "model":"Sratocastor","back_wood":Wood.ALDER,"top_wood":Wood.ALDER } + instrument1 = Instrument.Instrument("1", 1499.95, specs1) + + specs2 = {"instrument":InstrumentCategory.GUITAR,"strings":10,"builder":Builder.FENDER, "type":Type.ELECTRIC, "model":"abc","back_wood":Wood.ALDER,"top_wood":Wood.ALDER } + instrument2 = Instrument.Instrument("2", 1543.95, specs2) + + specs3 = {"instrument":InstrumentCategory.GUITAR,"strings":12,"builder":Builder.FENDER, "type":Type.ELECTRIC, "model":"Sratocastor","back_wood":Wood.ALDER,"top_wood":Wood.ALDER } + instrument3 = Instrument.Instrument("3", 1249.95, specs3) + + specs4 = {"instrument":InstrumentCategory.MANDOLIN,"style":Style.STYLE1,"builder":Builder.FENDER, "type":Type.ELECTRIC, "model":"abc","back_wood":Wood.ALDER,"top_wood":Wood.ALDER } + instrument4 = Instrument.Instrument("4", 1543.95, specs4) + + specs5 = {"instrument":InstrumentCategory.MANDOLIN,"style":Style.STYLE2,"builder":Builder.FENDER, "type":Type.ELECTRIC, "model":"Sratocastor","back_wood":Wood.ALDER,"top_wood":Wood.ALDER } + instrument5 = Instrument.Instrument("5", 1249.95, specs5) + + specs6 = {"instrument":InstrumentCategory.BANJO,"builder":Builder.FENDER, "type":Type.ELECTRIC, "model":"abc","back_wood":Wood.ALDER,"top_wood":Wood.ALDER } + instrument6 = Instrument.Instrument("6", 1543.95, specs6) + + specs7 = {"instrument":InstrumentCategory.BANJO,"builder":Builder.FENDER, "type":Type.ELECTRIC, "model":"Sratocastor","back_wood":Wood.ALDER,"top_wood":Wood.ALDER } + instrument7 = Instrument.Instrument("7", 1249.95, specs7) + + self.inv.add_instrument(instrument1) + self.inv.add_instrument(instrument2) + self.inv.add_instrument(instrument3) + self.inv.add_instrument(instrument4) + self.inv.add_instrument(instrument5) + self.inv.add_instrument(instrument6) + self.inv.add_instrument(instrument7) + +obj = FindGuitarTester() +obj.main() \ No newline at end of file diff --git a/ch-5(added_support_for_other instruments_in_guitar_shop)/Instrument.py b/ch-5(added_support_for_other instruments_in_guitar_shop)/Instrument.py new file mode 100644 index 0000000..2c24241 --- /dev/null +++ b/ch-5(added_support_for_other instruments_in_guitar_shop)/Instrument.py @@ -0,0 +1,9 @@ +class Instrument(): + + def __init__(self, srl_num, price, spec): + self.srl_num = srl_num + self.price = price + self.instrument_spec = spec + + def get_spec(self): + return self.instrument_spec \ No newline at end of file diff --git a/ch-5(added_support_for_other instruments_in_guitar_shop)/InstrumentSpec.py b/ch-5(added_support_for_other instruments_in_guitar_shop)/InstrumentSpec.py new file mode 100644 index 0000000..6b1e5ee --- /dev/null +++ b/ch-5(added_support_for_other instruments_in_guitar_shop)/InstrumentSpec.py @@ -0,0 +1,17 @@ +import collections + +class InstrumentSpec(): + def __init__(self, spec): + self.spec = spec + + def get_all_specs(self): + return self.specs + + def get_spec(self, key_spec): + return self.specs[key_spec] + + def match_spec(self, instrument_spec): + for key in self.spec.keys(): + if key in instrument_spec and self.spec[key] != instrument_spec[key]: + return 0 + return 1 \ No newline at end of file diff --git a/ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/Instrument.cpython-37.pyc b/ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/Instrument.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1198003b8d1a2fca9c6a2f2747b9e4f264179fff GIT binary patch literal 648 zcmZuvJ5Ss|5Z?9UFeeaFkWx`lAzUOKO%x%LLqZfekmybpBjee-bL3ZM?E>Tu{tSO< z+jNnjp-YvSJC1zmUh;5wqQ4FlwSvO+3`--KmL>J_alU47qOLhNqQnsVhy@W&x)QiIg5AX8Vz$ z*S!MOdyKmG89h{7t;ezN)+`lJb)^d%$}{7(@|T8S83#=)oBppc}!Z!Qw6|J%H zx4`qXk||H zLEy-NSKvW><9g6kAu!0irGO0 z40y@{_MCwL=ahl-Ndz4DocZntu-Sf*n@X=Ul~?mp#WCfgLzZM8#SrY8*GwWZ{EE+f-na(CeSub`hnnDj zWx9vvcL|Tem-BGHfFxgpQ)QAxe)E+s-lZxt;Zj8)4-;)Fd2sOb_B4!__a5Gf02D~G zF3Un!^03e{i*hK^BsVh2;CyDSLD4qo_sASA9LA z+geO$@Tgag9?=3Gjb7tY;u1JBP0c$ag-|JN<04e!I~&|radv+<%c5)?eC=`=W>FO{ z?fV!r7$VO2HNL|=elqDa^Iz=DAJEYAC{t24Ln*TY)+zZTDUa4sx_Qww8ofn|dZf2W z(T-kFG*C?|Lkw(vk9!XN?5!_?D{+ygDz1_uH}>wr*EX5m3GeX+!xL(VorWj=0KIkN AhX4Qo literal 0 HcmV?d00001 diff --git a/ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/Mandolin.cpython-37.pyc b/ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/Mandolin.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..72a31d1cbaaa818d68e0ec5b3decfd6bc853fc2f GIT binary patch literal 694 zcmZWmy>8S%5T5lw@*fb6dE%4 z05Xu_24tw<60X8bNO2Bn^qc;`X~}kyaO=3IZJJNaUbbH> zlVWuN84zC|-UKJ?C2eC6K3NY*-42;G&3$An{DaE4&i1u39gdtV&&u*rM{}P%pDfiF zPw4i4&ncSj@a#-cD?~p-tQ*;D_V*A!_k|uK19&^Ut`*sPFS2o{s+PBPiaOzfT@S?0D2 z`#0R9KS%J?M?LLd@MP5_V@$(Tzf`JUSH0Kodc6+N`uXG6=O+^2H~(msPv8xG_5lS2 zN@OsE51^#-E0Qo=trIl z>}siv3lY;iEfFbEt}`9Aoo{tEF#(ae_IQ*bMr@1Z7YN7KI%k@&b))>DQ zg>tR3-Xq~|AtqUDE#i0hldG4blfmeHq0)RhI@UIw<_|xaVw~xP9nEyCaFQBZ;_2zz z$H${&_VoE-tdv$r-7O1K;-oOR*bZ%}Rh+KUGB#*u#WEWGFUPax+ORL&xMcw1t~kH9 zSJDidkfHVBon@<~dqH3;owyd}s1kEI_nKXaGsZCYHu*DYj+7jb-E4B-!HuBvhC}2V zCUl)eTqZNLWY(T^oTvqkq-jy%FlW>u6QJTaejYqtlc$H ziyh75g(gQkh-BL;W86jjvWm0KKebLZv+Hf`N_3VXZtmsFn?~v$8kK5UL)i@sXCmni bKK^?T{37f0j$=243tw$IdCl@zJ{`)xi_g}F literal 0 HcmV?d00001 diff --git a/ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/guitar.cpython-37.pyc b/ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/guitar.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..72827007322b0117514ac682f15f1c8b96f159db GIT binary patch literal 693 zcmZ8ey>8S%5T5nV;au*NCN)ARig1y1G*N^gi4>(EK}u&?jEr~h&S?F^u3dnx%Sm|# zI#TjV+fY#P3RKM4=R{(pnVs3$neUs~v-x}qB;Q~D`nWFueseHNK+aoI`<#pfDKsQ- z3DT4P2BfdxGu-)!km45N;19il>zwT<{?@SvsYX#9U|ABL0NGD|wQ>zfI3;SyapPLfK+jz4&12 zPg<2WU8zjsqA<3_o11rs7iqpadi^SsQb{EArZz1uYJ+7~$yyhcB`P?gt?DLDhv2yR zYIrhM>yZKRZEu+Tc%+}xcl5$1>p7{NkXh5>hoObrBaqf~rK;NPJcie0b{-A?uZxyy z$VU|Yk2vPy2`{h8N`>gAh-EE1&HfDWOPA>((-Su{?mFLYE>~J3K4HefFpgnp!{f19 i9yao3L4Ol_$@J=xdVlp)KX?Q2(}Bes-at=068`{+7o^z$ literal 0 HcmV?d00001 diff --git a/ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/guitarSpec.cpython-37.pyc b/ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/guitarSpec.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..13aa1020d7365bd147e27e82590546e77674b650 GIT binary patch literal 845 zcmYjPOK;Oa5T5lTNz()lJdPEos79hUE(jqWl`0OTNV!=SBgeZ*9Q zkdAb(LAnaoaOH+ViWvmn9reI8;kYw*TbN@i6i_FG&J8T+gmkV4q1)B2^r-f3z=O~y zB)=V=)v1m3tWrtR-(qlPXUuLM3s>+%G*06-UgI~tTVFsU8bC(^p@?bVw!Wz=rP~2w zTBH`SJuK=Rjn!$fG(o@hjLH_;C&;!xuhUFYv!9nzW#PlLpuRd+g++T&sjxT4?`0{& zp6zlV+5^NSi;Y4234b&BD*7~wK9rKMqf=$lW%2B@F6WubO|(+6#6_x&#q;xblhY_! zy?A*XOQ|H%j8&;EE=rAgT*xw`t7%|db}XP-l~oXJ7EH-Wb)i`qcEbV0V{!Rt&)LcD zxd{o{8D}Q0BkwsCTk^!M(33{2owd8m4XoX-j-Ifn(jg+<>7AexnnU1ehG>U*Y?Bol znx?%^6mN8N29EAgW9Tle4un2n0RGSPA%`&q-ZBFUAV%V;@WkbldoS4I2R)Xrh;v2q z4G~G5I^%kT_^pn!&6kdl4!0d|RY_EqA#QHvt9N5`6EGp{9e)F7Py`-OYyp literal 0 HcmV?d00001 diff --git a/ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/inventory.cpython-37.pyc b/ch-5(added_support_for_other instruments_in_guitar_shop)/__pycache__/inventory.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a26a3afdd045582ff02af91924985328d2811303 GIT binary patch literal 1047 zcmZuwy>HV%6u&z=iDQybGBI>O3>B83VqrlD0gZ$hXpuTpvJ5BVyCiP?l{*`?ku%Xh zBpLaays|N{urcwT(>N*WS?|O5KKy&XJHPAqZ34^t{p*X%2>FRGn`MCW21E}*y(fYQ zdJXcOxkRv2;urz!Hw&uQ*-ycd#HE6`Oi;nDiE9W$m|#uO5^b<8(GeEdw&+41yXt;O zzR4s{)m1=m8luIPM<5z8PDn{OfPeye?9i&EAzy-HY8j1x5M@Hr-wW~5`*`Xdr6Now z-bm_jl05pP(yx(>wKtW%;Nwu~oS&S$Js5ex^x2Ciz7SGyU1V9Raz0KKkNrfXQJ82R zCVWzaxv#jMrkUe~8=!~TRb_FAhdJj6RHGtvK5S+=+=PQV1W~leYCY5*I3+nJOIp$u zrOjweVOrJpvrHz!VG1iM8_?vch=Hbh(zR+~XaEBMkWCo(HeeoZ!Q4)2AYt>=-plg$Jc9RCpS@7$-8{!H6ju6`?(9 zQ;W`bkls#hkYY!ittRg|I1{p9mj^d!_ZLP8oH`J=ij=;gS@IxO33T64= z2_p{RneS~6W1V#Dbnp%(ek?h!Y|i6U6cPG8&S!-mts|-p%~TiFJyd;ETYhT~iBb5^ fpw!G-)H2{{*Sqk;)b_5j%6hf_?rW_5148}*=}7GB literal 0 HcmV?d00001 diff --git a/ch-5(added_support_for_other instruments_in_guitar_shop)/inventory.py b/ch-5(added_support_for_other instruments_in_guitar_shop)/inventory.py new file mode 100644 index 0000000..9b6af4c --- /dev/null +++ b/ch-5(added_support_for_other instruments_in_guitar_shop)/inventory.py @@ -0,0 +1,19 @@ +class Inventory: + def __init__(self): + self.store = [] + + def add_instrument(self, instrument): + self.store.append(instrument) + + def get_instrument(self, srl_num): + for instrument in self.store: + if instrument.srl_num == srl_num: + return instrument + return None + + def search(self, specs_to_search): + instruments_found = [] + for instrument in self.store: + if specs_to_search.match_spec(instrument.get_spec()): + instruments_found.append(instrument) + return instruments_found \ No newline at end of file diff --git a/ch-7(Game System Framework)/Board/Board.py b/ch-7(Game System Framework)/Board/Board.py new file mode 100644 index 0000000..fe6dfdb --- /dev/null +++ b/ch-7(Game System Framework)/Board/Board.py @@ -0,0 +1,27 @@ +import Tile +class Board: + def __init__(self, height, width): + self.height = height + self.width = width + self.board = [[Tile.Tile() for _ in range(width)] for _ in range(height)] + + def get_tile(self, x, y): + return self.board[x-1][y-1] + + def add_unit(self,unit, x, y): + tile = self.get_tile(x,y) + tile.add_unit(unit) + + def get_unit(self, x, y): + tile = self.get_tile(x,y) + return tile.get_unit() + + #remove given unit from one tile + def remove_unit(self,unit,x,y): + tile = self.get_tile(x,y) + tile.remove_unit(unit) + + #remove all units from one tile + def remove_all_units(self,x,y): + tile = self.get_tile(x,y) + tile.remove_all_units() \ No newline at end of file diff --git a/ch-7(Game System Framework)/Board/Tile.py b/ch-7(Game System Framework)/Board/Tile.py new file mode 100644 index 0000000..daeeece --- /dev/null +++ b/ch-7(Game System Framework)/Board/Tile.py @@ -0,0 +1,18 @@ +class Tile: + def __init__(self): + self.units = [] + + def add_unit(self,unit): + self.units.append(unit) + + def get_unit(self): + return self.units + + def remove_unit(self,inp_unit): + for i in range(len(self.units)): + if self.units[i] == inp_unit: + self.units.pop(i) + break + + def remove_all_units(self): + self.units.clear() \ No newline at end of file diff --git a/ch-7(Game System Framework)/Units/Units.py b/ch-7(Game System Framework)/Units/Units.py new file mode 100644 index 0000000..3daefc3 --- /dev/null +++ b/ch-7(Game System Framework)/Units/Units.py @@ -0,0 +1,6 @@ +class Unit: + def __init__(self,type,properties): + self.type = type + self.properties = properties + + \ No newline at end of file