当前位置: 首页>>代码示例>>Python>>正文


Python Game.next方法代码示例

本文整理汇总了Python中Game.Game.next方法的典型用法代码示例。如果您正苦于以下问题:Python Game.next方法的具体用法?Python Game.next怎么用?Python Game.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Game.Game的用法示例。


在下文中一共展示了Game.next方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: play

# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import next [as 别名]
 def play():
     game = Game()
     print(game.current_board())
     while True:
         prompt = "Player %s>> " % game.current_player()
         index = list(map(int,list(input(prompt))))
         try:
             game.move(index)
         except RuntimeError:
             print("That position has already been used")
             continue
         except IndexError:
             print("Invalid position specified")
             continue
         print(game.current_board())
         if game.finished():
             print("Player %s wins!" % game.current_player())
             break
         game.next()
开发者ID:yyttr3,项目名称:Small_projects,代码行数:21,代码来源:main.py

示例2: TTTGame

# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import next [as 别名]
class TTTGame(Widget):
    def __init__(self,**kwargs):
        super(TTTGame,self).__init__(**kwargs)
        self.size_hint = (1,1)
        self.internal_game = Game()
    def getCenter(self):
    	c_x = int(self.center_x)
    	c_y = int(self.center_y)
    	return (c_x,c_y)
    def oneThird_region(self):
    	onethird_x = int(self.center_x/3)
    	onethird_y = int(self.center_y/3)
    	return (onethird_x,onethird_y)
    def getRegions_x(self):
    	(cx,cy) = self.getCenter()
    	(onethird_x,onethird_y) = self.oneThird_region()
    	region0 = [0,cx - onethird_x]
    	region1 = [cx - onethird_x,cx + onethird_x]
    	region2 = [cx + onethird_x,self.width]
    	return [region0,region1,region2]
    def getRegions_y(self):
    	(cx,cy) = self.getCenter()
    	(onethird_x,onethird_y) = self.oneThird_region()
    	region0 = [cy + onethird_y,self.height]
    	region1 = [cy - onethird_y,cy + onethird_y]
    	region2 = [0,cy - onethird_y]
    	return [region0,region1,region2]
    def get_index(self,position,regions):
    	index = 0
    	for region in regions:
    		if position in range(*region):
    			cord = index
    		index += 1
    	return index
    def on_touch_down(self,touch):
       	x_regions = self.getRegions_x()
       	y_regions = self.getRegions_y()
       	print(str(x_regions))
       	touchX,touchY = (int(touch.x),int(touch.y))
       	print("TouchX: "+str(touchX))
       	X_cord = get_index(touchX,x_regions)
       	Y_cord = get_index(touchY,y_regions)
       	cord = [X_cord,Y_cord]
       	self.advance_game(cord)

    def draw_letter(self,x,y,letter):
        letter = Label(text=letter,font_size=70)
        x_region = self.getRegions_x()[x]
        y_region = self.getRegions_y()[y]
        letter.center_x = (x_region[0]+x_region[1])/2
        letter.top = (y_region[0]+y_region[1])/2
        self.add_widget(letter)
    def advance_game(self,cord):
        try:
            self.internal_game.move(cord)
            print(self.internal_game.current_board())
            if self.internal_game.finished():
                print("Player %s wins!!" % self.internal_game.current_player())
                sys.exit(0)
        
            self.draw_letter(cord[0],cord[1],self.internal_game.current_player())
            self.internal_game.next()
        except IndexError:
            print("Invalid board position")
        except RuntimeError:
            print("That position has already beed used")
开发者ID:yyttr3,项目名称:Small_projects,代码行数:68,代码来源:GUI.py


注:本文中的Game.Game.next方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。