Hi guys, I'm having issues. I've been learning programming on and off for years with the goal of making VERY simple games on very simple GUIs. Simple as in text readouts to bland Tkinter buttons. I'm really not looking to be some professional programmer, I just want to make simple retro style turn based games for myself.
However I keep having Issues, I feel as if I am yet again doing things the incredibly slow way and manually writing like 5 lines of code to get 1 button to work. I also have been having issues making classes readout into labels, I think the classes i've set up are faulty or im using them wrong, they never readout on the labels. But this is besides the point, I'd have to code 3 or 4 times what I currently have just to have the storage of chosen weapons pre game. It feels wrong to me.
one of my current projects is this 'Terrorist simulator'. It's mostly a joke program to help me learn, the concept being you are a group of terrorists taking a house, you can perform several actions and negotiate with the SWAT outside with them eventually deciding to assault the building and kill you all(unless you have escaped before then!)
The design is fine, I know what screens I need, what logic I need and where it goes. But I feel my coding is woefully inefficient and poorly designed. I have copious notes on such things.
Does anyone have any pointers on how I could improve my coding? I'm coding in python 2.7.
I've read plenty of stuff on making games but theyre mostly platformers using pygame or fps or whatnot, I just want to make pretty much rpg/strategy games with as simple a GUI as I can possibly do.
*The buttonmake and buttonkill etc are dead, I'm not using them. I don't think it works to make create a button through a function this way, I had issues with it.
"""Swat game
make items dictionary
fix two menus open at same time bug
"""
import random
from Tkinter import *
#guns
class guns():
glockdmg=1
galildmg=3
ak47dmg=4
class stats():
#skills
Bravery=1
Charisma=1
Respect=1
Negotiating=1
Pistols=1
Rifles=1
Submachineguns=1
Knives=1
Explosives=1
Hacking=1
Lockpicking=1
class attr():
#attributes
Mood= "Nostalgic"
Weapon="Bad breath"
hp=1
class terrorist(guns,stats,attr):
gun=""
moral=5
class player(terrorist):
php=1
#ASSIGNS CURRENT PLAYER TO THIS
current_player=""
jeff = player
jeff.gun="glock"
jeff.hp=2
print jeff.php
#die roll
def droll(d):
roll = random.randint(1,(d-1))
return roll
#initrandomisation
def initrand(terrorist):
#random stats
for t in terrorist:
t1s[t] = droll(10)
#randomise stats
#window
root = Tk()
root.title("gui")
root.geometry("360x320")
app = Frame(root)
app.grid()
#IMAGES
#title
imgPath = r"tpic.gif"
photo = PhotoImage(file = imgPath)
tpic = Label(app,image = photo)
tpic.image = photo # keep a reference!
#interface quicks
def buttonmake(name,desc,order):
name = Button(app, text = desc, command = order )
name.grid()
def buttonkill(name):
name.grid_forget()
def labelmake(name,color,row,column):
name = Label(app, bg=color,height=2,width=5)
name.grid(row=row, column=column)
#print skills BROKEN ONLY SHOWS 1
#def readout(terrorist,element):
#opening/closing stats box
def peekd():
statsl.grid(row=1,columnspan=4, pady = 50)
statc.grid(row=2, columnspan=4)
def peeku():
statsl.grid_forget()
statc.grid_forget()
#open/close negotiation window
def negpeekd():
moodl.grid(row=2,column=1, sticky=W, columnspan=2)
h_trade.grid(row=3,column=1,sticky=W,columnspan=2)
negc.grid(row=4,column=1,sticky=W)
chosentitle.grid(row=2,column=3, columnspan =2)
n1.grid(row=3,column=3,columnspan =2)
convo.grid(row=2, column=2,rowspan=4)
def negpeeku():
moodl.grid_forget()
h_trade.grid_forget()
negc.grid_forget()
n1.grid_forget()
chosenl.grid_forget()
chosentitle.grid_forget()
convo.grid_forget()
#popup
def newwindow():
root = Tk()
root.title("test")
root.geometry("200x400")
app = Frame(root)
app.grid()
selected = StringVar()
def negsel():
sel = "You have picked " + str(selected.get())
chosenl.config(text = sel)
chosenl.grid(row=4,column=3,columnspan =2)
def start():
events.config(text=tintro)
tpic.grid_forget()
sbutton.config(text="Quit")
#moral to be implimented
mood = "Calm"
group= ""
evil1=""
evil2=""
tintro = "You are a terrorist for the " + str(group) + "and you are going to make a statement to the westerners for their " + str(evil1) + "and " + str(evil2) + "\nYou are outside the house of the Kardashian's, a wealthy family to make an example of.\n\nWhat do you do now?"
#menu start button
sbutton = Button(app, text = "Start",activebackground = "red", bd = 4, cursor = "dot", command = start, bg = "red")
sbutton.grid(row=0, column = 0,sticky=W)
#menu negotiation
neg = Button(app, text = "Negotiate",activebackground = "red", bd = 4, cursor = "dot", command = negpeekd)
neg.grid(row=0, column = 1,sticky=W)
#conversation window
convo = Message(app,text="conversation here",relief=RAISED)
#terrorist pic
tpic.grid(row=9,columnspan=10)
#event messages
events = Message(app, text = "Press start...",width="250",pady=10,relief=RAISED)
events.grid(row=10, columnspan=10)
#menu team management
tm = Button(app, text = "Team management", activebackground = "red", bd = 4, cursor = "dot")
tm.grid(row=0, column = 2,sticky=W)
#show stats
statsl = Message(app,text = "",relief=RAISED,width=150)
#Negotiation options elements
moodl = Message(app, text = "Mood: "+str(mood), relief=RAISED,justify=LEFT)
h_trade = Button(app, text = "Trade", activebackground = "red", bd = 4, cursor = "dot",justify=LEFT)
#negotiation wholist
chosentitle = Message(app, text = "Who negotiates?")
n1 = Radiobutton(app, text="Jeff", value="Jeff", variable = selected, command = negsel)
#show selection
chosenl = Message(app)
#stats window
stats = Button(app, text = "Stats", activebackground = "red", bd = 4, command = peekd,cursor = "dot", padx = 48, bg = "blue")
stats.grid(row=0, column = 3)
#close windows
statc = Button(app, text = "close", activebackground = "red", bd = 4, command = peeku,cursor = "dot",bg = "red")
negc = Button(app, text = "close", activebackground = "red", bd = 4, command = negpeeku,cursor = "dot",bg = "red")
if player.php<=0:
events.config(text= "YOU DIED, NOOB!")
#init loop
root.mainloop()