Python to develop Gobang game

Gobang source code, original code, only for python open source project learning.At present, the computer is clumsy. The ...

Gobang source code, original code, only for python open source project learning.
At present, the computer is clumsy. The next version will improve the computer algorithm
ps: in the process of learning python, many people often give up because they can't solve problems or don't have good tutorials, so I built a python full stack development exchange. Skirt: after a long time of fighting and thinking (Digital homophony) conversion, we can find the latest Python tutorial project. The problem that we don't understand is solved by the old driver. We can supervise each other together Supervision and common progress
The second version has been released with another blog post. If you are interested, you can check and download it.

import pygame import time SCREEN_WIDTH=900 SCREEN_HEIGHT=800 BG_COLOR=pygame.Color(200, 200, 200) Line_COLOR=pygame.Color(255, 255, 200) TEXT_COLOR=pygame.Color(255, 0, 0) # define color BLACK = ( 0, 0, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) GREEN = ( 0, 255, 0) BLUE = ( 0, 0, 255) class MainGame(): window = None Start_X = 50 Start_Y = 50 Line_Span = 40 Max_X = Start_X + 18 * Line_Span Max_Y = Start_Y + 18 * Line_Span player1Color = 'B' player2Color = 'W' overColor = 'S' # 1 for player 1, 2 for player 20 for end Putdownflag = player1Color ChessmanList = [] def __init__(self): '''Initialization''' def startGame(self): MainGame.window = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT]) pygame.display.set_caption("Gobang") #Initialization while True: time.sleep(0.1) #Get events MainGame.window.fill(BG_COLOR) self.drawchChessboard() self.bitechessman() self.VictoryOrDefeat() self.Computerplay() self.getEvent() pygame.display.update() pygame.display.flip() def drawchChessboard(self): for i in range(0,19): x = MainGame.Start_X + i * MainGame.Line_Span y = MainGame.Start_Y + i * MainGame.Line_Span pygame.draw.line(MainGame.window, BLACK, [x, MainGame.Start_Y], [x, MainGame.Max_Y], 1) pygame.draw.line(MainGame.window, BLACK, [MainGame.Start_X, y], [MainGame.Max_X, y], 1) def getEvent(self): # Get all events eventList = pygame.event.get() for event in eventList: if event.type

13 February 2020, 16:35 | Views: 3334

Add new comment

For adding a comment, please log in
or create account

0 comments