??====================================Author:YoungwookKim(Korean)========================================================================Contact:rumia0601@gmail.com========================================================================????? p?? T?!====================================????,??? ???t? ???? ?D? ??t??? JŔ??.t? ?,t? ???????? ܭY?D? ???X?$? ??.???t?,t? ??????@? ????t? ??.ܭY?@? ??X??:5x52(??? 0????? ? h?? ?]?,??@? ?]?X? ?|? 8??,T? ι@? ????X? ?]?D? ?t??? ??t??!???t?|?t? HP?? ???X?? $???t?|?t?,HP?? ?????.?? ?L? ?L? 8? ?|? ?? ????? 2(??? 0???t? ??$????!?貈? ? ?X???̹ t? ?ҠѬ??? ???? ? ̹䴴? ?? ? ?ǔ? ????t??.?? ?,2(??? 0???D? ̹?? ??%?t?|? ??.?Ż?????Ƭ??? ?? p?t?0?(0(??? 0????? ?L?)?? P? ????(1(??? 0????? ?L?)D? ??%?XՔ? ??D? L? ? ???.2(??? 0???@? ?ƌ? X?̹ T? ????t? ??...image::AdvancedOutputAlpha1.gif:class:inlined-right..code-block::python:linenos:importsys,pygamepygame.init()size=width,height=320,240speed=[2,2]black=0,0,0screen=pygame.display.set_mode(size)ball=pygame.image.load("AdvancedOutputAlpha1.gif")ballrect=ball.get_rect()while1:foreventinpygame.event.get():ifevent.type==pygame.QUIT:sys.exit()ballrect=ballrect.move(speed)ifballrect.left<0orballrect.right>width:speed[0]=-speed[0]ifballrect.top<0orballrect.bottom>height:speed[1]=-speed[1]screen.fill(black)screen.blit(ball,ballrect)pygame.display.flip()..image::AdvancedOutputAlpha2.gif:class:inlined-right..code-block::python:linenos:importsys,pygamepygame.init()size=width,height=320,240speed=[2,2]black=0,0,0screen=pygame.display.set_mode(size)ball=pygame.image.load("AdvancedOutputAlpha2.gif")ballrect=ball.get_rect()while1:foreventinpygame.event.get():ifevent.type==pygame.QUIT:sys.exit()ballrect=ballrect.move(speed)ifballrect.left<0orballrect.right>width:speed[0]=-speed[0]ifballrect.top<0orballrect.bottom>height:speed[1]=-speed[1]screen.fill(black)screen.blit(ball,ballrect)pygame.display.flip()..image::AdvancedOutputAlpha3.gif:class:inlined-right..code-block::python:linenos:importsys,pygamepygame.init()size=width,height=320,240speed=[2,2]black=0,0,0screen=pygame.display.set_mode(size)ball=pygame.image.load("AdvancedOutputAlpha3.gif")ballrect=ball.get_rect()while1:foreventinpygame.event.get():ifevent.type==pygame.QUIT:sys.exit()ballrect=ballrect.move(speed)ifballrect.left<0orballrect.right>width:speed[0]=-speed[0]ifballrect.top<0orballrect.bottom>height:speed[1]=-speed[1]screen.fill(black)screen.blit(ball,ballrect)pygame.display.flip()generateboardh?? 4????? ̹䴴??? 2(??? 0????? h?? ?]?,??@? ?]?X? ??|? ?X???.$???`? DՔ? ???.??,printboardh?? 1(??? 0??Ř??? 2(?5? 0???D? ??%???.??%? ????@? board[i][j]? 1x??? D?̲ ???? 0?|? ?|????.t? ?????@? ? ? ??%? ??t??.L?P???|? ?̬?X?$?t? ????X? l?0?|? ???? ȴ? l?0?|? Ĭ??t?|? t? ? ?ɝɠ? ? ???.tǃ?@? ?d?????? ? ?? ?? ??,?tnj??? ??? ??1? (?? ?????? GUIt???̹ T?ܴ ??1?@? CUI)L?8?t??.????,t? l??? ????@? ? ?X? ????? ι?.????D? t????? ?|?? ???t?????t?p??? $???|? L? ????L?D? #?<?t????? ??D? #?<?t?????t?p??? $???|? L? ???? ????|? #?<?t???????D? T? lЌ? X?? ????D? T? 䲑ň? #????t??t? x?0ј?tǤ?|? ???? Flood-itD? l????t??l??? ????t? ? ?X?0? L?8??? ????ɔ? ι?.<8?? T?ܴ>::importpygame,sys,randomfrompygame.localsimport*maxHP=10white=(255,255,255)gray=(127,127,127)black=(0,0,0)red=(255,0,0)green=(0,255,0)blue=(0,0,255)pygame.init()pygame.display.set_caption("RedorBlackProject")width=640height=480myScreen=pygame.display.set_mode((width,height))myTextFont=pygame.font.Font("HoonWhitecatR.ttf",32)myText=myTextFont.render((str(maxHP)+"/"+str(maxHP)),True,red,gray)myTextArea=myText.get_rect()myTextArea.center=(width/2,height/2)fpsClock=pygame.time.Clock()defmain():HP=5board,b_red,b_black=generateBoard(5,5)#1whileTrue:myText=myTextFont.render((str(HP)+"/"+str(maxHP)),True,red,gray)myScreen.fill(gray)myScreen.blit(myText,myTextArea)drawHP(HP)drawButtons()drawBoard(board)#2foreventinpygame.event.get():ifevent.type==QUIT:pygame.quit()sys.exit()elifevent.type==KEYDOWN:ifevent.key==K_UP:ifHP!=10:HP=HP+1elifevent.key==K_DOWN:ifHP!=0:HP=HP-1elifevent.type==MOUSEBUTTONUP:x,y=event.posifpygame.Rect(270,425,45,45).collidepoint(x,y):#3ifb_red>=b_black:ifHP!=10:HP=HP+1board,b_red,b_black=generateBoard(5,5)elifb_red<b_black:ifHP!=0:HP=HP-1board,b_red,b_black=generateBoard(5,5)elifpygame.Rect(325,425,45,45).collidepoint(x,y):#4ifb_red<=b_black:ifHP!=10:HP=HP+1board,b_red,b_black=generateBoard(5,5)elifb_red>b_black:ifHP!=0:HP=HP-1board,b_red,b_black=generateBoard(5,5)pygame.display.update()fpsClock.tick(60)defdrawHP(HP):r=int((height-40)/maxHP)pygame.draw.rect(myScreen,gray,(20,20,20,20+((maxHP-0.5)*r)))foriinrange(maxHP):ifHP>=(maxHP-i):pygame.draw.rect(myScreen,blue,(20,20+(i*r),20,r))pygame.draw.rect(myScreen,white,(20,20+(i*r),20,r),1)returndefdrawButtons():r=45r_margin=10colors=[red,black]num=2margin=int((width-((r*num)+(r_margin*(num-1))))/2)foriinrange(0,num):left=margin+(i*r)+(i*r_margin)up=height-r-10pygame.draw.rect(myScreen,colors[i],(left,up,r,r))pygame.draw.rect(myScreen,gray,(left+2,up+2,r-4,r-4),2)defgenerateBoard(width,height):#5board=[]b_red=0b_black=0forxinrange(width):column=[]foryinrange(height):column.append(random.randint(0,1))board.append(column)forxinrange(width):foryinrange(height):if(board[x][y]==1):b_red=b_red+1elif(board[x][y]==0):b_black=b_black+1returnboard,b_red,b_blackdefdrawBoard(board):#6r=50b_width=5b_height=5l_margin=int((width-(b_width*r))/2)u_margin=int((height-(b_height*r))/2)forxinrange(5):foryinrange(5):left=x*r+l_marginup=y*r+u_marginifboard[x][y]==1:color=red;elifboard[x][y]==0:color=blackpygame.draw.rect(myScreen,color,(left,up,r,r))left=l_marginup=u_marginpygame.draw.rect(myScreen,white,(left-1,up-1,r*5+1,r*b_height+1),1)if__name__=='__main__':main()
Edit on GitHub