public void polymorphPlace() { Crate crate = new Crate(currentField); Truck truck = new Truck(currentField); Wall wall = new Wall(); FloorField floorField = new FloorField(); WallField wallField = new WallField(); EmptyField emptyField = new EmptyField(); floorField.Place(crate); wallField.Place(crate); emptyField.Place(crate); }
public void polymorphToChar() { Crate crate = new Crate(currentField); Truck truck = new Truck(currentField); Wall wall = new Wall(); FloorField floorField = new FloorField(); TargetField targetField = new TargetField(); WallField wallField = new WallField(); EmptyField emptyField = new EmptyField(); crate.ToChar(); truck.ToChar(); wall.ToChar(); floorField.ToChar(); wallField.ToChar(); emptyField.ToChar(); targetField.ToChar(); }
private void CreateFields(char[,] charArray, Player p, Game game, Employee employee) { List <Field> fs = new List <Field>(); //Create 2d array with fields Field[,] f = new Field[levelWidth, levelHeight]; for (int x = 0; x < levelWidth; x++) { for (int y = levelHeight - 1; y > -1; y--) { char c = charArray[x, y]; switch (c) { case '#': f[x, y] = new Wall(); fs.Add(f[x, y]); break; case '.': f[x, y] = new Field { Game = game }; fs.Add(f[x, y]); break; case 'o': f[x, y] = new Field { HasCrate = true, Game = game }; f[x, y].Moveable = new Crate { CurrentField = f[x, y] }; fs.Add(f[x, y]); break; case 'x': f[x, y] = new DestinationField { Game = game }; game.DesFieldCounter++; fs.Add(f[x, y]); break; case '~': f[x, y] = new PitfallField(); fs.Add(f[x, y]); break; case '@': f[x, y] = new Field { Moveable = p }; p.CurrentField = f[x, y]; fs.Add(f[x, y]); break; case '$': f[x, y] = new Field { Moveable = employee }; employee.CurrentField = f[x, y]; fs.Add(f[x, y]); break; case ' ': f[x, y] = new EmptyField(); fs.Add(f[x, y]); break; } } } //link the fields with each other for (int x = 0; x < levelWidth; x++) { for (int y = levelHeight - 1; y > 0; y--) { if (x == 0 && first) { firstField2 = f[x, y]; first = false; } if (y != levelHeight - 1) { f[x, y].UpperField = f[x, y + 1]; } if (y != 0) { f[x, y].LowerField = f[x, y - 1]; } if (x != 0) { f[x, y].LeftField = f[x - 1, y]; } if (x != levelWidth - 1) { f[x, y].RightField = f[x + 1, y]; } } } }