· 7 years ago · Sep 19, 2018, 05:46 PM
1#!/usr/bin/python3.6
2# barloovapy002.py
3# coding: utf-8
4#
5# Original program: goshemighty Written in Turbo Pascal 5.5 last edit 01/24/2000
6# Sporadic Python conversion began Aug-27-2018 - doc edits and variable conversion
7# Code conversion began Sep-01-2018 - Entity class (subclass: npc)
8# Sep-07-2018 - Created Items class (Parent for all major item types) # End V001
9# Sep-11-2018 - v002
10# Added Weapon class (subclass of Item), begin work on UI, potion class
11# Created wepon dictionary # Not sure yet how to use it
12# End v002
13# Sep-16-2018 -v003
14# begin player generation
15#
16import tkinter as tk
17import random
18import time
19# Table of contents
20# Import modules:
21# tkinter = GUI, time = logging/special events, random = everything
22# Global variables:
23# seed,
24#
25# UI Code Goes Here
26#
27# Class definitions:
28# Entity (subclass- Plyr, Npc)
29# Item (nest all tangible items)
30# Functions / Methods:
31# rnd, keys (should transition to ui management)
32#
33# Original program layout: ## This is provided for historical curoisity
34# Added Python-style comments to the historical code outline
35# Should remove these lines completely at some point. The program is evolving in a different direction
36# Variable definitions : Redundant in Python
37# Functions / Methods:
38# keys, rnd <sets entry to uppercase, random generator>
39# makestats <Sets up the player> # Transferred to Humanoid class definition
40# final <Endgame scoring> # The game no longer has a "final goal."
41# damage <calculate damage, weariness>
42# dostats, seestats, setstats setmap <various game procedures> # All of this goes into the GUI
43# arm, wpn, trp #
44# puzzles (p1-p5) # These are all attributes/dictionaries in Python code
45# cns, other, pzl #
46# smarts, strength, agility, fatigue (* could be compressed to a single *)
47# artfct # now a class
48# magic1 # Not even being considered yet
49# attacks, enemies # Attacks will be a def fn, and enemies has become the Npc class
50# setup # Performed through callable class and function methods
51# playgame # Main / Win Loop
52#
53# Begin Python 3.6 version of the Barloova program
54#
55seed = 12 # Global variable for random number generator
56class Entity: # Top character definition - instances include "p"lyr and "en"emy
57 max = 34; # Max points. Modifies by race, role, gender(m=+1st,f+1iq), age, level(4pts ea.)
58 name = "player"
59 lvl = 1
60 st = dx = iq = 4 # Primary stats modifies by race
61 moves = 2 # Modifies by race and role
62 race, role = "race", "occupation" # Create race, occupation dictionaries
63 roomnum = 1 # Is this still necessary?
64 weary = 0 # weariness affects movement, pacer, magic, healing, and more.
65 kills = 0 # Total kills in game
66 age = 17 # This is modified during player setup, ranging from 17-45
67 sex = "gender" # gender helps determine basic stats during player setup
68 scr = art = pot = kys = wt = 0 # Main game items, wt equals weight carried
69 curdmg = totdmg = 0 # Current damage and game total accumulated
70 wep, wepdam, wepcon, wepuses = "weapntype", "weapndamage", "Weapncondition", "Number of uses"
71 arm, armdam, armcon, armuses = "armrtype", "armrdamage", "armrcondition", "Number of hits"
72
73 def __init__(self, name): # Initialize the class
74 self.name = name # Set up the class here, then call it dynamically
75
76
77class Npc(Entity): # Nonplaying characters are a subclass of the entity class
78 count = 0 # npcs have to be counted and named, plyr does not.
79 names = []
80
81 def __init__(self, name): # Allows for multiple NPCs in an encounter
82 self.number = Npc.count # Should be set to the number of npcs to create
83 self.name = name # Set up the class here, then call it dynamically
84 Npc.count += 1 # I wonder if the whole class should be dynamic?
85 Npc.names.append(name)
86 # This will be random NPC encounter generation. Use and discard as needed
87 l=[]
88 # l.append(Npc("en1")) # This should be part of a -for- or -while- loop
89 # l.append(Npc("en2")) #etc
90
91class Items: # Parent container for all "things"
92 # Children include potions, weapons, armor, artifacts, etc)
93 # Begin global item initialization
94 itemnm = "name" # This is redundant as a general name. Make it a proper name? 'The potion <arghsplat>'
95 itmcat = ("weapon", "armor", "artifact", "scroll", "potion", "other") # This is for fast comparisons
96 useon = ("plyr", "npc", "none", "puzzle", "unknown") # In what ways can the item be used?
97 desc = "item description" # A text string. Could be used to indicate approximate condition
98 dxmin = iqmin = stmin = "0" # Minimum stats required to use this item
99 itemwt = '.1' # Item weight. Not yet used. It exists as a future marker
100 numuse = '1' # How many times can this item be used? -1 is infinite
101 is_ranged = False # Can this item be thrown?
102 def __init__(self, name): # Enable instances of Items
103 self.name = name
104 # End global item initialization
105
106
107# Child classes outdent to the top class level. They ARE new classes, with inheritance
108class Wpn(Items):
109 def __init__(self, wepname, type, wepdmg, useleft, wepcon, spcl): # Enable instances of Items
110 self.wepname = name # name = 'weapon name'
111 self.type = 'weapon' # This is how the inventory is sorted by item type
112 # Impale, Slice, Chop, Range (add weptype???)
113 self.wepdmg = '2' # default damage. This number is always modified at use time
114 self.useleft = '-1' # -1 is infinite
115 self.wepcon = '100' # condition can be modified on "found" weapons. if useleft != -1: wepcon = wepcon-1
116 self.spcl = set('none') #arm cursed/enchanted/special-traits
117
118class arm(Items):
119 def __init__(self, armname, type, armdmg, useleft, armcon, spcl): # Enable instances of Items
120 self.armname = name # name = 'armor name'
121 self.type = 'armor'
122 self.armdmg = '2' # default protection. This number will change with armor condition
123 self.useleft = '0' # Applies to magic and special items
124 self.armcon = '100' # condition can be modified on "found" weapons. if useleft != -1: armcon = armcon-1
125 self.spcl = set('none') # cursed/enchanted/special-traits
126
127class Potn(Items):
128 pass
129
130class Scrl(Items):
131 pass
132class Art(Items):
133 pass
134class Othr(Items): # Includes things like food, unknown, or special items
135 pass
136
137
138def rnd(): # Simple random number generator. Seed variable should be global
139 seed = random.randint(1, seed+1)