.
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | # Drugwars
12 | ### The DOS game from the 80s re-written in Python from Scratch!
13 |
14 | Play in your browser [Here](https://Drugwars-Online-Version.m4cs.repl.run)
15 |
16 |
17 | # Installation
18 |
19 | **Recommended:** Using pip
20 |
21 | ```
22 | pip3 install drugwars
23 |
24 | # To Update
25 | pip3 install --upgrade drugwars
26 | ```
27 |
28 | Installing from source
29 |
30 | ```
31 | git clone https://github.com/M4cs/drugwars
32 | cd drugwars
33 | python3 setup.py install
34 | drugwars
35 | ```
36 |
37 | # How to Play
38 |
39 | ### Gameplay
40 |
41 | The game is played inside of your terminal and uses letters and numbers to select things and take part actions.
42 |
43 | You start with 2000 dollars and 5500 dollars in debt to the loan shark. The goal of the game is to pay off the loan shark and get as much money as possible while avoiding cops or getting mugged.
44 |
45 | Cops can shoot at you and you have 20 hit points until you die and the game ends. You are able to purchase guns occasionally which will give you a chance to kill the cops.
46 |
47 | You have 30 days to buy and sell as many drugs as possible to make a profit. Prices are randomly generated so it's all dependent on the market in the area you're at.
48 |
49 | There are events that can happen inbetween moving areas. These can either be good for you or bad, it's all random.
50 |
51 | You have access to a bank and stash in the Bronx which allows you to store money and drugs to keep them safe while getting mugged or caught by the cops.
52 |
53 | ### Rules
54 |
55 | - You cannot go back to a location if you have chosen jet, you must travel somewhere else.
56 | - You can only go to the loan shark, bank, and stash in the Bronx.
57 | - You only have 30 days to make your money and pay back the loan shark.
58 | - Your debt increases each day with interest so pay it back ASAP
59 | - Your savings will increase each day with interest as well.
60 |
61 | ### Controls
62 |
63 | **When asked yes or no questions:** Respond with `y` or `n`
64 |
65 | **When asked to (B)uy, (S)ell, or (J)et:** Respond with `b` to buy, `s` to sell, or `j` to jet
66 |
67 | **When asked to (R)un or (F)ight:** Respond with `r` to run, or `f` to fight
68 |
69 | **When asked where to go:** Respond with a number `1-6`, these correspond to a location on the table
70 |
71 | ### Troubleshooting
72 |
73 | **I pressed buy or sell and I didn't mean to!**
74 |
75 | Simply choose a drug and set 0 as the quantity.
76 |
77 | **I jetted but want to go back.**
78 |
79 | You can't this is a game mechanic. Be careful with your choices!
80 |
81 | # Why did I make this?
82 |
83 | Drugwars is a game I've been playing for a long time, well before I learned how to program. Now that I'm apt in Python I thought what the hell, why not rewrite a game I love in Python and release it. Well that's what I'm doing and here it is. Enjoy :)
84 |
85 | # Changelog
86 |
87 | v1.3 (by aconamos)
88 | ```
89 | - Added "a"/"all", "h"/"half", and percent values to selling/buying drugs
90 | - Added amount of days option
91 | - Fixed score going into negative
92 | ```
93 |
94 | v1.2.1
95 |
96 | ```
97 | - Fix End Game
98 | - Add Endgame
99 | - Change Coat Probability
100 | ```
101 |
102 | v1.2.0
103 |
104 | ```
105 | - Optimized Drug Stashes
106 | - Optimized Stash Menu
107 | - Optimized Classes
108 | - Optimized Helpers
109 | - Bug Fixes
110 | - Added Withdraw to Stash (it was missing lol)
111 | ```
112 |
113 | v1.1.10
114 |
115 | ```
116 | - Adds "a"/"all" and "h"/"half" features in Loan Shark and Bank
117 | ```
118 |
119 | v1.1.9
120 |
121 | ```
122 | - Fix infinite loop in Issue #2
123 | ```
124 |
125 | v1.1.8
126 |
127 | ```
128 | - Added difficulty screen
129 | ```
130 |
131 | v1.1.7
132 |
133 | ```
134 | - Fix loan shark balance
135 | - Fix input bugs
136 | ```
137 |
138 | v1.1.6:
139 |
140 | ```
141 | - Fix borrowing
142 | ```
143 |
144 | v1.1.5:
145 |
146 | ```
147 | - Fix actions breaking
148 | ```
149 |
150 | v1.1.4:
151 |
152 | ```
153 | - Remove Auto update
154 | ```
155 |
156 | v1.1.3:
157 |
158 | ```
159 | - Fix logic around pricing events
160 | ```
161 |
162 | v1.1.2:
163 |
164 | ```
165 | - Disable Actions from occuring first round
166 | ```
167 |
168 | v1.1.1:
169 |
170 | ```
171 | - Adds auto update check (Set DO_NOT_UPDATE to 1 to skip)
172 | ```
173 |
174 | v1.1.0:
175 |
176 | ```
177 | - Adds upgrade trench coat
178 | - Changes chances of getting away from Headass
179 | - Fixes crashing bugs
180 | ```
181 |
--------------------------------------------------------------------------------
/drugwars/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/M4cs/drugwars/0e8362d7958e05561f7b8d8d7007bca49d613337/drugwars/__init__.py
--------------------------------------------------------------------------------
/drugwars/__main__.py:
--------------------------------------------------------------------------------
1 | from drugwars.events import *
2 | from drugwars.classes import Player
3 | import requests
4 | import os
5 |
6 | def main():
7 | clear()
8 | try:
9 | logo = '''\
10 | ___ ___ __ _______
11 | / _ \/ _ \/ / / / ___/
12 | / // / , _/ /_/ / (_ /
13 | /____/_/|_|\____/\___/ ___
14 | | | /| / / _ | / _ \/ __/
15 | | |/ |/ / __ |/ , _/\ \
16 | |__/|__/_/ |_/_/|_/___/'''
17 |
18 | title_screen = [
19 | [logo],
20 | [" Created by Max Bridgland"],
21 | [" Based on the DOS Game of the 80s"],
22 | [""],
23 | [" Press ENTER to Play or Ctrl+C to Quit"],
24 | [""],
25 | [" Version: 1.2.1 Report Bugs on GitHub"],
26 | ["https://github.com/M4cs/Drugwars/issues/new"]
27 | ]
28 | print(SingleTable(title_screen).table)
29 | input()
30 | p = Player()
31 | clear()
32 | diff = difficulty_screen()
33 | if diff == 0:
34 | p.shark.balance = 5500
35 | elif diff == 1:
36 | p.shark.balance = 6500
37 | elif diff == 2:
38 | p.shark.balance = 8000
39 |
40 | p.days_end = days_screen()
41 |
42 | main_screen(p)
43 | except KeyboardInterrupt:
44 | exit()
45 |
46 | if __name__ == "__main__":
47 | main()
--------------------------------------------------------------------------------
/drugwars/classes.py:
--------------------------------------------------------------------------------
1 | from random import randint, choice, seed, shuffle
2 | from .helpers import round_down
3 |
4 | class Shark():
5 | def __init__(self, player):
6 | self.player = player
7 | self.balance = 5500
8 |
9 | def interest(self):
10 | self.balance = int(round_down(self.balance * 1.08))
11 |
12 | def check_can_borrow(self, amount):
13 | if self.balance == 0 and amount <= int(round_down(self.player.money)):
14 | return True
15 | else:
16 | if amount <= int(round_down(self.balance)) and amount <= int(round_down(self.player.money)):
17 | return True
18 | else:
19 | return False
20 |
21 | def check_can_dep(self, amount):
22 | if amount <= self.player.money:
23 | return True
24 | else:
25 | return False
26 |
27 | def deposit(self, amount):
28 | self.player.money -= amount
29 | self.balance -= amount
30 |
31 | def withdraw(self, amount):
32 | self.player.money += amount
33 | self.balance += amount
34 |
35 | class Bank:
36 | def __init__(self, player):
37 | self.player = player
38 | self.balance = 0
39 |
40 | def interest(self):
41 | self.balance = int(round_down(self.balance * 1.05))
42 |
43 | def deposit(self, amount):
44 | self.player.money -= amount
45 | self.balance += amount
46 |
47 | def withdraw(self, amount):
48 | self.player.money += amount
49 | self.balance -= amount
50 |
51 | def check_can_wd(self, amount):
52 | if amount <= self.balance:
53 | return True
54 | else:
55 | return False
56 |
57 | def check_can_dep(self, amount):
58 | if amount <= self.player.money:
59 | return True
60 | else:
61 | return False
62 |
63 | class Stash:
64 | def __init__(self, player):
65 | self.player = player
66 | self.cocaine = 0
67 | self.heroin = 0
68 | self.acid = 0
69 | self.weed = 0
70 | self.speed = 0
71 | self.ludes = 0
72 |
73 | def withdraw(self, drug, amount):
74 | if hasattr(self.player, drug):
75 | dref = getattr(self.player, drug)
76 | dref += amount
77 | setattr(self.player, drug, dref)
78 | sref = getattr(self, drug)
79 | sref -= amount
80 | setattr(self, drug, sref)
81 |
82 | def transfer(self, drug, amount):
83 | if hasattr(self.player, drug):
84 | dref = getattr(self.player, drug)
85 | dref -= amount
86 | setattr(self.player, drug, dref)
87 | sref = getattr(self, drug)
88 | sref += amount
89 | setattr(self, drug, sref)
90 |
91 | def can_transfer(self, drug, amount):
92 | if hasattr(self.player, drug):
93 | dref = getattr(self.player, drug)
94 | return dref >= amount
95 | return False
96 |
97 | def can_withdraw(self, drug, amount):
98 | if hasattr(self, drug):
99 | dref = getattr(self, drug)
100 | return dref >= amount
101 | return False
102 |
103 | class Player:
104 | def __init__(self):
105 | self.is_first_round = True
106 | self.money = 2000
107 | self.guns = 0
108 | self.days = 0
109 | self.days_end = 30
110 | self.health = 20
111 | self.max_trench = 100
112 | self.cocaine = 0
113 | self.heroin = 0
114 | self.acid = 0
115 | self.weed = 0
116 | self.speed = 0
117 | self.ludes = 0
118 | self.bank = Bank(self)
119 | self.stash = Stash(self)
120 | self.shark = Shark(self)
121 | self.current_area = "Bronx"
122 |
123 | def buy(self, drug, amount, price):
124 | dref = getattr(self, drug)
125 | dref += amount
126 | setattr(self, drug, dref)
127 | self.money -= (amount * price)
128 |
129 | def len_inventory(self):
130 | return (self.cocaine + self.heroin + self.acid + self.weed + self.speed + self.ludes)
131 |
132 | def coat_space(self):
133 | return self.max_trench - (self.cocaine + self.heroin + self.acid + self.weed + self.speed + self.ludes)
134 |
135 | def get_max(self, drug, price):
136 | max_amt = int(round_down(self.money / price))
137 | if max_amt > self.coat_space():
138 | return self.coat_space()
139 | else:
140 | return max_amt
141 |
142 | def get_max_sell(self, drug):
143 | if drug == 'cocaine':
144 | return self.cocaine
145 | elif drug == 'heroin':
146 | return self.heroin
147 | elif drug == 'acid':
148 | return self.acid
149 | elif drug == 'weed':
150 | return self.weed
151 | elif drug == 'speed':
152 | return self.speed
153 | elif drug == 'ludes':
154 | return self.ludes
155 |
156 | def can_buy(self, price, amount):
157 | return self.money >= (price * amount) and (self.len_inventory() + amount) <= self.max_trench
158 |
159 | def can_sell(self, amount, drug):
160 | dref = getattr(self, drug)
161 | return dref - amount >= 0
162 |
163 | def get_amt(self, drug):
164 | if hasattr(self, drug):
165 | return getattr(self, drug)
166 | return None
167 |
168 | def sell(self, drug, amount, price):
169 | dref = getattr(self, drug)
170 | dref -= amount
171 | setattr(self, drug, dref)
172 | self.money += (amount * price)
173 |
174 | class Prices:
175 | def __init__(self, player):
176 | seed(randint(-10000, 10000))
177 | self.player = player
178 | self.cocaine = randint(15000, 29999)
179 | self.heroin = randint(5000, 13999)
180 | self.acid = randint(1000, 4999)
181 | self.weed = randint(300, 899)
182 | self.speed = randint(90, 249)
183 | self.ludes = randint(10, 89)
184 | self.actions = []
185 | events = [
186 | lambda self: self.cops_bust_cocaine(),
187 | lambda self: self.addicts_buy_coke(),
188 | lambda self: self.cops_bust_heroin(),
189 | lambda self: self.addicts_buy_herion(),
190 | lambda self: self.cheap_acid(),
191 | lambda self: self.cheap_cocaine(),
192 | lambda self: self.cheap_heroin(),
193 | lambda self: self.cheap_ludes(),
194 | lambda self: self.cheap_speed(),
195 | lambda self: self.cheap_weed(),
196 | ]
197 | shuffle(events)
198 | self.action = None
199 | self.has_done_action = False
200 | if not self.player.is_first_round:
201 | for a in events:
202 | if self.has_done_action:
203 | break
204 | else:
205 | a(self)
206 | if len(self.actions) > 0:
207 | self.action = self.actions[0]
208 |
209 | def cops_bust_cocaine(self):
210 | if 1 == randint(1, 35):
211 | self.cocaine *= 2
212 | self.actions.append("** Cops raided a coke house! Prices are rising!!! **")
213 |
214 | def addicts_buy_coke(self):
215 | if 1 == randint(1, 35):
216 | self.cocaine *= 4
217 | self.actions.append("** Cokeheads everywhere are ready to pay. Prices are skyrocketing!! **")
218 |
219 | def cops_bust_heroin(self):
220 | if 1 == randint(1, 25):
221 | self.heroin *= 2
222 | self.actions.append("** Cops raided a heroin kingpin's warehouse! Prices are rising!!! **")
223 |
224 | def addicts_buy_herion(self):
225 | if 1 == randint(1, 35):
226 | self.heroin *= 4
227 | self.actions.append("** Heroin junkies everywhere need their fix. Prices are skyrocketing!! **")
228 |
229 | def cheap_acid(self):
230 | if 1 == randint(1, 25):
231 | self.acid /= 4
232 | self.actions.append("** Somebody found a reliable method for making acid. It's super cheap! **")
233 |
234 | def cheap_ludes(self):
235 | if 1 == randint(1, 20):
236 | self.ludes /= 4
237 | self.actions.append("** The pharmacy got robbed! Ludes are extremely cheap **")
238 |
239 | def cheap_weed(self):
240 | if 1 == randint(1, 20):
241 | self.weed /= 4
242 | self.actions.append("** Hempfest time! Weed is basically being handed out! **")
243 |
244 | def cheap_heroin(self):
245 | if 1 == randint(1, 35):
246 | self.heroin /= 4
247 | self.actions.append("** Heroin markets are flooded! Prices have dropped!! **")
248 |
249 | def cheap_cocaine(self):
250 | if 1 == randint(1, 40):
251 | self.cocaine /= 4
252 | self.actions.append("** Holy shit! You found a time machine to the 80s. Coke is cheap! **")
253 |
254 | def cheap_speed(self):
255 | if 1 == randint(1, 20):
256 | self.speed /= 4
257 | self.actions.append("** Speed markets are flooded! Prices are dropping! **")
--------------------------------------------------------------------------------
/drugwars/events.py:
--------------------------------------------------------------------------------
1 | from terminaltables import SingleTable
2 | from .helpers import check_ans_yn, clear, round_down, check_ans_bsj, check_drug_inp, get_price
3 | from .classes import Prices
4 | from random import randint, choice
5 |
6 | def cops_chase(player):
7 | if 1 == randint(1, 10):
8 | cops = 0
9 | r = randint(1, 10)
10 | if r >= 1 or r <= 6:
11 | cops = 2
12 | elif r >= 7 or r <= 9:
13 | cops = 3
14 | else:
15 | cops = 4
16 | print(SingleTable([["Officer Headass and " + str(cops) + " other(s) are chasing you!"]]).table)
17 | if player.guns >= 1:
18 | while True:
19 | print(SingleTable([["Would you like to (R)un or (F)ight?"], ["HP: " + str(player.health) + "/ 20"]]).table)
20 | a = input("\n> ")
21 | aout = check_ans_yn(a)
22 | if aout == 1:
23 | if 1 == randint(1,3):
24 | drug = choice(["cocaine", "heroin", "acid", "weed", "speed", "ludes"])
25 | pdrug = player.get_amt(drug)
26 | if pdrug > 0:
27 | amnt = randint(1, 10)
28 | pdrug -= amnt
29 | clear()
30 | print(SingleTable([["You got away but you dropped " + str(amnt) + " bags of " + drug.capitalize() + " while running!!"]]).table)
31 | else:
32 | print(SingleTable([["You got away!"]]).table)
33 | input("Press ENTER to Continue")
34 | break
35 | else:
36 | if randint(1, 6) in [1,6]:
37 | player.health -= 1
38 | clear()
39 | print(SingleTable([["You got hit by one of their shots and lost some health!"]]).table)
40 | else:
41 | drug = choice(["cocaine", "heroin", "acid", "weed", "speed", "ludes"])
42 | pdrug = player.get_amt(drug)
43 | if pdrug > 0:
44 | amnt = randint(1, 10)
45 | pdrug -= amnt
46 | clear()
47 | print(SingleTable([["You got away but you dropped " + str(amnt) + " bags of " + drug.capitalize() + " while running!!"]]).table)
48 | else:
49 | print(SingleTable([["You got away!"]]).table)
50 | input("Press ENTER to Continue")
51 | break
52 | elif aout == 2:
53 | if 1 == randint(1,6):
54 | cops -= 1
55 | if cops == 0:
56 | drug = choice(["cocaine", "heroin", "acid", "weed", "speed", "ludes"])
57 | pdrug = player.get_amt(drug)
58 | if pdrug > 0:
59 | amnt = randint(1, 10)
60 | pdrug -= amnt
61 | clear()
62 | print(SingleTable([["You got away but you dropped " + str(amnt) + " bags of " + drug.capitalize() + " while running!!"]]).table)
63 | else:
64 | print(SingleTable([["You got away!"]]).table)
65 | input("Press ENTER to Continue")
66 | break
67 | clear()
68 | print(SingleTable([["You took one of them out!"]]).table)
69 | else:
70 | player.health -= 1
71 | clear()
72 | print(SingleTable([["You got hit by one of their shots and lost some health!"]]).table)
73 | else:
74 | while True:
75 | print(SingleTable([["Press ENTER to Try and Run"], ["HP: " + str(player.health) + "/ 20"]]).table)
76 | input()
77 | if 1 == randint(1,3):
78 | drug = choice(["cocaine", "heroin", "acid", "weed", "speed", "ludes"])
79 | pdrug = player.get_amt(drug)
80 | if pdrug > 0:
81 | amnt = randint(1, 10)
82 | pdrug -= amnt
83 | clear()
84 | print(SingleTable([["You got away but you dropped " + str(amnt) + " bags of " + drug.capitalize() + " while running!!"]]).table)
85 | else:
86 | print(SingleTable([["You got away!"]]).table)
87 | input("Press ENTER to Continue")
88 | break
89 | else:
90 | player.health -= 1
91 | clear()
92 | print(SingleTable([["You got hit by one of their shots and lost some health!"]]).table)
93 | clear()
94 | print(SingleTable([["You got away from the pigs!"]]).table)
95 | input("Press ENTER to Continue")
96 |
97 |
98 | def ask_bank(player):
99 | clear()
100 | while True:
101 | print(SingleTable([['Would you like to visit the bank?']]).table)
102 | ans = input("\n> ")
103 | aout = check_ans_yn(ans)
104 | if aout == 1:
105 | clear()
106 | visit_bank(player)
107 | break
108 | elif aout == 2:
109 | clear()
110 | break
111 |
112 | def ask_loan_shark(player):
113 | clear()
114 | while True:
115 | print(SingleTable([['Would you like to visit the loan shark?']]).table)
116 | ans = input("\n> ")
117 | aout = check_ans_yn(ans)
118 | if aout == 1:
119 | clear()
120 | visit_loan_shark(player)
121 | break
122 | elif aout == 2:
123 | clear()
124 | break
125 |
126 | def ask_stash(player):
127 | clear()
128 | while True:
129 | print(SingleTable([['Would you like to stash any drugs?']]).table)
130 | ans = input("\n> ")
131 | aout = check_ans_yn(ans)
132 | if aout == 1:
133 | clear()
134 | visit_stash(player)
135 | break
136 | elif aout == 2:
137 | clear()
138 | break
139 |
140 | def visit_stash(player):
141 | stashes = ["cocaine", "heroin", "acid", "weed", "speed", "ludes"]
142 | for stash in stashes:
143 | clear()
144 | while True:
145 | print(SingleTable([['How much ' + stash + ' would you like to deposit?'], ['Stash: ' + str(getattr(player.stash, stash)) + ' | Coat: ' + str(getattr(player, stash))]]).table)
146 | try:
147 | ans = int(input("\n> "))
148 | if ans == 0:
149 | break
150 | else:
151 | if player.stash.can_transfer(stash, ans):
152 | player.stash.transfer(stash, ans)
153 | break
154 | else:
155 | clear()
156 | print(SingleTable([["You don't have that much!"]]).table)
157 | except ValueError as e:
158 | clear()
159 | print(SingleTable([["That isn't a number!"]]).table)
160 | while True:
161 | print(SingleTable([['How much ' + stash + ' would you like to take out?'], ['Stash: ' + str(getattr(player.stash, stash)) + ' | Coat: ' + str(getattr(player, stash))]]).table)
162 | try:
163 | ans = int(input("\n> "))
164 | if ans == 0:
165 | break
166 | else:
167 | if player.stash.can_withdraw(stash, ans):
168 | player.stash.withdraw(stash, ans)
169 | break
170 | else:
171 | clear()
172 | print(SingleTable([["You don't have that much in your stash!"]]).table)
173 | except ValueError as e:
174 | clear()
175 | print(SingleTable([["That isn't a number!"]]).table)
176 |
177 | def visit_bank(player):
178 | clear()
179 | if player.money > 0:
180 | while True:
181 | print(SingleTable([['How much would you like to deposit?'], ['Bank: ' + str(player.bank.balance) + ' | Wallet: ' + str(player.money)]]).table)
182 | try:
183 | ans = input("\n> ")
184 | if ans.lower() == "h" or ans.lower() == "half":
185 | if player.bank.check_can_dep(int(round_down(player.money / 2))):
186 | player.bank.deposit(int(round_down(player.money / 2)))
187 | break
188 | ans = int(ans)
189 | if ans == 0:
190 | break
191 | else:
192 | if player.bank.check_can_dep(ans):
193 | player.bank.deposit(ans)
194 | break
195 | else:
196 | clear()
197 | print(SingleTable([["You don't have that much!"]]).table)
198 | except ValueError as e:
199 | clear()
200 | print(SingleTable([["That isn't a number!"]]).table)
201 | clear()
202 | if player.bank.balance > 0:
203 | while True:
204 | print(SingleTable([['How much would you like to withdraw?'], ['Bank: ' + str(player.bank.balance) + ' | Wallet: ' + str(player.money)]]).table)
205 | try:
206 | ans = input("\n> ")
207 | if ans.lower() == "a" or ans.lower() == "all":
208 | player.bank.withdraw(player.bank.balance)
209 | break
210 | if ans.lower() == "h" or ans.lower() == "half":
211 | player.bank.withdraw(int(round_down(player.shark.balance / 2)))
212 | break
213 | ans = int(ans)
214 | if ans == 0:
215 | break
216 | else:
217 | if player.bank.check_can_wd(ans):
218 | player.bank.withdraw(ans)
219 | break
220 | else:
221 | clear()
222 | print(SingleTable([["You don't have that much!"]]).table)
223 | except ValueError as e:
224 | clear()
225 | print(SingleTable([["That isn't a number!"]]).table)
226 |
227 | def visit_loan_shark(player):
228 | clear()
229 | while True:
230 | print(SingleTable([['How much would you like to repay?'], ['Debt: ' + str(player.shark.balance) + ' | Wallet: ' + str(player.money)]]).table)
231 | try:
232 | ans = input("\n> ")
233 | if ans.lower() == "a" or ans.lower() == "all":
234 | if player.shark.check_can_dep(player.shark.balance):
235 | player.shark.deposit(player.shark.balance)
236 | break
237 | if ans.lower() == "h" or ans.lower() == "half":
238 | if player.shark.check_can_dep(int(round_down(player.shark.balance / 2))):
239 | player.shark.deposit(int(round_down(player.shark.balance / 2)))
240 | break
241 | ans = int(ans)
242 | if ans == 0:
243 | break
244 | elif ans > player.shark.balance:
245 | clear()
246 | print(SingleTable([["That's more than you owe!"]]).table)
247 | else:
248 | if player.shark.check_can_dep(ans):
249 | player.shark.deposit(ans)
250 | break
251 | else:
252 | clear()
253 | print(SingleTable([["You don't have enough!"]]).table)
254 | except ValueError as e:
255 | clear()
256 | print(SingleTable([["That isn't a number!"]]).table)
257 | clear()
258 | while True:
259 | print(SingleTable([['How much would you like to borrow?'], ['Debt: ' + str(player.shark.balance) + ' | Wallet: ' + str(player.money)]]).table)
260 | try:
261 | ans = int(input("\n> "))
262 | if ans == 0:
263 | break
264 | else:
265 | if player.shark.check_can_borrow(ans):
266 | player.shark.withdraw(ans)
267 | break
268 | else:
269 | clear()
270 | print(SingleTable([["You can't take more than you owe or have already!"]]).table)
271 | except ValueError as e:
272 | clear()
273 | print(SingleTable([["That isn't a number!"]]).table)
274 |
275 | def upgrade_coat(p):
276 | clear()
277 | while True:
278 | price = randint(150, 250)
279 | if p.money >= price:
280 | print(SingleTable([["** Would you like to buy 15 more pockets for more drugs? It's $" + str(price) + " **"], ["Wallet: ", p.money]]).table)
281 | a = input("\n> ")
282 | ao = check_ans_yn(a)
283 | if ao == 1:
284 | p.max_trench += 15
285 | p.money -= price
286 | clear()
287 | print(SingleTable([["You bought more trench pockets for $" + str(price)]]).table)
288 | input("Press ENTER to Continue")
289 | break
290 | elif ao == 2:
291 | break
292 | else:
293 | clear()
294 | print(SingleTable([["Please enter Y or N"]]).table)
295 | break
296 | input("Press ENTER to Continue")
297 | clear()
298 | else:
299 | break
300 |
301 | def get_mugged(p):
302 | clear()
303 | if 1 == randint(1, 8):
304 | clear()
305 | print(SingleTable([["You got mugged!! You lost " + str(p.money - int(round_down(p.money * 0.80))) + " dollars!"]]).table)
306 | p.money = int(round_down(p.money * 0.80))
307 | input("Press ENTER to Continue")
308 | clear()
309 |
310 | def find_drugs(p):
311 | clear()
312 | if 1 == randint(1, 10):
313 | clear()
314 | amnt = randint(1, 10)
315 | drug = randint(1, 8)
316 | dstr = ""
317 | if p.len_inventory() + amnt <= p.max_trench:
318 | if drug == 1:
319 | dstr = "Cocaine"
320 | p.cocaine += amnt
321 | if drug == 2:
322 | dstr = "Heroin"
323 | p.heroin += amnt
324 | if drug == 3:
325 | dstr = "Acid"
326 | p.acid += amnt
327 | if drug == 4:
328 | dstr = "Weed"
329 | p.weed += amnt
330 | if drug == 5:
331 | dstr = "Speed"
332 | p.speed += amnt
333 | if drug == 6:
334 | dstr = "Ludes"
335 | p.ludes += amnt
336 | print(SingleTable([["You found " + str(amnt) + " bags of " + dstr + " on the ground... \n FUCK YEAH"]]).table)
337 | input("Press ENTER to Continue")
338 |
339 | def buy_gun(p):
340 | clear()
341 | if 1 == randint(1, 5):
342 | clear()
343 | while True:
344 | price = randint(200, 300)
345 | print(SingleTable([["** Would you like to buy a gun for $" + str(price) + "? **"], ["Wallet: ", p.money]]).table)
346 | a = input("\n> ")
347 | ao = check_ans_yn(a)
348 | if ao == 1:
349 | p.guns += 1
350 | p.money -= price
351 | clear()
352 | print(SingleTable([["You bought a gun for $" + str(price)]]).table)
353 | input("Press ENTER to Continue")
354 | break
355 | elif ao == 2:
356 | break
357 | else:
358 | clear()
359 | print(SingleTable([["Please enter Y or N"]]).table)
360 | break
361 | input("Press ENTER to Continue")
362 |
363 | def you_win(p):
364 | clear()
365 | score = int(round_down((p.bank.balance + p.money - p.shark.balance) / 10000000 * 100))
366 | if score > 100:
367 | score = 100
368 | if p.bank.balance + p.money - p.shark.balance < 0:
369 | score = 0
370 | print(SingleTable([["GAME OVER", f"You Reached {p.days_end} Days!"]]).table)
371 | print(SingleTable([["Your Total Money:", p.bank.balance + p.money - p.shark.balance]]).table)
372 | print(SingleTable([["Your Score:", str(score) + " out of 100"]]).table)
373 | if score >= 0 and score <= 30:
374 | print(SingleTable([["Dealer Rank", "Small Time Pusha... WEAK"]]).table)
375 | elif score >= 31 and score <= 50:
376 | print(SingleTable([["Dealer Rank", "Own The Block... NOT BAD"]]).table)
377 | elif score >= 51 and score <= 75:
378 | print(SingleTable([["Dealer Rank", "Run The Town... PRETTY GOOD"]]).table)
379 | elif score >= 76 and score <= 99:
380 | print(SingleTable([["Dealer Rank", "Kingpin... GOD DAMN"]]).table)
381 | else:
382 | print(SingleTable([["Dealer Rank", "PABLO ESCOBAR... YOU ARE A GOD"]]).table)
383 | exit()
384 |
385 | def buy_menu(prices, inventory_table, pricing_table, money_table, p):
386 | while True:
387 | print(SingleTable(inventory_table()).table)
388 | print(SingleTable(pricing_table(), title="Prices").table)
389 | print(SingleTable(money_table(), title="Money").table)
390 | print(SingleTable([["What would you like to buy?"]]).table)
391 | desired = input("\n> ")
392 | if not check_drug_inp(desired):
393 | clear()
394 | print(SingleTable([["Enter the first letter of a drug to choose!"]]).table)
395 | else:
396 | # Get some useful variables that will clean up the code a lot
397 | drug = check_drug_inp(desired)
398 | price = round_down(get_price(prices, drug))
399 | max_allowed = p.get_max(drug, price)
400 |
401 | print(SingleTable([["How much would you like to buy?"], [f"Max Allowed: {str(max_allowed)}"]]).table)
402 | desiredamnt = input("\n> ")
403 |
404 | # Calculate amount
405 | try:
406 | amnt = int(desiredamnt)
407 | except ValueError:
408 | if desiredamnt.count('%') > 0:
409 | if int(desiredamnt.replace('%', '')) > 100:
410 | tmp = 100
411 | else:
412 | tmp = int(desiredamnt.replace('%', ''))
413 |
414 | amnt = round_down(max_allowed * (tmp / 100))
415 | else:
416 | if desiredamnt == 'a' or desiredamnt == 'all':
417 | amnt = max_allowed
418 | elif desiredamnt == 'h' or desiredamnt == 'half':
419 | amnt = round_down(max_allowed / 2)
420 | else:
421 | clear()
422 | print(SingleTable([["That isn't a valid amount!"]]).table)
423 | continue
424 |
425 | # Buy the drug
426 | if p.can_buy(price, amnt):
427 | p.buy(drug, amnt, price)
428 | clear()
429 | print(SingleTable([[f"You bought {str(amnt)} of {drug}!"]]).table)
430 | break
431 | else:
432 | clear()
433 | print(SingleTable([["You don't have enough money/coat space to buy that!"]]).table)
434 | break
435 |
436 | def sell_menu(prices, inventory_table, pricing_table, money_table, p):
437 | while True:
438 | print(SingleTable(inventory_table()).table)
439 | print(SingleTable(pricing_table(), title="Prices").table)
440 | print(SingleTable(money_table(), title="Money").table)
441 | print(SingleTable([["What would you like to sell?"]]).table)
442 | desired = input("\n> ")
443 | if not check_drug_inp(desired):
444 | clear()
445 | print(SingleTable([["Enter the first letter of a drug to choose!"]]).table)
446 | else:
447 | # Get some useful variables that will clean up the code a lot
448 | drug = check_drug_inp(desired)
449 | price = round_down(get_price(prices, drug))
450 | max_allowed = p.get_max_sell(drug)
451 |
452 | print(SingleTable([["How much would you like to sell?"], [f"You have: {str(p.get_amt(drug))} {drug}"]]).table)
453 | desiredamnt = input("\n> ")
454 |
455 | # Calculate amount
456 | try:
457 | amnt = int(desiredamnt)
458 | except ValueError:
459 | if desiredamnt.count('%') > 0:
460 | if int(desiredamnt.replace('%', '')) > 100:
461 | tmp = 100
462 | else:
463 | tmp = int(desiredamnt.replace('%', ''))
464 |
465 | amnt = round_down(max_allowed * (tmp / 100))
466 | else:
467 | if desiredamnt == 'a' or desiredamnt == 'all':
468 | amnt = max_allowed
469 | elif desiredamnt == 'h' or desiredamnt == 'half':
470 | amnt = round_down(max_allowed / 2)
471 | else:
472 | clear()
473 | print(SingleTable([["That isn't a valid amount!"]]).table)
474 | continue
475 |
476 | # Sell the drug
477 | if p.can_sell(amnt, drug):
478 | p.sell(drug, amnt, price)
479 | clear()
480 | print(SingleTable([[f"You sold {str(amnt)} of {drug}!"]]).table)
481 | break
482 | else:
483 | clear()
484 | print(SingleTable([["You don't have that many drugs!"]]).table)
485 | break
486 |
487 | def location_menu(p):
488 | while True:
489 | clear()
490 | loc_index = ['Bronx', 'Ghetto', 'Central Park', 'Manhattan', 'Coney Island', 'Brooklyn']
491 | location_table = [
492 | ['1) Bronx', '2) Ghetto', '3) Central Park'],
493 | ['4) Manhattan', '5) Coney Island', '6) Brooklyn']
494 | ]
495 | print(SingleTable(location_table, title="Where you gonna go? Current Location: " + p.current_area).table)
496 | try:
497 | loc = int(input("\n> ")) - 1
498 | if loc > 5 or loc < 0:
499 | clear()
500 | print(SingleTable([["Choose a number between 1 and 6!"]]).table)
501 | else:
502 | if loc_index[loc] == p.current_area:
503 | clear()
504 | else:
505 | loc += 1
506 | if loc == 1:
507 | p.current_area = "Bronx"
508 | if loc == 2:
509 | p.current_area = "Ghetto"
510 | if loc == 3:
511 | p.current_area = "Central Park"
512 | if loc == 4:
513 | p.current_area = "Manhattan"
514 | if loc == 5:
515 | p.current_area = "Coney Island"
516 | if loc == 6:
517 | p.current_area = "Brooklyn"
518 | p.days += 1
519 | break
520 | except ValueError:
521 | clear()
522 | print(SingleTable([["That isn't a number!"]]).table)
523 |
524 | def difficulty_screen():
525 | clear()
526 | while True:
527 | diff_table = [
528 | ["(E)asy", "(N)ormal", "(H)ard"],
529 | ]
530 | print(SingleTable(diff_table, "Difficulty Level").table)
531 | print("What level of difficulty would you like to play at?")
532 | diff = input("\n> ")
533 | if diff.lower() == "e":
534 | return 0
535 | elif diff.lower() == "n":
536 | return 1
537 | elif diff.lower() == "h":
538 | return 2
539 | else:
540 | clear()
541 | print(SingleTable([["Options Are: E, N, or H!!"]]).table)
542 |
543 |
544 | def days_screen():
545 | clear()
546 | while True:
547 | day_table = [
548 | ["(A) 30 Days", "(B) 60 Days", "(C) 90 Days"]
549 | ]
550 | print(SingleTable(day_table, "Number of Days").table)
551 | print("How many days would you like to play?")
552 | test = input("\n> ")
553 | if test.lower() == 'a':
554 | return 30
555 | elif test.lower() == 'b':
556 | return 60
557 | elif test.lower() == 'c':
558 | return 90
559 | else:
560 | clear()
561 | print(SingleTable([["Options Are: A, B, or C."]]).table)
562 |
563 |
564 | def main_screen(p):
565 | prices = Prices(p)
566 | if p.days == p.days_end:
567 | you_win(p)
568 | if not p.is_first_round:
569 | achoice = choice([lambda p: cops_chase(p), lambda p: buy_gun(p), lambda p: get_mugged(p), lambda p: find_drugs(p), lambda p: upgrade_coat(p)])
570 | achoice(p)
571 | if prices.action != None and not p.is_first_round:
572 | print(SingleTable([[prices.action]]).table)
573 | input("Press ENTER to Continue")
574 | current_area = p.current_area
575 | if not p.is_first_round and current_area == "Bronx":
576 | clear()
577 | ask_loan_shark(p)
578 | ask_bank(p)
579 | ask_stash(p)
580 | while True:
581 | clear()
582 | inventory_table = lambda : [
583 | ['Inventory', 'Days Left: ' + str(p.days_end - p.days)],
584 | ['Cocaine: ' + str(round_down(p.cocaine)), 'Weed: ' + str(round_down(p.weed))],
585 | ['Heroin: ' + str(round_down(p.heroin)), 'Speed: ' + str(round_down(p.speed))],
586 | ['Acid: ' + str(round_down(p.acid)), 'Ludes: ' + str(round_down(p.ludes))],
587 | ]
588 | pricing_table = lambda : [
589 | ['Current Area: ' + p.current_area, 'Coat Space: ' + str(p.coat_space()) + " / " + str(p.max_trench)],
590 | ['Cocaine: ' + str(round_down(prices.cocaine)), 'Weed: ' + str(round_down(prices.weed))],
591 | ['Heroin: ' + str(round_down(prices.heroin)), 'Speed: ' + str(round_down(prices.speed))],
592 | ['Acid: ' + str(round_down(prices.acid)), 'Ludes: ' + str(round_down(prices.ludes))]
593 | ]
594 | money_table = lambda : [
595 | ['Debt: ' + str(int(round_down(p.shark.balance))) ,'Guns: ' + str(p.guns), 'Bank: ' + str(int(round_down(p.bank.balance))), 'Wallet: ' + str(int(round_down(p.money)))]
596 | ]
597 | print(SingleTable(inventory_table()).table)
598 | print(SingleTable(pricing_table(), title="Prices").table)
599 | print(SingleTable(money_table(), title="Money").table)
600 | print(SingleTable([["Are you going to (B)uy, (S)ell, or (J)et?"]]).table)
601 | ans = input("\n> ")
602 | anout = check_ans_bsj(ans)
603 | clear()
604 | if anout == 1:
605 | buy_menu(prices, inventory_table, pricing_table, money_table, p)
606 | elif anout == 2:
607 | sell_menu(prices, inventory_table, pricing_table, money_table, p)
608 | elif anout == 3:
609 | location_menu(p)
610 | else:
611 | clear()
612 | print(SingleTable([["That isn't an option. Choose B, S, or J"]]).table)
613 | if p.current_area != current_area:
614 | break
615 | p.is_first_round = False
616 | p.bank.interest()
617 | p.shark.interest()
618 | main_screen(p)
--------------------------------------------------------------------------------
/drugwars/helpers.py:
--------------------------------------------------------------------------------
1 | import os, math
2 |
3 | def check_ans_yn(a):
4 | if a.lower() == "y" or a.lower() == "r":
5 | return 1
6 | elif a.lower() == "n" or a.lower() == "f":
7 | return 2
8 | else:
9 | return 0
10 |
11 | def check_drug_inp(a):
12 | a = a.lower()
13 | drugs = {
14 | "c": "cocaine",
15 | "h": "heroin",
16 | "a": "acid",
17 | "w": "weed",
18 | "s": "speed",
19 | "l": "ludes"
20 | }
21 | if len(a) == 0:
22 | return None
23 | for k, v in drugs.items():
24 | if k == a[0]:
25 | return v
26 | return None
27 |
28 | def check_ans_bsj(a):
29 | if a.lower() == "b":
30 | return 1
31 | elif a.lower() == "s":
32 | return 2
33 | elif a.lower() == "j":
34 | return 3
35 | else:
36 | return 0
37 |
38 | def clear():
39 | os.system('cls' if os.name == 'nt' else 'clear')
40 |
41 | def round_down(n, decimals=0):
42 | multiplier = 10 ** decimals
43 | return int(math.floor(n * multiplier) / multiplier)
44 |
45 | def get_price(prices, drug):
46 | if drug == 'cocaine':
47 | return prices.cocaine
48 | elif drug == 'heroin':
49 | return prices.heroin
50 | elif drug == 'acid':
51 | return prices.acid
52 | elif drug == 'weed':
53 | return prices.weed
54 | elif drug == 'speed':
55 | return prices.speed
56 | elif drug == 'ludes':
57 | return prices.ludes
58 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | terminaltables==3.1.0
2 | requests==2.24.0
3 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import sys, requests
4 | from setuptools import setup, find_packages
5 |
6 | setup(
7 | name='drugwars',
8 | version='1.2.1-post3',
9 | author='Max Bridgland',
10 | author_email='mabridgland@protonmail.com',
11 | description='The 80s DOS game re-written in Python',
12 | long_description=open('./README.md', 'r').read(),
13 | long_description_content_type='text/markdown',
14 | url='https://github.com/M4cs/Drugwars',
15 | packages=find_packages(),
16 | install_requires=[
17 | 'terminaltables',
18 | 'requests'
19 | ],
20 | license='GNU General Public License v3 (GPLv3) (GPL)',
21 | zip_safe=True,
22 | entry_points={
23 | 'console_scripts':[
24 | 'drugwars = drugwars.__main__:main',
25 | ],
26 | },
27 | classifiers=[ # Used by PyPI to classify the project and make it searchable
28 | 'Development Status :: 5 - Production/Stable',
29 | 'Environment :: Console',
30 | 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
31 | 'Natural Language :: English',
32 | 'Operating System :: Microsoft',
33 | 'Operating System :: MacOS',
34 | 'Operating System :: Unix',
35 | 'Programming Language :: Python :: 3',
36 | 'Programming Language :: Python :: Implementation :: CPython',
37 | 'Topic :: Games/Entertainment :: Turn Based Strategy'
38 | ]
39 | )
40 |
--------------------------------------------------------------------------------