diff --git a/basegame.py b/basegame.py index 8371157..0299edc 100644 --- a/basegame.py +++ b/basegame.py @@ -3,9 +3,13 @@ import json import random class Card: - isVisible = False - isAccessible = False - + def __init__(self): + self.name = "" + self.isVisible = False + self.isAccessible = False +class Game: + def __init__(self): + self.board class Player: def __init__(self): self.name = "Player" @@ -25,7 +29,7 @@ class Player: def display(self): print(self.name) print(f"Gold: {self.goldScore} Strength: {self.strengthScore} Magic: {self.magicScore}") - print(f"Citizens: {len(self.ownedCitizens)} Monsters: {len(self.ownedMonsters)} Domains: {len(self.ownedDomains)}") + print(f"Starters: {len(self.ownedStarters)} Citizens: {len(self.ownedCitizens)} Monsters: {len(self.ownedMonsters)} Domains: {len(self.ownedDomains)}") if self.shadowCount != 0: tempChar = '' if self.shadowCount > 1: @@ -46,6 +50,13 @@ class Player: if self.workerCount > 1: tempChar = 's' print(f"{self.workerCount} Worker icon{tempChar}") + print(f"Starters:") + for starter in self.ownedStarters: + print(f"{starter.name} {starter.rollMatch1} {starter.rollMatch2} {starter.goldPayoutOnTurn} {starter.goldPayoutOffTurn} {starter.strengthPayoutOnTurn} {starter.strengthPayoutOffTurn}") + for citizen in self.ownedCitizens: + print(f"{citizen.name} {citizen.goldCost} {citizen.rollMatch1} {citizen.rollMatch2} {citizen.goldPayoutOnTurn} {citizen.goldPayoutOffTurn} {citizen.strengthPayoutOnTurn} {citizen.strengthPayoutOffTurn}") + for monster in self.ownedMonsters: + print(f"{monster.name} {citizen.goldCost} {citizen.rollMatch1} {citizen.rollMatch2} {citizen.goldPayoutOnTurn} {citizen.goldPayoutOffTurn} {citizen.strengthPayoutOnTurn} {citizen.strengthPayoutOffTurn}") def calc_roles(self): for citizen in self.ownedCitizens: self.shadowCount = self.shadowCount + citizen.shadowCount @@ -59,11 +70,24 @@ class Player: self.workerCount = self.workerCount + domain.workerCount class Starter(Card): - rollActivation = 0 + def __init__(self, name, roll_match1, roll_match2, gold_payout_on_turn, gold_payout_off_turn, strength_payout_on_turn, strength_payout_off_turn, magic_payout_on_turn, magic_payout_off_turn, has_special_payout_on_turn, has_special_payout_off_turn, special_payout_on_turn, special_payout_off_turn): + self.name = name + self.rollMatch1 = roll_match1 + self.rollMatch2 = roll_match2 + self.goldPayoutOnTurn = gold_payout_on_turn + self.goldPayoutOffTurn = gold_payout_off_turn + self.strengthPayoutOnTurn = strength_payout_on_turn + self.strengthPayoutOffTurn = strength_payout_off_turn + self.magicPayoutOnTurn = magic_payout_on_turn + self.magicPayoutOffTurn = magic_payout_off_turn + self.hasSpecialPayoutOnTurn = has_special_payout_on_turn + self.hasSpecialPayoutOffTurn = has_special_payout_off_turn + self.specialPayoutOnTurn = special_payout_on_turn + self.specialPayoutOffTurn = special_payout_off_turn class Citizen(Card): - def __init__(self, input_name, gold_cost, roll_match1, roll_match2, shadow_count, holy_count, soldier_count, worker_count, gold_payout_on_turn, gold_payout_off_turn, strength_payout_on_turn, strength_payout_off_turn, magic_payout_on_turn, magic_payout_off_turn, has_special_payout_on_turn, has_special_payout_off_turn, special_payout_on_turn, special_payout_off_turn, special_citizen): - self.name = input_name + def __init__(self, name, gold_cost, roll_match1, roll_match2, shadow_count, holy_count, soldier_count, worker_count, gold_payout_on_turn, gold_payout_off_turn, strength_payout_on_turn, strength_payout_off_turn, magic_payout_on_turn, magic_payout_off_turn, has_special_payout_on_turn, has_special_payout_off_turn, special_payout_on_turn, special_payout_off_turn, special_citizen): + self.name = name self.goldCost = gold_cost self.rollMatch1 = roll_match1 self.rollMatch2 = roll_match2 @@ -83,28 +107,28 @@ class Citizen(Card): self.specialPayoutOffTurn = special_payout_off_turn self.specialCitizen = special_citizen def display(self): - print("\n%s" % self.name) - print("Cost: {} Gold".format(self.goldCost)) + print(f"\n{self.name}") + print(f"Cost: {self.goldCost} Gold") if self.shadowCount != 0: tempChar = '' if self.shadowCount > 1: tempChar = 's' - print("{} Shadow icon{}".format(self.shadowCount, tempChar)) + print(f"{self.shadowCount} Shadow icon{tempChar}") if self.holyCount != 0: tempChar = '' if self.holyCount > 1: tempChar = 's' - print("{} Holy icon{}".format(self.holyCount, tempChar)) + print(f"{self.holyCount} Holy icon{tempChar}") if self.soldierCount != 0: tempChar = '' if self.soldierCount > 1: tempChar = 's' - print("{} Soldier icon{}".format(self.soldierCount, tempChar)) + print(f"{self.soldierCount} Soldier icon{tempChar}") if self.workerCount != 0: tempChar = '' if self.workerCount > 1: tempChar = 's' - print("{} Worker icon{}".format(self.workerCount, tempChar)) + print(f"{self.workerCount} Worker icon{tempChar}") class Domain(Card): def __init__(self, input_name, gold_cost, shadow_count, holy_count, soldier_count, worker_count, vp_reward, has_activation_effect, has_passive_effect, passive_effect, activation_effect, input_text): @@ -127,22 +151,22 @@ class Domain(Card): tempChar = '' if self.shadowCount > 1: tempChar = 's' - print("{} Shadow icon{}".format(self.shadowCount, tempChar)) + print(f"{self.shadowCount} Shadow icon{tempChar}") if self.holyCount != 0: tempChar = '' if self.holyCount > 1: tempChar = 's' - print("{} Holy icon{}".format(self.holyCount, tempChar)) + print(f"{self.holyCount} Holy icon{tempChar}") if self.soldierCount != 0: tempChar = '' if self.soldierCount > 1: tempChar = 's' - print("{} Soldier icon{}".format(self.soldierCount, tempChar)) + print(f"{self.soldierCount} Soldier icon{tempChar}") if self.workerCount != 0: tempChar = '' if self.workerCount > 1: tempChar = 's' - print("{} Worker icon{}".format(self.workerCount, tempChar)) + print(f"{self.workerCount} Worker icon{tempChar}") print(self.text) class Monster(Card): @@ -163,7 +187,7 @@ class Monster(Card): self.specialCost = special_cost self.isExtra = is_extra def display(self): - print("{} is a {} from {}".format(self.name, self.type, self.area)) + print(f"{self.name} is a {self.type} from {self.area}") def add_strength_cost(self, addedStrength): self.strengthCost = self.strengthCost + addedStrength def add_magic_cost(self, addedMagic): @@ -199,47 +223,47 @@ class Duke(Card): tempChar = '' if self.shadowMultiplier > 1: tempChar = 's' - print("{} Victory Point{} per Shadow".format(self.shadowMultiplier, tempChar)) + print(f"{self.shadowMultiplier} Victory Point{tempChar} per Shadow") if self.holyMultiplier != 0: tempChar = '' if self.holyMultiplier > 1: tempChar = 's' - print("{} Victory Point{} per Holy".format(self.holyMultiplier, tempChar)) + print(f"{self.holyMultiplier} Victory Point{tempChar} per Holy") if self.soldierMultiplier != 0: tempChar = '' if self.soldierMultiplier > 1: tempChar = 's' - print("{} Victory Point{} per Soldier".format(self.soldierMultiplier, tempChar)) + print(f"{self.soldierMultiplier} Victory Point{tempChar} per Soldier") if self.workerMultiplier != 0: tempChar = '' if self.workerMultiplier > 1: tempChar = 's' - print("{} Victory Point{} per Worker".format(self.workerMultiplier, tempChar)) + print(f"{self.workerMultiplier} Victory Point{tempChar} per Worker") if self.monsterMultiplier != 0: tempChar = '' if self.monsterMultiplier > 1: tempChar = 's' - print("{} Victory Point{} per Monster".format(self.monsterMultiplier, tempChar)) + print(f"{self.monsterMultiplier} Victory Point{tempChar} per Monster") if self.citizenMultiplier != 0: tempChar = '' if self.citizenMultiplier > 1: tempChar = 's' - print("{} Victory Point{} per Citizen".format(self.citizenMultiplier, tempChar)) + print(f"{self.citizenMultiplier} Victory Point{tempChar} per Citizen") if self.domainMultiplier != 0: tempChar = '' if self.domainMultiplier > 1: tempChar = 's' - print("{} Victory Point{} per Domain".format(self.domainMultiplier, tempChar)) + print(f"{self.domainMultiplier} Victory Point{tempChar} per Domain") if self.bossMultiplier != 0: tempChar = '' if self.bossMultiplier > 1: tempChar = 's' - print("{} Victory Point{} per Boss".format(self.bossMultiplier, tempChar)) + print(f"{self.bossMultiplier} Victory Point{tempChar} per Boss") if self.titanMultiplier != 0: tempChar = '' if self.titanMultiplier > 1: tempChar = 's' - print("{} Victory Point{} per Titan".format(self.titanMultiplier, tempChar)) + print(f"{self.titanMultiplier} Victory Point{tempChar} per Titan") class Board: @@ -254,6 +278,7 @@ class Board: self.domainStack = [] self.citizenStack = [] self.monsterStack = [] + self.starterStack = [] self.dieOne = 0 self.dieTwo = 0 self.dieSum = 0 @@ -288,6 +313,12 @@ class Board: #for citizen in self.citizenStack: # citizen.display() + myCursor.execute("SELECT * FROM starters") + myResult = myCursor.fetchall() + for row in myResult: + myStarter = Starter(row['name'], row['roll_match1'], row['roll_match2'], row['gold_payout_on_turn'], row['gold_payout_off_turn'], row['strength_payout_on_turn'], row['strength_payout_off_turn'], row['magic_payout_on_turn'], row['magic_payout_off_turn'], row['has_special_payout_on_turn'], row['has_special_payout_off_turn'], row['special_payout_on_turn'], row['special_payout_off_turn']) + self.starterStack.append(myStarter) + myCursor.execute("SELECT * FROM monsters") myResult = myCursor.fetchall() for row in myResult: @@ -304,8 +335,9 @@ class Board: self.playerList.append(myPlayer) random.shuffle(self.playerList) self.playerList[0].isFirst = True - -#end create player list and establish order + for player in self.playerList: + player.ownedStarters.append(self.starterStack[0]) + player.ownedStarters.append(self.starterStack[1]) def roll_phase(self): self.dieOne = random.randint(1, 6) diff --git a/clientgui.py b/clientgui.py new file mode 100644 index 0000000..84075ae --- /dev/null +++ b/clientgui.py @@ -0,0 +1,45 @@ +import wx +import socket + +class MyFrame(wx.Frame): + def __init__(self): + super().__init__(parent=None, title='VCK Online') + panel = wx.Panel(self) + my_sizer = wx.BoxSizer(wx.VERTICAL) + self.text_ctrl = wx.TextCtrl(panel) + my_sizer.Add(self.text_ctrl, 0, wx.ALL | wx.EXPAND, 5) + my_btn = wx.Button(panel, label='Press Me') + my_btn.Bind(wx.EVT_BUTTON, self.on_press) + my_sizer.Add(my_btn, 0, wx.ALL | wx.CENTER, 5) + panel.SetSizer(my_sizer) + self.host = "lukesau.com" + self.port = 5000 # socket server port number + self.Show() + + + def on_press(self, event): + message = self.text_ctrl.GetValue() + if not message: + print("You didn't enter anything!") + else: + client_socket = socket.socket() # instantiate + client_socket.connect((self.host, self.port)) # connect to the server + client_socket.send(message.encode()) # send message + data = client_socket.recv(1024).decode() # receive response + print('Received from server: ' + data) # show in terminal + self.text_ctrl.SetValue("") + client_socket.close() + def sync_with_server(self): + client_socket = socket.socket() # instantiate + client_socket.connect((self.host, self.port)) # connect to the server + + + +if __name__ == '__main__': + app = wx.App() + frame = MyFrame() + app.MainLoop() + + + + diff --git a/create_starters_table.sql b/create_starters_table.sql index 7a3ce1c..92ca3b2 100644 --- a/create_starters_table.sql +++ b/create_starters_table.sql @@ -1,13 +1,8 @@ CREATE TABLE vckonline.starters ( idstarters int(11) auto_increment NOT NULL, name varchar(45) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL, - gold_cost int(11) NOT NULL, roll_match1 int(11) NOT NULL, roll_match2 int(11) DEFAULT 0 NULL, - shadow_count int(11) DEFAULT 0 NOT NULL, - holy_count int(11) DEFAULT 0 NOT NULL, - soldier_count int(11) DEFAULT 0 NOT NULL, - worker_count int(11) DEFAULT 0 NOT NULL, gold_payout_on_turn int(11) DEFAULT 0 NOT NULL, gold_payout_off_turn int(11) DEFAULT 0 NOT NULL, strength_payout_on_turn int(11) DEFAULT 0 NOT NULL, @@ -18,7 +13,6 @@ CREATE TABLE vckonline.starters ( has_special_payout_off_turn tinyint(4) DEFAULT 0 NOT NULL, special_payout_on_turn mediumtext CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL NULL, special_payout_off_turn mediumtext CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL NULL, - special_citizen tinyint(4) DEFAULT 0 NOT NULL, PRIMARY KEY (idstarters) ) ENGINE=InnoDB diff --git a/insert_starter.sql b/insert_starter.sql index 3c386c0..a487340 100644 --- a/insert_starter.sql +++ b/insert_starter.sql @@ -1,12 +1,7 @@ INSERT INTO `vckonline`.`starters` (`name`, -`gold_cost`, `roll_match1`, `roll_match2`, -`shadow_count`, -`holy_count`, -`soldier_count`, -`worker_count`, `gold_payout_on_turn`, `gold_payout_off_turn`, `strength_payout_on_turn`, @@ -16,17 +11,11 @@ INSERT INTO `vckonline`.`starters` `has_special_payout_on_turn`, `has_special_payout_off_turn`, `special_payout_on_turn`, -`special_payout_off_turn`, -`special_citizen`) +`special_payout_off_turn`) VALUES ('Peasant',/*name*/ -0,/*gold_cost*/ 5,/*roll_match1*/ 0,/*roll_match2*/ -0,/*shadow_count*/ -0,/*holy_count*/ -0,/*soldier_count*/ -0,/*worker_count*/ 1,/*gold_payout_on_turn*/ 1,/*gold_payout_off_turn*/ 0,/*strength_payout_on_turn*/ @@ -36,5 +25,4 @@ VALUES 0,/*has_special_payout_on_turn*/ 0,/*has_special_payout_off_turn*/ 0,/*special_payout_on_turn*/ -0,/*special_payout_off_turn*/ -1/*special_citizen*/); +0/*special_payout_off_turn*/); diff --git a/vckoclient.html b/vckoclient.html new file mode 100644 index 0000000..0b9e0e2 --- /dev/null +++ b/vckoclient.html @@ -0,0 +1,49 @@ + + + + + + + + + + + + + WebSocker Client + + + + + + + + + + + + diff --git a/vckoserver.py b/vckoserver.py new file mode 100644 index 0000000..23a30d3 --- /dev/null +++ b/vckoserver.py @@ -0,0 +1,31 @@ +import socket + + +def server_program(): + # get the hostname + host = socket.gethostname() + port = 5000 # initiate port no above 1024 + + server_socket = socket.socket() # get instance + # look closely. The bind() function takes tuple as argument + server_socket.bind((host, port)) # bind host address and port together + + # configure how many client the server can listen simultaneously + server_socket.listen(5) + conn, address = server_socket.accept() # accept new connection + while True: + print("Connection from: " + str(address)) + while True: + # receive data stream. it won't accept data packet greater than 1024 bytes + data = conn.recv(1024).decode() + if not data: + # if data is not received break + break + print("from connected user: " + str(data)) + data = f"you sent: {str(data)}" + conn.send(data.encode()) # send data to the client + conn.close() # close the connection + + +if __name__ == '__main__': + server_program()