import pygame , sys , random

from pygame. locals import *

# set up game

pygame. init ( )

mainClock = pygame. time . Clock ( )

# create window

WINDOWWIDTH = 600

WINDOWHEIGHT = 600

screen = pygame. display . set_mode ( ( WINDOWWIDTH , WINDOWHEIGHT ) , 0 , 32 )

pygame. display . set_caption ( 'Cettlers of Satan' )

# location of all possible settlements

settlementLoc = [ ( 260 , 240 ) , ( 230 , 290 ) , ( 320 , 240 ) , ( 350 , 290 ) , ( 320 , 340 ) , ( 260 , 340 ) ,

( 230 , 390 ) , ( 260 , 445 ) , ( 320 , 440 ) , ( 350 , 390 ) , ( 410 , 290 ) , ( 440 , 240 ) ,

( 410 , 190 ) , ( 350 , 190 ) , ( 320 , 135 ) , ( 260 , 340 ) , ( 260 , 140 ) , ( 230 , 190 ) ,

( 170 , 190 ) , ( 140 , 240 ) , ( 170 , 290 ) , ( 140 , 340 ) , ( 170 , 390 ) , ( 260 , 550 ) ,

( 320 , 550 ) , ( 350 , 500 ) , ( 410 , 500 ) , ( 440 , 445 ) , ( 500 , 445 ) , ( 530 , 395 ) ,

( 500 , 340 ) , ( 530 , 290 ) , ( 500 , 240 ) , ( 530 , 190 ) , ( 500 , 135 ) , ( 440 , 135 ) ,

( 410 , 80 ) , ( 350 , 80 ) , ( 320 , 30 ) , ( 260 , 30 ) , ( 230 , 80 ) , ( 170 , 80 ) , ( 140 , 135 ) ,

( 80 , 135 ) , ( 50 , 190 ) , ( 80 , 240 ) , ( 50 , 290 ) , ( 80 , 340 ) , ( 50 , 395 ) , ( 80 , 445 ) ,

( 140 , 445 ) , ( 170 , 500 ) , ( 230 , 500 ) ]

""" Constants """

CLAY = ( 255 , 0 , 0 )

ORE = ( 190 , 190 , 190 )

WHEAT = ( 255 , 215 , 0 )

SHEEP = ( 124 , 252 , 0 )

WOOD = ( 0 , 100 , 0 )

SAND = ( 139 , 69 , 19 )

P1 = ( 0 , 0 , 255 )

P2 = ( 255 , 20 , 147 )

P3 = ( 255 , 165 , 0 )

P4 = ( 70 , 130 , 180 )

""" The Board Class """

class Board:

hexes = [ ]

settlements = [ ]

instruction = ""

def __init__ ( self , size ) :

self . tiles = [ ]

self . tiles + = [ CLAY , ORE ] * 3

self . tiles + = [ WHEAT , SHEEP , WOOD ] * 4

self . tiles + = [ SAND ]

# shuffle up the order of the tiles

random . shuffle ( self . tiles )

self . cX = screen. get_rect ( ) . centerx

self . cY = screen. get_rect ( ) . centery

self . hexHeight = 0.866 * size

""" The Hex's """

# Centre

self . hexes . append ( Hex ( ( self . cX , self . cY ) , size , self . tiles [ 0 ] ) )

# Second Row

self . hexes . append ( Hex ( ( self . cX , self . cY - ( 2 * self . hexHeight ) ) , size , self . tiles [ 1 ] ) )

self . hexes . append ( Hex ( ( self . cX , self . cY + ( 2 * self . hexHeight ) ) , size , self . tiles [ 2 ] ) )

self . hexes . append ( Hex ( ( self . cX - ( 1.5 *size ) , self . cY - self . hexHeight ) , size , self . tiles [ 3 ] ) )

self . hexes . append ( Hex ( ( self . cX + ( 1.5 *size ) , self . cY - self . hexHeight ) , size , self . tiles [ 4 ] ) )

self . hexes . append ( Hex ( ( self . cX - ( 1.5 *size ) , self . cY + self . hexHeight ) , size , self . tiles [ 5 ] ) )

self . hexes . append ( Hex ( ( self . cX + ( 1.5 *size ) , self . cY + self . hexHeight ) , size , self . tiles [ 6 ] ) )

# Third Row

self . hexes . append ( Hex ( ( self . cX - ( 3 *size ) , self . cY ) , size , self . tiles [ 7 ] ) )

