Пример #1
0
 def on_release(self, pile, auto=False):
     Logger.debug("Cards: on_release %s %d auto=%s" % (pile.type, pile.index, auto))
     top = pile.top()
     if top.cards() == 0 or top.top_card() is None:
         return False
     # Logger.debug("Cards: %d cards released top=%s bot=%s" %
     #             (top.cards(), top.top_card(), top.bottom_card()))
     # build on foundation or tableau?
     if auto:
         for dest in self.foundation():
             if self.try_move(pile, dest, top.cards(), collide=False):
                 return top
     else:
         for dest in self.foundation() + self.tableau() + self.waste():
             if self.try_move(pile, dest, top.cards(), collide=True):
                 # add self.turn condition
                 if dest.type == "waste" and dest.index == 1 and self.turn:
                     rank = top.images[0].card.rank
                     suit = top.images[0].card.suit
                     suits = {
                         "c": "Clubs",
                         "h": "Hearts",
                         "s": "Spades",
                         "d": "Diamonds",
                     }
                     suit = suits[suit]
                     Backend.get_instance().write.put(
                         "done:" + str(rank) + " " + suit
                     )
                     self.turn = False
                     self.cards = 0
                 return top
     Logger.debug("Cards: move back")
     pile.move_cards_back()
     return None
Пример #2
0
    def test_3_backend_down(self):

        # Stop and restart backend ...
        print ("")
        print ("stop backend")
        self.p.kill()

        with assert_raises(BackendException) as cm:
            connection = self.backend.login("admin", "admin")
        ex = cm.exception
        print ex
        assert_true(ex.code == 1000)

        print ("")
        print ("start backend")
        # cls.p = subprocess.Popen(['uwsgi', '-w', 'applications_backend:app', '--socket', '0.0.0.0:5000', '--protocol=http', '--enable-threads'])
        FNULL = open(os.devnull, 'w')
        self.p = subprocess.Popen(['applications_backend', '--database', 'test_applications_backend', '--hostname', '127.0.0.1', '--port', '5000'])
        time.sleep(1)
        self.backend = Backend('http://127.0.0.1:5000')

        # Login is now possible because backend recreated super admin user
        assert self.backend.login("admin", "admin")
        assert self.backend.token

        print ("stop backend")
        self.p.kill()
Пример #3
0
    def test_2_refused_connection_without_user(self):
        # Login and delete defined contacts ...
        self.backend.login("admin", "admin")
        self.backend.delete("user", {})

        # No login possible ...
        assert not self.backend.login("admin", "admin")

        # Stop and restart backend ...
        print ("")
        print ("stop backend")
        self.p.kill()
        print ("")
        print ("start backend")
        # cls.p = subprocess.Popen(['uwsgi', '-w', 'applications_backend:app', '--socket', '0.0.0.0:5000', '--protocol=http', '--enable-threads'])
        FNULL = open(os.devnull, 'w')
        self.p = subprocess.Popen(['applications_backend', '--database', 'test_applications_backend', '--hostname', '127.0.0.1', '--port', '5000'])
        time.sleep(1)
        self.backend = Backend('http://127.0.0.1:5000')

        # Login is now possible because backend recreated super admin user
        assert self.backend.login("admin", "admin")
        print "Super admin is now defined in backend ..."
        assert self.backend.token

        print ("stop backend")
        self.p.kill()
Пример #4
0
    def __init__(self):
        super().__init__()

        # Sprite list with all the cards, no matter what pile they are in.
        self.card_list = None

        arcade.set_background_color(arcade.color.AMAZON)

        # List of cards we are dragging with the mouse
        self.held_cards = None

        # Original location of cards we are dragging with the mouse in case
        # they have to go back.
        self.held_cards_original_position = None

        # Sprite list with all the mats tha cards lay on.
        self.pile_mat_list = None

        # Create a list of lists, each holds a pile of cards.
        self.piles = None

        self.natural_set = False
        self.jocker = None

        self.backend = Backend.get_instance()
        self.id = self.backend.id
        self.turn = False
        self.deck = 0
Пример #5
0
def main():
    """ Main method """
    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
    menu_view = MenuView()
    window.show_view(menu_view)
    arcade.run()
    backend = Backend.get_instance()
    backend.end()
Пример #6
0
 def check_button(obj):
     if sm.buttonText == "Join":
         self.backend = Backend.get_instance()
         self.backend.host = "http://" + sm.txt.text
         try:
             self.id = self.backend.join()
         except Exception as e:
             if isinstance(e, ErrorResponse):
                 text = str(e)
             else:
                 text = "Invalid IP Address"
             self.error_popup(text)
     if sm.buttonText == "Start" and self.id is not None:
         self.root.remove_widget(sm)
         try:
             self.new_game()
         except Exception as e:
             self.start_menu()
             self.error_popup(str(e))
