This program is to make a hangman game using GTK programming as an interface. More...
#include <string.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sqlite3.h>
Go to the source code of this file.
Defines | |
#define | BUFFER 4096 |
#define | MAX_IMAGES 8 |
Functions | |
static int | callback (void *NotUsed, int argc, char **argv, char **azColName) |
Standard callback function used to display the results sqlite3. | |
void | setup_tables () |
This function sets up the database name and table. | |
void | get_random_element (char *category) |
This function will return a random element from choosen category. | |
void | enter_callback (GtkWidget *widget, GtkWidget *entry) |
void | playername_callback (GtkWidget *widget, GtkWidget *entry) |
int | update_entryText (char ch) |
This function will update the text entry. | |
void | set_images (int wrongcount) |
This function will display and hide image depents on number of wrongcount. | |
void | update_score (int score) |
This function will display and update score from text file scorefile.txt. | |
void | win_or_loose (int res) |
This function will pop up a GAME OVER msg and YOU WON msg and change the hangman picture arcording to worgcount. | |
gint | action_button_a (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'A' are clicked. | |
gint | action_button_b (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'B' are clicked. | |
gint | action_button_c (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'C' are clicked. | |
gint | action_button_d (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'D' are clicked. | |
gint | action_button_e (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'E' are clicked. | |
gint | action_button_f (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'F' are clicked. | |
gint | action_button_g (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'G' are clicked. | |
gint | action_button_h (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'H' are clicked. | |
gint | action_button_i (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'I' are clicked. | |
gint | action_button_j (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'J' are clicked. | |
gint | action_button_k (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'K' are clicked. | |
gint | action_button_l (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'L' are clicked. | |
gint | action_button_m (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'M' are clicked. | |
gint | action_button_n (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'N' are clicked. | |
gint | action_button_o (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'O' are clicked. | |
gint | action_button_p (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'P' are clicked. | |
gint | action_button_q (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'Q' are clicked. | |
gint | action_button_r (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'R' are clicked. | |
gint | action_button_s (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'S' are clicked. | |
gint | action_button_t (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'T' are clicked. | |
gint | action_button_u (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'U' are clicked. | |
gint | action_button_v (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'V' are clicked. | |
gint | action_button_w (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'W' are clicked. | |
gint | action_button_x (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'X' are clicked. | |
gint | action_button_y (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'Y' are clicked. | |
gint | action_button_z (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'Z' are clicked. | |
gint | popup_box (char *message) |
gint | action_button_country (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'country' are clicked. | |
gint | action_button_animal (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'animal' are clicked. | |
gint | action_button_fruit (GtkWidget *widget, GdkEvent *event, gpointer value) |
This funtion is taken action when 'fruit' are clicked. | |
int | main (int argc, char *argv[]) |
This is where program execution starts. | |
Variables | |
sqlite3 * | db1 |
GtkWidget * | window |
GtkWidget * | vbox |
GtkWidget * | entry |
GtkWidget * | table |
GtkWidget * | playername |
GtkWidget * | button [25] |
GtkWidget * | button1 |
GtkWidget * | button2 |
GtkWidget * | button3 |
GtkWidget * | image |
GtkWidget * | image0 |
GtkWidget * | image1 |
GtkWidget * | image2 |
GtkWidget * | image3 |
GtkWidget * | image4 |
GtkWidget * | image5 |
GtkWidget * | image6 |
GtkWidget * | label |
GtkWidget * | label1 |
GtkWidget * | label2 |
GtkWidget * | label3 |
GtkWidget * | label4 |
GtkWidget * | dialog |
GtkWidget * | dialog2 |
GtkWidget * | dialog3 |
GtkWidget * | dialog4 |
char | randomname [10] |
char | randomcategory [2] |
char | showstring [10] |
int | wrongcount = 0 |
const gchar * | entry_text |
const gchar | str [30] |
const gchar * | playername_text |
This program is to make a hangman game using GTK programming as an interface.
The program will use GtkWidget of GtkLabel, GtkImage, GtkButton, GtkEntry and GtkWindow to show the hangman game to user.
Definition in file hm.c.
#define BUFFER 4096 |
Definition at line 15 of file hm.c.
Referenced by get_random_element(), setup_tables(), and update_score().
#define MAX_IMAGES 8 |
Definition at line 16 of file hm.c.
Referenced by win_or_loose().
gint action_button_a | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'A' are clicked.
Definition at line 362 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_animal | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'animal' are clicked.
Definition at line 949 of file hm.c.
References entry, get_random_element(), playername, popup_box(), randomcategory, randomname, set_images(), showstring, and wrongcount.
Referenced by main().
gint action_button_b | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'B' are clicked.
Definition at line 382 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_c | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'C' are clicked.
Definition at line 403 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_country | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'country' are clicked.
Definition at line 915 of file hm.c.
References entry, get_random_element(), playername, popup_box(), randomcategory, randomname, set_images(), showstring, and wrongcount.
Referenced by main().
gint action_button_d | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'D' are clicked.
Definition at line 424 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_e | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'E' are clicked.
Definition at line 445 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_f | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'F' are clicked.
Definition at line 466 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_fruit | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'fruit' are clicked.
Definition at line 986 of file hm.c.
References entry, get_random_element(), playername, popup_box(), randomcategory, randomname, set_images(), showstring, and wrongcount.
Referenced by main().
gint action_button_g | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'G' are clicked.
Definition at line 487 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_h | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'H' are clicked.
Definition at line 508 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_i | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'I' are clicked.
Definition at line 529 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_j | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'J' are clicked.
Definition at line 550 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_k | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'K' are clicked.
Definition at line 571 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_l | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'L' are clicked.
Definition at line 592 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_m | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'M' are clicked.
Definition at line 613 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_n | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'N' are clicked.
Definition at line 634 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_o | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'O' are clicked.
Definition at line 655 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_p | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'P' are clicked.
Definition at line 676 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_q | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'Q' are clicked.
Definition at line 697 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_r | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'R' are clicked.
Definition at line 718 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_s | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'S' are clicked.
Definition at line 739 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_t | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'T' are clicked.
Definition at line 760 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_u | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'U' are clicked.
Definition at line 781 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_v | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'V' are clicked.
Definition at line 801 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_w | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'W' are clicked.
Definition at line 822 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_x | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'X' are clicked.
Definition at line 843 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_y | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'Y' are clicked.
Definition at line 864 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
gint action_button_z | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | value | |||
) |
This funtion is taken action when 'Z' are clicked.
Definition at line 885 of file hm.c.
References dialog, entry, update_entryText(), and win_or_loose().
Referenced by main().
static int callback | ( | void * | NotUsed, | |
int | argc, | |||
char ** | argv, | |||
char ** | azColName | |||
) | [static] |
Standard callback function used to display the results sqlite3.
Definition at line 63 of file hm.c.
References randomname.
Referenced by get_random_element(), and setup_tables().
void enter_callback | ( | GtkWidget * | widget, | |
GtkWidget * | entry | |||
) |
void get_random_element | ( | char * | category | ) |
This function will return a random element from choosen category.
Definition at line 101 of file hm.c.
References BUFFER, callback(), and db1.
Referenced by action_button_animal(), action_button_country(), and action_button_fruit().
int main | ( | int | argc, | |
char * | argv[] | |||
) |
This is where program execution starts.
All arguments are passed to gtk for processing, which removes any arguments relevant to it.
argc | Number of arguments passed. | |
argv | NULL terminated array of command line arguments. |
Definition at line 1024 of file hm.c.
References action_button_a(), action_button_animal(), action_button_b(), action_button_c(), action_button_country(), action_button_d(), action_button_e(), action_button_f(), action_button_fruit(), action_button_g(), action_button_h(), action_button_i(), action_button_j(), action_button_k(), action_button_l(), action_button_m(), action_button_n(), action_button_o(), action_button_p(), action_button_q(), action_button_r(), action_button_s(), action_button_t(), action_button_u(), action_button_v(), action_button_w(), action_button_x(), action_button_y(), action_button_z(), button, button1, button2, button3, enter_callback(), entry, entry_text, image0, image1, image2, image3, image4, image5, image6, label, label1, label2, label3, label4, playername, playername_callback(), playername_text, set_images(), setup_tables(), table, vbox, window, and wrongcount.
void playername_callback | ( | GtkWidget * | widget, | |
GtkWidget * | entry | |||
) |
gint popup_box | ( | char * | message | ) |
Definition at line 902 of file hm.c.
References dialog.
Referenced by action_button_animal(), action_button_country(), and action_button_fruit().
void set_images | ( | int | wrongcount | ) |
This function will display and hide image depents on number of wrongcount.
Definition at line 156 of file hm.c.
References image0, image1, image2, image3, image4, image5, and image6.
Referenced by action_button_animal(), action_button_country(), action_button_fruit(), main(), and win_or_loose().
void setup_tables | ( | ) |
int update_entryText | ( | char | ch | ) |
This function will update the text entry.
Definition at line 137 of file hm.c.
References randomname, and showstring.
Referenced by action_button_a(), action_button_b(), action_button_c(), action_button_d(), action_button_e(), action_button_f(), action_button_g(), action_button_h(), action_button_i(), action_button_j(), action_button_k(), action_button_l(), action_button_m(), action_button_n(), action_button_o(), action_button_p(), action_button_q(), action_button_r(), action_button_s(), action_button_t(), action_button_u(), action_button_v(), action_button_w(), action_button_x(), action_button_y(), and action_button_z().
void update_score | ( | int | score | ) |
This function will display and update score from text file scorefile.txt.
Definition at line 241 of file hm.c.
References BUFFER, label, and playername.
Referenced by win_or_loose().
void win_or_loose | ( | int | res | ) |
This function will pop up a GAME OVER msg and YOU WON msg and change the hangman picture arcording to worgcount.
Definition at line 296 of file hm.c.
References dialog2, dialog3, entry, image, MAX_IMAGES, playername, randomname, set_images(), showstring, update_score(), and wrongcount.
Referenced by action_button_a(), action_button_b(), action_button_c(), action_button_d(), action_button_e(), action_button_f(), action_button_g(), action_button_h(), action_button_i(), action_button_j(), action_button_k(), action_button_l(), action_button_m(), action_button_n(), action_button_o(), action_button_p(), action_button_q(), action_button_r(), action_button_s(), action_button_t(), action_button_u(), action_button_v(), action_button_w(), action_button_x(), action_button_y(), and action_button_z().
sqlite3* db1 |
Definition at line 18 of file hm.c.
Referenced by get_random_element(), and setup_tables().
GtkWidget* dialog |
Definition at line 48 of file hm.c.
Referenced by action_button_a(), action_button_b(), action_button_c(), action_button_d(), action_button_e(), action_button_f(), action_button_g(), action_button_h(), action_button_i(), action_button_j(), action_button_k(), action_button_l(), action_button_m(), action_button_n(), action_button_o(), action_button_p(), action_button_q(), action_button_r(), action_button_s(), action_button_t(), action_button_u(), action_button_v(), action_button_w(), action_button_x(), action_button_y(), action_button_z(), and popup_box().
GtkWidget* dialog2 |
Definition at line 49 of file hm.c.
Referenced by win_or_loose().
GtkWidget* dialog3 |
Definition at line 50 of file hm.c.
Referenced by win_or_loose().
GtkWidget* entry |
Definition at line 22 of file hm.c.
Referenced by action_button_a(), action_button_animal(), action_button_b(), action_button_c(), action_button_country(), action_button_d(), action_button_e(), action_button_f(), action_button_fruit(), action_button_g(), action_button_h(), action_button_i(), action_button_j(), action_button_k(), action_button_l(), action_button_m(), action_button_n(), action_button_o(), action_button_p(), action_button_q(), action_button_r(), action_button_s(), action_button_t(), action_button_u(), action_button_v(), action_button_w(), action_button_x(), action_button_y(), action_button_z(), main(), and win_or_loose().
const gchar* entry_text |
Definition at line 57 of file hm.c.
Referenced by enter_callback(), and main().
GtkWidget* image |
Definition at line 33 of file hm.c.
Referenced by win_or_loose().
GtkWidget* image0 |
Definition at line 34 of file hm.c.
Referenced by main(), and set_images().
GtkWidget* image1 |
Definition at line 35 of file hm.c.
Referenced by main(), and set_images().
GtkWidget* image2 |
Definition at line 36 of file hm.c.
Referenced by main(), and set_images().
GtkWidget* image3 |
Definition at line 37 of file hm.c.
Referenced by main(), and set_images().
GtkWidget* image4 |
Definition at line 38 of file hm.c.
Referenced by main(), and set_images().
GtkWidget* image5 |
Definition at line 39 of file hm.c.
Referenced by main(), and set_images().
GtkWidget* image6 |
Definition at line 40 of file hm.c.
Referenced by main(), and set_images().
GtkWidget* label |
Definition at line 42 of file hm.c.
Referenced by main(), and update_score().
GtkWidget* playername |
Definition at line 25 of file hm.c.
Referenced by action_button_animal(), action_button_country(), action_button_fruit(), main(), update_score(), and win_or_loose().
const gchar * playername_text |
Definition at line 57 of file hm.c.
Referenced by main(), and playername_callback().
char randomcategory[2] |
Definition at line 54 of file hm.c.
Referenced by action_button_animal(), action_button_country(), and action_button_fruit().
char randomname[10] |
Definition at line 53 of file hm.c.
Referenced by action_button_animal(), action_button_country(), action_button_fruit(), callback(), update_entryText(), and win_or_loose().
char showstring[10] |
Definition at line 55 of file hm.c.
Referenced by action_button_animal(), action_button_country(), action_button_fruit(), update_entryText(), and win_or_loose().
const gchar str[30] |
Definition at line 57 of file hm.c.
Referenced by enter_callback().
int wrongcount = 0 |
Definition at line 56 of file hm.c.
Referenced by action_button_animal(), action_button_country(), action_button_fruit(), main(), and win_or_loose().