Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit eb89c4a

Browse files
committed
move character classes to separate file, and remove global mob and player from main
1 parent bad9f24 commit eb89c4a

File tree

5 files changed

+189
-264
lines changed

5 files changed

+189
-264
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ Worldmap.db
1111
map.csv
1212
csvReader.py
1313
checkingDB.py
14+
.idea

Main.py

+58-130
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,24 @@
33
##-- Waste Land --##
44

55
##-- Import Modules --##
6-
import cmd
76
import os
87
import random
98
import sys
10-
import textwrap
119
import time
1210

1311

1412
##-- Custom Imports --##
1513
from Map_Gen import Engine
1614
from Map_Gen import Biome
17-
from script import InfoDics, Items, Map, Mobs, NPC, Screen, Story
15+
from script.Character import *
16+
from script import InfoDics, Items, Screen, Story
1817

1918
import ChangeLog
2019

21-
##-- Globel Varibles --##
20+
##-- Global Variables --##
2221
player_name = 'X' ##-- This is for the Funtion char_creation() --##
2322
player_class_choice = 'X' ##-- This is also for the Funtion char_creation() --##
24-
player_in_game = 'X' ##-- Again this is also for the Funtion char_creation() --##
25-
mob = 'X' ##-- This varible is to hold the current mob player is fighing --##
23+
player_in_game = None ##-- Again this is also for the Funtion char_creation() --##
2624
gender = 'X' ##-- This varible sets the pronouns for the story and is set in the function in char_creation() in gender_call() --##
2725
opening = True ##-- Only True if hasnt seen opening story --##
2826
turn = True ##-- If True it's the players turn --##
@@ -53,75 +51,7 @@ def pause():
5351

5452
input("Press Enter To Continue:> ")
5553

56-
##-- Inventory layout --##
5754

58-
class PlayerInventory:
59-
60-
def __init__(self):
61-
62-
self.inventory_item_limit = 10
63-
self.bag = []
64-
self.equiped_weapon = Items.fist
65-
self.equiped_armor = Items.farm_clothing
66-
67-
##-- Below code is not in use and will change one I start using it --##
68-
def add_to_inventory(self, add_item):
69-
70-
self.add_item = add_item
71-
if len(self.bag) < self.inventory_item_limit:
72-
self.bag.append(self.add_item)
73-
74-
def remove_from_inv(self, remove_item):
75-
76-
self.remove_item = remove_item
77-
78-
def hand_swap(self, requested_item):
79-
80-
self.requested_item = requested_item
81-
82-
##-- Player Inventory __init__ Call --##
83-
84-
player_inventory = PlayerInventory()
85-
86-
##-- Setting up player classes --##
87-
##-- The player class handles all the players stat creation --##
88-
##-- The Mage, Warrior, Archer and Assassin classes will inherit the Player class --##
89-
class Player:
90-
91-
def __init__(self, name, player_class, max_health, melee_attack, magic_attack,
92-
max_mana, max_stamina, defense, pures, luck):
93-
94-
self.name = name
95-
self.player_class = player_class
96-
self.level = 1
97-
self.exp = 0
98-
self.max_health = max_health
99-
self.health = self.max_health ##-- Not sure if this is smart but this should only set health to max on making the character --##
100-
self.melee_attack = melee_attack
101-
self.magic_attack = magic_attack
102-
self.max_mana = max_mana
103-
self.mana = self.max_mana
104-
self.max_stamina = max_stamina
105-
self.stamina = self.max_stamina
106-
self.defense = defense
107-
self.pures = pures
108-
self.luck = luck
109-
110-
class Mage(Player):
111-
pass
112-
113-
class Warrior(Player):
114-
##-- Adrenaline Junky --##
115-
##-- Lets Warrior the ablity to take 1 hits before death --##
116-
##-- Ability can level up as player gets stronger --##
117-
pass
118-
119-
class Archer(Player):
120-
pass
121-
122-
class Assassin(Player):
123-
pass
124-
12555
##-- Main() is the first function --##
12656
##-- Gets input from player to either Start Load Help or Exit --##
12757

