Example #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
Example #2
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
Example #3
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()
Example #4
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))
Example #5
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()
Example #6
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
Example #7
0
 def on_show(self):
     """ Called when switching to this view"""
     arcade.set_background_color(arcade.color.WHITE)
     self.id = Backend.get_instance().join()