Пример #7
0
    def do_move(self, move, reverse=False, replay=False):
        orig, dest = self.game.do_move(move, reverse)
        # user callback
        if not replay:
            self.game.on_moved(move)

    # callbacks to allow android save and resume
    def on_pause(self):
        return True

    def on_resume(self):
        pass

    def framerate(self):
        return 1.0 / self.config.getfloat("settings", "fps")


# defined in kv file


class AppPopup(Popup):
    pass


if __name__ == "__main__":
    try:
        Solitaire().run()
    finally:
        Backend.get_instance().end()
Пример #8
0
 def get(self):
     if self.turn and self.piles["waste"][1].size(
     ) == 1 and self.cards == 0:
         Backend.get_instance().write.put("get")
         self.cards += 1
Пример #9
0
class Test_0_LoginCreation(unittest2.TestCase):

    @classmethod
    def setUpClass(cls):
        print ("")
        print ("start backend")
        # cls.p = subprocess.Popen(['uwsgi', '-w', 'applications_backend:app', '--socket', '0.0.0.0:5000', '--protocol=http', '--enable-threads'])
        FNULL = open(os.devnull, 'w')
        cls.p = subprocess.Popen(['applications_backend', '--database', 'test_applications_backend', '--hostname', '127.0.0.1', '--port', '5000'])
        time.sleep(1)
        cls.backend = Backend('http://127.0.0.1:5000')

    @classmethod
    def tearDownClass(cls):
        print ("")
        print ("stop backend")
        cls.p.kill()

    def test_1_refused_connection_credentials(self):
        print 'test refused connection with username/password'

        with assert_raises(BackendException) as cm:
            connection = self.backend.login(None, None)
        ex = cm.exception
        print ex
        assert_true(ex.code == 1001)
        assert_true(ex.message == "Missing mandatory parameters")

        with assert_raises(BackendException) as cm:
            connection = self.backend.login('admin', None)
        ex = cm.exception
        print ex
        assert_true(ex.code == 1001)
        assert_true(ex.message == "Missing mandatory parameters")

        with assert_raises(BackendException) as cm:
            connection = self.backend.login(None, 'bad_password')
        ex = cm.exception
        print ex
        assert_true(ex.code == 1001)
        assert_true(ex.message == "Missing mandatory parameters")

        connection = self.backend.login('admin', 'bad_password')
        assert not self.backend.authenticated

        connection = self.backend.login('admin', 'admin')
        assert self.backend.authenticated
        assert self.backend.token

    def test_2_refused_connection_without_user(self):
        # Login and delete defined contacts ...
        self.backend.login("admin", "admin")
        self.backend.delete("user", {})

        # No login possible ...
        assert not self.backend.login("admin", "admin")

        # Stop and restart backend ...
        print ("")
        print ("stop backend")
        self.p.kill()
        print ("")
        print ("start backend")
        # cls.p = subprocess.Popen(['uwsgi', '-w', 'applications_backend:app', '--socket', '0.0.0.0:5000', '--protocol=http', '--enable-threads'])
        FNULL = open(os.devnull, 'w')
        self.p = subprocess.Popen(['applications_backend', '--database', 'test_applications_backend', '--hostname', '127.0.0.1', '--port', '5000'])
        time.sleep(1)
        self.backend = Backend('http://127.0.0.1:5000')

        # Login is now possible because backend recreated super admin user
        assert self.backend.login("admin", "admin")
        print "Super admin is now defined in backend ..."
        assert self.backend.token

        print ("stop backend")
        self.p.kill()

    def test_3_backend_down(self):

        # Stop and restart backend ...
        print ("")
        print ("stop backend")
        self.p.kill()

        with assert_raises(BackendException) as cm:
            connection = self.backend.login("admin", "admin")
        ex = cm.exception
        print ex
        assert_true(ex.code == 1000)

        print ("")
        print ("start backend")
        # cls.p = subprocess.Popen(['uwsgi', '-w', 'applications_backend:app', '--socket', '0.0.0.0:5000', '--protocol=http', '--enable-threads'])
        FNULL = open(os.devnull, 'w')
        self.p = subprocess.Popen(['applications_backend', '--database', 'test_applications_backend', '--hostname', '127.0.0.1', '--port', '5000'])
        time.sleep(1)
        self.backend = Backend('http://127.0.0.1:5000')

        # Login is now possible because backend recreated super admin user
        assert self.backend.login("admin", "admin")
        assert self.backend.token

        print ("stop backend")
        self.p.kill()
Пример #10
0
 def on_show(self):
     """ Called when switching to this view"""
     arcade.set_background_color(arcade.color.WHITE)
     self.id = Backend.get_instance().join()