[four-in-a-row/KaKnife/four-in-a-row-vala: 38/65] reduce dependance on global vars and fix issue with scorebox



commit e897a1ea1ef00933c0ab567c11f09c97e2612bfe
Author: Jacob Humphrey <jacob ryan humphrey gmail com>
Date:   Fri Dec 14 22:13:22 2018 -0600

    reduce dependance on global vars and fix issue with scorebox

 src/four-in-a-row.vala |  6 +++---
 src/scorebox.vala      | 28 +++++++++++++++-------------
 2 files changed, 18 insertions(+), 16 deletions(-)
---
diff --git a/src/four-in-a-row.vala b/src/four-in-a-row.vala
index 21d4d29..859499f 100644
--- a/src/four-in-a-row.vala
+++ b/src/four-in-a-row.vala
@@ -179,7 +179,7 @@ class FourInARow : Gtk.Application {
             window.show_all();
             GameBoardView.instance.refresh_pixmaps();
             GameBoardView.instance.draw_all();
-            Scorebox.instance.update();       /* update visible player descriptions */
+            Scorebox.instance.update(score);       /* update visible player descriptions */
             prompt_player();
             game_reset();
         }
@@ -313,7 +313,7 @@ class FourInARow : Gtk.Application {
 
         if (gameover) {
             score[winner]++;
-            Scorebox.instance.update();
+            Scorebox.instance.update(score);
             prompt_player();
         } else {
             swap_player();
@@ -582,7 +582,7 @@ class FourInARow : Gtk.Application {
 
         if (gameover) {
             score[winner]--;
-            Scorebox.instance.update();
+            Scorebox.instance.update(score);
             gameover = false;
             prompt_player();
         } else {
diff --git a/src/scorebox.vala b/src/scorebox.vala
index 06130f0..8978e9c 100644
--- a/src/scorebox.vala
+++ b/src/scorebox.vala
@@ -16,7 +16,7 @@ class Scorebox : Gtk.Dialog {
             return _instance.once(() => {
                 var scorebox = new Scorebox();
                 //scorebox.show_all();
-                scorebox.update();
+                //scorebox.update();
                 return scorebox;
             });
         }
@@ -64,7 +64,7 @@ class Scorebox : Gtk.Dialog {
         label_name[PlayerID.PLAYER2].yalign = 0.5f;
 
         label_score[PlayerID.PLAYER2] = new Gtk.Label(null);
-        grid2.attach(label_score[PlayerID.PLAYER2], 1, 0, 1, 1);
+        grid2.attach(label_score[PlayerID.PLAYER2], 1, 1, 1, 1);
         label_score[PlayerID.PLAYER2].set_xalign(0);
         label_score[PlayerID.PLAYER2].set_yalign(0.5f);
 
@@ -74,7 +74,7 @@ class Scorebox : Gtk.Dialog {
         label_name[PlayerID.NOBODY].set_yalign(0.5f);
 
         label_score[PlayerID.NOBODY] = new Gtk.Label(null);
-        grid2.attach(label_score[PlayerID.NOBODY], 1, 0, 1, 1);
+        grid2.attach(label_score[PlayerID.NOBODY], 1, 2, 1, 1);
         label_score[PlayerID.NOBODY].set_xalign(0);
         label_score[PlayerID.NOBODY].set_yalign(0.5f);
         grid.show_all();
@@ -87,23 +87,25 @@ class Scorebox : Gtk.Dialog {
      *
      * updates the scorebox with the latest scores
      */
-    public void update() {
+    public void update(int[] scores) {
+               print("%i", p.get_n_human_players());
         if (p.get_n_human_players() == 1) {
             if (p.level[PlayerID.PLAYER1] == Level.HUMAN) {
-                label_score[PlayerID.PLAYER1].set_text(_("You:"));
-                label_score[PlayerID.PLAYER2].label = _("Me:");
+                               print("hi");
+                label_name[PlayerID.PLAYER1].set_text(_("You:"));
+                               label_name[PlayerID.PLAYER2].label = _("Me:");
             } else {
-                label_score[PlayerID.PLAYER2].set_text(_("You:"));
-                label_score[PlayerID.PLAYER1].label = _("Me:");
+                label_name[PlayerID.PLAYER2].set_text(_("You:"));
+                label_name[PlayerID.PLAYER1].label = _("Me:");
             }
         } else {
             label_name[PlayerID.PLAYER1].label = theme_get_player(PlayerID.PLAYER1);
             label_name[PlayerID.PLAYER2].label = theme_get_player(PlayerID.PLAYER2);
         }
-
-        label_score[PlayerID.PLAYER1].label = application.score[PlayerID.PLAYER1].to_string();
-        label_score[PlayerID.PLAYER2].label = application.score[PlayerID.PLAYER2].to_string();
-        label_score[PlayerID.NOBODY].label = application.score[PlayerID.NOBODY].to_string();
+               print("%i", scores[1]);
+        label_score[PlayerID.PLAYER1].label = scores[PlayerID.PLAYER1].to_string();
+        label_score[PlayerID.PLAYER2].label = scores[PlayerID.PLAYER2].to_string();
+        label_score[PlayerID.NOBODY].label = scores[PlayerID.NOBODY].to_string();
 
     }
 
@@ -111,6 +113,6 @@ class Scorebox : Gtk.Dialog {
         application.score[PlayerID.PLAYER1] = 0;
         application.score[PlayerID.PLAYER2] = 0;
         application.score[PlayerID.NOBODY] = 0;
-        update();
+        //update();
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]