Solitaire Creator

A solitaire Android app with the ability to create and share your own games

Written by Neil French with the support of Christian Eckhardt

Introduction

As a lover of games of solitaire, I have tried many different solitaire apps over the years. Many of them offered great features, but none of them contained all of the games I liked. In this project, I tasked myself with making a solitaire app that not only was fun and easy to play, but also could be infinitely expanded by its users. The game features

  • 19 of the most popular solitaire games pre-made
  • The ability to create, name, and share your own solitaire game with the rest of the community
  • Local and global highscores for every game (including games you create yourself)
  • Many personalization settings to customize your solitaire experience, such as deck images and background colors

The App Itself

At the heart of the app lies the game engine. In designing and writing my engine, I focused on giving the player a responsive drag-and-drop sandbox to play their games in. All animations were done using built in Android translations. An example of a simple animation method can be seen below.

					
    public void moveCard(final Card card, final float pX, final float pY) {
        final CustomImageView view = card.view;
        int distance = (int) Math.sqrt(Math.pow(pX - view.getX(), 2) + Math.pow(pY - view.getY(), 2));

        TranslateAnimation animation = new TranslateAnimation(0, pX - view.getX(), 0, pY - view.getY());

        try {
            animation.setDuration((long) (distance * 100 / Card.width / speedFactor));
        } catch (ArithmeticException e) {
            animation.setDuration(100);
            Log.e("Animate moveCard()", e.toString());
        }

        animation.setFillEnabled(true);

        view.setDestination(pX, pY);
        view.startAnimation(animation);
    }                        
					
				

The other major component of the app was the database implementation. I used Firebase as my database backend for its simplicity and scalability. My Firebase database holds game information scores and rulesets (for user-created games). An example of how I interact with Firebase to upload my user-built games follows.

					
    public void postToFirebase(String gameName, String gameDesc) {
        GameInformation g = new GameInformation(gameName, gameDesc);

        FirebaseDatabase db = FirebaseDatabase.getInstance();

        DatabaseReference gameRef = db.getReference("games").child(g.getName());

        gameRef.setValue(g);

        double parentWidth = gameLayout.getMeasuredWidth();
        double parentHeight = gameLayout.getMeasuredHeight();
        
        DatabaseReference viewPositions = gameRef.child("views");
        for (int i = 0; i < gameLayout.getChildCount(); i++) {
            View v = gameLayout.getChildAt(i);

            if (v instanceof ImageView && v.getId() != R.id.builderHideMenu) {
                ImageView iv = (ImageView) v;

                int imgId = Integer.parseInt(iv.getContentDescription().toString());

                double percentX = iv.getX() / parentWidth;
                double percentY = iv.getY() / parentHeight;
                
                CustomView c = new CustomView(imgId, percentX, percentY);
                viewPositions.push().setValue(c);
            }
        }
        finish();
    }                     
					
				

With the combination of these two elements, it should be easy for users to create, share, and play their own unique games.

Credits and Download

This game would not have been possible without the work of these talented individuals

The game can be dowloaded here. To play the game, load it into Android Studio, build a Firebase DB key, build the game, and target it at an Android device.