From f0db269e646cbb2a38da6ade4b74e10f5933fc83 Mon Sep 17 00:00:00 2001 From: LBY89 Date: Tue, 19 Apr 2022 09:36:08 +0300 Subject: [PATCH 1/2] English Version --- box.png | Bin 0 -> 253 bytes done.png | Bin 0 -> 635 bytes floor.png | Bin 0 -> 210 bytes peli.py | 4 +- peliEnglish.py | 119 +++++++++++++++++++++++++++++++++++++++++++++++ robot.png | Bin 0 -> 1099 bytes target.png | Bin 0 -> 395 bytes target_robot.png | Bin 0 -> 1237 bytes wall.png | Bin 0 -> 202 bytes 9 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 box.png create mode 100644 done.png create mode 100644 floor.png create mode 100644 peliEnglish.py create mode 100644 robot.png create mode 100644 target.png create mode 100644 target_robot.png create mode 100644 wall.png diff --git a/box.png b/box.png new file mode 100644 index 0000000000000000000000000000000000000000..b7a37e179883f5f8b7b26152b800787dfb3ce118 GIT binary patch literal 253 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1|;R|J2nC-mSQK*5Dp-y;YjHK@;M7UB8wRq z_>O=u<5X=vX`tYIPZ!6KjK;UO9JyK*L|Pv{UR=A=bow&w&4Fhh%@p|;d(J#dprl@e zOY>^fZl)h=E}U2#XL)?fwOLCXv>ypbwO_DkN&8*jJte5By3c!We{BU%t4EM# zYT2~R@_CYJ*_JKG6ixUR7IO4DXUI4`hG;+tT}aT>Y@uF$2 ZWyj5h^UZX9BY;k2@O1TaS?83{1OUiZS9SmZ literal 0 HcmV?d00001 diff --git a/done.png b/done.png new file mode 100644 index 0000000000000000000000000000000000000000..db1a01d444e47f8241ddbaceb7afaf33ea8b734f GIT binary patch literal 635 zcmV->0)+jEP)Z5oS^OM1=k@PG8^sUU1qZz&0@v>~MAR$_wzFZLj&J$MLcVyBlz zC?s(s-|BSP=QIn;_s+w7?9LABvn)&D0*q--K#IWiAe~N6a~@+;tyTdSt%xV08=i=6 zcp|zH7<~))d_Je=aVtvM+j!U#0Vo!Wj+o@czwt5v6!znmo9;;4&EG{pKdUP)Iz+ zagnEohdgXH0r*202R%&mxtG!lv7_+_O+u-~U0k7H#rQW19|CUUa8{Ll5k@5jvN z8TkED5qBac@?&m}c04}3w$|2Y&(2DfABpIuv0NySI6I>o4s)`!Bw2bSq9W(fDCg0r zWJ%k&=EKSp(G5>TH?%(cy$`lT?4F2E6W6qsC!!mkh;Dcyx-oo@T>oYBzv7w|`2%%( Vhqz^>ilP7j002ovPDHLkV1f@|AkP2* literal 0 HcmV?d00001 diff --git a/floor.png b/floor.png new file mode 100644 index 0000000000000000000000000000000000000000..fe4e1a3ea66e9b77efeaf343c8c397e357325fa9 GIT binary patch literal 210 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1|;R|J2nC-mSQK*5Dp-y;YjHK@;M7UB8wRq z_>O=u<5X=vX`o<(%P|2dVi}eDny*bi8^3ku3EsFSj#ovhTNVQC OXYh3Ob6Mw<&;$Un%|tZ- literal 0 HcmV?d00001 diff --git a/peli.py b/peli.py index 21dc6b5..5965f6f 100644 --- a/peli.py +++ b/peli.py @@ -9,7 +9,7 @@ def __init__(self): self.korkeus = len(self.kartta) self.leveys = len(self.kartta[0]) - self.skaala = self.kuvat[0].get_width() + self.skaala = self.kuvat[0].get_width()#skaala = scale nayton_korkeus = self.skaala * self.korkeus nayton_leveys = self.skaala * self.leveys @@ -19,7 +19,7 @@ def __init__(self): pygame.display.set_caption("Sokoban") - self.silmukka() + self.silmukka()#self.main_loop() def lataa_kuvat(self): self.kuvat = [] diff --git a/peliEnglish.py b/peliEnglish.py new file mode 100644 index 0000000..c70d901 --- /dev/null +++ b/peliEnglish.py @@ -0,0 +1,119 @@ +import pygame + +class Sokoban: + def __init__(self): + pygame.init() + + self.load_images() + self.new_game() + + self.height = len(self.map) + self.width = len(self.map[0]) + self.scale = self.images[0].get_width() + + window_height = self.scale * self.height + window_width = self.scale * self.width + self.window = pygame.display.set_mode((window_width, window_height)) + + self.game_font = pygame.font.SysFont("Arial", 24) + + pygame.display.set_caption("Sokoban") + + self.main_loop() + + def load_images(self): + self.images = [] + for name in ["floor", "wall", "target", "box", "robot", "done", "target_robot"]: + self.images.append(pygame.image.load(name + ".png")) + + def new_game(self): + + self.map = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1], + [1, 2, 3, 0, 0, 0, 1, 0, 0, 1, 2, 3, 0, 0, 0, 0, 1], + [1, 0, 0, 1, 2, 3, 0, 2, 3, 0, 0, 0, 1, 0, 0, 0, 1], + [1, 0, 4, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] + + self.moves = 0 + + def main_loop(self): + while True: + self.check_events() + self.draw_window() + + def check_events(self): + for event in pygame.event.get(): + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT: + self.move(0, -1) + if event.key == pygame.K_RIGHT: + self.move(0, 1) + if event.key == pygame.K_UP: + self.move(-1, 0) + if event.key == pygame.K_DOWN: + self.move(1, 0) + + if event.type == pygame.QUIT: + exit() + def move(self, move_y, move_x): + robot_old_y, robot_old_x = self.find_robot() + robot_new_y = robot_old_y + move_y + robot_new_x = robot_old_x + move_x + + if self.map[robot_new_y][robot_new_x] == 1: + return + + if self.map[robot_new_y][robot_new_x] in [3, 5]: + box_new_y = robot_new_y + move_y + box_new_x = robot_new_x + move_x + + if self.map[box_new_y][box_new_x] in [1, 3, 5]: + return + + self.map[robot_new_y][robot_new_x] -= 3 + self.map[box_new_y][box_new_x] += 3 + + self.map[robot_old_y][robot_old_x] -= 4 + self.map[robot_new_y][robot_new_x] += 4 + + self.moves += 1 + + def find_robot(self ): + for y in range(self.height): + for x in range(self.width): + if self.map[y][x] in [4, 6]: + return (y, x) + + def draw_window(self): + self.window.fill((0, 0, 0)) + + for y in range(self.height): + for x in range(self.width): + square = self.map[y][x] + self.window.blit(self.images[square], (x * self.scale, y * self.scale)) + + game_text = self.game_font.render("F2 = new game", True, (255, 0, 0)) + self.window.blit(game_text, (200, self.height * self.scale + 10)) + + game_text = self.game_font.render("Esc = exit game", True, (255, 0, 0)) + self.window.blit(game_text, (400, self.height * self.scale + 10)) + + if self.game_solved(): + game_text = self.game_font.render("Congratulations, you solved the game!", True, (255, 0, 0)) + game_text_x = self.scale * self.width / 2 - game_text.get_width() / 2 + game_text_y = self.scale * self.height / 2 - game_text.get_height() / 2 + pygame.draw.rect(self.window, (0, 0, 0), (game_text_x, game_text_y, game_text.get_width(), game_text.get_height())) + self.window.blit(game_text, (game_text_x, game_text_y)) + + pygame.display.flip() + + def game_solved(self): + for y in range(self.height): + for x in range(self.width): + if self.map[y][x] in [2, 6]: + return False + return True + +if __name__ == "__main__": + Sokoban() \ No newline at end of file diff --git a/robot.png b/robot.png new file mode 100644 index 0000000000000000000000000000000000000000..988b4a2fd48bda2eee57afe35519abf32697a4a8 GIT binary patch literal 1099 zcmV-R1ho5!P)uL}R5e7zZ12O@A4O4^nwrYdEi5b$kH=|kZN+Z43yJ6R`GEgmMm!!5u~-bZ+nuL# zyWPZMF+3iR=&<66ba!{-^Z96RZ_m?pbadeJ`RMBE5*_xRPfH6nHZ}-{!vNIP)lpwx zPj7E8Yinycc0D~k93CEGGMO%QMx&9Tp&`vV2qChvvO<4<|K+>QW+NJn7PP&tbGcll zLqt&&tX6ALW4E`rMWi5xNERn2C;Ya!$j88+H8p%UJDa2bX?B)6RplJ`%Hg1)p+Q(| zp+rAYhd<{G?81nR=zIw&?kqEy4f2gX+(Bi9B2si}_rK!Htg+vEM@Qj$vX1opu zJ3viURi6H%N00a+kpN)OY!(?>ED@v8$oTm9zv^u^o5*lED4SlZY={W`v;u(uKRskQE~GiQu?Gi8MAg^7*r8 zH?|cCAw*PFWp{TM09n3S{Wv;0x*RJ4LWoREOmKdFo+FD!qbx2i($dlbz`?-*4u=E1 zUY|Es1cVT2Yir};;vz>D3WdPz}_Mv&Or!~&CN}`4<670 zWbbEBO{P4%x}6<5z23~2)m09F!51$W9v;@5gRo-$CGf?S_d;jDp8*fAy#EgTEhxSa zB37%F)u&IndeMCM&Ye8FyE8NVczrpRmU>kx84_aTvYK$jK#Ur{#Y_bs1kH!x9r R65{{>002ovPDHLkV1g1+^Ai97 literal 0 HcmV?d00001 diff --git a/target.png b/target.png new file mode 100644 index 0000000000000000000000000000000000000000..4c7eed7d918663e9e0b9e1b0a38c6f47e0b21b18 GIT binary patch literal 395 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1|;R|J2nC-mSQK*5Dp-y;YjHK@;M7UB8wRq z_>O=u<5X=vX$A&HT~8Oskc`H+v%L8ZEAY51Jhivz>ywle*Qu@tDr`J?62qpRI=(*H z&aLse|E%D(#&5qYA9>^|gqv-C?-Tx5^U~|&zLEt% zOXZmj-)Z<7z3Y)LUa~}wd-ZHN-iXgPgHQj;o)mMn@yaXqT!*c84Znf5yz*n3bgMzL z=jt2HlUvQL^fYREZ3=&fX3RKr>ffaq%?_7NUY(qI&2q&$`HknRetqEiyzZ$#&`W9^ n=Df_G?A<@@&#Ag<&?j>tmaa?V?7?fxKm-sgRv|MSmt&hvgrPNy@*HGurC0}usW z{GZOwP9Y9$HX9oo8z_px(9lqlZDL}Aa5zj|T^$1h148&*E*J0?GU9MJ2nK^JEG(qh z78Vu=27@>p4$-vYg|xJ^;BvWWXlO{WH8wWla=B=3ZWc}Z@2jN+i;Ii+d_Dlm%F3vy zsGzN_jk&qGq<*cft!!^^Q(j(vZYwD%p}V_Va|}X+%*@Qt(a~}KY&M$-1OjRMUbNZm z_NyaAQ50%wYE+F~Sy>Sgf*2uj?CtIG`{X1a1Ai43^4;iYlKtn=QOZIg4uP+%Rw^qi zg>efN5(WL0N)oEr`SJz`H~;}etrf14248ei?3Q`^qX6Vf36-|oZj2H|C zoK`EVKw*A0ierZ5J@dSh$O+ohrnqm?eFi;*wt({Yo^NtZLgLjiHSmh zAN4{+i4f#Z-K&*>bZcviUmiV5YKsBsdVf1UPIYy4s^6HpT}AFfF8Sq7PEP3Z`%{N- zD(GV0jQ&-K$xTQW>0eJbj8q|?{1;D-VzgJSSPTXS0Wg_NeE#G~R>MptlV<8fWH02B zY=lA~*4EYlkmc;^$Ii~q`PhtnIb=m!M$U*V77K@mhe@VDAi(70B(=4*0BmkC<;qwJxB(zMkXb z6y?%Ad%9mMA?*VL15{O2sS03scNd$@mK9Gr#P{r)GBP$chTrce8jaG|*Qd(I`1m-( z!^0F87c-(E7EMbOx7&@PC|Q5tX#GgUdXZIk9 zh(scIy!KW})&VF`L+00000NkvXXu0mjfI~F>= literal 0 HcmV?d00001 diff --git a/wall.png b/wall.png new file mode 100644 index 0000000000000000000000000000000000000000..19eab8b162ad580bbd4c7829cfda6ea05a492d86 GIT binary patch literal 202 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1|;R|J2nC-mSQK*5Dp-y;YjHK@;M7UB8wRq z_>O=u<5X=vX`o<^r;B4qM&sLC8+i{X2(UQz#QZ4byJ+5^v$5{2OUw3OQ`ApN@t(QO zyzkRB<&#GxpJ$cN?v`*$=IB*4X}dry_c_KNtW2 literal 0 HcmV?d00001 From b39e8ed5e6b77121aebf824d207c075a3168c182 Mon Sep 17 00:00:00 2001 From: LBY89 Date: Tue, 19 Apr 2022 10:13:26 +0300 Subject: [PATCH 2/2] Eng V --- peliEnglish.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/peliEnglish.py b/peliEnglish.py index c70d901..fa6f9d1 100644 --- a/peliEnglish.py +++ b/peliEnglish.py @@ -13,7 +13,7 @@ def __init__(self): window_height = self.scale * self.height window_width = self.scale * self.width - self.window = pygame.display.set_mode((window_width, window_height)) + self.window = pygame.display.set_mode((window_width, window_height + self.scale)) self.game_font = pygame.font.SysFont("Arial", 24) @@ -27,6 +27,7 @@ def load_images(self): self.images.append(pygame.image.load(name + ".png")) def new_game(self): + #each matrix pos represents an actrual object from self.images self.map = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1], @@ -38,11 +39,12 @@ def new_game(self): self.moves = 0 def main_loop(self): + #keep adding executions going next level while True: self.check_events() self.draw_window() - def check_events(self): + def check_events(self):#decides real game moves for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: @@ -93,6 +95,9 @@ def draw_window(self): square = self.map[y][x] self.window.blit(self.images[square], (x * self.scale, y * self.scale)) + game_text = self.game_font.render("Moves: " + str(self.moves), True, (255, 0, 0)) + self.window.blit(game_text, (25, self.height * self.scale + 10)) + game_text = self.game_font.render("F2 = new game", True, (255, 0, 0)) self.window.blit(game_text, (200, self.height * self.scale + 10))