From cfb99efff9a7eafee6bbdfafd8ef859962d73952 Mon Sep 17 00:00:00 2001 From: huangjielun <2872405629@qq.com> Date: Tue, 30 Aug 2022 16:07:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=8C=85=E5=9B=B4=E5=92=8C?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=BC=80=E5=A7=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 3 + src/__pycache__/init.cpython-38.pyc | Bin 0 -> 5517 bytes src/__pycache__/start_game.cpython-38.pyc | Bin 0 -> 2617 bytes src/images/capture-hint.png | Bin 0 -> 4120 bytes src/images/hint.png | Bin 0 -> 516 bytes src/init.py | 18 + src/main.py | 877 ++++++++-- src/main1.py | 1216 ++++++++++++++ src/main_an.py | 1826 +++++++++++++++++++++ src/path/path.py | 2 +- src/start_game.py | 2 +- 11 files changed, 3808 insertions(+), 136 deletions(-) create mode 100644 src/__pycache__/init.cpython-38.pyc create mode 100644 src/__pycache__/start_game.cpython-38.pyc create mode 100644 src/images/capture-hint.png create mode 100644 src/images/hint.png create mode 100644 src/main1.py create mode 100644 src/main_an.py diff --git a/.idea/misc.xml b/.idea/misc.xml index d56657a..009ceba 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,7 @@ + + \ No newline at end of file diff --git a/src/__pycache__/init.cpython-38.pyc b/src/__pycache__/init.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..31fce2a93bc76c95e38e0d74fe8fcae7e19b2c99 GIT binary patch literal 5517 zcmeHLOKcm*8QvGkKf%ew#n_W^|2~2ZH zduf;0Z@+K;|DT;1&dxu(7m~@ChGXtG$-*}VHSNz7oktkr37pj#UDJdn^s?r7SKZNz z+S|s4rfWrQ*=#e*W5Sp>oRAY1rV|mCW5YKpLLywWi}r@)#FUN*)7NpOZ4vc#Lg|=@ z`#Py~LL_~i@^#ABJxWJJkFV28r$w)?dzH?JK3`{)&We6t_bHtd1HR5GJt&5J-LLep z81Z#Z=}|G}>j5z?_T1E*L9tit!*xjP7ZbP+iv!{=Tt~#+;vlZ0LZ8#}lTD8CY~CpS z#L~3VUQ^SW>nLdo!VreK$-kxfCSjCvi|hc|MZy^2*M#pHfcpp|tYw4jO|lbY6J#IJ zZ$H_qWTRwvSl@TZUMCwOOM?{<)jrTR4F>Hr&gvwfrZu#hK7whG)o$q54QRb)KpRS% z4WnT$8FSjEIopiFzZn5+nyy(|t+}C#XV09Ualz6tczEMB9=K)Rq!GZA&^}=@pqS zmOhc~V(AyTwq+nt8y>8-WjJ6N5u;r!V`99EWslg~#j;QA?_!zgYQY2BB?gah7t5r` zcd^_f?(JeZB<|~CIo!o!)XZf|3=e3v5S}^Hd**5^4Xe@!N{^^gOB}_hnwTXPW{FX= zcg2NN>CQMT*N6)tF0A6B%T~v|B8Z7DhilvSvBfd?N8oQO|5(633jbKZKPK*ne-!>P zyNW&no|Pz`q~<>41MuJPiMS_~(>= zZ@_;5{=EVJLGcLu2jD-b{4)XnA^2x@&68pAC}M^XGpu6z0x=_q=|jv3%((6Ud{jJ! zm=VN`s+epbW(+aeUH2ImQ-~Qu%=i>?2vXqVvjrrh_QA9h!a0YtIu5u5w=d)dmw z<!O|8zGhHD%?>guJP3wCU(T&mUzm6f%V zOcGV5zp!R#*A6m|EUYZ99iA#zz^f-gTCN>baxvf3-4GW3OGSC8b;s?bAdjFdSo!Fu zRW3Oc&5MK_b9WEf$AoK?7s&ofc8=^Om>eZLhqgC|Y3QZ=JqD+FozkJlePq8P`xDte3C~mhgY36t2H|7Mm&nc$<_W(8 zsL^VsSaY0^BqRtnKyo%T;ifhDKQx)ao2pC=3F_3E{LAzG@)#~Et;>C2ZcHu|%f+?J zi>ozx7ft&KcM~RPkHEf&t%4ht3s)=UC0@&=%Bma1wOCnOl!87hl`GXE{>p`=%DNjX zx9fBx;9h*$k1zZ2xVGZUt@twI^Lt$Lxl=EA&0$NN#C9XG`RP=32klTdfT2z6j_tJ; zg)OGa*mAE-vAPp)_X5QoLe;A}<<;xax`VEwg(&k$-AQbB7R8+kb@-iU9W9D>cq4(r z7E@)dwt3^TfVQ)>qWc^YSR95es_JHamdqyPDxpvs^} z{;L^O-ivAJJ$~Kt+6_)zF4ih(P8Q0Gg$1m7$39Eelt)?pXRCSaQ)^Z!Q{K<&9v~bi zJV+7-5R=IN>DW3xp>KrwC6H_;|`QglWPT2~QDb2xkdT6P_VF zOL&ejOL(5}0)hEjzDVGnMV==xo6DC7O!)F;!Yc%a@G2m0Y$visL zJ}bbE7h7MOO5=6b*OssOs=)d}N}D3#>#)*Ek@9s!=^l~xwXHN>Xnh@38n3awjwy|o zS6|1K9uR}RPAEMjhJCGGq50{fVKqXHa3j*N8_`Cr5pN_K$)yx_t0S|L&xP94$S@g} zcTGkJYO@n1<0l`Lf+SQ4HNq9bWkQLtO!zXP zOjsqX5O&PLh%7G2V)gPZ*wnV(`v}7iG3sZunfGy~0l)m1tmEPum8xs;Q;usbRrvjA zrLJr5+6pJjrco e^*F%R`HSf>!`3a`G6Ve#_Bv!+cF1<@L;nI((Tb@6 literal 0 HcmV?d00001 diff --git a/src/__pycache__/start_game.cpython-38.pyc b/src/__pycache__/start_game.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cebb297e163ed0863c8ac5006282dcc6adada7a8 GIT binary patch literal 2617 zcma)7&2L*p5Z`?t_OqQ2*ZF9hQkp`Auz(^E96$)sq;47rZm3fgR)Ht??IwBgXZNik zj@%3MfP@e^AWjHuiBBOS4txlTsJL&gcDAygvC8&RFGAxYxf9q%*YiEw|W+{xXlvW zVM*>Xk0)4)Cs~?%EW=Z5fT!6Y&#)mrz=mNy%Lmy3KE!f-n2qr4qQyqp7-$>s9u%Wu zY{}|Tb_n>x-3g#ax_9scJ=&kK*wGonbA03~;UnVC*KBr-kMgmrgiUf~>BLk^sYbmRpy4|WJ%ju+ z@JCmHDAJ`J%4x^y*&X6roqmGA*fC?bM_`=bR>!R*WU=FN>oAc;<#2lfW>!sq2xXG> zLBIAPf3^j}r*HTU^lTK-86xg8OUR78u5Mfp$Knoux)y z>4X$@E~HLIExA+NFxNB3xbp@w0{5nX?O;u4&rNC$tlZ z>XLSpSX0^!8r6oBhhZx@0YoP%uaxC-^eK_Yfc;|zNa69tt?Qrt{_V!r2On>J{?X01 z-@ozYwZ)sCys`D&TemiUxV724dF}hHjn}s}-@EnASBp=#>dRHJ7|CEUQe~<9<#J7& zY__%M`(Zs)zK^>_IUs~)tpPeT7Q+WgdJY-BJVWg8hjGEPQI}c2R{wH*O zsBck!DljlkLBmYOyfg+q4+Bi1!G@BMMd6sI%mnUn{F%g(chZ zVE=(L!HNhfeozgA%Kfl5GF6q{1)oP9YdzOL{2sBqRV+dlK{V?SSl`!a->)@ztBT_R z-@n`{SK}FZ9L+m{1n=ygy^Y%^5gP`Awnum;J(|vXw!s2mZ#Q&v5`N?66>tH@U0IxB zw3Xe3^384K_UtSDjDWl5;Jxf7d*H$e*nzuoZYU`1%7q6Z$!+ev>0Y6LqzsboBM_o) zsz)g4SaGk?tEq0rAhbIG++cU8M|xDgYqSmT)mG2_dk4_7ch%2kM_hG#N3-gGTLBhi zy9avYG-qTSN`sp*2mLLf&BaPjQyLP46O9zzt9!{m=nG}~B4bfVSd zWhjuCPui_DT9MF6taXs`+CE=6tzGdllu&I02sN(V6xw<2!t8=}F1JFZ)1`K#L=ElI z8M97`C=xvHurzMqt58)1%U}`kFPW!q(x@gw7vM?off1PFoJ zHe^j&IhwOP>RD+gOGm97R63-9(6lu~hoJX>=BPunR6Yjl^2g-^&}jz?rty%@qP1Ks zm0MNi<1@fgNc}SBQafkxU2v!7PE9|fQ*&7Er{*pcbo%!2VV#_snLamn?z~Pudupao zTsWmOX7+``+}yc~fWBa+C6)p0&YUk4it-_2gi)28mSHVw)ImMID)V8zqBEz3XqGDN zscK8aVZ*B&N6d@BUZ@MgL|mtoEZ3u@hOB8f3d&WXUGv^+r`jlUc^__+Xk1zqfr`V9 lZrJ1K+Z985PsG*cNysV^p|#*XI}HwW{^Rq&wG%XZ^l!PPWZnP( literal 0 HcmV?d00001 diff --git a/src/images/capture-hint.png b/src/images/capture-hint.png new file mode 100644 index 0000000000000000000000000000000000000000..6763c6ea926598549453c8d7bc0327cc49ba4d60 GIT binary patch literal 4120 zcmbVP2{@Gd8lR%40v26Jfkm)F*aAX?HT)|t0a!1JQE=E-h%ne1zIo9g%!lj_bKvmlFjJ%% zf{HQ0!^|y^7&8+z&TJD5i^f=>(0CLEhd^TpXfuMTIqdrd2dwdF41y=o>ANl9%Niae z6mkhDRCsteG8~8G@B>j83k!e)i^5_N00JS1WD6+~2)01?2Lq8Vpz@hqA(O*~EizK} zazcgHaKO`VA+WeVY1xABX#x_4ilA^&7$kZzq_034^(T%S$`AQ!oJK{_L+C6zTPOgq zn4ef~5J$)n1abZi_0R2pG61BOO#W%(Z+&60ewq*n9m9Yyz9-~w(Sq%fTsq2=F5ran zsdUFMz)ju7Xt)FiKAj@u@V9d~AwLev{fEmiED$x!(3{Doal!>ge^Hzl)jwcLu)Eh6m9B(*IBw-(Ug`Ll{os(>DhK+4`?_hXR~OEjH}8 zI8gr@;@7>uH1`iUFfkUFKSvet@pIVG*}#P31EZ|);EWgqQvA)CxOsa-*7Uj8{82pE z>6r5R-Un^1zkjxs?81TNwaRV%)<6?dsu06=ms%VP?Mp8#xNjZwe8`ik*R4Y@DUekB z7Et`=PBXIl)2yKSh8<*=dHVcL{omjCJ2@_Ctq;{K9-Z24LQPDf$y~h`Y8nTr!b9Ql z(IZPHA)g9lcht$jHHK%#`XCnoal#fN*kM7(3Vuo-F7{BMH>*T9ubYie$|HMsXjl^U zW|G#fv2xH%bcjmSBtm=ZmuKkKwCssKnS12klE;!W@4jqeU0bFhS(8OdFc29Y(Y!xN zxH^@VO>>7sPT;d+Q32s@ykx|z4CM5?HgE$*CT8sReRc9v(4XtQBtsKk&=nDm&qy!u zN+U2Ou0}plt;@^OZIL}Z}_4x6g`u5<%J*gb3ki8 zpFC-^W*`#v>2^PS^7JK2Ts2-dmchB?sw;JFz8 z50$B*YxmwFg12t_G}xK_@LioP2~_mUZE%yZ>P-^4)qg)oXXrCaX&x=fItyExtZ>(? zKT>onvnL4f6e6@SSa_E4J|J=?`rNDTyB6jSvQM0PB9fJN_(KxQ^+ih|yIWObUMy#( z{-VRaV03rd3btE(3UkgByTbX7C|`xAUN@5;9IKkFg-jeLT$MfjHi;PT^Y55^f%khZ+A;IsW8j@!#--QT!aL3N5(F62rnv<6C$YAvFr=)65mSAO) zown-!0EI8kdD?pEc+bic8TB#qL%SdOwQj|~R3yTT#D;nTj8TIGOfgxvKL(WIKY?&v z6?Ht2ruZ!06rSdEJwtu;qw8BF@1Q(Ycs;Ev-j^IO(G|ZMn^I=G^`2bNnvwn`f*EPG zL=dp9ty1$0Dr%p)VK9H}){RaVg=#tlx}p5x+DC5;Q6>}JMWY$;N>$@vqShgwIg{=7 zpQ}4UIv$&+;z%iYD7LNicE0KCm{=}*jlHF`4hgJ zi0_yCkodTZdXV+d{;CgGymge@tl^08=NIRP+J8ot7D+zVAHF-O&-3wWHb1v>`b2x1 zSUalzaA|`D4@_81;7lF3}~$vc*Pzk9Zp>jLfBHTG&p^0DOh zg`S}?O;NHgTd@ah4yAtzOupkM@i?oamZ-liX7yT8@xeWE4>jLwR_PqMw=TMK+2~Mr zE7vDiC)$dKMq8^lNhNDvS&>BXD^m8XoYpkkk+AR}7hi5UN`=I?&X%gzNoju;;`dhU z>6S^&Rjx;>S2rowY<*x{m2kAjW=>sk=&0>~hMamk$-< z%aL^Vi(+i8>eL14(m%U4dqj4#&6}x5dFLxSPn}OOTrs`kk8_fO%$QOr!c3+L?{|4R z)7h=`q*>O2GgKVl!m#q;BYdIealX*GeQz0=F&+I^Ku02AB?;JL=Jy>-Pxmmw=S)B< zzFK3%8v9nb2>Nl&2EQsg?-|$^nt3v#f%5e135d=sYlH@GJe!&oG`*ui&}yRm!u?sQ zV$opM#XSLG#$!a5`PRqBD^=dH8>4duTjb07itHv+Hoh!oIK?-z_wi`#gmZMe{ttI= zXNI{CJbEIa-Nd?ftxs7hRlihpQjD97wmPbQE(_mG+mhjSpyU&#h*G)<>9 z9=CAbFiHw-2rKX}4;#>!@HTL}Hz&?K4xYML@zkJgM>$Shu)!_xwqtO~x^(%=%+9S0 zlMJ&WAco~f8*&FRzn*SdHwNo-HWr!oHF}&M&dixignXKq*ua}=pGj&N)spkGOpjM^ z`NgBZMKIr12?ei3-?i!Y6z#aqw$p279Frkp9|#8 zDusG@y$sNfR!-Za8QMYFxUNBBxWk_{?D-zwsghH;s(1XPbY zb~3U-y!DU97nkY_#cHCQEP=)PUfo)3Q&|!CVa=9WtGzyRjmf^RjCc`K zHCwc^KG+3?2bb`K2~kM@n{_uXJ%3=~HFzxbc>9oBpG(BKDcQCI8FDXL&K}%$VUuE8 zUu3<8Ylgs}IMkV`6k=MJeLZ?I0cb?EhMNIegaFkeB|5isGa=lUuxT%SXLw$XG|4&^KPBYNjyq@GZ5^*G=}veuUI^ z?w^^GgM+U>X>!$1?h)4AS-y}*nS8UoJ4uNMBcE2dzfDp#zrbhkPLvZN0;GVI-Tt$(q{RV;%SQ zj%*1rz9sU2TRUCDee5^n=d?5uT|U4eQput81Nv_H#sitH>D!sFW#gA-Hs(L0)odtE*Q=eSD^C3gvPl@{Z(JSvd)ahY$vvpU9ioG`+-ob)uwV7C#;ONveC8!#aRV8L zA9{LRLTW1{-?TaT`c2nGBkT%hbjO@XI`mkjl;5pd5 z^L_moHejHoLaD^&OX~cPx2s2LQ=x19t0*I`d(6E4!nm`^WF~SwSZltvews-ki(^chu&$_xOOMPM9pf~MkmEPA89;IW(+Pr zacX_C%y?vW8LCFd*iw(py9Tw_Q6@u=8=g=%np&@R+ECd={dn#X-O;q!&$wPwgQu`K zAFQ1RF###sST@wHJ0`TSBr5kDojiv#;1Qv!*)jPw)s7qYE(9hQfw(2gm6X>beJ`>7 z%~5_yzGE4$A?dKf)Sb}82DN;K@Z`*IFL*tY+h;0DdJRNW^(0cklt9<7TaoB<^A0gjw`4C>@?i zB2DFhtP_5kNLE=(jR(?I!m-ru)U2KOT|%DJQU;h6_Tp44Jk|hf%ffGMS9mjEob5v- zZh`R5psZ55sc`g%)9nzfwDnbZYgkq(9CazU32xh?SQ(NNq^(n|y~$`~s3RgjFdJt% zOJRSuvkcKp2Ar~(Q|%T|pDp(UTuJfCyO{W z2S1Zpm0Qc5vx_Nt1Mu!Yze*U=Z)iek7JUs$8-(Euz_B-}Nu4Zi2t)c$-tn~PUi8Qy z=msvggdxJIa}GBI+?p>T@5ej31@H|s?O<5EBmd9<0000 old_y: + for i in range(old_y+1,y): + if MAP[x][i] != 20 and MAP[x][i] != 8 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + for i in range(y+1,old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if x > old_x: + for i in range(old_x+1,x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + for i in range(x+1,old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + return 0 + elif id == 14: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else : + return 0 + +#TODO:Judge who win +def left_win(x,y,MAP,MAP1): + global r_animals + if r_animals == 0: + return 1 + if MAP1[x][y] == 18 and 1<=MAP[x][y]<=7: + return 1 + isWin = 0 + for i in range(8,15): + if ID[i] == 1: + isWin = left_Wall(i,MAP,MAP1) + if isWin == 0: + return 0 + if isWin == 1: + return 1 + return 0 + +def left_move(old_x,old_y,x,y,id,MAP,MAP1): + if id == 8: + if MAP[x][y] == 18: + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][y] == 7 or MAP1[x][y] == 17): + if MAP[x][y] == 7: + if MAP1[old_x][old_y] != 20: + return 1 + else: + return 0 + if MAP[x][y] == 1: + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][y] == 7 or MAP1[x][y] == 17): + if MAP[x][y] == 7: + if MAP1[old_x][old_y] != 20: + return 1 + else: + return 0 + if MAP[x][y] == 1: + return 1 + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: + return 1 + return 1 + else : + return 0 + elif id == 9: + if MAP[x][y] == 18 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 16 and MAP1[x][y] != 17 and (2 old_y: + for i in range(old_y + 1, y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[i][y] != 15 and MAP[x][i] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + for i in range(y + 1, old_y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[i][y] != 15 and MAP[x][i] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif y == old_y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=2): + if x > old_x: + for i in range(old_x + 1, x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 15 and MAP[i][y] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + for i in range(x + 1, old_x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 15 and MAP[i][y] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + return 0 + elif id == 10: + if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=3): + if 1 <= MAP[x][y] <= 3: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + return 0 + elif id == 11: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=4): + if 1 <= MAP[x][y] <= 4: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=4): + if 1 <= MAP[x][y] <= 4: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else : + return 0 + elif id == 12: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=5): + if 1 <= MAP[x][y] <= 5: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=5): + if 1 <= MAP[x][y] <= 5: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else : + return 0 + elif id == 13: + if MAP[x][y] == 18: + return 0 + if MAP[x][y] == 20: + return 0 + if abs(x - old_x) ==1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if y > old_y: + for i in range(old_y+1,y): + if MAP[x][i] != 20 and MAP[x][i] != 8 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + for i in range(y+1,old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if x > old_x: + for i in range(old_x+1,x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + for i in range(x+1,old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + return 0 + elif id == 14: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else : + return 0 + +def left_Wall(id,MAP,MAP1): + if 8<=id<=14: + if id == 8: + old_x,old_y = init.calc(r_mouse.x,r_mouse.y) + elif id == 9: + old_x, old_y = init.calc(r_eagle.x, r_eagle.y) + elif id == 10: + old_x, old_y = init.calc(r_fox.x, r_fox.y) + elif id == 11: + old_x, old_y = init.calc(r_wolf.x, r_wolf.y) + elif id == 12: + old_x, old_y = init.calc(r_leopard.x, r_leopard.y) + elif id == 13: + old_x, old_y = init.calc(r_lion.x, r_lion.y) + elif id == 14: + old_x, old_y = init.calc(r_elephant.x, r_elephant.y) + for x in range(0,9): + for y in range(0,6): + if left_move(old_x,old_y,x,y,id,MAP,MAP1): + return 0 + return 1 +def right_win(x,y,MAP,MAP1): + isWin = 0 + global l_animals + if l_animals == 0: + return 1 + if MAP1[x][y] == 16 and 8 <= MAP[x][y] <= 14: + return 1 + for i in range(1, 8): + if ID[i] == 1: + isWin = right_Wall(i,MAP,MAP1) + if isWin == 0: + return 0 + if isWin == 1: + return 1 + return 0 + +def right_move(old_x,old_y,x,y,id,MAP,MAP1): + if id == 1: + if MAP[x][y] == 16: + return 0 + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][y] == 14 or MAP1[x][y] == 15): + if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20: + return 0 + if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: + return 1 + if MAP[x][y] == 8: + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][y] == 14 or MAP1[x][y] == 15): + if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20: + return 0 + if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: + return 1 + if MAP[x][y] == 8: + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 2: + if MAP[x][y] == 16 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 18 and MAP1[x][y] != 15 and (9 < MAP[x][y] <= 14): + return 0 + if x == old_x and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 9): + if y > old_y: + for i in range(old_y + 1, y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 17 and MAP[x][i] != 16 and MAP[x][i] != 18): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + for i in range(y + 1, old_y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 17 and MAP[x][i] != 16 and MAP[x][i] != 18): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif y == old_y and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 9): + if x > old_x: + for i in range(old_x + 1, x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 17 and MAP[i][y] != 16 and MAP[i][y] != 18): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + for i in range(x + 1, old_x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 17 and MAP[i][y] != 16 and MAP[i][y] != 18): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 3: + if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 10): + if 8 <= MAP[x][y] <= 10: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - else : + return 0 + elif id == 4: + if MAP[x][y] == 16: return 0 - elif id == 13: - if MAP[x][y] == 18: + if (MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 11): + if 8 <= MAP[x][y] <= 11: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 11): + if 8 <= MAP[x][y] <= 11: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 5: + if MAP[x][y] == 16: + return 0 + if (MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 12): + if 8 <= MAP[x][y] <= 12: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 12): + if 8 <= MAP[x][y] <= 12: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 6: + if MAP[x][y] == 16: return 0 if MAP[x][y] == 20: return 0 - if abs(x - old_x) ==1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): - if 1 <= MAP[x][y] <= 6: - if MAP[x][y] == 1: + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 13): + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): - if 1 <= MAP[x][y] <= 6: - if MAP[x][y] == 1: + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 13): + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 13): if y > old_y: - for i in range(old_y+1,y): - if MAP[x][i] != 20 and MAP[x][i] != 8 : + for i in range(old_y + 1, y): + if MAP[x][i] != 20 and MAP[x][i] != 1: return 0 - if 1 <= MAP[x][y] <= 6: - if MAP[x][y] == 1: + if 8 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 else: - for i in range(y+1,old_y): - if MAP[x][i] != 20 and MAP[x][i] != 1 : + for i in range(y + 1, old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1: return 0 - if 1 <= MAP[x][y] <= 6: - if MAP[x][y] == 1: + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 13): if x > old_x: - for i in range(old_x+1,x): - if MAP[i][y] != 20 and MAP[i][y] != 1 : + for i in range(old_x + 1, x): + if MAP[i][y] != 20 and MAP[i][y] != 1: return 0 - if 1 <= MAP[x][y] <= 6: - if MAP[x][y] == 1: + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 else: - for i in range(x+1,old_x): - if MAP[i][y] != 20 and MAP[i][y] != 1 : + for i in range(x + 1, old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1: return 0 - if 1 <= MAP[x][y] <= 6: - if MAP[x][y] == 1: + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 else: return 0 - elif id == 14: - if MAP[x][y] == 18: + elif id == 7: + if MAP[x][y] == 16: return 0 - if(MAP[x][y] == 20): + if (MAP[x][y] == 20): return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): - if 2 <= MAP[x][y] <= 7: - if MAP[x][y] == 1: + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 9 <=MAP[x][y] <= 14): + if 9 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): - if 2 <= MAP[x][y] <= 7: - if MAP[x][y] == 1: + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 and MAP[x][y] == 18 or MAP1[x][y] == 15 or 9 <=MAP[x][y] <= 14): + if 9 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - else : + else: return 0 - -#TODO:Judge who win -def left_win(old_x,old_y,x,y,MAP,MAP1): - global r_animals - if r_animals == 0: - return 1 - if MAP1[x][y] == 18 and 1<=MAP[x][y]<=7: - return 1 - for i in range(8,15): - pass - return 0 - -def right_win(old_x,old_y,x,y,MAP,MAP1): - global l_animals - if l_animals == 0: - return 1 - if MAP1[x][y] == 16 and 8 <= MAP[x][y] <= 14: - return 1 - for i in range(1, 8): - pass - return 0 - +def right_Wall(id,MAP,MAP1): + if 1<=id<=7: + if id == 1: + old_x,old_y = init.calc(l_mouse.x,l_mouse.y) + elif id == 2: + old_x, old_y = init.calc(l_eagle.x, l_eagle.y) + elif id == 3: + old_x, old_y = init.calc(l_fox.x, l_fox.y) + elif id == 4: + old_x, old_y = init.calc(l_wolf.x, l_wolf.y) + elif id == 5: + old_x, old_y = init.calc(l_leopard.x, l_leopard.y) + elif id == 6: + old_x, old_y = init.calc(l_lion.x, l_lion.y) + elif id == 7: + old_x, old_y = init.calc(l_elephant.x, l_elephant.y) + for x in range(0,9): + for y in range(0,6): + if right_move(old_x,old_y,x,y,id,MAP,MAP1): + return 0 + return 1 def main(): global l_animals,r_animals BGM.play(-1) @@ -949,7 +1561,6 @@ def main(): game_status = start_game.starting_screen() if not game_status: return True - #TODO:updata MAP1 run = True clock = pygame.time.Clock() font = pygame.font.SysFont('kaiti',40) @@ -962,7 +1573,6 @@ def main(): elif event.type == pygame.MOUSEBUTTONDOWN: b1, b2, b3 = pygame.mouse.get_pressed() if b1 and not b3: - print(r_animals) mouse_x , mouse_y = event.pos old_x = x old_y = y @@ -986,7 +1596,6 @@ def main(): elif id == 7: Elephant.play() status = 1 - path() elif 7 < id <15 and turn == 1: if id == 8: Mouse.play() @@ -1021,9 +1630,7 @@ def main(): elif id == 2 and turn == 0 and status == 1: if MAP[x][y] == id: status = 1 - path() else: - #print(ismove(old_x,old_y,x,y,id,MAP)) if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : l_eagle.x , l_eagle.y = init.tran(x,y) MAP[old_x][old_y] = MAP1[old_x][old_y] @@ -1176,24 +1783,26 @@ def main(): turn = 0 else : status = 0 - #print(turn, status) - if left_win(old_x,old_y,x,y,MAP,MAP1): + if left_win(x,y,MAP,MAP1): run = False - if right_win(old_x,old_y,x,y,MAP,MAP1): + if right_win(x,y,MAP,MAP1): run = False - #print(old_x,old_y) - #print(x,y) draw_window(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox,r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) - if left_win(old_x, old_y, x, y, MAP, MAP1): + if left_win(x, y, MAP, MAP1): print_text(WIN, font, 500, 400, "Left Win!", RED) pygame.display.update() - if right_win(old_x, old_y, x, y, MAP, MAP1): + if right_win(x, y, MAP, MAP1): print_text(WIN, font, 500, 400, "Right Win!", BLUE) pygame.display.update() - os.system("pause") - pygame.quit() - + time.sleep(2) + #os.system("pause") if __name__ == "__main__": - main() \ No newline at end of file + again = 1 + while again == 1: + l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion, r_leopard, r_fox, r_mouse=init.refresh() + draw_window(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion, + r_leopard, r_mouse, r_fox) + main() + pygame.quit() diff --git a/src/main1.py b/src/main1.py new file mode 100644 index 0000000..aa536b6 --- /dev/null +++ b/src/main1.py @@ -0,0 +1,1216 @@ +import pygame +import init +import start_game +import time +import os +WIDTH , HEIGHT = 1200 , 800 + + +#模块############################### +ID = [1 for i in range(20)] +FPS = 60 +WIN = pygame.display.set_mode((WIDTH,HEIGHT)) +pygame.display.set_caption("Jungle") +SPACE = pygame.transform.scale(pygame.image.load('images/map.png'),(WIDTH,HEIGHT)) +CHESSSIZE_X=120 +CHESSSIZE_Y=100 #棋子大小 +################################################################## + +###########背景音乐########### +BGM = pygame.mixer.Sound('audio/BackgroudMusic.mp3') +Elephant = pygame.mixer.Sound('audio/Elephant.mp3') +Leopard = pygame.mixer.Sound('audio/Leopard.mp3') +Lion = pygame.mixer.Sound('audio/Lion.mp3') +Mouse = pygame.mixer.Sound('audio/Mouse.mp3') +#Start = pygame.mixer.Sound('audio/start.mp3') +Tiger = pygame.mixer.Sound('audio/Tiger.mp3') +Wolf = pygame.mixer.Sound('audio/Wolf.mp3') +Fox = pygame.mixer.Sound('audio/Fox..mp3') +Eagle = pygame.mixer.Sound('audio/Eagle.mp3') +pygame.mixer.music.set_volume(0.5) +#################################################### +hint = pygame.transform.scale(pygame.image.load("images/hint.png"),(CHESSSIZE_X,CHESSSIZE_Y)) +capture_hint = pygame.transform.scale(pygame.image.load("images/capture-hint.png"),(CHESSSIZE_X,CHESSSIZE_Y)) +#animals img +#Left +L_mouse = pygame.transform.scale(pygame.image.load('images/animals/left/1MouseLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +L_eagle = pygame.transform.scale(pygame.image.load('images/animals/left/2EagleLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +L_wolf = pygame.transform.scale(pygame.image.load('images/animals/left/3WolfLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +L_leopard = pygame.transform.scale(pygame.image.load('images/animals/left/4LeopardLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +L_tiger = pygame.transform.scale(pygame.image.load('images/animals/left/5TigerLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +L_lion = pygame.transform.scale(pygame.image.load('images/animals/left/6LionLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +L_elephant = pygame.transform.scale(pygame.image.load('images/animals/left/7ElephantLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +L_fox = pygame.transform.scale(pygame.image.load('images/animals/left/8FoxLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) + +#Right +R_mouse = pygame.transform.scale(pygame.image.load('images/animals/right/1MouseRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +R_eagle = pygame.transform.scale(pygame.image.load('images/animals/right/2EagleRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +R_wolf = pygame.transform.scale(pygame.image.load('images/animals/right/3WolfRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +R_leopard = pygame.transform.scale(pygame.image.load('images/animals/right/4LeopardRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +R_tiger = pygame.transform.scale(pygame.image.load('images/animals/right/5TigerRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +R_lion = pygame.transform.scale(pygame.image.load('images/animals/right/6LionRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +R_elephant = pygame.transform.scale(pygame.image.load('images/animals/right/7ElephantRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +R_fox = pygame.transform.scale(pygame.image.load('images/animals/right/8FoxRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +############################################################################### + + +#colour########################################################### +BLACK = (0,0,0) +LIGHTBLUE = (40,191,255) +LIGHTBLUE2 = (0,0,255) +BGCOLOR = (230,230,250) +MAGENTA = (255,0,255) +LIGHTYELLOW= (255,225,0) +MYCOLOR = (255,165,0) +WHITE = (255,255,255) +GREEN = (0,255,0) +RED = (255,0,0) +BLUE = (0,0,255) +Crimson=(220,20,60) +LightPink=(255,182,193) +DeepSkyBlue=(0,191,255) +############################################################# + + +#TEXT +def print_text(WIN,font,x,y,text,fcolor=WHITE): + imgText = font .render(text,True,fcolor) + WIN.blit(imgText,(x,y)) + +###################################### +def draw_left_animals(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox): + if ID[7]: + WIN.blit(L_elephant,(l_elephant.x,l_elephant.y)) + if ID[2]: + WIN.blit(L_eagle, (l_eagle.x, l_eagle.y)) + if ID[4]: + WIN.blit(L_wolf, (l_wolf.x, l_wolf.y)) + if ID[6]: + WIN.blit(L_lion, (l_lion.x, l_lion.y)) + if ID[5]: + WIN.blit(L_leopard, (l_leopard.x, l_leopard.y)) + if ID[1]: + WIN.blit(L_mouse, (l_mouse.x, l_mouse.y)) + if ID[3]: + WIN.blit(L_fox, (l_fox.x, l_fox.y)) + +def draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox): + if ID[14]: + WIN.blit(R_elephant, (r_elephant.x, r_elephant.y)) + if ID[9]: + WIN.blit(R_eagle, (r_eagle.x, r_eagle.y)) + if ID[11]: + WIN.blit(R_wolf, (r_wolf.x,r_wolf.y)) + if ID[13]: + WIN.blit(R_lion, (r_lion.x, r_lion.y)) + if ID[12]: + WIN.blit(R_leopard, (r_leopard.x, r_leopard.y)) + if ID[8]: + WIN.blit(R_mouse, (r_mouse.x, r_mouse.y)) + if ID[10]: + WIN.blit(R_fox, (r_fox.x, r_fox.y)) + + +def draw_window(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox,r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox): + WIN.blit(SPACE,(0,0)) + draw_left_animals(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox) + draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) + #WIN.blit(L_fox,(fox.x,fox.y)) + pygame.display.update() +#TODO:传入动物编号id,动物现在的位置(x,y),将点击的动物圈起来,并显示可以移动的地方 +def path(): + pass + +#animals rect +l_elephant = pygame.Rect(int(2/9 * WIDTH),int(0 / 7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +l_eagle = pygame.Rect(int(1 / 9 *WIDTH),int(1 / 7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +l_wolf = pygame.Rect(int(2/9 * WIDTH),int(2/7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +l_lion = pygame.Rect(int(2/9 * WIDTH),int(3/7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +l_leopard = pygame.Rect(int(2/9 * WIDTH),int(4/7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +l_mouse = pygame.Rect(int(2/9 * WIDTH),int(6/7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +l_fox = pygame.Rect(int(1/9 * WIDTH),int(5/7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) + +r_elephant = pygame.Rect(int(6/9*WIDTH),int(6/7*HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +r_eagle = pygame.Rect(int(7/9*WIDTH),int(5/7*HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +r_wolf = pygame.Rect(int(6/9*WIDTH),int(4/7*HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +r_lion = pygame.Rect(int(6/9*WIDTH),int(3/7*HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +r_leopard = pygame.Rect(int(6/9*WIDTH),int(2/7*HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +r_fox = pygame.Rect(int(7/9*WIDTH),int(1/7*HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +r_mouse = pygame.Rect(int(6/9*WIDTH),int(0/7*HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +############################################# +l_animals =r_animals = 7 +def ismove(old_x,old_y,x,y,id,MAP,MAP1): + global l_animals + global r_animals + if id == 1: + if MAP[x][y] == 16: + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][y] == 14 or MAP1[x][y] == 15): + if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20: + return 0 + if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: + ID[14] = 0 + r_animals -= 1 + return 1 + if MAP[x][y] == 8: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][y] == 14 or MAP1[x][y] == 15): + if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20: + return 0 + if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: + ID[14] = 0 + r_animals -= 1 + return 1 + if MAP[x][y] == 8: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 2: + if MAP[x][y] == 16 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 18 and MAP1[x][y] != 15 and (9 < MAP[x][y] <= 14): + return 0 + if x == old_x and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=9): + if y > old_y: + for i in range(old_y+1,y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 17 and MAP[x][i] != 16 and MAP[x][i] != 18): + return 0 + if 8<=MAP[x][y]<=9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]]=0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else: + for i in range(y+1,old_y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 17 and MAP[x][i] != 16 and MAP[x][i] != 18 ): + return 0 + if 8<=MAP[x][y]<=9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]]=0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif y == old_y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=9): + if x > old_x: + for i in range(old_x+1,x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 17 and MAP[i][y] != 16 and MAP[i][y] != 18): + return 0 + if 8<=MAP[x][y]<=9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]]=0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else : + for i in range(x+1,old_x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 17 and MAP[i][y] != 16 and MAP[i][y] != 18): + return 0 + if 8<=MAP[x][y]<=9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]]=0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 3: + if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=10): + if 8 <= MAP[x][y] <= 10: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + return 0 + elif id == 4: + if MAP[x][y] == 16: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=11): + if 8 <= MAP[x][y] <= 11: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=11): + if 8 <= MAP[x][y] <= 11: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 5: + if MAP[x][y] == 16: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) ==1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=12): + if 8 <= MAP[x][y] <= 12: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=12): + if 8 <= MAP[x][y] <= 12 : + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 6: + if MAP[x][y] == 16: + return 0 + if MAP[x][y] == 20: + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=13): + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=13): + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=13): + if y > old_y: + for i in range(old_y+1,y): + if MAP[x][i] != 20 and MAP[x][i] != 1 : + return 0 + if 8 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else: + for i in range(y+1,old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1 : + return 0 + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=13): + if x > old_x: + for i in range(old_x+1,x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else: + for i in range(x+1,old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else: + return 0 + elif id == 7: + if MAP[x][y] == 16: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 9<=MAP[x][y]<=14): + if 9 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 and MAP[x][y] == 18 or MAP1[x][y] == 15 or 9<=MAP[x][y]<=14): + if 9 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 8: + if MAP[x][y] == 18: + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][y] == 7 or MAP1[x][y] == 17): + if MAP[x][y] == 7: + if MAP1[old_x][old_y] != 20: + ID[7] = 0 + l_animals -= 1 + return 1 + else: + return 0 + if MAP[x][y] == 1: + ID[1] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][y] == 7 or MAP1[x][y] == 17): + if MAP[x][y] == 7: + if MAP1[old_x][old_y] != 20: + ID[7] = 0 + l_animals -= 1 + return 1 + else: + return 0 + if MAP[x][y] == 1: + ID[1] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 9: + if MAP[x][y] == 18 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 16 and MAP1[x][y] != 17 and (2 old_y: + for i in range(old_y + 1, y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[i][y] != 15 and MAP[x][i] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + for i in range(y + 1, old_y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[i][y] != 15 and MAP[x][i] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif y == old_y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=2): + if x > old_x: + for i in range(old_x + 1, x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 15 and MAP[i][y] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + for i in range(x + 1, old_x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 15 and MAP[i][y] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + return 0 + elif id == 10: + if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=3): + if 1 <= MAP[x][y] <= 3: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + return 0 + elif id == 11: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=4): + if 1 <= MAP[x][y] <= 4: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=4): + if 1 <= MAP[x][y] <= 4: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 12: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=5): + if 1 <= MAP[x][y] <= 5: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=5): + if 1 <= MAP[x][y] <= 5: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + return 1 + return 1 + else : + return 0 + elif id == 13: + if MAP[x][y] == 18: + return 0 + if MAP[x][y] == 20: + return 0 + if abs(x - old_x) ==1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if y > old_y: + for i in range(old_y+1,y): + if MAP[x][i] != 20 and MAP[x][i] != 8 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + for i in range(y+1,old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if x > old_x: + for i in range(old_x+1,x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + for i in range(x+1,old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + return 0 + elif id == 14: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else : + return 0 + +def path(id, x, y, status, MAP, MAP1): + if status: + movement = [] + for i in range(9): + for j in range(7): + if ismove(x, y, i, j, id, MAP,MAP1): + movement.append([i, j]) + for i, j in movement: + WIN.blit(hint, init.tran(i,j)) + WIN.blit(capture_hint,init.tran(x,y)) + pygame.display.update() +#TODO:Judge who win +def left_win(old_x,old_y,x,y,MAP,MAP1): + global r_animals + if r_animals == 0: + return 1 + if MAP1[x][y] == 18 and 1<=MAP[x][y]<=7: + return 1 + for i in range(8,15): + pass + return 0 + +def right_win(old_x,old_y,x,y,MAP,MAP1): + global l_animals + if l_animals == 0: + return 1 + if MAP1[x][y] == 16 and 8 <= MAP[x][y] <= 14: + return 1 + for i in range(1, 8): + pass + return 0 + +def main(): + global l_animals,r_animals + game_status = 1 + BGM.play(-1) + MAP = init.calc_map() + MAP1 = init.clac_MAP1() + game_status = start_game.starting_screen() + if not game_status: + return False + #TODO:updata MAP1 + run = True + clock = pygame.time.Clock() + font = pygame.font.SysFont('kaiti',40) + status = id = old_x = old_y = x = y = turn = 0 + while run: + clock.tick(FPS) + for event in pygame.event.get(): + if event.type == pygame.QUIT: + run = False + elif event.type == pygame.MOUSEBUTTONDOWN: + b1, b2, b3 = pygame.mouse.get_pressed() + if b1 and not b3: + print(r_animals) + mouse_x , mouse_y = event.pos + old_x = x + old_y = y + x = int(mouse_x / WIDTH * 9) + y = int(mouse_y / HEIGHT * 7) + if status == 0: + id = MAP[x][y] + if 0 < id < 8 and turn == 0: + if id == 1: + Mouse.play() + elif id == 2: + Eagle.play() + elif id == 3: + Fox.play() + elif id == 4: + Wolf.play() + elif id == 5: + Leopard.play() + elif id == 6: + Lion.play() + elif id == 7: + Elephant.play() + status = 1 + path(id, x, y, status, MAP, MAP1) + elif 7 < id <15 and turn == 1: + if id == 8: + Mouse.play() + if id == 9: + Eagle.play() + if id == 10: + Fox.play() + if id == 11: + Wolf.play() + if id == 12: + Leopard.play() + if id == 13: + Lion.play() + if id == 14: + Elephant.play() + status = 2 + path(id, x, y, status, MAP, MAP1) + #TODO: Cirlce the elective animal + else: + if id == 1 and turn == 0 and status == 1: + if MAP[x][y] == id: + status = 1 + else: + if(ismove(old_x,old_y,x,y,id,MAP,MAP1)): + print(MAP1[old_x][old_y]) + l_mouse.x,l_mouse.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 1 + else: + status = 0 + elif id == 2 and turn == 0 and status == 1: + if MAP[x][y] == id: + status = 1 + path(id, x, y, status, MAP, MAP1) + else: + #print(ismove(old_x,old_y,x,y,id,MAP)) + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + l_eagle.x , l_eagle.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 1 + else : + status = 0 + elif id == 3 and turn == 0 and status == 1: + if MAP[x][y] == id: + status = 1 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + l_fox.x , l_fox.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 1 + else : + status = 0 + elif id == 4 and turn == 0 and status == 1: + if MAP[x][y] == id: + status = 1 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + l_wolf.x , l_wolf.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 1 + else : + status = 0 + elif id == 5 and turn == 0 and status == 1: + if MAP[x][y] == id: + status = 1 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + l_leopard.x , l_leopard.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 1 + else : + status = 0 + elif id == 6 and turn == 0 and status == 1: + if MAP[x][y] == id: + status = 1 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + l_lion.x , l_lion.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 1 + else : + status = 0 + elif id == 7 and turn == 0 and status == 1: + if MAP[x][y] == id: + status = 1 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + l_elephant.x , l_elephant.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 1 + else : + status = 0 + elif id == 8 and turn == 1 and status == 2: + if MAP[x][y] == id: + status = 2 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + r_mouse.x , r_mouse.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 0 + else : + status = 0 + elif id == 9 and turn == 1 and status == 2: + if MAP[x][y] == id: + status = 2 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + r_eagle.x , r_eagle.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 0 + else : + status = 0 + elif id == 10 and turn == 1 and status == 2: + if MAP[x][y] == id: + status = 2 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + r_fox.x , r_fox.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 0 + else : + status = 0 + elif id == 11 and turn == 1 and status == 2: + if MAP[x][y] == id: + status = 2 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + r_wolf.x , r_wolf.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 0 + else : + status = 0 + elif id == 12 and turn == 1 and status == 2: + if MAP[x][y] == id: + status = 2 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + r_leopard.x , r_leopard.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 0 + else : + status = 0 + elif id == 13 and turn == 1 and status == 2: + if MAP[x][y] == id: + status = 2 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + r_lion.x , r_lion.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 0 + else : + status = 0 + elif id == 14 and turn == 1 and status == 2: + if MAP[x][y] == id: + status = 2 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + r_elephant.x , r_elephant.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 0 + else : + status = 0 + #print(turn, status) + if left_win(old_x,old_y,x,y,MAP,MAP1): + run = False + if right_win(old_x,old_y,x,y,MAP,MAP1): + run = False + #print(old_x,old_y) + #print(x,y) + draw_window(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox,r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) + if left_win(old_x, old_y, x, y, MAP, MAP1): + print_text(WIN, font, 500, 400, "Left Win!", RED) + pygame.display.update() + if right_win(old_x, old_y, x, y, MAP, MAP1): + print_text(WIN, font, 500, 400, "Right Win!", BLUE) + pygame.display.update() + os.system("pause") + pygame.quit() + + + +if __name__ == "__main__": + while main(): + main() + pygame.quit() \ No newline at end of file diff --git a/src/main_an.py b/src/main_an.py new file mode 100644 index 0000000..d05f341 --- /dev/null +++ b/src/main_an.py @@ -0,0 +1,1826 @@ +import pygame +import init +import start_game +import time +import os +#import path.path +WIDTH , HEIGHT = 1200 , 800 + + +#模块############################### +ID = [1 for i in range(20)] +FPS = 60 +WIN = pygame.display.set_mode((WIDTH,HEIGHT)) +pygame.display.set_caption("Jungle") +SPACE = pygame.transform.scale(pygame.image.load('images/map.png'),(WIDTH,HEIGHT)) +CHESSSIZE_X=120 +CHESSSIZE_Y=100 #棋子大小 +################################################################## + +###########背景音乐########### +BGM = pygame.mixer.Sound('audio/BackgroudMusic.mp3') +Elephant = pygame.mixer.Sound('audio/Elephant.mp3') +Leopard = pygame.mixer.Sound('audio/Leopard.mp3') +Lion = pygame.mixer.Sound('audio/Lion.mp3') +Mouse = pygame.mixer.Sound('audio/Mouse.mp3') +#Start = pygame.mixer.Sound('audio/start.mp3') +Tiger = pygame.mixer.Sound('audio/Tiger.mp3') +Wolf = pygame.mixer.Sound('audio/Wolf.mp3') +Fox = pygame.mixer.Sound('audio/Fox..mp3') +Eagle = pygame.mixer.Sound('audio/Eagle.mp3') +pygame.mixer.music.set_volume(0.5) +#################################################### +#animals img +hint = pygame.transform.scale(pygame.image.load("images/hint.png"),(CHESSSIZE_X,CHESSSIZE_Y)) +capture_hint = pygame.transform.scale(pygame.image.load("images/capture-hint.png"),(CHESSSIZE_X,CHESSSIZE_Y)) +#Left +L_mouse = pygame.transform.scale(pygame.image.load('images/animals/left/1MouseLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +L_eagle = pygame.transform.scale(pygame.image.load('images/animals/left/2EagleLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +L_wolf = pygame.transform.scale(pygame.image.load('images/animals/left/3WolfLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +L_leopard = pygame.transform.scale(pygame.image.load('images/animals/left/4LeopardLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +L_tiger = pygame.transform.scale(pygame.image.load('images/animals/left/5TigerLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +L_lion = pygame.transform.scale(pygame.image.load('images/animals/left/6LionLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +L_elephant = pygame.transform.scale(pygame.image.load('images/animals/left/7ElephantLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +L_fox = pygame.transform.scale(pygame.image.load('images/animals/left/8FoxLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) + +#Right +R_mouse = pygame.transform.scale(pygame.image.load('images/animals/right/1MouseRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +R_eagle = pygame.transform.scale(pygame.image.load('images/animals/right/2EagleRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +R_wolf = pygame.transform.scale(pygame.image.load('images/animals/right/3WolfRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +R_leopard = pygame.transform.scale(pygame.image.load('images/animals/right/4LeopardRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +R_tiger = pygame.transform.scale(pygame.image.load('images/animals/right/5TigerRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +R_lion = pygame.transform.scale(pygame.image.load('images/animals/right/6LionRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +R_elephant = pygame.transform.scale(pygame.image.load('images/animals/right/7ElephantRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +R_fox = pygame.transform.scale(pygame.image.load('images/animals/right/8FoxRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +############################################################################### + + +#colour########################################################### +BLACK = (0,0,0) +LIGHTBLUE = (40,191,255) +LIGHTBLUE2 = (0,0,255) +BGCOLOR = (230,230,250) +MAGENTA = (255,0,255) +LIGHTYELLOW= (255,225,0) +MYCOLOR = (255,165,0) +WHITE = (255,255,255) +GREEN = (0,255,0) +RED = (255,0,0) +BLUE = (0,0,255) +Crimson=(220,20,60) +LightPink=(255,182,193) +DeepSkyBlue=(0,191,255) +############################################################# + + +#TEXT +def print_text(WIN,font,x,y,text,fcolor=WHITE): + imgText = font .render(text,True,fcolor) + WIN.blit(imgText,(x,y)) + +###################################### +def draw_left_animals(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox): + if ID[7]: + WIN.blit(L_elephant,(l_elephant.x,l_elephant.y)) + if ID[2]: + WIN.blit(L_eagle, (l_eagle.x, l_eagle.y)) + if ID[4]: + WIN.blit(L_wolf, (l_wolf.x, l_wolf.y)) + if ID[6]: + WIN.blit(L_lion, (l_lion.x, l_lion.y)) + if ID[5]: + WIN.blit(L_leopard, (l_leopard.x, l_leopard.y)) + if ID[1]: + WIN.blit(L_mouse, (l_mouse.x, l_mouse.y)) + if ID[3]: + WIN.blit(L_fox, (l_fox.x, l_fox.y)) + +def draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox): + if ID[14]: + WIN.blit(R_elephant, (r_elephant.x, r_elephant.y)) + if ID[9]: + WIN.blit(R_eagle, (r_eagle.x, r_eagle.y)) + if ID[11]: + WIN.blit(R_wolf, (r_wolf.x,r_wolf.y)) + if ID[13]: + WIN.blit(R_lion, (r_lion.x, r_lion.y)) + if ID[12]: + WIN.blit(R_leopard, (r_leopard.x, r_leopard.y)) + if ID[8]: + WIN.blit(R_mouse, (r_mouse.x, r_mouse.y)) + if ID[10]: + WIN.blit(R_fox, (r_fox.x, r_fox.y)) + + +def draw_window(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox,r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox,id, x, y, status, MAP, MAP1,turn): + WIN.blit(SPACE,(0,0)) + path(id, x, y, status, MAP, MAP1, turn) + draw_left_animals(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox) + draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) + #WIN.blit(L_fox,(fox.x,fox.y)) + pygame.display.update() + +#animals rect +l_elephant = pygame.Rect(int(2/9 * WIDTH),int(0 / 7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +l_eagle = pygame.Rect(int(1 / 9 *WIDTH),int(1 / 7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +l_wolf = pygame.Rect(int(2/9 * WIDTH),int(2/7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +l_lion = pygame.Rect(int(2/9 * WIDTH),int(3/7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +l_leopard = pygame.Rect(int(2/9 * WIDTH),int(4/7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +l_mouse = pygame.Rect(int(2/9 * WIDTH),int(6/7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +l_fox = pygame.Rect(int(1/9 * WIDTH),int(5/7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) + +r_elephant = pygame.Rect(int(6/9*WIDTH),int(6/7*HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +r_eagle = pygame.Rect(int(7/9*WIDTH),int(5/7*HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +r_wolf = pygame.Rect(int(6/9*WIDTH),int(4/7*HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +r_lion = pygame.Rect(int(6/9*WIDTH),int(3/7*HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +r_leopard = pygame.Rect(int(6/9*WIDTH),int(2/7*HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +r_fox = pygame.Rect(int(7/9*WIDTH),int(1/7*HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +r_mouse = pygame.Rect(int(6/9*WIDTH),int(0/7*HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) +############################################# +l_animals =r_animals = 7 +def ismove(old_x,old_y,x,y,id,MAP,MAP1): + global l_animals + global r_animals + if id == 1: + if MAP[x][y] == 16: + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][y] == 14 or MAP1[x][y] == 15): + if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20: + return 0 + if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: + ID[14] = 0 + r_animals -= 1 + return 1 + if MAP[x][y] == 8: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][y] == 14 or MAP1[x][y] == 15): + if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20: + return 0 + if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: + ID[14] = 0 + r_animals -= 1 + return 1 + if MAP[x][y] == 8: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 2: + if MAP[x][y] == 16 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 18 and MAP1[x][y] != 15 and (9 < MAP[x][y] <= 14): + return 0 + if x == old_x and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=9): + if y > old_y: + for i in range(old_y+1,y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 17 and MAP[x][i] != 16 and MAP[x][i] != 18): + return 0 + if 8<=MAP[x][y]<=9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]]=0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else: + for i in range(y+1,old_y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 17 and MAP[x][i] != 16 and MAP[x][i] != 18 ): + return 0 + if 8<=MAP[x][y]<=9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]]=0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif y == old_y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=9): + if x > old_x: + for i in range(old_x+1,x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 17 and MAP[i][y] != 16 and MAP[i][y] != 18): + return 0 + if 8<=MAP[x][y]<=9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]]=0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else : + for i in range(x+1,old_x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 17 and MAP[i][y] != 16 and MAP[i][y] != 18): + return 0 + if 8<=MAP[x][y]<=9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]]=0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 3: + if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=10): + if 8 <= MAP[x][y] <= 10: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + return 0 + elif id == 4: + if MAP[x][y] == 16: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=11): + if 8 <= MAP[x][y] <= 11: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=11): + if 8 <= MAP[x][y] <= 11: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 5: + if MAP[x][y] == 16: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) ==1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=12): + if 8 <= MAP[x][y] <= 12: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=12): + if 8 <= MAP[x][y] <= 12 : + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 6: + if MAP[x][y] == 16: + return 0 + if MAP[x][y] == 20: + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=13): + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=13): + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=13): + if y > old_y: + for i in range(old_y+1,y): + if MAP[x][i] != 20 and MAP[x][i] != 1 : + return 0 + if 8 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else: + for i in range(y+1,old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1 : + return 0 + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8<=MAP[x][y]<=13): + if x > old_x: + for i in range(old_x+1,x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else: + for i in range(x+1,old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else: + return 0 + elif id == 7: + if MAP[x][y] == 16: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 9<=MAP[x][y]<=14): + if 9 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 and MAP[x][y] == 18 or MAP1[x][y] == 15 or 9<=MAP[x][y]<=14): + if 9 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 8: + if MAP[x][y] == 18: + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][y] == 7 or MAP1[x][y] == 17): + if MAP[x][y] == 7: + if MAP1[old_x][old_y] != 20: + ID[7] = 0 + l_animals -= 1 + return 1 + else: + return 0 + if MAP[x][y] == 1: + ID[1] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][y] == 7 or MAP1[x][y] == 17): + if MAP[x][y] == 7: + if MAP1[old_x][old_y] != 20: + ID[7] = 0 + l_animals -= 1 + return 1 + else: + return 0 + if MAP[x][y] == 1: + ID[1] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 9: + if MAP[x][y] == 18 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 16 and MAP1[x][y] != 17 and (2 old_y: + for i in range(old_y + 1, y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[i][y] != 15 and MAP[x][i] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + for i in range(y + 1, old_y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[i][y] != 15 and MAP[x][i] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif y == old_y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=2): + if x > old_x: + for i in range(old_x + 1, x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 15 and MAP[i][y] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + for i in range(x + 1, old_x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 15 and MAP[i][y] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + return 0 + elif id == 10: + if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=3): + if 1 <= MAP[x][y] <= 3: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + return 0 + elif id == 11: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=4): + if 1 <= MAP[x][y] <= 4: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=4): + if 1 <= MAP[x][y] <= 4: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 12: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=5): + if 1 <= MAP[x][y] <= 5: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=5): + if 1 <= MAP[x][y] <= 5: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 13: + if MAP[x][y] == 18: + return 0 + if MAP[x][y] == 20: + return 0 + if abs(x - old_x) ==1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if y > old_y: + for i in range(old_y+1,y): + if MAP[x][i] != 20 and MAP[x][i] != 8 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + for i in range(y+1,old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if x > old_x: + for i in range(old_x+1,x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + for i in range(x+1,old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + return 0 + elif id == 14: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else : + return 0 + +def path(id, x, y, status, MAP, MAP1, turn): + if status: + movement = [] + for i in range(9): + for j in range(7): + if turn == 0: + if right_move(x, y, i, j, id, MAP,MAP1): + movement.append([i, j]) + else: + if left_move(x, y, i, j, id, MAP,MAP1): + movement.append([i, j]) + for i, j in movement: + WIN.blit(hint, init.tran(i,j)) + WIN.blit(capture_hint,init.tran(x,y)) +#TODO:Judge who win +def left_win(x,y,MAP,MAP1): + global r_animals + if r_animals == 0: + return 1 + if MAP1[x][y] == 18 and 1<=MAP[x][y]<=7: + return 1 + isWin = 0 + for i in range(8,15): + if ID[i] == 1: + isWin = left_Wall(i,MAP,MAP1) + if isWin == 0: + return 0 + if isWin == 1: + return 1 + return 0 + +def left_move(old_x,old_y,x,y,id,MAP,MAP1): + if id == 8: + if MAP[x][y] == 18: + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][y] == 7 or MAP1[x][y] == 17): + if MAP[x][y] == 7: + if MAP1[old_x][old_y] != 20: + return 1 + else: + return 0 + if MAP[x][y] == 1: + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][y] == 7 or MAP1[x][y] == 17): + if MAP[x][y] == 7: + if MAP1[old_x][old_y] != 20: + return 1 + else: + return 0 + if MAP[x][y] == 1: + return 1 + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: + return 1 + return 1 + else : + return 0 + elif id == 9: + if MAP[x][y] == 18 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 16 and MAP1[x][y] != 17 and (2 old_y: + for i in range(old_y + 1, y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[i][y] != 15 and MAP[x][i] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + for i in range(y + 1, old_y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[i][y] != 15 and MAP[x][i] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif y == old_y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=2): + if x > old_x: + for i in range(old_x + 1, x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 15 and MAP[i][y] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + for i in range(x + 1, old_x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 15 and MAP[i][y] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + return 0 + elif id == 10: + if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=3): + if 1 <= MAP[x][y] <= 3: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + return 0 + elif id == 11: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=4): + if 1 <= MAP[x][y] <= 4: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=4): + if 1 <= MAP[x][y] <= 4: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else : + return 0 + elif id == 12: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=5): + if 1 <= MAP[x][y] <= 5: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=5): + if 1 <= MAP[x][y] <= 5: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else : + return 0 + elif id == 13: + if MAP[x][y] == 18: + return 0 + if MAP[x][y] == 20: + return 0 + if abs(x - old_x) ==1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if y > old_y: + for i in range(old_y+1,y): + if MAP[x][i] != 20 and MAP[x][i] != 8 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + for i in range(y+1,old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if x > old_x: + for i in range(old_x+1,x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + for i in range(x+1,old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + return 0 + elif id == 14: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else : + return 0 + +def left_Wall(id,MAP,MAP1): + if 8<=id<=14: + if id == 8: + old_x,old_y = init.calc(r_mouse.x,r_mouse.y) + elif id == 9: + old_x, old_y = init.calc(r_eagle.x, r_eagle.y) + elif id == 10: + old_x, old_y = init.calc(r_fox.x, r_fox.y) + elif id == 11: + old_x, old_y = init.calc(r_wolf.x, r_wolf.y) + elif id == 12: + old_x, old_y = init.calc(r_leopard.x, r_leopard.y) + elif id == 13: + old_x, old_y = init.calc(r_lion.x, r_lion.y) + elif id == 14: + old_x, old_y = init.calc(r_elephant.x, r_elephant.y) + for x in range(0,9): + for y in range(0,6): + if left_move(old_x,old_y,x,y,id,MAP,MAP1): + return 0 + return 1 +def right_win(x,y,MAP,MAP1): + isWin = 0 + global l_animals + if l_animals == 0: + return 1 + if MAP1[x][y] == 16 and 8 <= MAP[x][y] <= 14: + return 1 + for i in range(1, 8): + if ID[i] == 1: + isWin = right_Wall(i,MAP,MAP1) + if isWin == 0: + return 0 + if isWin == 1: + return 1 + return 0 + +def right_move(old_x,old_y,x,y,id,MAP,MAP1): + if id == 1: + if MAP[x][y] == 16: + return 0 + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][y] == 14 or MAP1[x][y] == 15): + if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20: + return 0 + if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: + return 1 + if MAP[x][y] == 8: + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][y] == 14 or MAP1[x][y] == 15): + if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20: + return 0 + if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: + return 1 + if MAP[x][y] == 8: + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 2: + if MAP[x][y] == 16 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 18 and MAP1[x][y] != 15 and (9 < MAP[x][y] <= 14): + return 0 + if x == old_x and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 9): + if y > old_y: + for i in range(old_y + 1, y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 17 and MAP[x][i] != 16 and MAP[x][i] != 18): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + for i in range(y + 1, old_y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 17 and MAP[x][i] != 16 and MAP[x][i] != 18): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif y == old_y and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 9): + if x > old_x: + for i in range(old_x + 1, x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 17 and MAP[i][y] != 16 and MAP[i][y] != 18): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + for i in range(x + 1, old_x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 17 and MAP[i][y] != 16 and MAP[i][y] != 18): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 3: + if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 10): + if 8 <= MAP[x][y] <= 10: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + return 0 + elif id == 4: + if MAP[x][y] == 16: + return 0 + if (MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 11): + if 8 <= MAP[x][y] <= 11: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 11): + if 8 <= MAP[x][y] <= 11: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 5: + if MAP[x][y] == 16: + return 0 + if (MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 12): + if 8 <= MAP[x][y] <= 12: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 12): + if 8 <= MAP[x][y] <= 12: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 6: + if MAP[x][y] == 16: + return 0 + if MAP[x][y] == 20: + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 13): + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 13): + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 13): + if y > old_y: + for i in range(old_y + 1, y): + if MAP[x][i] != 20 and MAP[x][i] != 1: + return 0 + if 8 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + for i in range(y + 1, old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1: + return 0 + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 13): + if x > old_x: + for i in range(old_x + 1, x): + if MAP[i][y] != 20 and MAP[i][y] != 1: + return 0 + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + for i in range(x + 1, old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1: + return 0 + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 7: + if MAP[x][y] == 16: + return 0 + if (MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 9 <=MAP[x][y] <= 14): + if 9 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 and MAP[x][y] == 18 or MAP1[x][y] == 15 or 9 <=MAP[x][y] <= 14): + if 9 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 +def right_Wall(id,MAP,MAP1): + if 1<=id<=7: + if id == 1: + old_x,old_y = init.calc(l_mouse.x,l_mouse.y) + elif id == 2: + old_x, old_y = init.calc(l_eagle.x, l_eagle.y) + elif id == 3: + old_x, old_y = init.calc(l_fox.x, l_fox.y) + elif id == 4: + old_x, old_y = init.calc(l_wolf.x, l_wolf.y) + elif id == 5: + old_x, old_y = init.calc(l_leopard.x, l_leopard.y) + elif id == 6: + old_x, old_y = init.calc(l_lion.x, l_lion.y) + elif id == 7: + old_x, old_y = init.calc(l_elephant.x, l_elephant.y) + for x in range(0,9): + for y in range(0,6): + if right_move(old_x,old_y,x,y,id,MAP,MAP1): + return 0 + return 1 +def main(): + global l_animals,r_animals + BGM.play(-1) + MAP = init.calc_map() + MAP1 = init.clac_MAP1() + game_status = start_game.starting_screen() + if not game_status: + return True + run = True + clock = pygame.time.Clock() + font = pygame.font.SysFont('kaiti',40) + status = id = old_x = old_y = x = y = turn = 0 + while run: + clock.tick(FPS) + for event in pygame.event.get(): + if event.type == pygame.QUIT: + run = False + elif event.type == pygame.MOUSEBUTTONDOWN: + b1, b2, b3 = pygame.mouse.get_pressed() + if b1 and not b3: + mouse_x , mouse_y = event.pos + old_x = x + old_y = y + x = int(mouse_x / WIDTH * 9) + y = int(mouse_y / HEIGHT * 7) + if status == 0: + id = MAP[x][y] + if 0 < id < 8 and turn == 0: + if id == 1: + Mouse.play() + elif id == 2: + Eagle.play() + elif id == 3: + Fox.play() + elif id == 4: + Wolf.play() + elif id == 5: + Leopard.play() + elif id == 6: + Lion.play() + elif id == 7: + Elephant.play() + status = 1 + elif 7 < id <15 and turn == 1: + if id == 8: + Mouse.play() + if id == 9: + Eagle.play() + if id == 10: + Fox.play() + if id == 11: + Wolf.play() + if id == 12: + Leopard.play() + if id == 13: + Lion.play() + if id == 14: + Elephant.play() + status = 2 + #TODO: Cirlce the elective animal + else: + if id == 1 and turn == 0 and status == 1: + if MAP[x][y] == id: + status = 1 + else: + if(ismove(old_x,old_y,x,y,id,MAP,MAP1)): + print(MAP1[old_x][old_y]) + l_mouse.x,l_mouse.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 1 + else: + status = 0 + elif id == 2 and turn == 0 and status == 1: + if MAP[x][y] == id: + status = 1 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + l_eagle.x , l_eagle.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 1 + else : + status = 0 + elif id == 3 and turn == 0 and status == 1: + if MAP[x][y] == id: + status = 1 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + l_fox.x , l_fox.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 1 + else : + status = 0 + elif id == 4 and turn == 0 and status == 1: + if MAP[x][y] == id: + status = 1 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + l_wolf.x , l_wolf.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 1 + else : + status = 0 + elif id == 5 and turn == 0 and status == 1: + if MAP[x][y] == id: + status = 1 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + l_leopard.x , l_leopard.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 1 + else : + status = 0 + elif id == 6 and turn == 0 and status == 1: + if MAP[x][y] == id: + status = 1 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + l_lion.x , l_lion.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 1 + else : + status = 0 + elif id == 7 and turn == 0 and status == 1: + if MAP[x][y] == id: + status = 1 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + l_elephant.x , l_elephant.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 1 + else : + status = 0 + elif id == 8 and turn == 1 and status == 2: + if MAP[x][y] == id: + status = 2 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + r_mouse.x , r_mouse.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 0 + else : + status = 0 + elif id == 9 and turn == 1 and status == 2: + if MAP[x][y] == id: + status = 2 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + r_eagle.x , r_eagle.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 0 + else : + status = 0 + elif id == 10 and turn == 1 and status == 2: + if MAP[x][y] == id: + status = 2 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + r_fox.x , r_fox.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 0 + else : + status = 0 + elif id == 11 and turn == 1 and status == 2: + if MAP[x][y] == id: + status = 2 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + r_wolf.x , r_wolf.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 0 + else : + status = 0 + elif id == 12 and turn == 1 and status == 2: + if MAP[x][y] == id: + status = 2 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + r_leopard.x , r_leopard.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 0 + else : + status = 0 + elif id == 13 and turn == 1 and status == 2: + if MAP[x][y] == id: + status = 2 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + r_lion.x , r_lion.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 0 + else : + status = 0 + elif id == 14 and turn == 1 and status == 2: + if MAP[x][y] == id: + status = 2 + else: + if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : + r_elephant.x , r_elephant.y = init.tran(x,y) + MAP[old_x][old_y] = MAP1[old_x][old_y] + MAP[x][y] = id + status = 0 + turn = 0 + else : + status = 0 + if left_win(x,y,MAP,MAP1): + run = False + if right_win(x,y,MAP,MAP1): + run = False + draw_window(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox,r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox,id, x, y, status, MAP, MAP1,turn) + + if left_win(x, y, MAP, MAP1): + print_text(WIN, font, 500, 400, "Left Win!", RED) + pygame.display.update() + if right_win(x, y, MAP, MAP1): + print_text(WIN, font, 500, 400, "Right Win!", BLUE) + pygame.display.update() + time.sleep(2) + #os.system("pause") + + +if __name__ == "__main__": + again = 1 + while again == 1: + l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion, r_leopard, r_fox, r_mouse=init.refresh() + draw_window(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion, + r_leopard, r_mouse, r_fox,0,0,0,0,0,0,0) + main() + pygame.quit() diff --git a/src/path/path.py b/src/path/path.py index 0b73811..743ecfb 100644 --- a/src/path/path.py +++ b/src/path/path.py @@ -1,5 +1,5 @@ import pygame -import win32con + rules = {} for i in range(1, 8): diff --git a/src/start_game.py b/src/start_game.py index 544a183..5b14df0 100644 --- a/src/start_game.py +++ b/src/start_game.py @@ -1,6 +1,6 @@ import pygame import init -import main + font_addr = pygame.font.get_default_font() font = pygame.font.Font(font_addr, 36)