private void Check(int x, int y, Dungeon dung, Player creature) // checking if there are a creature on a cell where player tries to move { if (dung.CreatureCheck(creature.X + x, creature.Y + y)) { creature.Attack(dung, dung.GetEnemyAtCoordinates(creature.X + x, creature.Y + y), 1); if (creature.Hp <= 0) { creature.Die(dung); dung.GameOver(); } else if (!dung.CreatureCheck(creature.X + x, creature.Y + y)) { Move(x, y, dung, creature); } } else if (dung.GiveInteraction(creature.X + x, creature.Y + y) == Interaction.UpLadder || dung.GiveInteraction(creature.X + x, creature.Y + y) == Interaction.DownLadder) { if (dung.GiveInteraction(creature.X + x, creature.Y + y) == Interaction.UpLadder) { creature.NextLvl(dung, +1); } else if (dung.GiveInteraction(creature.X + x, creature.Y + y) == Interaction.DownLadder) { creature.NextLvl(dung, -1); } } else { Move(x, y, dung, creature); } }
//Interacting with an object in all 4 directions from player public void Interact(int x, int y, Dungeon dung, Player creature) { for (int i = -1; i < 2; i += 2) { if (dung.GiveInteraction(x + i, y) == Interaction.ClosedChest) { creature.NewItem(dung.GiveItem(x + i, y)); } else if (dung.GiveInteraction(x + i, y) == Interaction.ClosedDoor || dung.GiveInteraction(x + i, y) == Interaction.OpenedDoor) { dung.OpenInteraction(x + i, y); } } for (int j = -1; j < 2; j = j + 2) { if (dung.GiveInteraction(x, y + j) == Interaction.ClosedChest) { creature.NewItem(dung.GiveItem(x, y + j)); } else if (dung.GiveInteraction(x, y + j) == Interaction.ClosedDoor || dung.GiveInteraction(x, y + j) == Interaction.OpenedDoor) { dung.OpenInteraction(x, y + j); } } }
protected void Generation(Dungeon dung) // algorythm for the procedural generation { for (int i = 0; i < 50; i++) // here is where the main dungeon "box" is made { for (int j = 0; j < 50; j++) { if (i == 0 || i == 50 - 1) { _mapTiles[i, j] = SolidTiles.Wall; } else if (i != 0 && i != 50 - 1) { if (j != 0 && j != 50 - 1) { _mapTiles[i, j] = SolidTiles.Floor; } else { _mapTiles[i, j] = SolidTiles.Wall; } } else { Console.WriteLine("Error"); } _mapcoordinates[i, j] = new XY(); } } //x = _mapTiles.GetLength(0) / 2 - rand.Next(-5, 5); int[] horizontal = new int[4]; // arrays for the int[] vertical = new int[4]; // cut points int arrayindex1 = 0; int arrayindex2 = 0; horizontal[arrayindex1] = (_mapTiles.GetLength(0) / 2) - rand.Next(-2, 2); // creating first vertical[arrayindex2] = (_mapTiles.GetLength(1) / 2) + rand.Next(-1, 1); // cut points for (int r = 0; r < 6; r++) // now here is where room starts to show up { i = 1; if (isHorizontal) // checking if it should be the horizontal or vertical cut of the dungeon { while (dung.CheckTile(horizontal[arrayindex1], i) != SolidTiles.Wall) { if (dung.GiveInteraction(horizontal[arrayindex1], i) != Interaction.ClosedDoor) { _mapTiles[horizontal[arrayindex1], i] = SolidTiles.Wall; i++; } } temp = rand.Next(5, i); _mapTiles[horizontal[arrayindex1], temp] = SolidTiles.Floor; _mapcoordinates[horizontal[arrayindex1], temp].AddInteraction(Interaction.ClosedDoor); arrayindex1++; horizontal[arrayindex1] = horizontal[arrayindex1 - 1] / 2; isHorizontal = false; } else if (!isHorizontal) { while (dung.CheckTile(i, vertical[arrayindex2]) != SolidTiles.Wall) { if (dung.GiveInteraction(i, vertical[arrayindex2]) != Interaction.ClosedDoor) { _mapTiles[i, vertical[arrayindex2]] = SolidTiles.Wall; i++; } } temp = rand.Next(5, i); _mapTiles[temp, vertical[arrayindex2]] = SolidTiles.Floor; _mapcoordinates[temp, vertical[arrayindex2]].AddInteraction(Interaction.ClosedDoor); arrayindex2++; vertical[arrayindex2] = vertical[arrayindex2 - 1] / 2; isHorizontal = true; } } EnemyGen(dung.GetLevel()); InteractionGen(dung.GetLevel()); ItemGen(); }