Mountain Kingdom - a chat real time two player, two device game using the CloudDB and a Canvas

Mountain Kingdom - a chat real time two player, two device game using the CloudDB and a Canvas

icon
Trolls live in mountainous terrain. The trolls are part of a mountain kingdom. Travel between the lands is difficult.

Trolls are suspicious folk. They avoid one another. When two trolls get too close together, magical things happen.

The troll caverns are famous. There are few mine heads (mine entrances).
mine The caverns, under the mountains provide quick movement between and within the Troll hjem lands. Use a mine to avoid trecking the fjords, mountains and valleys. Traveling using interconnected caverns is unpredictable. Visit the mine head for a thrilling ride.

Visit as many troll lands as you can before your opponent visits all. Visit six lands, you win.
Avoid contact with your opponent or intentionally seek him/her out and take the risk.

GAME SCREENS

![BlueWins|281x500] on a Tablet (splash screen and game play) .

on a small cell phone. Blue Wins!

The app is dependent on the MIT CloudDB , on your Internet connect or network connection speed, server activity and reliability of your device screen in recognizing a screen touch.

The button 'joystick' allows you to move your Troll left, right, up and down. Hold the joystick central Button for a long press to change which troll controls by the active device. Opponents should decide before hand as to which troll they control. Honesty is assumed (but can it be relied upon)? Or, you can code a way to do this automatically.

It is not possible to program a lightning fast game using this technology; substitute strategy and guile for speed.

Can there be more than two players? Certainly, when you provide additional code. The game might not play as fast. Certainly try. Modify the code to suit.

REQUIREMENTS
Two Android devices, each loaded with the identical apk; a network or WIFI connection, a stable CloudDB server. Use your own Redis server for best results; the MIT default server works quite well except when it is experiencing heavy usage. If you develop a game for commercial purposes, please use your own Redis server. The default CloudDB server is for testing and for occasional personal use and experimentation.

The Mountain_King was tested on an Android 4.2.2 cell phone and an Android 8.1 Tablet.

TUTORIAL
Is this a tutorial for beginners? Oh, no, it is a lot of working code with minimal documentation. The Block code certainly can be navigated by an advanced developer and possibly modified by a beginner. It rained today and I could not work outside. This app is several hours of coding. An appropriate tutorial would possibly require several days of work and I would rather code.

For an explanation about how parts of the app work, please reference the following:

Issues involving different Canvas dimensions (pixel H x W) are avoided. Set the Canvas background to an image 350 x320 pixels.

Issues involving synchronization displaying Troll locations to display simultaneously on each device was solved by keeping coordinates for each Troll in a single item List and setting the appropriate tags when the Troll's coordinates change.

BACKGROUND MUSIC
An Android game without sounds is so boring.

The background music is from Edvard Grieg's In the Hall of the Mountain King performed by the Czech National Symphony Orchestra ( https://en.wikipedia.org/wiki/In_the_Hall_of_the_Mountain_King ). The sound clip should not be used for commercial purposes.

ISSUES
When one device goes to sleep, the synchronization gets off. Just move a player on the sleepy device to reestablish synchronization. Ordinarily this will not be a problem as both players will be active.

Occasionally, one of the movement Buttons will go 'stale'. A control button will refuse to respond for a second or two. I don't have an explanation for this. It might be a CloudDB problem with server usage or a device hardware/memory issue or an issue with the touch screen on the device.

WHAT TO DO NEXT?

  • Add more trolls (players)
  • Add more mine heads
  • larger Canvas for play on two Tablets
  • use your own Canvas background. It must contain areas of solid colors.
  • specific coordinates for individual mine heads
  • sprites instead of balls?
  • code for FirebaseDB (just swap out the comparable CloudDB components)
  • refactor (simplify/improve) the code. Original code almost always can be made more efficient.
  • go outside and play
  • change the app's response when Trolls meet. Perhaps add conversation dialog using the Notifier.
  • leaderboard
  • find gold at random locations on the Canvas and implement multiple ways of accumulating points.
  • a splash screen describing the game
  • build an entirely different game based on what you can learn from this app's coding
  • or you could load the aia Mountain_Kingdom.aia (1.5 MB) , create and share the apk and play the game!

Have fun.

Regards,
SteveJG

9 Likes

good morning everyone, I ask for help from anyone who can help me.
in this game I would like to change the background but I can't understand how to then carry out the controls.
in particular I don't understand the following blocks .....
what are the numbers for ???
thanks

image

SIMPLE Mountain Kingdom TUTORIAL :wink:

The numbers are the color codes used in the colored background map areas. You can find the the color number of an area in the Canvas using the GetPixelColor(x,y) Block to capture the color of the given pixel . Use a touched(x,y,touchedAnySprite) Block with the GetPixelColor Block and a Label. Add the Blocks; when the user touches the canvas and then immediately lifts his or her finger the touch will provide the color code using the blocks below

Touch each area on the Canvas background and you can determine that
Pink is -20791
Light blue is -6694422
Purple is -60759966
Blue is -16735512
Orange is -32985
Grey is -3947581


This image shows what happens when the Pink map area is touched.

The colors are used so that the app can determine which area of the map a player is currently in.

The Places is a List of Pairs using the color code for various regions of the background color 'map' in the game (color code/name I assigned the map region in this game).

The availableExcursionDestinations is a simple list of the 'map's' color codes.

I am glad you apparently like the game and aia I provided. Have fun. :grinning:

@SteveJG
thank you for the answer, it was really very helpful.
of course I like it, it's very interesting.
thanks

1 Like