Compare commits

..

3 Commits

@ -3,6 +3,9 @@ const io = std.io;
const mem = std.mem; const mem = std.mem;
const os = std.os; const os = std.os;
var player1Name: []const u8 = undefined;
var player2Name: []const u8 = undefined;
pub fn main() anyerror!void { pub fn main() anyerror!void {
std.log.info("All your codebase are belong to us.", .{}); std.log.info("All your codebase are belong to us.", .{});
@ -15,6 +18,12 @@ pub fn main() anyerror!void {
// var fba = std.heap.FixedBufferAllocator.init(&buffer); // var fba = std.heap.FixedBufferAllocator.init(&buffer);
// const allocator = fba.allocator(); // const allocator = fba.allocator();
// Useage of app:
// 1. create players
// 2. set up new table
// 3. mark points as game is being played
// 4. rematch? (keep players)
try stdOut.writer().print(">", .{}); try stdOut.writer().print(">", .{});
while (!quit) { while (!quit) {
const input = (try nextLine(stdIn.reader(), &buffer)).?; const input = (try nextLine(stdIn.reader(), &buffer)).?;
@ -37,11 +46,19 @@ fn nextLine(reader: anytype, buffer: []u8) !?[]const u8 {
} }
} }
//TODO: Create command parser
fn parser(query: []const u8) !void { fn parser(query: []const u8) !void {
const stdOut = io.getStdOut();
if (mem.eql(u8, query, "quit")) { if (mem.eql(u8, query, "quit")) {
try quitApp(); try quitApp();
} }
if (mem.eql(u8, query, "player1")) {
player1Name = try getInput();
try stdOut.writer().print("Player 1 is now {s}\n", .{player1Name});
}
if (mem.eql(u8, query, "player2")) {
player1Name = try getInput();
try stdOut.writer().print("Player 1 is now {s}\n", .{player1Name});
}
} }
fn quitApp() !void { fn quitApp() !void {
@ -50,8 +67,9 @@ fn quitApp() !void {
os.exit(0); os.exit(0);
} }
//TODO: Create inital settings fn getInput() ![]const u8{
const stdIn = io.getStdIn();
test "basic test" { var buffer: [1000]u8 = undefined;
try std.testing.expectEqual(10, 3 + 7); const input = (try nextLine(stdIn.reader(), &buffer)).?;
} return input;
}
Loading…
Cancel
Save