Multiplayer Tic-tac-toe [C2][Web2py(Python)][AJAX][Cross-domain]

2

Index

Attached Files

The following files have been attached to this tutorial:

.capx

space-tic-tac-toe.capx

Download now 7.75 MB
.zip

web2py-files.zip

Download now 4.42 KB

Stats

6,042 visits, 12,426 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Setting up web2py

When you download the web2py_win.zip file from the website, extract it to any location you seem fit.

Download my "web2py files.zip", you'll find two files there db.py and default.py.

Go to [your extraction location]\web2py\applications\welcome\

And replace the files:

db.py in the models folder,

default.py in the controllers folder.

Launching web2py

Back in the web2py/ directory, you can make a shortcut of web2py.exe to your desktop:

.

You'll see this when you launch it:

.

Keep everything as it is, just type in a password, it doesn't have to be strong as you're on localhost "127.0.0.1".

Now if you've replaced the files in the folders mentioned before, everything is actually set up at this point.

However you can access and edit the files in the admin interface:

.

Enter your password here:

.

Select to edit the Welcome application:

.

And here are the files:

.

Now the game

You'll see all the events and variables in the .capx file, I tried to comment on everything, so it could be understood as easily as possible.

The game consists of 18 global variables and 92 events. Could possibly be optimized to work with less, but that's not the goal of this tutorial.

We have 2 space ships, 9 rocks, a field to enter your nickname and some other text fields.

When you enter the nickname and press the "Find an opponent" it sends a request with your nickname to the web2py website, where the database checks if there's an active room with a free slot and you join that one. If there are no rooms that have a free slot, you're just assigned a new room id and your personal player id for identification. Then you wait for another player to connect.

When both players are connected, one textfield displays which player has the first move and another textfield shows the active event group, if it's GP1, it's your turn, if GP2, your waiting for the other player to make his move.

If you manage to connect 3 tic/tacs into a line, the game is over, your enemy's tacs are destroyed and your plane launches an attack destroying him. The game restarts in 5 sec after.

If there's a draw, both player ships destroy each other.

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!