-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
160 lines (129 loc) · 10.4 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Pithon
import kivy, sys, random
from kivy.app import App
from kivy.config import Config
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.screenmanager import SlideTransition
from kivy.storage.jsonstore import JsonStore
from jnius import cast, autoclass
from kivy.utils import platform
reload(sys)
sys.setdefaultencoding("utf-8")
Config.set("graphics", "width", "326")
Config.set("graphics", "height", "518")
def sinsert(string, place, stuff):
string = list(string)
string.insert(place, stuff)
return "".join(string)
def addtosequence(sequence, pi, score, group, shift):
if score % group == shift:
sequence += " "
if len(sequence) > (9 + group):
sequence = u"…" + sequence[2 + (score % group == shift):]
number = pi[score+1]
sequence += number
return sequence
def removecolour(string):
string = string.replace("[/color]", "")
while "[color" in string:
string = string[:string.find("[color")] + string[string.find("color") + 14:]
return string
bad = ["Maybe next time!", "Getting there!", "Uh oh!", "Keep it up!", "You can do it!", "Not bad!", "You'll get there!"]
good = ["Nice!", "Well done!", "Killin' it!", "Awesome!", "Very good!", "Fantastic!", "Hell yeah!", "Stupendous!", "Amazing!", "Wonderful!", "Glorious!"]
numbers = {}
numbers["pi"] = "3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485"
numbers["tau"] = "6.283185307179586476925286766559005768394338798750211641949889184615632812572417997256069650684234135964296173026564613294187689219101164463450718816256962234900568205403877042211119289245897909860763928857621951 33186689225695129646757356633054240381829129713384692069722090865329642678721452049828254744917401321263117634976304184192565850818343072873578518072002266106109764093304276829390388302321886611454073151918390618437223476386522358621023709614892475992549913470377150544978245587636602389825966734672488131328617204278989279044947438140435972188740554107843435258635350476934963693533881026400113625429052712165557154268551557921834727435744293688180244990686029309917074210158455937851784708403991222425804392172806883631962725954954261992103741442269999999674595609990211946346563219263719004891891069381660528504461650668937007052386237634202000627 567750577317506641676284123435533829460719650698085751093746231912572776470757518750391556371556106434245361322600385575322239181843284039787619"
numbers["e"] = "2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746639193200305992181741359662904357290033429526059563073813232862794349076323382988075319525101901157383418793070215408914993488416750924476146066808226480016847741185374234544243710753907774499206955170276183860626133138458300075204493382656029760673711320070932870912744374704723069697720931014169283681902551510865746377211125238978442505695369677078544996996794686445490598793163688923009879312773617821542499922957635148220826989519366803318252886939849646510582093923982948879332036250944311730123819706841614039701983767932068328237646480429531180232878250981945581530175671736133206981125099618188159304169035159888851934580727386673858942287922849989208680582574927961048419844436346324496848756023362482704197862320900216099023530436994184914631409343173814364054625315209618369088870701676839642437814059271456354906130310720851038375051011574770417189861068739696552126715468895703503540212340784981933432106"
numbers["phi"] = "1.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748475408807538689175212663386222353693179318006076672635443338908659593958290563832266131992829026788067520876689250171169620703222104321626954862629631361443814975870122034080588795445474924618569536486444924104432077134494704956584678850987433944221254487706647809158846074998871240076521705751797883416625624940758906970400028121042762177111777805315317141011704666599146697987317613560067087480710131795236894275219484353056783002287856997829778347845878228911097625003026961561700250464338243776486102838312683303724292675263116533924731671112115881863851331620384005222165791286675294654906811317159934323597349498509040947621322298101726107059611645629909816290555208524790352406020172799747175342777592778625619432082750513121815628551222480939471234145170223735805772786160086883829523045926478780178899219902707769038953219681986151437803149974110692608867429622675756052317277752035361393621076738937645560606059"
numbers["sqrt(2)"] = "1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157273501384623091229702492483605585073721264412149709993583141322266592750559275579995050115278206057147010955997160597027453459686201472851741864088919860955232923048430871432145083976260362799525140798968725339654633180882964062061525835239505474575028775996172983557522033753185701135437460340849884716038689997069900481503054402779031645424782306849293691862158057846311159666871301301561856898723723528850926486124949771542183342042856860601468247207714358548741556570696776537202264854470158588016207584749226572260020855844665214583988939443709265918003113882464681570826301005948587040031864803421948972782906410450726368813137398552561173220402450912277002269411275736272804957381089675040183698683684507257993647290607629969413804756548237289971803268024744206292691248590521810044598421505911202494413417285314781058036033710773091828693147101711116839165817268894197587165821521282295184884720896946338628915628827"
store = JsonStore("pithon.json")
if not store.exists("pithon"):
store.put("highscore", highscore = {"pi": 0, "tau": 0, "e": 0, "phi": 0, "sqrt(2)": 0})
store.put("pithon", inverted = False, group = 3, shift = 0, number = "pi")
class MainLayout(BoxLayout):
def keypadpress(self, number):
#self.ids["loginmanager"].current = "main"
store = JsonStore("pithon.json")
group = store.get("pithon")["group"]
shift = store.get("pithon")["shift"]
numbah = store.get("pithon")["number"]
pi = numbers[numbah]
highscore = store.get("highscore")["highscore"]
if group == 0:
group, shift = 3, 4
actualpi = self.ids["actualpi"]
score = int(self.ids["score"].text)
text = removecolour(actualpi.text)
length = len(text)
if number == pi[score+1]:
if score == 999:
self.ids["other"].transition = SlideTransition()
self.ids["other"].current = "ripscreen"
self.ids["message"].text = "You beat {}!".format(numbah)
highscore[numbah] = score
store.put("highscore", highscore = highscore)
else:
text = addtosequence(text, pi, score, group, shift)
text = sinsert(text, -1, "[color=#8BC34A]") + "[/color]"
actualpi.text = text
self.ids["score"].text = str(score + 1)
else:
if score > highscore[numbah]:
self.ids["message"].text = "New high score!"
highscore[numbah] = score
store.put("highscore", highscore = highscore)
elif score < 12:
self.ids["message"].text = random.choice(bad)
else:
self.ids["message"].text = random.choice(good)
self.ids["other"].transition = SlideTransition()
self.ids["other"].current = "ripscreen"
text = removecolour(actualpi.text)
for i in range(group):
text = addtosequence(text, pi, score + i, group, shift)
text = sinsert(text, -group - 1 + (shift == 4), "[color=#FF5252]")
actualpi.text = text
def whatsthehighscore(self):
store = JsonStore("pithon.json")
number = store.get("pithon")["number"]
highscore = store.get("highscore")["highscore"][number]
return highscore
def whatsup(self):
store = JsonStore("pithon.json")
inverted = store.get("pithon")["inverted"]
return inverted
def whatsthehaps(self):
store = JsonStore("pithon.json")
begin = numbers[store.get("pithon")["number"]][:4]
return begin
def getsettings(self):
store = JsonStore("pithon.json")
return [store.get("pithon")["inverted"], store.get("pithon")["group"], store.get("pithon")["shift"], store.get("pithon")["number"]]
def updatesettings(self, i, g, s, n):
store = JsonStore("pithon.json")
store.put("pithon", inverted = i, group = g, shift = s, number = n)
def openshare(self, score):
PythonActivity = autoclass("org.renpy.android.PythonActivity")
String = autoclass("java.lang.String")
Intent = autoclass("android.content.Intent")
intent = Intent()
intent.setType("text/plain")
store = JsonStore("pithon.json")
pi = store.get("pithon")["number"]
intent.putExtra(Intent.EXTRA_SUBJECT, String("Pithon"))
intent.putExtra(Intent.EXTRA_TEXT, String("I can remember {} places of {} using #pithon! https://play.google.com/store/apps/details?id=org.andriapps.pithon".format(score, pi).replace("sqrt(2)", "√2")))
intent.setAction(Intent.ACTION_SEND)
currentActivity = cast("android.app.Activity", PythonActivity.mActivity)
currentActivity.startActivity(intent)
class MyApp(App):
def on_pause(self):
return True
def on_resume(self):
pass
def build(self):
return MainLayout()
if __name__ == "__main__":
MyApp().run()