generated from Code-Institute-Org/python-essentials-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stats.py
106 lines (83 loc) · 2.81 KB
/
stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import random
import gspread
from google.oauth2.service_account import Credentials
SCOPE = [
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/drive",
]
CREDS = Credentials.from_service_account_file("creds.json")
SCOPED_CREDS = CREDS.with_scopes(SCOPE)
GSPREAD_CLIENT = gspread.authorize(SCOPED_CREDS)
SHEET = GSPREAD_CLIENT.open("the_cave")
# Game start up stat functions.
def default_player_stats():
"""
Places default player stats into google sheet before any modifications can
be made or buffs.
"""
worksheet_to_update = SHEET.worksheet("character")
# character's default health points
worksheet_to_update.update_cell(2, 5, int(100))
# character's default luck
worksheet_to_update.update_cell(2, 6, int(10))
# character's default dexterity
worksheet_to_update.update_cell(2, 7, int(10))
# character's default strength
worksheet_to_update.update_cell(2, 8, int(10))
# character's default attack
worksheet_to_update.update_cell(2, 9, int(10))
# character's default defense
worksheet_to_update.update_cell(2, 10, int(20))
def default_player_inventory():
"""
Clears worksheet of any previous inventory.
"""
worksheet_to_update = SHEET.worksheet("inventory")
worksheet_to_update.clear()
# Game-play stat roll functions.
def roll_dex():
"""
Gets player's dexterity and rolls extra score.
"""
worksheet_to_pull = SHEET.worksheet("character")
dexterity = worksheet_to_pull.acell("G2").value
dice_roll = random.randint(0, 20)
final_dex = int(dexterity) + dice_roll
return final_dex
def roll_luck():
"""
Gets player's luck and rolls extra score.
"""
worksheet_to_pull = SHEET.worksheet("character")
luck = worksheet_to_pull.acell("F2").value
dice_roll = random.randint(0, 15)
final_luck = int(luck) + dice_roll
return final_luck
def roll_strength():
"""
Gets player's strength and rolls extra score.
"""
worksheet_to_pull = SHEET.worksheet("character")
strength = worksheet_to_pull.acell("H2").value
dice_roll = random.randint(0, 15)
final_strength = int(strength) + dice_roll
return final_strength
def roll_attack():
"""
Gets player's attack and rolls extra score.
"""
worksheet_to_pull = SHEET.worksheet("character")
attack = worksheet_to_pull.acell("I2").value
dice_roll = random.randint(0, 15)
final_attack = int(attack) + dice_roll
return final_attack
# Alter player stat functions.
def update_hp(num):
"""
Updates player's health points.
"""
worksheet_to_update = SHEET.worksheet("character")
health = worksheet_to_update.acell("E2").value
new_health = int(health) - int(num)
worksheet_to_update.update("E2", int(new_health))