.
This commit is contained in:
23352
b0-valeria-card-kingdoms-rulebook.pdf
Normal file
23352
b0-valeria-card-kingdoms-rulebook.pdf
Normal file
File diff suppressed because it is too large
Load Diff
75
game.py
75
game.py
@@ -5,6 +5,7 @@ from typing import List
|
|||||||
import mariadb
|
import mariadb
|
||||||
from constants import *
|
from constants import *
|
||||||
from cards import *
|
from cards import *
|
||||||
|
import threading
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
@@ -194,32 +195,12 @@ class Game:
|
|||||||
payout[0] = -9999
|
payout[0] = -9999
|
||||||
case "choose":
|
case "choose":
|
||||||
print("Matched choose")
|
print("Matched choose")
|
||||||
self.action_required['player_id'] = player_id
|
self.action_required['id'] = player_id
|
||||||
self.action_required['action'] = command
|
self.action_required['action'] = command
|
||||||
# need to pause execution here until we get player input
|
# need to pause execution here until we get player input
|
||||||
while self.action_required['player_id'] != self.game_id:
|
print("pee")
|
||||||
time.sleep(1)
|
input_thread = threading.Thread(target=self.wait_for_input, args=(split_command, player_id))
|
||||||
choice = []
|
input_thread.start()
|
||||||
match self.action_required['action']:
|
|
||||||
case 'choose 1':
|
|
||||||
choice = [second_word, third_word]
|
|
||||||
case 'choose 2':
|
|
||||||
choice = [fourth_word, split_command[4]]
|
|
||||||
case 'choose 3':
|
|
||||||
choice = [split_command[5], split_command[6]] # [sixth_word, seventh_word]
|
|
||||||
case _:
|
|
||||||
payout[0] = -9999
|
|
||||||
match choice[0]:
|
|
||||||
case 'g':
|
|
||||||
payout[0] = payout[0] + choice[1]
|
|
||||||
case 's':
|
|
||||||
payout[1] = payout[1] + choice[1]
|
|
||||||
case 'm':
|
|
||||||
payout[2] = payout[2] + choice[1]
|
|
||||||
case 'v':
|
|
||||||
payout[3] = payout[3] + choice[1]
|
|
||||||
case _:
|
|
||||||
payout[0] = -9999
|
|
||||||
case _:
|
case _:
|
||||||
payout[0] = -9999
|
payout[0] = -9999
|
||||||
print(payout)
|
print(payout)
|
||||||
@@ -239,6 +220,50 @@ class Game:
|
|||||||
|
|
||||||
return return_dict
|
return return_dict
|
||||||
|
|
||||||
|
def wait_for_input(self, command, player_id):
|
||||||
|
print("waiting for input")
|
||||||
|
while self.action_required["id"] != self.game_id:
|
||||||
|
time.sleep(1) # wait for 1 second before checking again
|
||||||
|
print("input received")
|
||||||
|
choice = []
|
||||||
|
payout = [0, 0, 0, 0]
|
||||||
|
match self.action_required['action']:
|
||||||
|
case 'choose 1':
|
||||||
|
choice = [command[1], command[2]]
|
||||||
|
case 'choose 2':
|
||||||
|
choice = [command[3], command[4]]
|
||||||
|
case 'choose 3':
|
||||||
|
choice = [command[5], command[6]] # [sixth_word, seventh_word]
|
||||||
|
case _:
|
||||||
|
payout[0] = -9999
|
||||||
|
match choice[0]:
|
||||||
|
case 'g':
|
||||||
|
payout[0] = payout[0] + int(choice[1])
|
||||||
|
case 's':
|
||||||
|
payout[1] = payout[1] + int(choice[1])
|
||||||
|
case 'm':
|
||||||
|
payout[2] = payout[2] + int(choice[1])
|
||||||
|
case 'v':
|
||||||
|
payout[3] = payout[3] + int(choice[1])
|
||||||
|
case _:
|
||||||
|
payout[0] = -9999
|
||||||
|
for player in self.player_list:
|
||||||
|
if player.player_id == player_id:
|
||||||
|
player.gold_score = player.gold_score + payout[0]
|
||||||
|
player.strength_score = player.strength_score + payout[1]
|
||||||
|
player.magic_score = player.magic_score + payout[2]
|
||||||
|
player.victory_score = player.victory_score + payout[3]
|
||||||
|
for player in self.player_list:
|
||||||
|
print(f"Player {player.name}: {player.gold_score} G, {player.strength_score} S, {player.magic_score} M,"
|
||||||
|
f" {player.victory_score} VP, Monsters: {len(player.owned_monsters)}, "
|
||||||
|
f"Citizens: {len(player.owned_citizens)}, Domains {len(player.owned_domains)}")
|
||||||
|
|
||||||
|
def act_on_required_action(self, player_id, action):
|
||||||
|
if self.action_required['id'] == player_id:
|
||||||
|
print("correct player responded to action")
|
||||||
|
self.action_required['action'] = action
|
||||||
|
self.action_required['id'] = self.game_id
|
||||||
|
|
||||||
def update_payout_for_role(self, role_name, player_id, payout, split_command):
|
def update_payout_for_role(self, role_name, player_id, payout, split_command):
|
||||||
role_count = 0
|
role_count = 0
|
||||||
for player in self.player_list:
|
for player in self.player_list:
|
||||||
@@ -435,7 +460,7 @@ def load_game_data(game_id, preset, player_list_from_lobby):
|
|||||||
"action_phase": []
|
"action_phase": []
|
||||||
}
|
}
|
||||||
action_required = {
|
action_required = {
|
||||||
"player_id": "",
|
"id": "",
|
||||||
"action": ""
|
"action": ""
|
||||||
}
|
}
|
||||||
match preset:
|
match preset:
|
||||||
|
|||||||
7
vckonline setup.txt
Normal file
7
vckonline setup.txt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
virtualenv --no-site-packages --distribute .env && source .env/bin/activate && pip install -r requirements.txt
|
||||||
|
|
||||||
|
|
||||||
|
dnf install python3-devel mysql-devel
|
||||||
|
pip install mysql-connector-python
|
||||||
|
pip install mapping
|
||||||
|
pip install wxpython
|
||||||
11
vckonline.py
11
vckonline.py
@@ -7,12 +7,17 @@ player2_id = shortuuid.uuid()
|
|||||||
player1 = Player(player1_id, "Player 1")
|
player1 = Player(player1_id, "Player 1")
|
||||||
player2 = Player(player2_id, "Player 2")
|
player2 = Player(player2_id, "Player 2")
|
||||||
player_list = [player1, player2]
|
player_list = [player1, player2]
|
||||||
|
game_id = str(uuid.uuid4())
|
||||||
try:
|
try:
|
||||||
base1_new_game_state = load_game_data(str(uuid.uuid4()), "base1", player_list)
|
base1_new_game_state = load_game_data(game_id, "base1", player_list)
|
||||||
game = Game(base1_new_game_state)
|
game = Game(base1_new_game_state)
|
||||||
game.slay_monster(player1_id, 14, 0, 0)
|
game.hire_citizen(player1_id, 2, 0, 0)
|
||||||
|
game.hire_citizen(player2_id, 2, 0, 0)
|
||||||
|
game.die_one = 2
|
||||||
|
game.die_two = 5
|
||||||
|
game.die_sum = 7
|
||||||
game.harvest_phase()
|
game.harvest_phase()
|
||||||
|
game.act_on_required_action(player1_id, "choose 1")
|
||||||
game_json = json.dumps(game, cls=GameObjectEncoder, indent=2)
|
game_json = json.dumps(game, cls=GameObjectEncoder, indent=2)
|
||||||
with open("game_state.txt", "w") as dump:
|
with open("game_state.txt", "w") as dump:
|
||||||
dump.write(game_json)
|
dump.write(game_json)
|
||||||
|
|||||||
Reference in New Issue
Block a user