[gnome-robots] invert control for game status
- From: Andrey Kutejko <akutejko src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-robots] invert control for game status
- Date: Tue, 6 Oct 2020 19:31:42 +0000 (UTC)
commit 1581009d7e23c6a3f412d650169762e031cb4a09
Author: Andrey Kutejko <andy128k gmail com>
Date: Mon Sep 21 00:05:36 2020 +0200
invert control for game status
src/game-area.vala | 4 ++++
src/game.vala | 30 ++++++++++++++++--------------
src/robots.vala | 5 +++++
3 files changed, 25 insertions(+), 14 deletions(-)
---
diff --git a/src/game-area.vala b/src/game-area.vala
index 817b817..2448db8 100644
--- a/src/game-area.vala
+++ b/src/game-area.vala
@@ -77,6 +77,8 @@ public class GameArea : DrawingArea {
}
}
+ public signal void updated (Game game);
+
public GameArea (Game game,
Theme theme,
Bubble aieee_bubble,
@@ -226,6 +228,8 @@ public class GameArea : DrawingArea {
game.tick ();
+ updated (game);
+
queue_draw ();
return true;
}
diff --git a/src/game.vala b/src/game.vala
index a21c998..066b294 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -32,6 +32,12 @@ public class Game {
public const int DEAD_DELAY = 30;
public const int CHANGE_DELAY = 20;
+ public struct Status {
+ public int score;
+ public int current_level;
+ public int safe_teleports;
+ }
+
public enum State {
PLAYING = 1,
WAITING,
@@ -76,6 +82,16 @@ public class Game {
private int score_step = 0;
private int safe_teleports = 0;
+ public Status status {
+ get {
+ return Status () {
+ score = score,
+ current_level = current_level + 1,
+ safe_teleports = safe_teleports
+ };
+ }
+ }
+
struct ArenaChange {
Arena arena;
Arena.Coords player;
@@ -131,7 +147,6 @@ public class Game {
play_sound (Sound.DIE);
arena[player.x, player.y] = ObjectType.PLAYER;
endlev_counter = 0;
- set_move_action_sensitivity (false);
}
/**
@@ -179,8 +194,6 @@ public class Game {
if (safe_teleports > config.max_safe_teleports) {
safe_teleports = config.max_safe_teleports;
}
-
- update_game_status (score, current_level + 1, safe_teleports);
}
private int max_robots () {
@@ -234,8 +247,6 @@ public class Game {
safe_teleports = config.max_safe_teleports;
}
- update_game_status (score, current_level, safe_teleports);
-
for (int i = 0; i < num_robots1; ++i) {
place_randomly (ObjectType.ROBOT1);
}
@@ -287,11 +298,8 @@ public class Game {
state = State.COMPLETE;
play_sound (Sound.YAHOO);
endlev_counter = 0;
- set_move_action_sensitivity (false);
}
}
-
- update_game_status (score, current_level + 1, safe_teleports);
}
public void tick () {
@@ -317,8 +325,6 @@ public class Game {
++current_level;
generate_level ();
state = State.PLAYING;
- set_move_action_sensitivity (true);
- update_game_status (score, current_level + 1, safe_teleports);
splat = null;
}
} else if (state == State.DEAD) {
@@ -350,9 +356,6 @@ public class Game {
generate_level ();
state = State.PLAYING;
-
- update_game_status (score, current_level + 1, safe_teleports);
- set_move_action_sensitivity (true);
}
/**
@@ -668,7 +671,6 @@ public class Game {
}
safe_teleports -= 1;
- update_game_status (score, current_level, safe_teleports);
update_arena (change);
splat = null;
diff --git a/src/robots.vala b/src/robots.vala
index 9cf0bc4..cf01e0a 100644
--- a/src/robots.vala
+++ b/src/robots.vala
@@ -332,6 +332,11 @@ void activate (Gtk.Application app) {
yahoo_bubble,
splat_bubble);
game_area.destroy.connect (() => game_area = null);
+ game_area.updated.connect (game => {
+ var status = game.status;
+ update_game_status (status.score, status.current_level, status.safe_teleports);
+ set_move_action_sensitivity (game.state != Game.State.COMPLETE && game.state != Game.State.DEAD);
+ });
var gridframe = new Games.GridFrame (game.width, game.height);
gridframe.add (game_area);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]