Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Mar 28th, 2020 125 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <gtk/gtk.h>
  2.  
  3. #define ACE 0
  4. #define CARDS 13
  5. #define SUITS 4
  6. #define MAX_CARDS 10
  7. #define SCREENLINECOUNT 17
  8.  
  9. struct table {
  10.  
  11.     int cards_dealer[MAX_CARDS];
  12.    
  13.     int cards_player[MAX_CARDS];
  14.    
  15.     int points[MAX_CARDS];                      /* Points for each hand */
  16.    
  17.     int total_player, total_dealer;             /* total points */
  18.        
  19.     int hand_player, hand_dealer;               /* number of cards dealt */
  20.    
  21.     int aces_player, aces_dealer;               /* N° of aces: These variable are used to attribute values 1/11 to Aces*/
  22.    
  23.     int credit;
  24.    
  25.     int bet;
  26.    
  27.     int end;
  28.    
  29.     GtkWidget *fixed;
  30.    
  31. };
  32.  
  33. enum outcomes {NO_WINNER, PLAYER_WINS, BLACKJACK, DEALER_WINS, TIE, GAME_OVER, ID_DEALER, ID_PLAYER};
  34.  
  35. static void destroy (GtkWidget *window, gpointer data);
  36.  
  37. void button_clicked(GtkWidget *widget, struct table *game);
  38.  
  39. int main (int argc, char *argv[])
  40. {
  41.         GtkWidget *window, *button;
  42.        
  43.         struct table game;
  44.            
  45.         game.hand_dealer = 2;
  46.         game.hand_player = 2;
  47.        
  48.         gtk_init (&argc, &argv);
  49.         window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  50.         gtk_window_set_title (GTK_WINDOW (window), "Show Images");
  51.         gtk_window_maximize (GTK_WINDOW (window));
  52.         g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL);
  53.        
  54.         GtkCssProvider *css_provider = gtk_css_provider_new();
  55.         gtk_css_provider_load_from_path (css_provider, "style.css", NULL);
  56.        
  57.         GdkScreen *myScreen= gdk_screen_get_default ();
  58.         gtk_style_context_add_provider_for_screen
  59.                                (myScreen,
  60.                                 GTK_STYLE_PROVIDER (css_provider),
  61.                                 GTK_STYLE_PROVIDER_PRIORITY_USER);
  62.            
  63.         game.fixed = gtk_fixed_new();
  64.         gtk_container_add (GTK_CONTAINER (window), game.fixed);
  65.    
  66.         button = gtk_button_new_with_label("HIT");
  67.         gtk_fixed_put(GTK_FIXED(game.fixed), button, 300, 650);
  68.         gtk_widget_set_size_request(button, 80, 30);
  69.         g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(button_clicked), &game);      
  70.  
  71.         button = gtk_button_new_with_label("STAND");
  72.         gtk_fixed_put(GTK_FIXED(game.fixed), button, 500, 650);
  73.         gtk_widget_set_size_request(button, 80, 30);
  74.  
  75.         button = gtk_button_new_with_label("QUIT");
  76.         gtk_fixed_put(GTK_FIXED(game.fixed), button, 700, 650);
  77.         gtk_widget_set_size_request(button, 80, 30);
  78.         g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(destroy), &game);     
  79.        
  80.         gtk_widget_show_all (window);
  81.         gtk_main ();
  82.         return 0;
  83. }
  84.  
  85. void button_clicked(GtkWidget *widget, struct table *game)
  86. {    
  87.     const gchar* cards_dealer[] = {"resized_cards/010.png", "resized_cards/011.png", "resized_cards/312.png"};
  88.     const gchar* cards_player[] = {"resized_cards/00.png", "resized_cards/01.png", "resized_cards/03.png"};
  89.    
  90.     static int current_hand = 0;
  91.     static int gap1, gap2;
  92.    
  93.     gap1 = gap2 = 0;
  94.    
  95.     GtkWidget *image_dealer;
  96.     GtkWidget *image_player;
  97.    
  98.     if (current_hand == 0) {
  99.         image_dealer = gtk_image_new_from_file ("resized_cards/back.png");
  100.         gtk_fixed_put(GTK_FIXED(game->fixed), image_dealer, 200+gap1, 100);
  101.         gap1 += 50;    
  102.     }
  103.    
  104.     if (current_hand < game->hand_dealer) {
  105.         image_dealer = gtk_image_new_from_file (cards_dealer[game->hand_dealer]);
  106.         gtk_fixed_put(GTK_FIXED(game->fixed), image_dealer, 200+gap1, 100);
  107.         gap1 += 50;
  108.         game->hand_dealer++;
  109.     }
  110.        
  111.     if (current_hand < game->hand_player) {
  112.         image_player = gtk_image_new_from_file (cards_player[game->hand_player]);
  113.         gtk_fixed_put(GTK_FIXED(game->fixed), image_player, 200+gap2, 450);
  114.         gap2 += 50;
  115.         game->hand_player++;
  116.     }
  117.    
  118.     current_hand++;
  119.        
  120.     gtk_widget_show(image_dealer);
  121.     gtk_widget_show(image_player);
  122. }
  123.  
  124. static void destroy (GtkWidget *window, gpointer data)
  125. {
  126.     gtk_main_quit ();
  127. }
  128.  
  129. void init_game(struct table *game) {
  130.  
  131.     game->total_player = game->total_dealer = 0;
  132.  
  133.     game->aces_player = game->aces_dealer = 0;
  134.    
  135.     game->hand_dealer = game->hand_player = 2;
  136.    
  137.     game->end = 0;
  138.    
  139.     /*draw_cards(player);*/
  140.    
  141.     /*assign_points(player); */
  142.            
  143.     /*assign_points(player); */
  144.    
  145.     game->credit = 50;
  146.  
  147. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top