@@ -234,24 +164,24 @@ def class_selection():
234164
##-- class to be Mage, Warrior, Archer or Assassin --##
235165
##-- Mage --##
236166
if player_class_choice == 'Mage':
237-
player_in_game = Mage(player_name,'Mage',max_health=80,melee_attack=1,magic_attack=10,
167+
player_in_game = Mage(char_name=player_name, player_class='Mage',max_health=80,melee_attack=1,magic_attack=10,
238168
max_mana=50, max_stamina=10, defense=1, pures=0, luck=1)
239-
player_inventory.in_hand = Items.weak_staff
169+
player_in_game.equipped_weapon = Items.weak_staff
240170
##-- Warrior --##
241171
elif player_class_choice == 'Warrior':
242-
player_in_game = Warrior(player_name,'Warrior',max_health=150,melee_attack=10,magic_attack=0,
172+
player_in_game = Warrior(char_name=player_name, player_class='Warrior',max_health=150,melee_attack=10,magic_attack=0,
243173
max_mana=5, max_stamina=50, defense=4, pures=0, luck=0)
244-
player_inventory.in_hand = Items.rusty_short_sword
174+
player_in_game.equipped_weapon = Items.rusty_short_sword
245175
##-- Archer --##
246176
elif player_class_choice == 'Archer':
247-
player_in_game = Archer(player_name,'Archer',max_health=100,melee_attack=5,magic_attack=0,
177+
player_in_game = Archer(char_name=player_name, player_class='Archer',max_health=100,melee_attack=5,magic_attack=0,
248178
max_mana=50, max_stamina=10, defense=1, pures=0, luck=5)
249-
player_inventory.in_hand = Items.common_hunting_bow
179+
player_in_game.equipped_weapon = Items.common_hunting_bow
250180
##-- Assassin --##
251181
elif player_class_choice == 'Assassin':
252-
player_in_game = Assassin(player_name,'Assassin',max_health=50,melee_attack=20,magic_attack=10,
182+
player_in_game = Assassin(char_name=player_name,player_class='Assassin',max_health=50,melee_attack=20,magic_attack=10,
253183
max_mana=25, max_stamina=10, defense=2, pures=100, luck=10)
254-
player_inventory.in_hand = Items.rusty_dagger
184+
player_in_game.equipped_weapon = Items.rusty_dagger
255185

256186
gender_call()
257187
##-- Back to main loop --##
@@ -260,15 +190,12 @@ def class_selection():
260190
##-- Makes a random mob with in the range of the players level --##
261191

262192
def random_enemy():
263-
global mob
264-
biome_info = Engine.get_tile(x,y)
193+
biome_info = Engine.get_tile(x,y)
265194
spawns = Biome.world_biomes[biome_info[0][2]]['spawns']
266195
if spawns == ["None"]:
267-
mob = "X"
268-
return
196+
return None
269197
random_mob = random.choice(spawns)
270-
mob = Mobs.hostail_mobs[random_mob]
271-
# mob = Mobs.random_enemy(player_in_game.level)
198+
return hostile_mobs[random_mob]
272199

273200
##-- Encounter is to handle if we fight or not --##
274201
##-- This probably needs some work --##
@@ -280,9 +207,10 @@ def encounter():
280207
##-- num is subject to change as I add possible encounters --##
281208

282209
num = random.randint(1, 1000)
283-
random_enemy()
210+
mob = random_enemy()
284211
clear()
285-
print(f"You ran in a {mob.name} on the path.")
212+
if mob is not None:
213+
print(f"You ran in a {mob.char_name} on the path.")
286214
pause()
287215
#combat()
288216
if biome_or_subBiome == False:
@@ -308,64 +236,64 @@ def level_up(player):
308236

309237
##-- This is to set up the fighting system --##
310238

311-
def combat():
239+
def combat(mob):
312240

313241
clear()
314242
Screen.vs_screen(player_in_game, mob)
315-
Screen.stat_screen(player_in_game, player_inventory, mob)
243+
Screen.stat_screen(player_in_game, mob)
316244
option = input('\n(1): Attack\n(2): Magic\n(3): Use Item\n(4): Run\nChoose A Number:> ')
317245

318246
if option == '1':
319-
attack()
247+
attack(mob)
320248

321249
elif option == '2':
322-
magic()
250+
magic(mob)
323251

324252
elif option == '3':
325-
use_item()
253+
use_item(mob)
326254

327255
elif option =='4':
328-
run()
256+
run(mob)
329257
##-- Attack handles melee and magic attacks --##
330258
##-- Unlike most games magic attacks aren't --##
331259
##-- Just spells "magic attack" uses the --##
332260
##-- Magic of the weapon in hand to deal --##
333261
##-- Damage. But spells will be delt with a --##
334262
##-- Different functions --##
335263

336-
def attack():
264+
def attack(mob):
337265

338-
player_melee_attack = random.randint(round(player_in_game.melee_attack / 2), player_in_game.melee_attack + player_inventory.equiped_weapon.melee_damage)
339-
player_magic_attack = random.randint(round(player_in_game.magic_attack / 2), player_in_game.magic_attack + player_inventory.equiped_weapon.magic_damage)
266+
player_melee_attack = random.randint(round(player_in_game.melee_attack / 2), player_in_game.melee_attack + player_in_game.equipped_weapon.melee_damage)
267+
player_magic_attack = random.randint(round(player_in_game.magic_attack / 2), player_in_game.magic_attack + player_in_game.equipped_weapon.magic_damage)
340268
enemy_attack = random.randint(round(mob.melee_attack / 2), mob.melee_attack)
341269
clear()
342270
Screen.vs_screen(player_in_game, mob)
343-
Screen.stat_screen(player_in_game,player_inventory, mob)
271+
Screen.stat_screen(player_in_game, mob)
344272
attack_type = input('\n(1): Melee Attack\n(2): Magic Attack\nChoose A Number:> ')
345273
if attack_type == '1':
346274
if player_melee_attack == player_in_game.melee_attack / 2: ##-- Player Attack --##
347-
print(f"\n{player_in_game.name} {player_inventory.in_hand.action_word}") ##-- finish me --##
275+
print(f"\n{player_in_game.name} {player_in_game.equipped_weapon.action_word}") ##-- finish me --##
348276
else:
349277
mob.health -= player_melee_attack
350278
clear()
351279
print(f'\nYou just dealed {player_melee_attack} damage.')
352280

353281
input('\nPess Enter To Continue:> ')
354282
if mob.health <= 0:
355-
win()
283+
win(mob)
356284

357285
if enemy_attack == round(mob.melee_attack / 2): ##-- Mob Attack --##
358286
clear()
359-
print(f'\n{mob.name} missed!')
287+
print(f'\n{mob.char_name} missed!')
360288
else:
361289
player_in_game.health -= enemy_attack
362290
clear()
363-
print(f'\n{mob.name} just dealed {enemy_attack} damage to you.')
364-
input('\nPess Enter To Continue:> ')
291+
print(f'\n{mob.char_name} just dealed {enemy_attack} damage to you.')
292+
input('\nPress Enter To Continue:> ')
365293
if player_in_game.health <= 0:
366-
dead()
294+
dead(mob)
367295
else:
368-
combat()
296+
combat(mob)
369297

370298
elif attack_type == '2':
371299

@@ -379,36 +307,36 @@ def attack():
379307

380308
input('\nPress Enter To Continue:> ')
381309
if mob.health <= 0:
382-
win()
310+
win(mob)
383311

384312
if enemy_attack == round(mob.magic_attack / 2): ##-- Mob Attack --##
385313
clear()
386-
print(f'\n{mob.name} missed!')
314+
print(f'\n{mob.char_name} missed!')
387315
else:
388316
player_in_game.health -= enemy_attack
389317
clear()
390-
print(f'\n{mob.name} just dealed {enemy_attack} damage to you.')
318+
print(f'\n{mob.char_name} just dealed {enemy_attack} damage to you.')
391319
input('\nPess Enter To Continue:> ')
392320
if player_in_game.health <= 0:
393-
dead()
321+
dead(mob)
394322
else:
395-
combat()
323+
combat(mob)
396324

397325
##-- Handles Spell Attacks and Healing or what ever else I can dream up --##
398-
def magic():
326+
def magic(mob):
399327
print("not working yet. Sorry!")
400328
pause()
401-
attack()
329+
attack(mob)
402330

403331
##-- Handles the use of potions or and other usable item --##
404332
##-- In combat or out --##
405-
def use_item():
333+
def use_item(mob):
406334
print("not working yet. Sorry!")
407335
pause()
408-
attack()
336+
attack(mob)
409337

410338
##-- Run or Flee is to get away from the enemy in a fight --##
411-
def run():
339+
def run(mob):
412340
running = random.randint(1, 3)
413341
if running == 1:
414342
clear()
@@ -422,34 +350,34 @@ def run():
422350
enemy_attack = random.randint(round(mob.melee_attack / 2), mob.melee_attack)
423351
if enemy_attack == round(mob.melee_attack / 2):
424352
clear()
425-
print(f'\n{mob.name} missed!')
353+
print(f'\n{mob.char_name} missed!')
426354
else:
427355
player_in_game.health -= enemy_attack
428356
clear()
429-
print(f'\n{mob.name} just dealed {enemy_attack} damage to you.')
357+
print(f'\n{mob.char_name} just dealed {enemy_attack} damage to you.')
430358
input('\nPess Enter To Continue:> ')
431359
if player_in_game.health <= 0:
432-
dead()
360+
dead(mob)
433361
else:
434-
combat()
362+
combat(mob)
435363

436364
##-- If you when a fight this function handles what happens --##
437365

438-
def win():
366+
def win(mob):
439367
clear()
440368
player_in_game.pures += mob.pures
441369
player_in_game.exp += mob.exp_gained
442-
message = f"You just defeated a {mob.name}\nGold Looted: {mob.pures}\nEXP Gained: {mob.exp_gained}"
370+
message = f"You just defeated a {mob.char_name}\nGold Looted: {mob.pures}\nEXP Gained: {mob.exp_gained}"
443371
print(message)
444-
input('\nPess Enter To Continue:> ')
372+
input('\nPress Enter To Continue:> ')
445373
if biome_or_subBiome == False:
446374
main_game_loop()
447375
else:
448376
sub_map_move()
449377
##-- If in an unfortunate event the player dies this function is called --##
450378

451-
def dead():
452-
print(f'You have died from {mob.name}')
379+
def dead(mob):
380+
print(f'You have died from {mob.char_name}')
453381
pause()
454382
main()
455383

@@ -460,7 +388,7 @@ def get_resouces():
460388
random_item = random.choice(biome_item)
461389
item = Items.resources[random_item]
462390

463-
player_inventory.add_item(item)
391+
player_in_game.add_to_inventory(item)
464392
pause()
465393
if biome_or_subBiome == False:
466394
main_game_loop()
@@ -469,8 +397,8 @@ def get_resouces():
469397

470398

471399
def look_in_inventory():
472-
print(player_inventory.bag)
473-
print(player_inventory.inventory_item_limit)
400+
print(player_in_game.inventory)
401+
print(player_in_game.inventory_limit)
474402
pause()
475403
if biome_or_subBiome == False:
476404
main_game_loop()
@@ -588,7 +516,7 @@ def main_game_loop():
588516
# print('Loading...........')
589517
if opening == True:
590518

591-
Story.intro_story(player_in_game.name)
519+
Story.intro_story(player_in_game.char_name)
592520
input("Press Enter to continue: ")
593521
opening = False
594522
map_info = Engine.get_tile(x,y)

0 commit comments

Comments
 (0)