placing and removing of flags
This commit is contained in:
		
							parent
							
								
									6d130398eb
								
							
						
					
					
						commit
						7b6005ef4c
					
				
							
								
								
									
										23
									
								
								minebash.py
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								minebash.py
									
									
									
									
									
								
							@ -10,6 +10,7 @@ NOTHING = 0
 | 
				
			|||||||
MINE = -1
 | 
					MINE = -1
 | 
				
			||||||
FLAG = -2
 | 
					FLAG = -2
 | 
				
			||||||
UNKNOWN = -3
 | 
					UNKNOWN = -3
 | 
				
			||||||
 | 
					FLAG_MINE = -4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CURSOR_POSITION=[0,0]
 | 
					CURSOR_POSITION=[0,0]
 | 
				
			||||||
FIELDS_CLEARED = 0
 | 
					FIELDS_CLEARED = 0
 | 
				
			||||||
@ -17,7 +18,7 @@ FIELDS_CLEARED = 0
 | 
				
			|||||||
width, height = 9, 9
 | 
					width, height = 9, 9
 | 
				
			||||||
MINECOUNT = 10
 | 
					MINECOUNT = 10
 | 
				
			||||||
#put logic for program param here
 | 
					#put logic for program param here
 | 
				
			||||||
playfield = [[-3 for x in range(width)] for y in range(height)]
 | 
					playfield = [[UNKNOWN for x in range(width)] for y in range(height)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
headline = '.'
 | 
					headline = '.'
 | 
				
			||||||
midline = '|'
 | 
					midline = '|'
 | 
				
			||||||
@ -39,7 +40,7 @@ def calculate_hint(col, row):
 | 
				
			|||||||
            if x >= 0 and x < len(playfield):
 | 
					            if x >= 0 and x < len(playfield):
 | 
				
			||||||
                for y in range(row-1, row+2):
 | 
					                for y in range(row-1, row+2):
 | 
				
			||||||
                    if y >= 0 and y < len(playfield[0]):
 | 
					                    if y >= 0 and y < len(playfield[0]):
 | 
				
			||||||
                        if(playfield[y][x] == MINE):
 | 
					                        if playfield[y][x] == MINE or playfield[y][x] == FLAG_MINE:
 | 
				
			||||||
                            hint+=1
 | 
					                            hint+=1
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        hint = MINE
 | 
					        hint = MINE
 | 
				
			||||||
@ -118,6 +119,8 @@ def print_playfield(playfield):
 | 
				
			|||||||
                rowstring += str(cell)
 | 
					                rowstring += str(cell)
 | 
				
			||||||
            elif cell == UNKNOWN or cell == MINE:
 | 
					            elif cell == UNKNOWN or cell == MINE:
 | 
				
			||||||
                rowstring+= '#'
 | 
					                rowstring+= '#'
 | 
				
			||||||
 | 
					            elif cell == FLAG_MINE or cell == FLAG:
 | 
				
			||||||
 | 
					                rowstring += 'P'
 | 
				
			||||||
            #elif cell == MINE:
 | 
					            #elif cell == MINE:
 | 
				
			||||||
            #    rowstring += 'X'
 | 
					            #    rowstring += 'X'
 | 
				
			||||||
            if selected:
 | 
					            if selected:
 | 
				
			||||||
@ -133,7 +136,7 @@ def print_playfield(playfield):
 | 
				
			|||||||
            #print midline
 | 
					            #print midline
 | 
				
			||||||
    #print currentline
 | 
					    #print currentline
 | 
				
			||||||
    #print tailline
 | 
					    #print tailline
 | 
				
			||||||
    stdscr.addstr(currentline, 0, tailline + str(FIELDS_CLEARED))
 | 
					    stdscr.addstr(currentline, 0, tailline)
 | 
				
			||||||
    currentline +=1
 | 
					    currentline +=1
 | 
				
			||||||
    #print tailline
 | 
					    #print tailline
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -161,6 +164,18 @@ def check_score():
 | 
				
			|||||||
    if FIELDS_CLEARED == (width*height)-MINECOUNT:
 | 
					    if FIELDS_CLEARED == (width*height)-MINECOUNT:
 | 
				
			||||||
        gameover(True)
 | 
					        gameover(True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def place_flag(x, y):
 | 
				
			||||||
 | 
					    global playfield
 | 
				
			||||||
 | 
					    #playfield[y][x] = playfield[y][x]
 | 
				
			||||||
 | 
					    if playfield[y][x] == MINE:
 | 
				
			||||||
 | 
					        playfield[y][x] = FLAG_MINE
 | 
				
			||||||
 | 
					    elif playfield[y][x] == UNKNOWN:
 | 
				
			||||||
 | 
					        playfield[y][x] = FLAG
 | 
				
			||||||
 | 
					    elif playfield[y][x] == FLAG_MINE:
 | 
				
			||||||
 | 
					        playfield[y][x] = MINE
 | 
				
			||||||
 | 
					    elif playfield[y][x] == FLAG:
 | 
				
			||||||
 | 
					        playfield[y][x] = UNKNOWN
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def handle_input(k):
 | 
					def handle_input(k):
 | 
				
			||||||
    global CURSOR_POSITION
 | 
					    global CURSOR_POSITION
 | 
				
			||||||
    if k == curses.KEY_LEFT:
 | 
					    if k == curses.KEY_LEFT:
 | 
				
			||||||
@ -175,6 +190,8 @@ def handle_input(k):
 | 
				
			|||||||
    elif k == curses.KEY_DOWN:
 | 
					    elif k == curses.KEY_DOWN:
 | 
				
			||||||
        if CURSOR_POSITION[1] < height-1:
 | 
					        if CURSOR_POSITION[1] < height-1:
 | 
				
			||||||
            CURSOR_POSITION[1] +=1
 | 
					            CURSOR_POSITION[1] +=1
 | 
				
			||||||
 | 
					    elif k == ord('f'):
 | 
				
			||||||
 | 
					        place_flag(CURSOR_POSITION[0], CURSOR_POSITION[1])
 | 
				
			||||||
    elif k == ord(' '):
 | 
					    elif k == ord(' '):
 | 
				
			||||||
        hit(CURSOR_POSITION[0], CURSOR_POSITION[1])      
 | 
					        hit(CURSOR_POSITION[0], CURSOR_POSITION[1])      
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user