public void OnKeyButtonDown(object sender, KeyEventArgs e) { var keyCode = e.Key.ToString(); var direction = string.Empty; switch (keyCode) { case "Up": this.NewDirection = Directions.UP; break; case "Down": this.NewDirection = Directions.DOWN; break; case "Left": this.NewDirection = Directions.LEFT; break; case "Right": this.NewDirection = Directions.RIGHT; break; default: this.NewDirection = Directions.NONE; break; } }
public Input(Window applicationWindow, IMapRenderer maprenderer) { this._ApplicationWindow = applicationWindow; this._MapRenderer = maprenderer; this._ApplicationWindow.KeyDown += new KeyEventHandler(OnKeyButtonDown); this.NewDirection = Directions.NONE; }
public Game(Canvas displayCanvas, Window applicationwindow) { GameLevel = 1; GameScore = 0; PlayerLives = 3; /* * this._Tiles = new string[][]{ * new string []{"1", "1" , "1" , "1" , "1" , "1" , "1" , "1" , "1" }, * new string []{"1", "0" , "0" , "0" , "0" , "0" , "0" , "0" , "1" }, * new string []{"1", "0" , "0" , "0" , "0" , "0" , "0" , "0" , "1" }, * new string []{"1", "0" , "0" , "0" , "0" , "0" , "0" , "0" , "1" }, * new string []{"1", "1" , "1" , "1" , "1" , "1" , "1" , "1" , "1" }};*/ LoadLevel(); this._DisplayCanvas = displayCanvas; this._MapRenderer = new CanvasMapRenderer(this._DisplayCanvas, new Geom.Rectangle(0, 0, 88, 88)); this._Input = new Input(applicationwindow, _MapRenderer); this._Invalid = true; this._PlayerPosition = new Geom.Point(1, 1); Timer.Interval = new TimeSpan(0, 0, 0, 0, 24); Timer.Tick += new EventHandler(Update); Timer.Start(); }
public void Move(Geom.Point newDirection) { Geom.Point tmpPoint = this._PlayerPosition.Clone(); tmpPoint.x += newDirection.x; tmpPoint.y += newDirection.y; string tile = this._Map.GetTileType(tmpPoint); switch (tile) { case "0": this._PlayerPosition = tmpPoint; this._Invalid = true; break; case "2": this._PlayerPosition = tmpPoint; this._Invalid = true; this._Map.PickupDiamond(this._PlayerPosition); break; case "3": this._PlayerPosition = tmpPoint; this._Invalid = true; this._Map.Die(this._PlayerPosition); EnemyHit(); Relocate(new Geom.Point(1, 1)); break; case "4": this._PlayerPosition = tmpPoint; this._Invalid = true; GameLevel++; LoadLevel(); break; case "5": this._PlayerPosition = tmpPoint; this._Invalid = true; break; case "6": this._PlayerPosition = tmpPoint; this._Invalid = true; break; } }
public void Die(Geom.Point playerPosition) { this._Tiles[playerPosition.x][playerPosition.y] = "1"; Game.GameScore = Game.GameScore - 200; }
public void PickupDiamond(Geom.Point playerPosition) { this._Tiles[playerPosition.x][playerPosition.y] = "0"; Game.GameScore = Game.GameScore + 100; }
public string GetTileType(Geom.Point point) { return(this._Tiles[point.x][point.y].ToString()); }
public void Clear() { this.NewDirection = Directions.NONE; }
public void Relocate(Geom.Point location) { _PlayerPosition = location; }