private void level2() { //fill the grid with blank squares for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { drawContents("Images\\path.bmp", x, y); } } Window.obstacles.Clear(); Levels populateGrid = new Levels(Window); //placing mario in row 0 , colum 0 initially Window.box = new Box(); Window.wullie = new Wullie(); //initialise coordinates Window.winLocation = new Coordinate(9, 9); Window.wullie.WullieLocation = new Coordinate(0, 0); Window.wullie.TargetLocation = new Coordinate(); Window.box.BoxLocation = new Coordinate(1, 1); //draw contents on grid drawContents("Images\\Wullie.bmp", Window.wullie.WullieLocation); drawContents("Images\\bin1.BMP", 10, 10); drawContents("Images\\union.bmp", Window.box.BoxLocation.Row, Window.box.BoxLocation.Column); //create obstacles. for (int i = 7; i < 10; i++) { Window.obstacles.Add(new Coordinate(i, 3)); } for (int i = 7; i < 10; i++) { for (int o = 0; o < 4; o++) { Window.obstacles.Add(new Coordinate(i, o)); } } for (int i = 1; i < 3; i++) { for (int o = 6; o < 10; o++) { Window.obstacles.Add(new Coordinate(i, o)); } } for (int i = 7; i < 10; i++) { Window.obstacles.Add(new Coordinate(8, i)); } Window.obstacles.Add(new Coordinate(6, 0)); Window.obstacles.Add(new Coordinate(4, 5)); Window.obstacles.Add(new Coordinate(2, 4)); Window.obstacles.Add(new Coordinate(5, 2)); Window.obstacles.Add(new Coordinate(5, 6)); Window.obstacles.Add(new Coordinate(5, 7)); Window.obstacles.Add(new Coordinate(1, 3)); Window.obstacles.Add(new Coordinate(2, 3)); Window.obstacles.Add(new Coordinate(1, 8)); Window.obstacles.Add(new Coordinate(3, 4)); Window.obstacles.Add(new Coordinate(7, 5)); foreach (Coordinate coord in Window.obstacles) { this.drawContents("Images\\wall.Bmp", coord); } //removing an obstacle and placing new one. Window.obstacles.RemoveAll(x => x.Row == 6 && x.Column == 8); drawContents("images\\path.bmp", 6, 8); }
private void level3() { for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { drawContents("Images\\path.bmp", x, y); } } Window.obstacles.Clear(); Levels populateGrid = new Levels(Window); //placing mario in row 0 , colum 0 initially Window.box = new Box(); Window.wullie = new Wullie(); //sets the win location Window.winLocation = new Coordinate(0, 9); //initialises coordinates Window.wullie.WullieLocation = new Coordinate(9, 9); Window.wullie.TargetLocation = new Coordinate(); Window.box.BoxLocation = new Coordinate(2, 2); Window.box.BoxLocation.Row = 8; Window.box.BoxLocation.Column = 1; //draw starting positions drawContents("Images\\Wullie.bmp", Window.wullie.WullieLocation); drawContents("Images\\bin1.BMP", 0, 9); drawContents("Images\\union.bmp", Window.box.BoxLocation.Row, Window.box.BoxLocation.Column); //create obstacles for (int i = 1; i < 9; i++) { Window.obstacles.Add(new Coordinate(i, 9)); } for (int i = 8; i < 10; i++) { Window.obstacles.Add(new Coordinate(i, 6)); Window.obstacles.Add(new Coordinate(i, 7)); } for (int i = 4; i < 6; i++) { Window.obstacles.Add(new Coordinate(7, i)); } for (int i = 0; i < 4; i++) { for (int o = 2; o < 5; o++) { Window.obstacles.Add(new Coordinate(o, i)); Window.obstacles.Add(new Coordinate(o, i)); Window.obstacles.Add(new Coordinate(o, i)); Window.obstacles.Add(new Coordinate(o, i)); Window.obstacles.Add(new Coordinate(o, i)); Window.obstacles.Add(new Coordinate(o, i)); Window.obstacles.Add(new Coordinate(o, i)); } } for (int i = 5; i < 9; i++) { Window.obstacles.Add(new Coordinate(1, i)); Window.obstacles.Add(new Coordinate(2, i)); } for (int i = 0; i < 3; i++) { for (int o = 0; o < 2; o++) { Window.obstacles.Add(new Coordinate(i, o)); } } for (int i = 8; i < 10; i++) { Window.obstacles.Add(new Coordinate(i, 5)); } for (int i = 0; i < 2; i++) { Window.obstacles.Add(new Coordinate(6, i)); Window.obstacles.Add(new Coordinate(9, i)); } for (int i = 5; i < 7; i++) { Window.obstacles.Add(new Coordinate(5, i)); Window.obstacles.Add(new Coordinate(4, i)); } Window.obstacles.Add(new Coordinate(5, 3)); Window.obstacles.Add(new Coordinate(5, 8)); foreach (Coordinate coord in Window.obstacles) { this.drawContents("Images\\wall.Bmp", coord); } }
public void move(string direction) { int i = 0, j = 0; switch (direction) { case "left": i = 0; j = -1; break; case "up": i = -1; j = 0; break; case "right": i = 0; j = 1; break; case "down": i = 1; j = 0; break; default: break; } // if mario is within the boundary if (boundaryCheckWullie(i, j) == true) { //assign mario a grid coordinate Window.wullie.TargetLocation.Row = targetCellRow; Window.wullie.TargetLocation.Column = targetCellColumn; Window.box.boxTargetLocation.Row = targetCellRow + i; Window.box.boxTargetLocation.Column = targetCellColumn + j; //checks to see if Player has won before allowing move if (!Window.box.BoxLocation.Equals(Window.winLocation)) { //checks to see if the target Location contains an obstacle AND that the target location is not a box location if (Window.obstacles.Exists(x => x.Row == Window.wullie.TargetLocation.Row && x.Column == Window.wullie.TargetLocation.Column) == false && !Window.wullie.TargetLocation.Equals(Window.box.BoxLocation)) { PopulateGrid = new Levels(Window); //draw mario in new position PopulateGrid.drawContents("Images\\Wullie.bmp", Window.wullie.TargetLocation); //update the original cell where the mario was to be a blank cell PopulateGrid.drawContents("Images\\path.bmp", Window.wullie.WullieLocation); //redraws the winlocation each time wullie moves PopulateGrid.drawContents("images\\bin1.bmp", Window.winLocation); //update the location of mario to these new co-ordinates Window.wullie.updateLocation(); MoveCount += 1; Window.MoveCount.Text = Convert.ToString(MoveCount); winCheck(Window.box.BoxLocation); } //checks to see if the target location is a box location else if (Window.wullie.TargetLocation.Equals(Window.box.BoxLocation)) { //checks if the obstacle list contains the box's target location. if (Window.obstacles.Exists(x => x.Row == Window.box.boxTargetLocation.Row && x.Column == Window.box.boxTargetLocation.Column) == false) { if (Window.box.boxTargetLocation.Row < 10 && Window.box.boxTargetLocation.Column < 10 && Window.box.boxTargetLocation.Row >= 0 && Window.box.boxTargetLocation.Column >= 0) { PopulateGrid = new Levels(Window); //draw mario in new position PopulateGrid.drawContents("Images\\Wullie.bmp", Window.wullie.TargetLocation); PopulateGrid.drawContents("images\\path.bmp", Window.wullie.WullieLocation); PopulateGrid.drawContents("images\\union.bmp", Window.box.boxTargetLocation); Window.moveables.Add(Window.box); Window.moveables.Add(Window.wullie); //uses polymorphism to update the location for each object foreach (Coordinate x in Window.moveables) { x.updateLocation(); } //update move count MoveCount += 1; Window.MoveCount.Text = Convert.ToString(MoveCount); //check if level is complete winCheck(Window.box.BoxLocation); } } } } } }