self . hexes . append ( Hex ( ( self . cX + ( 3 *size ) , self . cY ) , size , self . tiles [ 8 ] ) )

self . hexes . append ( Hex ( ( self . cX , self . cY - ( 4 * self . hexHeight ) ) , size , self . tiles [ 9 ] ) )

self . hexes . append ( Hex ( ( self . cX , self . cY + ( 4 * self . hexHeight ) ) , size , self . tiles [ 10 ] ) )

self . hexes . append ( Hex ( ( self . cX + ( 1.5 *size ) , self . cY + ( 3 * self . hexHeight ) ) , size , self . tiles [ 11 ] ) )

self . hexes . append ( Hex ( ( self . cX + ( 1.5 *size ) , self . cY - ( 3 * self . hexHeight ) ) , size , self . tiles [ 12 ] ) )

self . hexes . append ( Hex ( ( self . cX - ( 1.5 *size ) , self . cY - ( 3 * self . hexHeight ) ) , size , self . tiles [ 13 ] ) )

self . hexes . append ( Hex ( ( self . cX - ( 1.5 *size ) , self . cY + ( 3 * self . hexHeight ) ) , size , self . tiles [ 14 ] ) )

self . hexes . append ( Hex ( ( self . cX + ( 3 *size ) , self . cY + ( 2 * self . hexHeight ) ) , size , self . tiles [ 15 ] ) )

self . hexes . append ( Hex ( ( self . cX + ( 3 *size ) , self . cY - ( 2 * self . hexHeight ) ) , size , self . tiles [ 16 ] ) )

self . hexes . append ( Hex ( ( self . cX - ( 3 *size ) , self . cY + ( 2 * self . hexHeight ) ) , size , self . tiles [ 17 ] ) )

self . hexes . append ( Hex ( ( self . cX - ( 3 *size ) , self . cY - ( 2 * self . hexHeight ) ) , size , self . tiles [ 18 ] ) )

# set up the settlement locations

for s in settlementLoc:

self . settlements . append ( Settlement ( s ) )

# default message for the users

self . instruction = "Select your first settlement"

def draw ( self ) :

# draw the HEXes

for h in self . hexes :

h. draw ( )

# draw the settlement locations

for item in self . settlements :

item. draw ( )

# message to user

basicFont = pygame. font . SysFont ( None , 24 )

text = basicFont. render ( "Select your first settlement" , True , ( 255 , 255 , 255 ) , ( 0 , 0 , 0 ) )

textRect = text. get_rect ( )

textRect. left = 5

textRect. top = 560

screen. blit ( text , textRect )

""" Create a settlement class"""

class Settlement:

def __init__ ( self , location ) :

self . locationx = location [ 0 ]

self . locationy = location [ 1 ]

self . neighbours = [ ]

self . city = False

self . owner = - 1

def draw ( self ) :

pygame. draw . rect ( screen , ( 0 , 0 , 0 ) , ( self . locationx , self . locationy , 20 , 20 ) , 2 )

""" Create a hex class """

class Hex:

def __init__ ( self , centre , size , color ) :

self . hexX = centre [ 0 ]

self . hexY = centre [ 1 ]

self . hexSize = size

self . color = color

# calculate each 6 points so we only do it once

self . points = [ ]

self . points . append ( ( self . hexX - self . hexSize , self . hexY ) )

self . points . append ( ( self . hexX - ( self . hexSize / 2 ) , self . hexY - ( 0.866 * self . hexSize ) ) )

self . points . append ( ( self . hexX + ( self . hexSize / 2 ) , self . hexY - ( 0.866 * self . hexSize ) ) )

self . points . append ( ( self . hexX + self . hexSize , self . hexY ) )

self . points . append ( ( self . hexX + ( self . hexSize / 2 ) , self . hexY + ( 0.866 * self . hexSize ) ) )

self . points . append ( ( self . hexX - ( self . hexSize / 2 ) , self . hexY + ( 0.866 * self . hexSize ) ) )

def draw ( self ) :

pygame. draw . polygon ( screen , self . color , self . points , 0 )

""" Set up the information for the settlements """

settlers = Board ( 60 )

# set up the locations of each house

roads = [ ]

# run the game loop

while True :

# check for the QUIT event

for event in pygame. event . get ( ) :

if event. type == QUIT:

pygame. quit ( )

sys . exit ( )

## draw the board

settlers. draw ( )

# draw the window onto the screen

pygame. display . update ( )