Jumbled Words Game

Published on . Written by

Jumbled Words Game

Game is an interactive way of using leisure and even pass time. People love to play games irrespective of age. When doing python application development, why not build your own game to interact with your computer. Some logics and knowledge of few libraries and you can have your own game in laptop/computer desktop by programming it with python.


Skyfi Labs Projects
We would be using basically two libraries random and pygame, one for logic and other for the GUI work. At the start it may not look so good but in the later stages when you practice and improve on graphical work it would be lovely to play this game.

Read more..

SLNOTE
OUTLINE:

This is a very simple game that can be played on the GUI interface also but to make it user friendly we add the GUI window with graphics. The game would be of two players, who would turn wise get random words which have letters jumbled. 1 point for correct, 0 for incorrect or no word filling. It will continue until the players selected to stop and in the end, it declares to scores with winner name.

PREREQUISITE:

  • Knowledge of basic python language and use of libraries
  • Should have Tkinter installed in system library ( pip install Tkinter / pip3 install Tkinter )
  • Have a minimum touch with classes concepts (OOPs)

SLLATEST
REQUIREMENTS:

Hardware:

  • One Laptop or Desktop with any OS (Linux/Windows/iOS)
Software/Technology:

  • A Browser ( Chrome/Firefox/Opera/Safari/IE) to run the program. I prefer chrome or firefox as it provides a console to see behind the work of program like like the IDE of python ( to use just right-click on mouse and select ‘Inspect’ or Ctrl+Shift+I to open it and switch to console tag in this window)
  • A text editor ( Visual Studio(VS) Code/Atom/Sublime/Notepad ) to code. I prefer VS code as it completes the code from its libraries and themes are attractive.
  • Internet Connection
IMPLEMENTATION:

We will be doing it in parts and combine in one to make it work, before that in the first two lines import random, import pygame:-

LOGIC ( can be used on CUI ):

this will be done in 4 steps:

1. Create a library of words for the game

  • create a list of words, with as many words you want
  • choose a random word in the following way
pick=random.choice(words)

  • return this word
2. define a function to jumble words

  • jumble the word in following way:
jumbled="".join(random.sample(word,len(word)))

  • return the jumbled word
3. function to give ending lines of game

  • your choice of presentation
  • print the winner of game (name)
  • then the scorers
  • after that a thanking note
4. define the game

  • declare two variable and take name of players
  • declare two variables for points , initially as zero
  • declare a turn variable equal to zero
  • now start a loop ( while (1) ) , 1 because we want to continue untill the players want
  • declare computer’s task to choose a word from library created
  • create a question word with the function calling
  • print this
  • now we use If-Else to create a question answer format similar to both players
  • from If we check turn = even then player 1 Else player 2 chance, but the code is same except naming
  • first print player name +“ your turn”
  • next take input from player
  • again use if else to check answer given and update the score
  • same for both players code, update value of turn by 1
  • now take input to continue = 1 or end = 0
  • check if 0 then call thanking function and break the loop
  • else continue
GUI (user friendly):

  • first we need to import the following libraries:
import tkinter as tk

import math, random 

from PIL import Image, ImageTk

from tkinter import Tk, RIGHT, BOTH, RAISED

from tkinter.ttk import Frame, Label, Button, Style

  • we initialise the tkinter first and give title in title bar:
root= tk.Tk()

root.title(“title”)

  • define configuration of screen
canvas1 = tk.Canvas(root, width = 1080, height = 800, relief = 'raised')

canvas1.pack()

  • now we need to modify the last two functions as for CUI to bring in graphics
  • we add one more function to our code for players entry so that to clear screen for the game
  • we declare a global variable for heading this page of entry now two variables for labeling of data of player name
  • two more for taking input
player1_entry = tk.Entry(root)

  • one button to call function remove these from pages after entry and call play function
  • do labeling configuration in the following way:
entry_label = tk.Label(root, text='enter players profile')

entry_label.config(font=('helvetica', 25))

canvas1.create_window(500, 50, window=entry_label)

  • positioning is of the form (x,y)
  • when you hit the button to add name delete function is called which removes these labels for upcoming labels in the following way:
player1_label.destroy()

  • now play function is called
  • rest is same all printed things are converted to Labels and displayed through the canvas
  • with respect to turning logic two delete function things previously turn wise
  • one label of question is common so to be deleted by both functions
  • now for continue, we first delete present labels then call the question for continuing
  • get the entry and rest is now thank u function is called with use of button otherwise, it is continued
The game is made and if you want you can work on pygame , the only problem is that it does not take input as no method in the library of it so you can get the library wanted on github just search “ pygame_textinput ” use this by importing the module.

You want then turn it into exe file

You can get help from my github profile:

https://github.com/vaibhavkumar-779/


SLDYK
Kit required to develop Jumbled Words Game:
Technologies you will learn by working on Jumbled Words Game:


Any Questions?