From 24612b0901b75663fa2a6e96befb63d1220a2094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Fri, 4 Apr 2014 17:28:53 +0200 Subject: [PATCH] Interfaces der DefaultGui angepasst --- src/Backend.cs | 6 +++--- src/DefaultGui/DefaultGui.cs | 23 +++++++++++------------ src/DefaultGui/IBackend.cs | 6 +++--- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/Backend.cs b/src/Backend.cs index f6116ff..3b3ab0d 100644 --- a/src/Backend.cs +++ b/src/Backend.cs @@ -17,17 +17,17 @@ namespace Frontend Rec = new Receiver(Client, Parse); } - public List getDragons() + public IEnumerable getDragons() { return null; } - public List getPlayers() + public IEnumerable getPlayers() { return null; } - public ITile[][] getMap() + public ITile[,] getMap() { return null; } diff --git a/src/DefaultGui/DefaultGui.cs b/src/DefaultGui/DefaultGui.cs index 13a503c..39fb924 100644 --- a/src/DefaultGui/DefaultGui.cs +++ b/src/DefaultGui/DefaultGui.cs @@ -120,14 +120,13 @@ namespace Frontend /// private void board_PaintMap(object sender, System.Windows.Forms.PaintEventArgs e) { Size tileSize = this.getTileSize(); - ITile[][] cells = this.backend.getMap(); + ITile[,] cells = this.backend.getMap(); // validity checked beforehand in getTileSize Debug.Assert(cells != null); BufferedGraphics buffer = BufferedGraphicsManager.Current.Allocate(this.board.CreateGraphics(), this.board.DisplayRectangle); - Graphics g = this.CreateGraphics(); - for(int x = 0; x < cells.Length; x++) { - for(int y = 0; y < cells[x].Length; y++) { - this.drawMapTile(buffer.Graphics, cells[x][y], x * tileSize.Width, y * tileSize.Height, tileSize.Width, tileSize.Height); + for(int x = 0; x < cells.GetLength(0); x++) { + for(int y = 0; y < cells.GetLength(1); y++) { + this.drawMapTile(buffer.Graphics, cells[x,y], x * tileSize.Width, y * tileSize.Height, tileSize.Width, tileSize.Height); } } buffer.Render(); @@ -140,12 +139,12 @@ namespace Frontend /// private void board_PaintEntities(object sender, System.Windows.Forms.PaintEventArgs e) { - List dragons = this.backend.getDragons(); + IEnumerable dragons = this.backend.getDragons(); foreach (IPositionable dragon in dragons) { this.drawDragon(e.Graphics, dragon); } - List players = this.backend.getPlayers(); + IEnumerable players = this.backend.getPlayers(); foreach (IPositionable player in players) { this.drawPlayer(e.Graphics, player); @@ -234,21 +233,21 @@ namespace Frontend /// the size of one tile to fit the whole map on the board protected Size getTileSize() { - IPositionable[][] cells = this.backend.getMap(); + IPositionable[,] cells = this.backend.getMap(); if (cells == null) { throw new ArgumentNullException("backend returned null as map"); } - if (cells.Length == 0) + if (cells.GetLength(0) == 0) { throw new IndexOutOfRangeException("outer dimension of the retrieved map has length 0"); } - if (cells[0].Length == 0) + if (cells.GetLength(1) == 0) { throw new IndexOutOfRangeException("inner dimension of the retrieved map has length 0"); } - int cellWidth = this.board.Size.Width / cells.Length; - int cellHeight = this.board.Size.Height / cells[0].Length; + int cellWidth = this.board.Size.Width / cells.GetLength(0); + int cellHeight = this.board.Size.Height / cells.GetLength(1); return new Size(cellWidth, cellHeight); } diff --git a/src/DefaultGui/IBackend.cs b/src/DefaultGui/IBackend.cs index fbb5280..807fb48 100644 --- a/src/DefaultGui/IBackend.cs +++ b/src/DefaultGui/IBackend.cs @@ -15,18 +15,18 @@ namespace Frontend /// Method to get an arbitrary collection of dragons /// /// a list of dragons that are currently on the map - List getDragons(); + IEnumerable getDragons(); /// /// Method to get an arbitrary collection of players /// /// list of players that are currently on the map - List getPlayers(); + IEnumerable getPlayers(); /// /// Method to get a 2d-grid-representation of the map. The map doesn't actually has to be a 2d-array, but you should /// somehow be able to convert it into one. /// /// a 2d-array of ITiles, representing the map - ITile[][] getMap(); + ITile[,] getMap(); /// /// Sends a command to the server (such as ask:mv:dwn) ///