[gnome-nibbles/arnaudb/use-uint8: 6/9] Use uint8 more.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/arnaudb/use-uint8: 6/9] Use uint8 more.
- Date: Fri, 3 Jul 2020 15:30:22 +0000 (UTC)
commit e0af49f511658c205233a1bce1bc2852c7293665
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Fri Jul 3 00:36:25 2020 +0200
Use uint8 more.
src/nibbles-game.vala | 14 +++++++-------
src/nibbles-test.vala | 2 +-
src/nibbles-view.vala | 4 ++--
src/worm.vala | 30 +++++++++++++++++-------------
4 files changed, 27 insertions(+), 23 deletions(-)
---
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index fcc4af4..caa2237 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -47,8 +47,8 @@ private class NibblesGame : Object
/* Board data */
internal int[,] board;
- public int width { internal get; protected construct; }
- public int height { internal get; protected construct; }
+ public uint8 width { internal get; protected construct; }
+ public uint8 height { internal get; protected construct; }
/* Worms data */
internal int numhumans { internal get; internal set; }
@@ -84,7 +84,7 @@ private class NibblesGame : Object
boni.bonus_removed.connect ((bonus) => bonus_removed (bonus));
}
- internal NibblesGame (int start_level, int speed, int gamedelay, bool fakes, int width, int height, bool
no_random = false)
+ internal NibblesGame (int start_level, int speed, int gamedelay, bool fakes, uint8 width, uint8 height,
bool no_random = false)
{
Object (skip_score: (start_level != 1), current_level: start_level, speed: speed, gamedelay:
gamedelay, fakes: fakes, width: width, height: height);
@@ -93,7 +93,7 @@ private class NibblesGame : Object
internal bool load_board (string [] future_board, uint8 regular_bonus)
{
- if (future_board.length != height)
+ if (future_board.length != (int) height)
return false;
boni.reset (regular_bonus);
@@ -101,12 +101,12 @@ private class NibblesGame : Object
string tmpboard;
int count = 0;
- for (int i = 0; i < height; i++)
+ for (uint8 i = 0; i < height; i++)
{
tmpboard = future_board [i];
- if (tmpboard.char_count () != width)
+ if (tmpboard.char_count () != (int) width)
return false;
- for (int j = 0; j < width; j++)
+ for (uint8 j = 0; j < width; j++)
{
unichar char_value = tmpboard.get_char (tmpboard.index_of_nth_char (j));
switch (char_value)
diff --git a/src/nibbles-test.vala b/src/nibbles-test.vala
index e159be9..28910c3 100644
--- a/src/nibbles-test.vala
+++ b/src/nibbles-test.vala
@@ -60,7 +60,7 @@ namespace NibblesTest
/* speed */ 0,
/* delay */ 0,
/* fakes */ false,
- /* size x and y */ board [0].char_count (), board.length,
+ /* size x and y */ (uint8) board [0].char_count (), (uint8)
board.length,
/* no random */ true);
game.numhumans = 0;
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index 7074a8e..a3724e3 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -110,8 +110,8 @@ private class NibblesView : GtkClutter.Embed
}
}
- internal const int WIDTH = 92;
- internal const int HEIGHT = 66;
+ internal const uint8 WIDTH = 92;
+ internal const uint8 HEIGHT = 66;
internal const int GAMEDELAY = 35;
private const int MINIMUM_TILE_SIZE = 7;
diff --git a/src/worm.vala b/src/worm.vala
index 90b2dca..b9df10e 100644
--- a/src/worm.vala
+++ b/src/worm.vala
@@ -69,32 +69,36 @@ private struct Position
int x;
int y;
- internal void move (WormDirection direction, int width, int height)
+ internal void move (WormDirection direction, uint8 width, uint8 height)
{
switch (direction)
{
case WormDirection.UP:
- y--;
- if (y < 0)
+ if (y == 0)
y = height - 1;
+ else
+ y--;
break;
case WormDirection.DOWN:
- y++;
- if (y >= height)
+ if (y >= height - 1)
y = 0;
+ else
+ y++;
break;
case WormDirection.LEFT:
- x--;
- if (x < 0)
+ if (x == 0)
x = width - 1;
+ else
+ x--;
break;
case WormDirection.RIGHT:
- x++;
- if (x >= width)
+ if (x >= width - 1)
x = 0;
+ else
+ x++;
break;
default:
@@ -170,8 +174,8 @@ private class Worm : Object
internal signal void bonus_found ();
- public int width { private get; protected construct; }
- public int height { private get; protected construct; }
+ public uint8 width { private get; protected construct; }
+ public uint8 height { private get; protected construct; }
public int capacity { private get; protected construct; }
construct
@@ -179,7 +183,7 @@ private class Worm : Object
deadend_board = new uint [width, height];
}
- internal Worm (int id, int width, int height)
+ internal Worm (int id, uint8 width, uint8 height)
{
int capacity = width * height;
Object (id: id, width: width, height: height, capacity: capacity);
@@ -554,7 +558,7 @@ private class Worm : Object
deadend_board [new_position.x, new_position.y] = deadend_runnumber;
int cl = (length * length) / 16;
- if (cl < width)
+ if (cl < (int) width)
cl = width;
return ai_deadend (board, numworms, new_position, cl);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]