本文整理汇总了Python中Game.Game类的典型用法代码示例。如果您正苦于以下问题:Python Game类的具体用法?Python Game怎么用?Python Game使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Game类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
parser = argparse.ArgumentParser(description='Start the server')
parser.add_argument('--p', help='Port number',
type=int, default=8080)
parser.add_argument('--min', help='Minimal player to start the game',
type=int, default=2)
parser.add_argument('--max', help='Maximal player to start a game',
type=int, default=10)
parser.add_argument('--lobby', help='Time to count down in the lobby in second)',
type=int, default=2)
parser.add_argument('--t', help='Time to wait until kick someone in second',
type=int, default=30)
parser.add_argument('--d', help='Debug flag',
type=int, default=1)
args = parser.parse_args(sys.argv[1:])
com = Com(args.p, args.d)
game = Game(com, args.min, args.max, args.lobby, args.t, args.d)
com.start_server()
game.setup_new_game()
while com.check_signal():
game.check_time()
示例2: MainWindow
class MainWindow(Frame):
def __init__(self, master, rows, columns):
Frame.__init__(self, master)
self.matrix = Matrix(master, rows, columns)
self.matrix.grid(row=0, column=0)
self.game = Game(rows, columns)
self.game.set_matrix(self.matrix)
self.start_button = Button(master, text="Start")
self.start_button.grid(row=1, column=0)
self.start_button["command"] = self.game.start_clicked
self.quit_button = Button(master, text="Quit")
self.quit_button.grid(row=1, column=1)
self.quit_button["command"] = self.quit
self.master = master
master.title("Life")
# override the "X" close button
self.master.protocol("WM_DELETE_WINDOW", self.quit)
def quit(self):
print "quitting"
self.game.quit_clicked()
self.master.quit()
示例3: game_looper
def game_looper(level):
game = Game(level)
result = 0
while not result == -5:
result = game.run()
again = 'n'
if result == -1:
print 'You were crushed'
again = raw_input('Try again? (Y/N): ')
elif result == -2:
print 'You fell to your death'
again = raw_input('Try again? (Y/N): ')
else:
print 'You escaped that room!'
again = result
if again:
if again[0] == 'N' or again[0] == 'n':
break
elif again[0] == 'Y' or again[0] == 'y':
game = Game(level)
elif result != -1 and result !=-2:
game = Game(again)
else:
break
else:
break
示例4: getGames
def getGames(self):
data = self.loadData();
games = []
for row in data:
items = row.split(',')
gamedate = items[0]
awayTeamStr = self.getTeam(items[1])
if (len(items[2]) > 0):
awayTeamScore = items[2]
else:
awayTeamScore = 0
homeTeamStr = self.getTeam(items[3])
if (len(items[4]) > 0):
homeTeamScore = items[4]
else:
homeTeamScore = 0
g = Game(gamedate, awayTeamStr, awayTeamScore, homeTeamStr, homeTeamScore)
if (gamedate < str(date.today()) and not g.wasPlayed()):
# if here, means game was postponed or cancelled. it screws up the upcoming games
# if one of the teams in the postponed games was involved
pass
else:
games.append(g)
return games
示例5: main
def main():
#theres a better way to do this, but this is faster
fn = sys.argv[2] if (len(sys.argv) == 3 and sys.argv[1] == '-c') else 'default.cfg'
g.init(fn) # read in the input file to the project's globals
game = Game() # create the initial game board
log = open(g.logfile, 'w')
prepare_log(log)
best_soln = [(None, -maxint, -maxint, -maxint)]
for n in range(g.runs):
print 'Starting run #' + str(n+1) + '\n'
log.write('Run ' + str(n+1) + '\n')
result = evolution(game, log)
best_soln = determine_dominance(best_soln, result)
if n < g.runs-1 and not g.datafile:
create_soln_file(best_soln)
g.seed = randint(0, maxint)
game.rand = Random(g.seed)
game.new_random_board()
log.close()
print 'finished calculations'
create_soln_file(best_soln)
示例6: main
def main():
"""hack"""
parser = SafeConfigParser()
parser.read('config.ini')
shots = parser.getint('shots', 'number_of_tryes')
current_word = Word()
category = current_word.random_category()
user = Player()
player = user.ask_for_name()
con = mdb.connect('localhost', 'testuser', '1', 'hangman');
cur = con.cursor()
with con:
cur.execute("INSERT INTO player(player_name) VALUES('%s');" % (player))
file_name = "%s.log" % player
logging.basicConfig(filename=file_name, level=logging.DEBUG,
format='%(message)s')
logging.info("USER:%s start the game and has %s wrong turns",
player, shots )
logging.info("###### [word]:[hidden]:[guess]:[wrong_guess]:[right_guess]")
word = current_word.random_word()
with con:
cur.execute("insert into game(currentWord) values('%s');" %(word))
print word
play_fun = Game(word,player)
play_fun.play()
示例7: eval_func
def eval_func(chromosome):
player = Player(chromosome)
game = Game([player] + player_list, verbose=False, quiet=True) # Start the game in quiet mode.
ranking = game.play_game()
score = ranking.index('GA Player')
return score * score
示例8: test_make_move_in_occupied_square
def test_make_move_in_occupied_square(self):
"""
Trying to place a piece in an occupied square should throw a runtime exception.
"""
game = Game(Player, Player)
game.make_move(game.player1, 5)
self.assertRaises(RuntimeError, game.make_move, game.player1, 5)
示例9: __init__
def __init__( self, pos ):
super( TinyWorld, self ).__init__( pos, "sprites/worlds/"+str(Game.level)+"/tiny-1.png", 9 )
Game.addSprite( "tiny-worlds", self )
self.addAnimState( "panic", 0, 3, 12 )
self.setAnimState( "panic" )
示例10: test_calculates_for_strike
def test_calculates_for_strike(self):
game = Game()
game.roll(10)
game.roll(5)
game.roll(4)
self.assertEqual(28, game.score)
示例11: test_calculates_for_spare
def test_calculates_for_spare(self):
game = Game()
game.roll(5)
game.roll(5)
game.roll(3)
self.assertEqual(16, game.score)
示例12: test_calculates_score_no_spare_no_strike
def test_calculates_score_no_spare_no_strike(self):
game = Game()
noOfStruckPins = 5
game.roll(noOfStruckPins)
self.assertEqual(game.score, noOfStruckPins)
示例13: start_onmouseclick
def start_onmouseclick(self, event):
self.start.onmouseclick(event)
self.on_exit()
game = Game()
game.run()
self.start.onmouseclickup(event)
self.on_enter()
示例14: interactive
def interactive(ply):
g = Game()
mode, end = g.game_type()
end = int(end)
if mode: # mode is true means new game
player_x = Player("x")
player_y = Player("y")
b = Board(player_x, player_y)
ai = Ai(ply)
remain = ["PlayerX King", "PlayerX Rook", "PlayerY King"]
g.ask_piece(b, player_x, player_y, remain)
b.display()
File.prompt("Who am I, PlayerX or PlayerY?")
localPlayer = input("Player [x/y]: ")
if re.match(r"[Xx]", localPlayer):
localPlayer = "x"
else:
localPlayer = "y"
# if local player is playerX, PlayerX is our ai moves
# PlayerY is opponents moves inputted by us
if localPlayer == "x":
for i in range(0, end):
# b.ai_move(player_x)
ai.move(b, player_x)
b.display()
File.debug(ai.value(b))
File.debug(ai.number_of_states)
ai.opponent_move(player_y, b)
b.display()
else:
for i in range(0, end):
ai.opponent_move(player_x, b)
b.display()
# b.ai_move(player_y)
ai.move(b, player_y)
b.display()
File.debug(ai.value(b))
File.debug(ai.number_of_states)
else:
player_x = Player("x")
player_y = Player("y")
b = Board(player_x, player_y)
File.test_file(b, g, player_x, player_y)
ai = Ai(ply)
# AI random moves test:
for i in range(0, end):
ai.move(b, player_x)
b.display()
File.debug(ai.value(b))
File.debug(ai.number_of_states)
ai.move(b, player_y)
b.display()
File.debug(ai.value(b))
File.debug(ai.number_of_states)
示例15: test_make_move_in_empty_square
def test_make_move_in_empty_square(self):
"""
Making a move should set that square in the board to the specified player's piece.
"""
game = Game(Player, Player)
self.assertEqual(None, game.board.get_square(5))
game.make_move(game.player1, 5)
self.assertEqual(game.player1.piece, game.board.get_square(5))