Permalink
Browse files

adding folder for samples

  • Loading branch information...
adam adam
adam authored and adam committed Jul 12, 2012
1 parent 32ad5eb commit 348bdd7191e8b0a1fd8fd72d7eedf4ce9e2ada4b
@@ -0,0 +1,32 @@
+
+class Board {
+ int ratio;
+ CanvasRenderingContext2D ctx;
+
+ Board() {
+ CanvasElement canvas = query("#board");
+ ratio = (canvas.height / 400).toInt();
+ ctx = canvas.getContext("2d");
+ }
+
+ draw() {
+ int i, j;
+ var sz = 50 * ratio;
+ ctx.fillStyle = "rgb(0,127,0)";
+ for (i = 0; i < 8; i++) {
+ for (j = 0; j < 8; j++) {
+ if ((i + j) % 2 == 1) {
+ ctx.fillRect (i*sz, j*sz, sz, sz);
+ }
+ }
+ }
+ ctx.fillStyle = "rgb(251,246,229)";
+ for (i = 0; i < 8; i++) {
+ for (j = 0; j < 8; j++) {
+ if ((i + j) % 2 == 0) {
+ ctx.fillRect (i*sz, j*sz, sz, sz);
+ }
+ }
+ }
+ }
+}
@@ -0,0 +1,27 @@
+
+body {
+ background-color: #F8F8F8;
+ font-family: 'Open Sans', sans-serif;
+ font-size: 14px;
+ font-weight: normal;
+ line-height: 1.2em;
+ margin: 15px;
+}
+
+p {
+ color: #333;
+}
+
+#container {
+ width: 100%;
+ height: 400px;
+ position: relative;
+ border: 1px solid #ccc;
+ background-color: #fff;
+}
+
+#text {
+ font-size: 24pt;
+ text-align: center;
+ margin-top: 140px;
+}
@@ -0,0 +1,21 @@
+
+#import('dart:html');
+#source("Board.dart");
+num rotatePos = 0;
+
+void main() {
+ //query("#text").text = "Welcome to Dart!";
+
+ //query("#text").on.click.add(rotateText);
+ Board b = new Board();
+ b.draw();
+}
+
+void rotateText(Event event) {
+ rotatePos += 360;
+
+ var textElement = query("#text");
+
+ textElement.style.transition = "1s";
+ textElement.style.transform = "rotate(${rotatePos}deg)";
+}
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Canvasclient</title>
+ <link rel="stylesheet" href="canvasclient.css">
+ </head>
+ <body>
+
+ <canvas id="board" height="400" width="400" />
+ <script type="application/dart" src="canvasclient.dart"></script>
+ <script src="http://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js"></script>
+ </body>
+</html>
@@ -0,0 +1,76 @@
+#import('dart:io');
+#import('../../Engine/ChessEngine.dart');
+
+printBoardCellLocations() {
+ StringBuffer sb = new StringBuffer();
+ for (int i=0; i<8; i++) {
+ for (int j=0; j<8; j++) {
+ sb.add("[$j $i] ");
+ }
+ sb.add("\n");
+ }
+
+ print(sb.toString());
+}
+
+printBoard(Engine e) {
+ printBoardCellLocations();
+ print("HumanPlayer = ${e.HumanPlayer}");
+ print("WhoseMove = ${e.WhoseMove}");
+ StringBuffer sb = new StringBuffer();
+ for (int i=0; i<8; i++) {
+ for (int j=0; j<8; j++) {
+ var pieceColor = e.GetPieceColorAt(j, i);
+ var pieceType = e.GetPieceTypeAt(j, i);
+
+
+ var c = pieceColor.toString().splitChars()[0];
+ var t = pieceType.toString().splitChars()[0];
+
+ if (t == "N") {
+ //sb.add("[$c ] ");
+ sb.add("[ ] ");
+ } else {
+ sb.add("[$c $t] ");
+ }
+ }
+ sb.add("\n");
+ }
+
+ print(sb.toString());
+}
+
+void main() {
+ InputStream input = stdin;
+ StringInputStream string_input = new StringInputStream(input);
+ Engine e = new Engine();
+ printBoard(e);
+
+ string_input.onData = () {
+ String s = string_input.readLine();
+ print(s);
+
+ List l = s.trim().split(new RegExp(" ", false, true));
+ print(l);
+
+ int src_col = Math.parseInt(l[0]);
+ int src_row = Math.parseInt(l[1]);
+ int dst_col = Math.parseInt(l[2]);
+ int dst_row = Math.parseInt(l[3]);
+
+ print("Player = ${e.WhoseMove.toString()}");
+
+ var IsValidMove = e.IsValidMove(src_col, src_row, dst_col, dst_row);
+ print("IsValidMove = ${IsValidMove}");
+
+ if (IsValidMove == true) {
+ var MovePiece = e.MovePiece(src_col, src_row, dst_col, dst_row);
+ print("MovePiece = ${MovePiece}");
+ } else {
+ print("Not valid move");
+ }
+
+ printBoard(e);
+ };
+
+}

0 comments on commit 348bdd7

Please sign in to comment.