trying to make gui

This commit is contained in:
2023-04-10 21:34:00 -07:00
parent 8c82234668
commit 8afef87a56
6 changed files with 188 additions and 49 deletions

View File

@@ -3,9 +3,13 @@ import json
import random import random
class Card: class Card:
isVisible = False def __init__(self):
isAccessible = False self.name = ""
self.isVisible = False
self.isAccessible = False
class Game:
def __init__(self):
self.board
class Player: class Player:
def __init__(self): def __init__(self):
self.name = "Player" self.name = "Player"
@@ -25,7 +29,7 @@ class Player:
def display(self): def display(self):
print(self.name) print(self.name)
print(f"Gold: {self.goldScore} Strength: {self.strengthScore} Magic: {self.magicScore}") 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: if self.shadowCount != 0:
tempChar = '' tempChar = ''
if self.shadowCount > 1: if self.shadowCount > 1:
@@ -46,6 +50,13 @@ class Player:
if self.workerCount > 1: if self.workerCount > 1:
tempChar = 's' tempChar = 's'
print(f"{self.workerCount} Worker icon{tempChar}") 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): def calc_roles(self):
for citizen in self.ownedCitizens: for citizen in self.ownedCitizens:
self.shadowCount = self.shadowCount + citizen.shadowCount self.shadowCount = self.shadowCount + citizen.shadowCount
@@ -59,11 +70,24 @@ class Player:
self.workerCount = self.workerCount + domain.workerCount self.workerCount = self.workerCount + domain.workerCount
class Starter(Card): 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): 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): 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 = input_name self.name = name
self.goldCost = gold_cost self.goldCost = gold_cost
self.rollMatch1 = roll_match1 self.rollMatch1 = roll_match1
self.rollMatch2 = roll_match2 self.rollMatch2 = roll_match2
@@ -83,28 +107,28 @@ class Citizen(Card):
self.specialPayoutOffTurn = special_payout_off_turn self.specialPayoutOffTurn = special_payout_off_turn
self.specialCitizen = special_citizen self.specialCitizen = special_citizen
def display(self): def display(self):
print("\n%s" % self.name) print(f"\n{self.name}")
print("Cost: {} Gold".format(self.goldCost)) print(f"Cost: {self.goldCost} Gold")
if self.shadowCount != 0: if self.shadowCount != 0:
tempChar = '' tempChar = ''
if self.shadowCount > 1: if self.shadowCount > 1:
tempChar = 's' tempChar = 's'
print("{} Shadow icon{}".format(self.shadowCount, tempChar)) print(f"{self.shadowCount} Shadow icon{tempChar}")
if self.holyCount != 0: if self.holyCount != 0:
tempChar = '' tempChar = ''
if self.holyCount > 1: if self.holyCount > 1:
tempChar = 's' tempChar = 's'
print("{} Holy icon{}".format(self.holyCount, tempChar)) print(f"{self.holyCount} Holy icon{tempChar}")
if self.soldierCount != 0: if self.soldierCount != 0:
tempChar = '' tempChar = ''
if self.soldierCount > 1: if self.soldierCount > 1:
tempChar = 's' tempChar = 's'
print("{} Soldier icon{}".format(self.soldierCount, tempChar)) print(f"{self.soldierCount} Soldier icon{tempChar}")
if self.workerCount != 0: if self.workerCount != 0:
tempChar = '' tempChar = ''
if self.workerCount > 1: if self.workerCount > 1:
tempChar = 's' tempChar = 's'
print("{} Worker icon{}".format(self.workerCount, tempChar)) print(f"{self.workerCount} Worker icon{tempChar}")
class Domain(Card): 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): 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 = '' tempChar = ''
if self.shadowCount > 1: if self.shadowCount > 1:
tempChar = 's' tempChar = 's'
print("{} Shadow icon{}".format(self.shadowCount, tempChar)) print(f"{self.shadowCount} Shadow icon{tempChar}")
if self.holyCount != 0: if self.holyCount != 0:
tempChar = '' tempChar = ''
if self.holyCount > 1: if self.holyCount > 1:
tempChar = 's' tempChar = 's'
print("{} Holy icon{}".format(self.holyCount, tempChar)) print(f"{self.holyCount} Holy icon{tempChar}")
if self.soldierCount != 0: if self.soldierCount != 0:
tempChar = '' tempChar = ''
if self.soldierCount > 1: if self.soldierCount > 1:
tempChar = 's' tempChar = 's'
print("{} Soldier icon{}".format(self.soldierCount, tempChar)) print(f"{self.soldierCount} Soldier icon{tempChar}")
if self.workerCount != 0: if self.workerCount != 0:
tempChar = '' tempChar = ''
if self.workerCount > 1: if self.workerCount > 1:
tempChar = 's' tempChar = 's'
print("{} Worker icon{}".format(self.workerCount, tempChar)) print(f"{self.workerCount} Worker icon{tempChar}")
print(self.text) print(self.text)
class Monster(Card): class Monster(Card):
@@ -163,7 +187,7 @@ class Monster(Card):
self.specialCost = special_cost self.specialCost = special_cost
self.isExtra = is_extra self.isExtra = is_extra
def display(self): 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): def add_strength_cost(self, addedStrength):
self.strengthCost = self.strengthCost + addedStrength self.strengthCost = self.strengthCost + addedStrength
def add_magic_cost(self, addedMagic): def add_magic_cost(self, addedMagic):
@@ -199,47 +223,47 @@ class Duke(Card):
tempChar = '' tempChar = ''
if self.shadowMultiplier > 1: if self.shadowMultiplier > 1:
tempChar = 's' tempChar = 's'
print("{} Victory Point{} per Shadow".format(self.shadowMultiplier, tempChar)) print(f"{self.shadowMultiplier} Victory Point{tempChar} per Shadow")
if self.holyMultiplier != 0: if self.holyMultiplier != 0:
tempChar = '' tempChar = ''
if self.holyMultiplier > 1: if self.holyMultiplier > 1:
tempChar = 's' tempChar = 's'
print("{} Victory Point{} per Holy".format(self.holyMultiplier, tempChar)) print(f"{self.holyMultiplier} Victory Point{tempChar} per Holy")
if self.soldierMultiplier != 0: if self.soldierMultiplier != 0:
tempChar = '' tempChar = ''
if self.soldierMultiplier > 1: if self.soldierMultiplier > 1:
tempChar = 's' tempChar = 's'
print("{} Victory Point{} per Soldier".format(self.soldierMultiplier, tempChar)) print(f"{self.soldierMultiplier} Victory Point{tempChar} per Soldier")
if self.workerMultiplier != 0: if self.workerMultiplier != 0:
tempChar = '' tempChar = ''
if self.workerMultiplier > 1: if self.workerMultiplier > 1:
tempChar = 's' tempChar = 's'
print("{} Victory Point{} per Worker".format(self.workerMultiplier, tempChar)) print(f"{self.workerMultiplier} Victory Point{tempChar} per Worker")
if self.monsterMultiplier != 0: if self.monsterMultiplier != 0:
tempChar = '' tempChar = ''
if self.monsterMultiplier > 1: if self.monsterMultiplier > 1:
tempChar = 's' tempChar = 's'
print("{} Victory Point{} per Monster".format(self.monsterMultiplier, tempChar)) print(f"{self.monsterMultiplier} Victory Point{tempChar} per Monster")
if self.citizenMultiplier != 0: if self.citizenMultiplier != 0:
tempChar = '' tempChar = ''
if self.citizenMultiplier > 1: if self.citizenMultiplier > 1:
tempChar = 's' tempChar = 's'
print("{} Victory Point{} per Citizen".format(self.citizenMultiplier, tempChar)) print(f"{self.citizenMultiplier} Victory Point{tempChar} per Citizen")
if self.domainMultiplier != 0: if self.domainMultiplier != 0:
tempChar = '' tempChar = ''
if self.domainMultiplier > 1: if self.domainMultiplier > 1:
tempChar = 's' tempChar = 's'
print("{} Victory Point{} per Domain".format(self.domainMultiplier, tempChar)) print(f"{self.domainMultiplier} Victory Point{tempChar} per Domain")
if self.bossMultiplier != 0: if self.bossMultiplier != 0:
tempChar = '' tempChar = ''
if self.bossMultiplier > 1: if self.bossMultiplier > 1:
tempChar = 's' tempChar = 's'
print("{} Victory Point{} per Boss".format(self.bossMultiplier, tempChar)) print(f"{self.bossMultiplier} Victory Point{tempChar} per Boss")
if self.titanMultiplier != 0: if self.titanMultiplier != 0:
tempChar = '' tempChar = ''
if self.titanMultiplier > 1: if self.titanMultiplier > 1:
tempChar = 's' tempChar = 's'
print("{} Victory Point{} per Titan".format(self.titanMultiplier, tempChar)) print(f"{self.titanMultiplier} Victory Point{tempChar} per Titan")
class Board: class Board:
@@ -254,6 +278,7 @@ class Board:
self.domainStack = [] self.domainStack = []
self.citizenStack = [] self.citizenStack = []
self.monsterStack = [] self.monsterStack = []
self.starterStack = []
self.dieOne = 0 self.dieOne = 0
self.dieTwo = 0 self.dieTwo = 0
self.dieSum = 0 self.dieSum = 0
@@ -288,6 +313,12 @@ class Board:
#for citizen in self.citizenStack: #for citizen in self.citizenStack:
# citizen.display() # 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") myCursor.execute("SELECT * FROM monsters")
myResult = myCursor.fetchall() myResult = myCursor.fetchall()
for row in myResult: for row in myResult:
@@ -304,8 +335,9 @@ class Board:
self.playerList.append(myPlayer) self.playerList.append(myPlayer)
random.shuffle(self.playerList) random.shuffle(self.playerList)
self.playerList[0].isFirst = True self.playerList[0].isFirst = True
for player in self.playerList:
#end create player list and establish order player.ownedStarters.append(self.starterStack[0])
player.ownedStarters.append(self.starterStack[1])
def roll_phase(self): def roll_phase(self):
self.dieOne = random.randint(1, 6) self.dieOne = random.randint(1, 6)

