Created
July 3, 2016 18:40
-
-
Save PifyZ/09c852bc66bb99b3a0b4170c86a63e77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tables | |
type | |
GroupName = enum | |
None | |
Purple | |
LightBlue | |
Pink | |
Orange | |
Red | |
Yellow | |
Green | |
DarkBlue | |
Station | |
Company | |
Group = ref object | |
priceHouse: int | |
priceHotel: int | |
priceMortgage: int | |
Cell = ref object | |
name: string | |
groupName: GroupName | |
prices: array[6, int] | |
let | |
groups = { | |
None: Group(priceHouse: 0, priceHotel: 0, priceMortgage: 0), | |
Purple: Group(priceHouse: 100, priceHotel: 100, priceMortgage: 0), | |
LightBlue: Group(priceHouse: 100, priceHotel: 100, priceMortgage: 0), | |
Pink: Group(priceHouse: 100, priceHotel: 100, priceMortgage: 0), | |
Orange: Group(priceHouse: 100, priceHotel: 100, priceMortgage: 0), | |
Red: Group(priceHouse: 100, priceHotel: 100, priceMortgage: 0), | |
Yellow: Group(priceHouse: 100, priceHotel: 100, priceMortgage: 0), | |
Green: Group(priceHouse: 100, priceHotel: 100, priceMortgage: 0), | |
DarkBlue: Group(priceHouse: 100, priceHotel: 100, priceMortgage: 0), | |
Station: Group(priceHouse: 100, priceHotel: 100, priceMortgage: 0), | |
Company: Group(priceHouse: 100, priceHotel: 100, priceMortgage: 0) | |
}.toTable | |
proc `$`(c: GroupName): string = | |
result = case c | |
of None: "-" | |
of Purple: "Violet" | |
of LightBlue: "Bleu clair" | |
of Pink: "Rose" | |
of Orange: "Orange" | |
of Red: "Rouge" | |
of Yellow: "Jaune" | |
of Green: "Vert" | |
of DarkBlue: "Bleu foncé" | |
of Station: "Station" | |
of Company: "Compagnie" | |
proc defaultCell(name: string): Cell = | |
Cell(name: "Case départ", | |
groupName: None, | |
prices: [ 0, 0, 0, 0, 0, 0 ]) | |
proc getGroup(cell: Cell): Group = | |
groups[cell.groupName] | |
proc priceToString(pos: int, price: int): string = | |
result = case pos | |
of 0: "Terrain nu" | |
of 1: "1 maison" | |
of 2: "2 maisons" | |
of 3: "3 maisons" | |
of 4: "4 maisons" | |
of 5: "Hôtel" | |
else: "-" | |
result &= " : " | |
result &= $price | |
let | |
cells = @[ | |
defaultCell("Case départ"), | |
Cell(name: "Boulevard de Belleville", | |
groupName: Purple, | |
prices: [ 0, 0, 0, 0, 0, 0 ]), | |
defaultCell("Caisse de communauté") | |
] | |
for cell in cells: | |
echo "----" | |
echo "Nom : " & cell.name | |
echo "Prix maison : " & $cell.getGroup().priceHouse | |
echo "Prix hôtel : " & $cell.getGroup().priceHotel | |
echo "Prix hypothèque : " & $cell.getGroup().priceMortgage | |
echo "Groupe : " & $cell.groupName | |
echo "Prix hôtel : " & $cell.getGroup().priceHotel | |
echo "Prix : " | |
for pos, price in cell.prices: | |
echo " " & priceToString(pos, price) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment