Skip to content

Repository files navigation

Scrabble Projet

A python french scrabble game made with a graphical interface and multiplayer over the internet, during my first year of bachelors as a semester project.

Playable and most stable version -> 0.5

The main purpose of this programme is to be able to play games of scrabble in solo versus AI or with friend in local or global (as long as they have a internet connection). The programme is composed in to three main script CoreScrabble which is here to bring the graphical interface to the user and the function that rule the game of scrabble. Then there is Server which provide a way to connect Client (CoreScrabble) to one another and there is AI which give the possibility to the computer to “play” the game. The others scripts File_Manager is here to make save and reading of data easier and finally Common_Function is a repertory of function that are not bound to a script but are used into the mains script.

The CoreScrabble

When CoreScrabble is launch the script initialize many variables which are going be use for different part of the programme Screen Variables are use to store data about the screen stat while Game Variables store many information like the allowed word, the grid, the pool, the hand and some screen variable that are bound to the game. Then the programme really starts by creating the window and initializing the graphical image. Then it launches the title screen which give many possibilities to user.

The Solo

When the user clicks on Solo, he can choose to create a new game, load a game or delete one. To create a game the user must enter the name of the save and his username, then the game starts by creating many element (the grid, the hand, the scoreboard) and filling the Game Variables with information. After that the actual game start, the user is able to change his hand which mean take every letters of his hand put them back into the pool and taking 7 new letters out or he can freely take the letter in his hand to place them on the grid and validate his turn if he thinks his move is correct if it is not correct, the letters he places return in his hand. If it is after many functions the letters that he places are compacted in a word with the information if it is in line or in column, which one, when the word start and when it end. Then with several others functions auxiliary words are detected by checking adjacent cell of the word, the programme verified if all of these words are valid. Then by combining this information with the grid, the total value of the move is calculated and the scoreboard is updated. Finally, the player turn is ended by rotating the turn to the new player the AI. The AI function given a certain grid and a certain hand will return a move that will be execute by the programme like changing his hand or placing a word and updating the scoreboard. When the turn rotates the programme check if the game should end because 3 turn passes with an empty pool, while there is no changes to the grid or if some have a empty hand and the pool is empty. If so, the victory screen is displayed. But during the game the user can also choose to quit which will save his game (the important variables) in the save file. So that the game can be reload later. When a game is reloaded from a save file, the variables are extracted locally in a function and their information is added to main game variables. The game starts and modified the grid and the hands to match visually.

The Multi

When a server is online the user can easily connect to it locally by clicking on join local server or by entering the server’s given by the host of the global server. Then the user is taken to a lobby where if he is the host (first player to connect to the server), he can add AI if there is not enough player to start the game. When enough players are in the lobby the host can start the game, but others players can only load the graphical interface of the game. In multiplayers the game is executing the same way as in solo but the information about the player action is send to the server to be send to the others players. And according to the information send by the server the client executes it like if it was the information send by an AI.

The Server

When the server script starts the host can chose if the server is for local or global connection. For local connection the server is immediately functional, but for global connection the host need to open the port 7564, to be able to send and receive information from the others players. Then when the game starts the server receive information treat it and send it back. The server stores the pool, the grid, the way that the turn rotates and even AI. But the host can also access the current information by type some command in the command prompt. Like /displaygrid who will display the grid of the current game or /poolsize to show how many letter there are in the pool.

The backup system

When we want to save some variable, we use the basic functions write of python. We created functions that take come argument a name of document, a name of variable and a variable (list, number, string, dictionary), in this function we transform the variable and its name in a string with a particular format which is writing in a txt document whose name is the name in the argument’s function. If it is just a number, for example we create a string like that: name of the variable + £ + string of the number. But for more complex variable, a dictionary for example, the format is a bit more complicated: we keep using ‘£’ to separate the name and the variable but we use ‘µ’ to separate the key and its value in the string and we also add ‘¤’ to separate different index. We save one variable in one line of the txt document. So, we also created function that knows how to read the format that we used to write variable. We just browse each line of the document and look for the name of the variable we want to use and just have to transform the string depending the type of the information we were searching. For example, with a dictionary, we read the string, then we split it in around ‘¤’, we split each element of the new list around ‘µ’ and to create the dictionary we browse the list of list and add to an empty dictionary a key which is the first element of the list inside the list of list and a value to this key which is the second element of the list inside the list of list and then we return the dictionary.

Credit

Davydex : Most of the code

Xerian : Backup system + help with the debugging

About

A python scrabble game made with a graphical interface, multiplayer during my first year of bachelors as a semester project.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages