Exemplo n.º 1
0
	def attack_button_clicked(self, row, col):
		
		#Shows message box.
		messagebox.showinfo('Attack Grid','You clicked on: \nRow:'+ str(row + 1) + '\nColumn:' + str(col + 1), icon = 'warning')
		
		#User drops bomb on AI defend grid.
		t00_0_ai.defend_grid.drop_bomb(self.attack_grid, row, col)
		
		#Disables buttons. 
		button = self.attack_grid_buttons[row][col]
		button['state'] = 'disabled'
		
		#Gets the ai's chosen location to drop bomb.
		row, column = t00_0_ai.get_choice()
		
		#AI dropbs bomb on you. 
		self.defend_grid.drop_bomb(t00_0_ai.attack_grid, row, col)
		
		#Updates attack and defend grid.
		self.update_GUI(self.attack_grid.grid, self.attack_grid_buttons)
		self.update_GUI(self.defend_grid.grid, self.defend_grid_buttons)
		
		
		#Win statement. Checks if the Vessels are sunk. Then displays winner. 
		if self.defend_grid.all_vessels_sunk():
			
			messagebox.showerror('You Lose!', 'The AI sunk all your ships :(', icon='error')
			self.set_grid('disabled', self.attack_grid_buttons)
			
		elif t00_0_ai.defend_grid.all_vessels_sunk():
			
			messagebox.showerror('You Win!', 'YOU ARE A WINNER!! :)', icon='info')
			self.set_grid('disabled', self.attack_grid_buttons)
Exemplo n.º 2
0
def main() :
    for index in range(0, grid.NUM_OF_VESSELS) :
        human.get_location(index)
        t00_0_ai.get_location(index)

#    t00_0_ai.attack_grid.drop_test_bombs()
#    human.attack_grid.drop_test_bombs()

    while (not has_winner()) :
        # user's turn
        row, column = human.get_choice()
        if (t00_0_ai.defend_grid.is_hit(row, column)) :
            print("HIT!!")
        else :
            print("You missed.")
        t00_0_ai.defend_grid.drop_bomb(human.attack_grid, row, column)
        print()

        #ai's turn
        row, column = t00_0_ai.get_choice()
        if (human.defend_grid.is_hit(row, column)) :
            print("You've been hit.")
        else :
            print("I missed.")
        human.defend_grid.drop_bomb(t00_0_ai.attack_grid, row, column)
        human.defend_grid.print_grid()

    announce_winner()
Exemplo n.º 3
0
    def attack_button_clicked(self, row, column):

        t00_0_ai.defend_grid.drop_bomb(self.attack_grid, row, column)
        ai_row, ai_column = t00_0_ai.get_choice()

        self.defend_grid.drop_bomb(t00_0_ai.attack_grid, ai_row, ai_column)

        button_clicked = self.attack_buttons[row][column]
        button_clicked['text'] = self.attack_grid.grid[row][column]
        entered_location = ("Column:", str(column + 1), "Row:", str(row + 1))

        tkinter.messagebox.showinfo("Attack Grid", \
               entered_location)

        self.win_state()
        button_clicked['state'] = 'disabled'
Exemplo n.º 4
0
	def attack_button_clicked(self,row,column) :
		
		t00_0_ai.defend_grid.drop_bomb(self.attack_grid,row,column)			
		ai_row,ai_column = t00_0_ai.get_choice()
		
		self.defend_grid.drop_bomb(t00_0_ai.attack_grid,ai_row,ai_column)
		
		button_clicked = self.attack_buttons[row][column]				
		button_clicked['text'] = self.attack_grid.grid[row][column]		
		entered_location = ("Column:",str(column+1), "Row:" , str(row+1))
		
		tkinter.messagebox.showinfo("Attack Grid", \
									entered_location)

		self.win_state()											
		button_clicked['state'] = 'disabled'								
Exemplo n.º 5
0
    def attack_button_clicked(self, row, col):

        #Shows message box.
        messagebox.showinfo('Attack Grid',
                            'You clicked on: \nRow:' + str(row + 1) +
                            '\nColumn:' + str(col + 1),
                            icon='warning')

        #User drops bomb on AI defend grid.
        t00_0_ai.defend_grid.drop_bomb(self.attack_grid, row, col)

        #Disables buttons.
        button = self.attack_grid_buttons[row][col]
        button['state'] = 'disabled'

        #Gets the ai's chosen location to drop bomb.
        row, column = t00_0_ai.get_choice()

        #AI dropbs bomb on you.
        self.defend_grid.drop_bomb(t00_0_ai.attack_grid, row, col)

        #Updates attack and defend grid.
        self.update_GUI(self.attack_grid.grid, self.attack_grid_buttons)
        self.update_GUI(self.defend_grid.grid, self.defend_grid_buttons)

        #Win statement. Checks if the Vessels are sunk. Then displays winner.
        if self.defend_grid.all_vessels_sunk():

            messagebox.showerror('You Lose!',
                                 'The AI sunk all your ships :(',
                                 icon='error')
            self.set_grid('disabled', self.attack_grid_buttons)

        elif t00_0_ai.defend_grid.all_vessels_sunk():

            messagebox.showerror('You Win!',
                                 'YOU ARE A WINNER!! :)',
                                 icon='info')
            self.set_grid('disabled', self.attack_grid_buttons)