Esempio n. 1
0
 static void Main(string[] args)
 {
     Console.WriteLine("Size: ");
     String input = Console.ReadLine();
     int size = Int32.Parse(input);
     Puzzle puzzle = new Puzzle(size);
     PuzzlePrinter printer = new PuzzlePrinter(puzzle);
     printer.PrintPuzzle();
     while (true)
     {
         Console.WriteLine("Move Target: ");
         input = Console.ReadLine();
         if (input != null)
         {
             if (input.Equals("quit"))
             {
                 break;
             }
             Tile targetTile = printer[input];
             if (targetTile != null)
             {
                 Puzzle.MoveProperties moveProperties = puzzle.MakeMove(targetTile.CurrentPosition);
                 if (moveProperties.Direction != Puzzle.MoveDirection.None)
                 {
                     printer.PrintPuzzle();
                 }
             }
         }
     }
 }
 public MainWindow()
 {
     InitializeComponent();
     Puzzle puzzle = new Puzzle(5);
     PuzzleRenderer puzzleRenderer = new PuzzleRenderer(Canvas,puzzle);
     SizeToContent = SizeToContent.WidthAndHeight;
     ResizeMode = ResizeMode.NoResize;
 }
        public PuzzleRenderer(Canvas canvas,Puzzle puzzle)
        {
            this.canvas = canvas;
            this.puzzle = puzzle;
            canvas.Width = TileRenderer.DefaultWidth * puzzle.Size;
            canvas.Height = TileRenderer.DefaultHeight * puzzle.Size;

            foreach (Tile tile in puzzle.GetAllTiles())
            {
                int tileNumber = tile.TargetPosition.VComponent*puzzle.Size + tile.TargetPosition.HComponent;
                string displayText = tileNumber.ToString(CultureInfo.InvariantCulture);
                TileRenderer tileRenderer = new TileRenderer(canvas, displayText, tile);
                tileRenderer.MouseUp += HandleClick;
                tileToRenderer.Add(tile, tileRenderer);
            }
        }
Esempio n. 4
0
 public PuzzlePrinter(Puzzle puzzle)
 {
     this.puzzle = puzzle;
     for (int i = 0; i < puzzle.Size; i++)
     {
         for (int j = 0; j < puzzle.Size; j++)
         {
             TilePosition position = new TilePosition(i, j);
             if (i == puzzle.Size - 1 && j == puzzle.Size - 1)
             {
                 tileTosting[puzzle[position]] = "#";
                 stringToTile["#"] = puzzle[position];
                 break;
             }
             int tileNumber = (j + (i*puzzle.Size));
             string numberString = tileNumber.ToString();
             tileTosting[puzzle[position]] = numberString;
             stringToTile[numberString] = puzzle[position];
         }
     }
 }
 /// <summary>
 /// Invoked when this page is about to be displayed in a Frame.
 /// </summary>
 /// <param name="e">Event data that describes how this page was reached.  The Parameter
 /// property is typically used to configure the page.</param>
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     puzzle = new Puzzle(6);
     PuzzleRenderer = new PuzzleRenderer(Canvas, puzzle);
     Shuffle();
 }