45
clientgui.py Normal file
View File

@@ -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()

View File

@@ -1,13 +1,8 @@
CREATE TABLE vckonline.starters ( CREATE TABLE vckonline.starters (
idstarters int(11) auto_increment NOT NULL, idstarters int(11) auto_increment NOT NULL,
name varchar(45) CHARACTER SET latin1 COLLATE latin1_swedish_ci 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_match1 int(11) NOT NULL,
roll_match2 int(11) DEFAULT 0 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_on_turn int(11) DEFAULT 0 NOT NULL,
gold_payout_off_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, 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, 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_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_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) PRIMARY KEY (idstarters)
) )
ENGINE=InnoDB ENGINE=InnoDB

View File

@@ -1,12 +1,7 @@
INSERT INTO `vckonline`.`starters` INSERT INTO `vckonline`.`starters`
(`name`, (`name`,
`gold_cost`,
`roll_match1`, `roll_match1`,
`roll_match2`, `roll_match2`,
`shadow_count`,
`holy_count`,
`soldier_count`,
`worker_count`,
`gold_payout_on_turn`, `gold_payout_on_turn`,
`gold_payout_off_turn`, `gold_payout_off_turn`,
`strength_payout_on_turn`, `strength_payout_on_turn`,
@@ -16,17 +11,11 @@ INSERT INTO `vckonline`.`starters`
`has_special_payout_on_turn`, `has_special_payout_on_turn`,
`has_special_payout_off_turn`, `has_special_payout_off_turn`,
`special_payout_on_turn`, `special_payout_on_turn`,
`special_payout_off_turn`, `special_payout_off_turn`)
`special_citizen`)
VALUES VALUES
('Peasant',/*name*/ ('Peasant',/*name*/
0,/*gold_cost*/
5,/*roll_match1*/ 5,/*roll_match1*/
0,/*roll_match2*/ 0,/*roll_match2*/
0,/*shadow_count*/
0,/*holy_count*/
0,/*soldier_count*/
0,/*worker_count*/
1,/*gold_payout_on_turn*/ 1,/*gold_payout_on_turn*/
1,/*gold_payout_off_turn*/ 1,/*gold_payout_off_turn*/
0,/*strength_payout_on_turn*/ 0,/*strength_payout_on_turn*/
@@ -36,5 +25,4 @@ VALUES
0,/*has_special_payout_on_turn*/ 0,/*has_special_payout_on_turn*/
0,/*has_special_payout_off_turn*/ 0,/*has_special_payout_off_turn*/
0,/*special_payout_on_turn*/ 0,/*special_payout_on_turn*/
0,/*special_payout_off_turn*/ 0/*special_payout_off_turn*/);
1/*special_citizen*/);

49
vckoclient.html Normal file
View File

@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebSocker Client</title>
</head>
<body>
<button onclick="contactServer">Click Here</button>
</body>
<script>
const socket = new WebSocket('ws://localhost:8000');
socket.addEventListener('open', function (event) {
socket.send('Connection Established');
});
socket.addEventListener('message', function (event) {
console.log(event.data);
});
const contactServer = () => {
socket.send("Initialize");
}
</script>
</html>

31
vckoserver.py Normal file
View File

@@ -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()