def test_reflections(self): """tests proper handling of reflections""" game = BlackBoxGame([ (4, 5), (8, 8), (8, 3), (1, 6)]) #print(game.get_score()) self.assertEqual(game.shoot_ray(0,5), (0,5)) # reflection check on top row self.assertEqual(game.shoot_ray(9,4), (9,4)) # reflection check on bottom row self.assertEqual(game.shoot_ray(7,9), (7,9)) # reflection check on right column
def setUp(self): """Initialize an instance of BlackBoxGame""" self._BlackBoxGame = BlackBoxGame.BlackBoxGame([(3, 2), (1, 7), (4, 6), (8, 8), (8, 2), (3, 1)]) self._BlackBoxGame1 = BlackBoxGame.BlackBoxGame([(3, 1), (3, 3), (7, 3)])
def test_invalid(self): """tests handling of invalid inputs and options""" game = BlackBoxGame([(3, 4), (4, 5), (8, 8), (7, 1), (7, 3), (3, 6), (1, 6)]) #print(game.get_score()) self.assertEqual(game.shoot_ray(9,9), False) # lower right corner square self.assertEqual(game.shoot_ray(0,9), False) # upper right corner square self.assertEqual(game.shoot_ray(0,0), False) # upper left corner square self.assertEqual(game.shoot_ray(9,0), False) # lower left corner square
def test_hit_miss(self): """tests proper handling of hits and misses""" game = BlackBoxGame([(8,8), (1,1), (1,8)]) #print(game.get_score()) self.assertEqual(game.shoot_ray(0,4), (9,4)) # vertical miss self.assertEqual(game.shoot_ray(4,9), (4,0)) # horizontal miss self.assertEqual(game.shoot_ray(1,0), None) # vertical hit self.assertEqual(game.shoot_ray(9,1), None) # horizontal hit
def test_guess(self): """tests proper handling of special cases""" game = BlackBoxGame([(3, 4), (4, 5), (8, 8), (7, 1), (7, 3), (3, 6), (1, 6)]) #print(game.get_score()) self.assertEqual(game.guess_atom(4,5), True) # correct guess self.assertEqual(game.guess_atom(8,8), True) # correct guess self.assertEqual(game.guess_atom(9,1), False) # incorrect guess self.assertEqual(game.guess_atom(1,1), False) # incorrect guess self.assertEqual(game.guess_atom(1,1), False) # repeat incorrect guess
def test_deflections(self): """tests proper handling of deflections""" game = BlackBoxGame([(7, 1), (7, 3), (3, 6), (1, 6)]) #print(game.get_score()) self.assertEqual(game.shoot_ray(4,9), (9,7)) # left to down deflection self.assertEqual(game.shoot_ray(9,4), (8,9)) # up to right deflection self.assertEqual(game.shoot_ray(0,4), (6,9)) # down to right deflection self.assertEqual(game.shoot_ray(9,5), (4,0)) # up to left deflection game.print_board()
def game_init(self): """Creates the BlackBoxGame object with 4 random atom locations. Returns the object. """ atom_list = [] #Generate 4 random coordinates for i in range(4): row = random.randint(1, 8) col = random.randint(1, 8) while (row, col) in atom_list: #Avoid random duplicates row = random.randint(1, 8) col = random.randint(1, 8) atom_list.append((row, col)) game = BlackBoxGame.BlackBoxGame(atom_list) return game
def test_mixed_detours(self): """tests proper handling of a mixture of deflections, double deflections and reflections""" game = BlackBoxGame([(2, 5), (6, 5), (6, 7)]) #print(game.get_score()) self.assertEqual(game.shoot_ray(3,9), (3,9)) # deflects 2 times self.assertEqual(game.shoot_ray(3,0), (5,0)) # detour
def test_double_deflections(self): """tests proper handling of double deflections""" game = BlackBoxGame([(5, 2), (5, 4), (3, 6), (1, 6)]) #print(game.get_score()) self.assertEqual(game.shoot_ray(2,9), (2,9)) # horizontal double deflection self.assertEqual(game.shoot_ray(9,3), (9,3)) # vertical double deflection
import tkinter as tk from BlackBoxGame import * """ Todo: 1. randomize atom starting positions or create popup window for player to input 2. setup print board in gui """ root = tk.Tk() game = BlackBoxGame([(8, 8), (1, 1), (1, 8)]) # setting the windows size root.geometry("1280x720") root.title("BlackBox Game") # declaring string variable # for storing coordinates for guessing and shooting shoot_row_var = tk.StringVar() shoot_col_var = tk.StringVar() guess_row_var = tk.StringVar() guess_col_var = tk.StringVar() # defining a function that will get the current score def getScore(): """ Todo: docstrings """ score = game.get_score() guessScoreLabel = tk.Label(root, text='Current Score:' + str(score)) guessScoreLabel.grid(row=10, column=1)