Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit c37da1f

Browse files
authored
Merge pull request #269 from varshachary/varsha
Flames game
2 parents e2407f8 + 34a3482 commit c37da1f

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

Basic-Scripts/flames.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
from tkinter import *
2+
# function for removing common characters with their corresponding occurrences
3+
def removeCommon(list1, list2):
4+
for i in range(len(list1)):
5+
for j in range(len(list2)):
6+
#drop the common charcter and return concatinated list with true flag
7+
if list1[i] == list2[j]:
8+
common = list1[i]
9+
list1.remove(common)
10+
list2.remove(common)
11+
# concatenation of two list elements with *
12+
# * is act as border mark here
13+
list3 = list1 + ["*"] + list2
14+
# return the concatenated list with True flag
15+
return [list3, True]
16+
#when no common characters are found
17+
list3 = list1 + ["*"] + list2
18+
return [list3, False]
19+
#convert the players name string to list
20+
def stringToListConvert(str):
21+
# converted all letters into lower case
22+
str=str.lower()
23+
# replace any space with empty string
24+
str.replace("","")
25+
# convert into list
26+
strList=list(str)
27+
return strList
28+
29+
# function for telling the relationship status
30+
def resultStatus():
31+
# take a 1st player name from Player1Field entry box
32+
p1 = Player1Field.get()
33+
# convert the players name string to list
34+
p1_list = stringToListConvert(p1)
35+
# take a 2nd player name from Player2Field entry box
36+
p2 = Player2Field.get()
37+
# convert the players name string to list
38+
p2_list = stringToListConvert(p2)
39+
# taking a flag as True initially
40+
flag = True
41+
# call removeCommon function untill common characters is found
42+
while flag:
43+
# function calling and store return value
44+
ret_list = removeCommon(p1_list, p2_list)
45+
# take out concatenated list from return list
46+
con_list = ret_list[0]
47+
# take out flag value from return list
48+
flag = ret_list[1]
49+
# find the index of "*" / border mark
50+
star_index = con_list.index("*")
51+
# all characters before * store in p1_list
52+
p1_list = con_list[: star_index]
53+
# all characters after * store in p2_list
54+
p2_list = con_list[star_index + 1:]
55+
# count total remaining characters
56+
count = len(p1_list) + len(p2_list)
57+
58+
# full form of FLAMES
59+
result = ["Friends", "Love", "Affection", "Marriage", "Enemy", "Siblings"]
60+
61+
# keep looping untill only one item is not remaining in the result list
62+
while len(result) > 1:
63+
split_index = (count % len(result) - 1)
64+
# anticlock-wise circular counting.
65+
if split_index >= 0:
66+
right = result[split_index + 1:]
67+
left = result[: split_index]
68+
result = right + left
69+
70+
else:
71+
result = result[: len(result) - 1]
72+
73+
# insert value
74+
Status_field.insert(10, result[0])
75+
76+
77+
# Function for clearing the contents of all text entry boxes
78+
def clear_all():
79+
Player1Field.delete(0, END)
80+
Player2Field.delete(0, END)
81+
Status_field.delete(0, END)
82+
83+
# set focus on the Player1Field entry box
84+
Player1Field.focus_set()
85+
86+
87+
# Driver code
88+
if __name__ == "__main__":
89+
master = Tk()
90+
# Set the background colour of GUI window
91+
master.configure(background='light blue')
92+
93+
# Set the configuration of GUI window
94+
master.geometry("350x125")
95+
96+
# set the name of tkinter GUI window
97+
master.title("Flames Game")
98+
99+
# Create a Player 1 Name: label
100+
label1 = Label(master, text="Player 1 Name: ",
101+
fg='black', bg='blue')
102+
103+
# Create a Player 2 Name: label
104+
label2 = Label(master, text="Player 2 Name: ",
105+
fg='black', bg='blue')
106+
107+
# Create a Relation Status: label
108+
label3 = Label(master, text="You both are: ",
109+
fg='black', bg='blue')
110+
111+
# placing the widgets at respective positions
112+
label1.grid(row=1, column=0, sticky="E")
113+
label2.grid(row=2, column=0, sticky="E")
114+
label3.grid(row=4, column=0, sticky="E")
115+
116+
# for filling or typing the information.
117+
Player1Field = Entry(master)
118+
Player2Field = Entry(master)
119+
Status_field = Entry(master)
120+
121+
# placing the widgets at respective positions
122+
Player1Field.grid(row=1, column=1, ipadx="50")
123+
Player2Field.grid(row=2, column=1, ipadx="50")
124+
Status_field.grid(row=4, column=1, ipadx="50")
125+
126+
127+
# Submit Button and attached to tell_status function
128+
button1 = Button(master, text="Submit", bg="red",
129+
fg="black", command=resultStatus)
130+
131+
132+
# Clear Button and attached to clear_all function
133+
button2 = Button(master, text="Clear", bg="red",
134+
fg="black", command=clear_all)
135+
136+
# placing the widgets at respective positions
137+
button1.grid(row=3, column=1)
138+
button2.grid(row=5, column=1)
139+
140+
# Start the GUI
141+
master.mainloop()

0 commit comments

Comments
 (0)