package Ġgame . ga ut emo . countdown game Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . SharedPreferences Ċ import Ġandroid . icu . util . Calendar Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . util . Log Ċ import Ġandroid . widget . Button Ċ import Ġandroid . widget . LinearLayout Ċ import Ġandroid . widget . TextView Ċ import Ġandroid . widget . Toast Ċ import Ġandroidx . fragment . app . FragmentManager Ċ import Ġandroidx . fragment . app . Fragment Transaction Ċ import Ġcom . google . firebase . firestore . Document Change Ċ import Ġcom . google . firebase . firestore . Document Reference Ċ import Ġcom . google . firebase . firestore . Firebase Fire store Ċ import Ġjava . util .* Ċ import Ġkotlin . random . Random Ċ Ċ class ĠMainActivity Ġ: ĠAppCompatActivity () Ġ{ ĊĠĠĠ Ġprivate Ġvar Ġname Ġ= Ġ" Random ĠHuman " ĊĠĠĠ Ġprivate Ġvar Ġuuid Ġ= Ġ" 1 2 3 " ĊĠĠĠ Ġprivate Ġval Ġgame Views Ġ= Ġmutable Map Of < String , ĠTextView >() ĊĠĠĠ Ġprivate Ġvar Ġshared Preferences : ĠSharedPreferences ? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġval Ġfire store Handler Ġ= ĠFire store Handler () ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ main ) ĊĊĠĠĠĠĠĠĠ Ġshared Preferences Ġ= Ġget SharedPreferences (" data ", ĠContext . MODE _ PRIVATE ) ĊĊĠĠĠĠĠĠĠ Ġinit Player () ĊĠĠĠĠĠĠĠ ĠfindViewById < Button >( R . id . random _ name ). setOnClickListener Ġ{ Ġchange Name ()} ĊĊĠĠĠĠĠĠĠ ĠfindViewById < Button >( R . id . create _ game ). setOnClickListener Ġ{ Ġcreate Game () Ġ} ĊĊĠĠĠĠĠĠĠ Ġinit Games Listener () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġinit Player (){ ĊĠĠĠĠĠĠĠ Ġname Ġ= Ġshared Preferences ?. getString (" username ", Ġ" Random ĠHuman ") Ġ?: Ġ" Random ĠHuman " ĊĠĠĠĠĠĠĠ ĠfindViewById < TextView >( R . id . username ). text Ġ= Ġname ĊĊĠĠĠĠĠĠĠ Ġif ( shared Preferences ?. contains (" uuid ") Ġ== Ġtrue ){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġuuid Ġ= Ġshared Preferences ?. getString (" uuid ", Ġ" 3 2 1 ") Ġ?: Ġ" 3 2 1 " ĊĠĠĠĠĠĠĠ Ġ} else { ĊĠĠĠĠĠĠĠĠĠĠĠ Ġuuid Ġ= ĠUUID . randomUUID (). toString () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġshared Preferences ?. edit ()?. putString (" uuid ", Ġuuid )?. apply () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġchange Name (){ ĊĠĠĠĠĠĠĠ Ġname Ġ= Ġpossible Names [ Random . nextInt ( possible Names . size )] ĊĠĠĠĠĠĠĠ ĠfindViewById < TextView >( R . id . username ). text Ġ= Ġname ĊĠĠĠĠĠĠĠ Ġshared Preferences ?. edit ()?. putString (" username ", Ġname )?. apply () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Game (){ ĊĠĠĠĠĠĠĠ Ġval Ġnow Ġ= ĠCalendar . getInstance () ĊĠĠĠĠĠĠĠ Ġval Ġgame Name Ġ= Ġ"$ name 's Ġgame Ġ${ now . get ( Calendar . HOUR )} :" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ"${ now . get ( Calendar . MINUTE )} :${ now . get ( Calendar . SECOND )}" ĊĠĠĠĠĠĠĠ Ġval Ġgame Ġ= ĠGameObject ( game Name , Ġuuid , Ġnow . time In Millis , Ġmutable Map Of ( Pair ( uuid , Ġname ))) ĊĠĠĠĠĠĠĠ Ġfire store Handler . save Game ( game , Ġ{ Ġgo To Lobby ( it . id , Ġtrue ) Ġ}, Ġ{ Ġtoast (" Could Ġnot Ġcreate Ġgame , Ġplease Ġtry Ġagain Ġlater ") }) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġgo To Lobby ( id : ĠString , Ġcreator : ĠBoolean ){ ĊĠĠĠĠĠĠĠ Ġsupport FragmentManager . in Transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġlob by Ġ= ĠL obby Fragment () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlob by . listen Lobby ( id , Ġcreator ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd ( android . R . id . content , Ġlob by ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġtoast ( msg : ĠString , Ġlength : ĠInt Ġ= ĠToast . LENGTH _ SHORT ){ ĊĠĠĠĠĠĠĠ ĠToast . makeText ( base Context , Ġmsg , Ġlength ). show () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġinit Games Listener (){ ĊĠĠĠĠĠĠĠ Ġval Ġadded : Ġ( String , ĠString ) Ġ-> ĠUnit Ġ= Ġ{ Ġid , Ġname Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtxt View Ġ= ĠTextView ( this ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtxt View . text Ġ= Ġname ĊĠĠĠĠĠĠĠĠĠĠĠ Ġgame Views [ id ] Ġ= Ġtxt View ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfindViewById < LinearLayout >( R . id . games ). addView ( txt View ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġremoved : Ġ( String ) Ġ-> ĠUnit Ġ= Ġ{ Ġid Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġv Ġ= Ġgame Views . remove ( id ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfindViewById < LinearLayout >( R . id . games ). remove View ( v ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġfire store Handler . listen Games ( added , Ġremoved , Ġ{ Ġtoast (" Could Ġnot Ġget Ġgames , Ġplease Ġrestart Ġthe Ġapp ") Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġbegin Game ( id : ĠString ){ ĊĠĠĠĠĠĠĠ Ġsupport FragmentManager . pop Back Stack () ĊĠĠĠĠĠĠĠ Ġsupport FragmentManager . in Transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġgame Ġ= ĠGame Fragment () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġgame . init Ref ( id , Ġuuid ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd ( android . R . id . content , Ġgame ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġinline Ġfun ĠFragment Manager . in Transaction ( func : ĠFragment Transaction . () Ġ-> ĠFragment Transaction ) Ġ{ ĊĠĠĠĠĠĠĠ Ġbegin Transaction (). addTo Back Stack ( null ). func (). commit () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject { ĊĠĠĠĠĠĠĠ Ġval Ġpossible Names Ġ= ĠarrayOf (" Aspect "," Kr aken "," B ender "," L yn ch "," Big ĠP apa "," Mad ĠDog "," B ow ser "," O ' Do yle "," B ru ise "," P sy cho "," C annon "," R anger "," C link "," Rat chet "," Co bra "," Re aper "," Col t "," R igs "," C rank "," Rip ley "," Cre ep "," Road kill "," Daemon "," R on in "," Dec ay "," R ubble "," Di ablo "," S as qu atch "," Do om "," Sc ar "," Dr ac ula "," Sh iver "," Dragon "," Sk inner "," F ender "," Sk ull ĠCr ush er "," F ester "," Slash er "," Fis he ye "," Ste el shot "," Fl ack "," Sur ge "," G argo yle "," Sy the "," Gr ave "," Trip "," Gun ner "," Tro oper "," Hash "," T week "," Has ht ag "," Ve in "," In dom in us "," Void "," I ron cl ad "," W ard on "," K iller "," W ra ith "," Kn uck les "," Zero ") ĊĠĠĠ Ġ} Ċ } Ċ