7 İşlemeler eddf9a6381 ... 1ac3799158

Yazar SHA1 Mesaj Tarih
  missing-semi-colon 1ac3799158 Add more levels 1 hafta önce
  missing-semi-colon 0100b3c3fd Loop through levels 1 hafta önce
  missing-semi-colon 4c66674733 Use same characters in level files as in code 1 hafta önce
  missing-semi-colon 006fe8a608 Clear screen on game start 1 hafta önce
  missing-semi-colon 7a78167473 Build with ncursesw 1 hafta önce
  missing-semi-colon e25c5af612 Better import 1 hafta önce
  missing-semi-colon c9182e4164 Set end pipe color 3 hafta önce

+ 2 - 2
pipes/build.zig

@@ -22,7 +22,7 @@ pub fn build(b: *std.Build) void {
         .optimize = optimize,
     });
     exe.linkLibC();
-    exe.linkSystemLibrary("ncurses");
+    exe.linkSystemLibrary("ncursesw");
 
     // This declares intent for the executable to be installed into the
     // standard location when the user invokes the "install" step (the default
@@ -58,7 +58,7 @@ pub fn build(b: *std.Build) void {
         .optimize = optimize,
     });
     exe_unit_tests.linkLibC();
-    exe_unit_tests.linkSystemLibrary("ncurses");
+    exe_unit_tests.linkSystemLibrary("ncursesw");
 
     const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
 

+ 8 - 0
pipes/levels/level1.txt

@@ -0,0 +1,8 @@
+10,10
+#
+#
+###╥
+##║
+###╚══╗
+######║
+######╨

+ 7 - 0
pipes/levels/level2.txt

@@ -0,0 +1,7 @@
+6,6
+####
+####══
+##║##╚
+╔#║═╡
+#║║
+##╨

+ 13 - 0
pipes/levels/level3.txt

@@ -0,0 +1,13 @@
+12,12
+####║####╚##
+#╞#####║####
+####║####║##
+#║#####║####
+##║#######║#
+════════════
+##║#######║#
+######║#####
+###║║#######
+#║######║#╡#
+####║##║╗║##
+#║######║###

+ 0 - 7
pipes/levels/test.txt

@@ -1,7 +0,0 @@
-10,10
-#########
-##b####3#
-#|#####
-##4--2
-#####|#
-#####d#---

+ 1 - 0
pipes/src/constants.zig

@@ -23,4 +23,5 @@ pub const CellColor = enum(u8) {
 	PIPE_HOVERED = 4,
 	PIPE_SELECTED = 5,
 	PIPE_FILLED = 6,
+	PIPE_END = 7,
 };

+ 4 - 3
pipes/src/game.zig

@@ -19,7 +19,7 @@ pub const Game = struct {
 	window: *curses.struct__win_st,
 	allocator: std.mem.Allocator = std.heap.page_allocator,
 	_level: Level = undefined,
-	_grid: Grid(u16) = undefined,
+	_grid: Grid(CellCharType) = undefined,
 	_selected: ?*Pipe = null,
 	_cursor: Vector = Vector{.x = 0, .y = 0},
 
@@ -46,7 +46,7 @@ pub const Game = struct {
 
 
 	pub fn main_loop(self: *Game) !void {
-		// TODO: why win text not clear?
+		_ = curses.clear();
 		while (true) {
 			try self.step();
 			if (try self._level.is_completed()) {
@@ -172,7 +172,8 @@ pub const Game = struct {
 		while (pipe_iter.next()) |entry| {
 			const pipe: *Pipe = entry.value_ptr;
 			const char: CellCharType = Game.get_pipe_char(pipe);
-			var color: CellColor = CellColor.PIPE_NORMAL;
+			var color: CellColor = if (pipe.is_end()) CellColor.PIPE_END
+					else CellColor.PIPE_NORMAL;
 
 			if (show_cursor) {
 				if (pipe == self._selected) {

+ 7 - 0
pipes/src/grid.zig

@@ -66,6 +66,8 @@ pub fn Grid(comptime CharType: type) type {
 							constants.CellChar.PIPE_CORNER_1);
 					const pipe_corner_4_char = @intFromEnum(
 							constants.CellChar.PIPE_CORNER_4);
+					const pipe_end_1_char = @intFromEnum(
+							constants.CellChar.PIPE_END_1);
 					const normal_color_id = @intFromEnum(
 							constants.CellColor.NORMAL);
 
@@ -82,6 +84,11 @@ pub fn Grid(comptime CharType: type) type {
 							.char = @intFromEnum(constants.CellChar.PIPE_HORIZ),
 							.color_pair_id = cell.color_pair_id,
 						};
+					} else if (cell.char == pipe_end_1_char) {
+						cell_to_print = &Cell(CharType){
+							.char = @intFromEnum(constants.CellChar.PIPE_HORIZ),
+							.color_pair_id = cell.color_pair_id,
+						};
 					} else {
 						cell_to_print = &Cell(CharType){
 							.char = ' ',

+ 16 - 14
pipes/src/level.zig

@@ -1,7 +1,8 @@
 const std = @import("std");
-const PriorityQueue = @import("std").PriorityQueue;
-const AutoHashMap = @import("std").AutoHashMap;
+const PriorityQueue = std.PriorityQueue;
+const AutoHashMap = std.AutoHashMap;
 
+const CellCharType = @import("constants.zig").CellCharType;
 const LevelReader = @import("level_reader.zig").LevelReader;
 const PipeType = @import("pipe.zig").PipeType;
 const Pipes = @import("pipes.zig").Pipes;
@@ -17,7 +18,7 @@ pub const Level = struct {
 
 
 	pub fn init(self: *Level, filename: []const u8) !void {
-		var level_reader = LevelReader{};
+		var level_reader = LevelReader(CellCharType){};
 		try level_reader.init(filename);
 		defer level_reader.deinit();
 
@@ -119,17 +120,18 @@ pub const Level = struct {
 	}
 
 
-	fn create_pipes(self: *Level, level_reader: *const LevelReader) !void {
-		const horiz_pipes = level_reader.get_positions('-');
-		const vert_pipes = level_reader.get_positions('|');
-		const corner_1_pipes = level_reader.get_positions('1');
-		const corner_2_pipes = level_reader.get_positions('2');
-		const corner_3_pipes = level_reader.get_positions('3');
-		const corner_4_pipes = level_reader.get_positions('4');
-		const end_1_pipes = level_reader.get_positions('a');
-		const end_2_pipes = level_reader.get_positions('b');
-		const end_3_pipes = level_reader.get_positions('c');
-		const end_4_pipes = level_reader.get_positions('d');
+	fn create_pipes(self: *Level, level_reader: *const LevelReader(CellCharType)
+			) !void {
+		const horiz_pipes = level_reader.get_positions('═');
+		const vert_pipes = level_reader.get_positions('║');
+		const corner_1_pipes = level_reader.get_positions('╔');
+		const corner_2_pipes = level_reader.get_positions('╗');
+		const corner_3_pipes = level_reader.get_positions('╝');
+		const corner_4_pipes = level_reader.get_positions('╚');
+		const end_1_pipes = level_reader.get_positions('╞');
+		const end_2_pipes = level_reader.get_positions('╥');
+		const end_3_pipes = level_reader.get_positions('╡');
+		const end_4_pipes = level_reader.get_positions('╨');
 
 		var end_pipe_pos: u2 = 0;
 

+ 0 - 0
pipes/src/level_reader.zig


Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor