Skip to content

Instantly share code, notes, and snippets.

@WideWord
Created November 18, 2015 08:55
Show Gist options
  • Save WideWord/547226f1437176aa066d to your computer and use it in GitHub Desktop.
Save WideWord/547226f1437176aa066d to your computer and use it in GitHub Desktop.
using System;
using System.Net.Sockets;
using System.IO;
using System.Text;
namespace Com.CodeGame.CodeRacing2015.DevKit.CSharpCgdk {
public struct Debug {
private static TcpClient client;
private static StreamWriter writer;
public static void connect(string host, int port) {
client = new TcpClient(host, port);
}
public static void disconnect() {
client.Close();
}
private static void sendCommand(string command) {
if (client != null) {
if (writer == null) {
writer = new StreamWriter(client.GetStream (), Encoding.ASCII);
}
writer.WriteLine(command);
}
System.Console.WriteLine(command);
}
public static void beginPre() {
sendCommand("begin pre");
}
public static void beginPost() {
sendCommand("begin post");
}
public static void endPre() {
sendCommand("end pre");
}
public static void endPost() {
sendCommand("end post");
}
private static string encodeColor(int color) {
int red = (color & 0xFF0000) >> 16;
int green = (color & 0x00FF00) >> 8;
int blue = color & 0x0000FF;
return "" + (double)red / 256.0 + " " + (double)green / 256.0 + " " + (double)blue / 256.0;
}
public static void circle(Vector position, double radius, int color) {
sendCommand("circle " + position.x + " " + position.y + " " + radius + " " + encodeColor(color));
}
public static void fillCircle(Vector position, double radius, int color) {
sendCommand("fill_circle " + position.x + " " + position.y + " " + radius + " " + encodeColor (color));
}
public static void rect(Vector p1, Vector p2, int color) {
sendCommand(String.Format("rect {0} {1} {2} {3} {4}", p1.x, p1.y, p2.x, p2.y, encodeColor(color)));
}
public static void fillRect(Vector p1, Vector p2, int color) {
sendCommand(String.Format("fill_rect {0} {1} {2} {3} {4}", p1.x, p1.y, p2.x, p2.y, encodeColor(color)));
}
public static void line(Vector p1, Vector p2, int color) {
sendCommand(String.Format("line {0} {1} {2} {3} {4}", p1.x, p1.y, p2.x, p2.y, encodeColor(color)));
}
public static void print(Vector pos, string msg, int color = 0) {
sendCommand(String.Format("text {0} {1} {2} {3}", pos.x, pos.y, msg, encodeColor(color)));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment