Forum Archive

[SOLVED!] Help STILL with restart

Pythonistapro777

So, I'm almost finished with my moon count game, similar to the carnival game where you guess the the number of balls in a jar.

However I need help with the restart scene. I want it so that when I click the button it not only runs the moon scene but also picks a new random amount of moons.

Thanks in advance!

Here's the code:

#coding: utf-8
from scene import *
from random import *
import console
number=randint(1,10)
number2=randint(1,10)
if int(number) == 1:
    answer="🌚\n"*int(number2)
if int(number) == 2:
    answer="🌚🌚\n"*int(number2)
if int(number) == 3:
    answer="🌚🌚🌚\n"*int(number2)
if int(number) == 4:
    answer="🌚🌚🌚🌚\n"*int(number2)
if int(number) == 5:
    answer="🌚🌚🌚🌚🌚\n"*int(number2)
if int(number) == 6:
    answer="🌚🌚🌚🌚🌚🌚\n"*int(number2)
if int(number) == 7:
    answer="🌚🌚🌚🌚🌚🌚🌚\n"*int(number2)
if int(number) == 8:
    answer="🌚🌚🌚🌚🌚🌚🌚🌚\n"*int(number2)
if int(number) == 9:
    answer="🌚🌚🌚🌚🌚🌚🌚🌚🌚\n"*int(number2)
if int(number) == 10:
    answer="🌚🌚🌚🌚🌚🌚🌚🌚🌚🌚\n"*int(number2)

anz=number*number2
moons=str(answer)

from scene import *
import time
import sys
class Intro(Scene):
    def draw(self):
        background(0.00, 0.05, 0.20)
        s = 45 if self.size.w > 100 else 7
        text('Welcome to\nMoon Count\n\n\n', 'Futura', s, *self.bounds.center().as_tuple())
        t = 100 if self.size.w > 100 else 7
        text('\n🌚', 'Futura', t, *self.bounds.center().as_tuple())
        s = 27 if self.size.w > 100 else 7
        text('\n\n\n\n\n\n\n\n\n\n\n\nBy: Adedayo Ogunnoiki', 'Futura', s, *self.bounds.center().as_tuple())

    def touch_ended(self, touch):
        run(Help())

import motion, scene
use_motion = True

class Help(Scene):
    def draw(self):
        background(0.00, 0.05, 0.20)
        s = 33 if self.size.w > 100 else 7
        text('This is a game \nwhere you are\nshown a random\namount of 🌚s;\nbetween 1 and 100 \nfor 1 second. \nThen you will have \n3 guesses to guess\nthe number of 🌚s\nthat were\ndisplayed.', 'Futura', s, *self.bounds.center().as_tuple())

    def touch_ended(self, touch):
        run(Moons())

import motion, scene

use_motion = True

class Moons (Scene):
    def setup(self):
        self.show_instructions = True
        self.p_size = 64 if self.size.w > 700 else 32
        self.layer = Layer(Rect(self.size.w * 0, self.size.h * 0, 900, 900))
        self.layer.background = Color(0, 0, 0)
        self.layer.animate('alpha', 0.0, duration=0.50, autoreverse=True)

    def draw(self):
        background(0, 0, 0)
        s = 32 if self.size.w > 100 else 7
        text(moons, 'Futura', s, *self.bounds.center().as_tuple())
        self.layer.update(self.dt)
        self.layer.draw()

    def touch_ended(self, touch):
        run(restart())


class restart(Scene):
    def setup(self):
        self.button = Button(Rect(self.size.w/2-80, self.size.h/2-80, 150, 150), 'Restart')
        self.button.background = Color(0,0.05,0.2)
        self.button.stroke = Color(0,0.05,0.2)
        self.button.image = 'White_Square'
        self.button.action = self.add_clicks
        self.add_layer(self.button)

    def add_clicks( sender):
        run(Moons())

    def draw(self):
        background(0,0.05,0.2)
        self.button.background = Color(0,0.05,0.2)
        self.button.draw()
        s = 45 if self.size.w > 100 else 7
        tint(255,255,255)


run(Intro())
ccc

Start with...

moon_count = randint(1,10)
line_count = randint(1,10)
answer = ('🌚' * moon_count + '\n') * line_count
anz = moon_count * line_count
moons = str(answer)
Pythonistapro777

@ccc I changed it but still have the same problem.

Webmaster4o

Do it the same way as with your magic 8 ball