//Moves the control to new location, preserves state public static void moveControlLocation(Tile toMove, TileTypes replaceWith, Zone zone, Point newLoc) { Point pos = TileOperators.getGridPosition(toMove); int posX = pos.Y; int posY = pos.X; Tile replacement = extractControlFromType(replaceWith, zone); setTileDetails(replacement, toMove.Width, posX, posY); setTileDetails(toMove, toMove.Width, newLoc.X, newLoc.Y); if (zone == Zone.Surface) { levelHandler.currentLevelSurfaceArray[posX, posY] = replacement; if (levelHandler.player.currentZone == Zone.Surface) { Program.formRef.RemoveControl(levelHandler.currentLevelSurfaceArray[newLoc.X, newLoc.Y]); Program.formRef.AddControl(replacement); replacement.Show(); } levelHandler.currentLevelSurfaceArray[newLoc.X, newLoc.Y] = toMove; } else if (zone == Zone.Cave) { levelHandler.currentLevelCaveArray[posX, posY] = replacement; if (levelHandler.player.currentZone == Zone.Cave) { Program.formRef.RemoveControl(levelHandler.currentLevelCaveArray[newLoc.X, newLoc.Y]); Program.formRef.AddControl(replacement); } levelHandler.currentLevelCaveArray[newLoc.X, newLoc.Y] = toMove; } }
//Changes the tile at a specific location, creates a new instance public static void changeTileAtLocation(Tile current, TileTypes replacement, Zone zone) { Point pos = TileOperators.getGridPosition(current); int posY = pos.X;//these must be inverted as the initial Point is inverted due to the initial inversion of the placements int posX = pos.Y; Tile newControl = extractControlFromType(replacement, zone); setTileDetails(newControl, current.Width, posX, posY); if (zone == Zone.Surface) { levelHandler.currentLevelSurfaceArray[posX, posY] = newControl; if (levelHandler.player.currentZone == Zone.Surface) { Program.formRef.RemoveControl(current); Program.formRef.AddControl(newControl); } } else if (zone == Zone.Cave) { levelHandler.currentLevelCaveArray[posX, posY] = newControl; if (levelHandler.player.currentZone == Zone.Cave) { Program.formRef.RemoveControl(current); Program.formRef.AddControl(newControl); } } }
private void uncover(Utils.MessageBox sender, bool result) { if (result && levelHandler.player.HasItem(ItemTypes.Spade)) { levelHandler.player.RemoveItem(ItemTypes.Spade); if (base.baseType == TileTypes.Grass) { TileOperators.changeTileAtLocation(this, TileTypes.Chest, Zone.Surface); } else if (base.baseType == TileTypes.Stone) { TileOperators.changeTileAtLocation(this, TileTypes.Chest, Zone.Cave); } levelHandler.player.callMove(); } else if (base.isInRange())//Player could theoretically move before pressing no { Point pos = TileOperators.getGridPosition(this); levelHandler.player.MovePlayer(pos.X, pos.Y); levelHandler.player.callMove(); } sender.Hide(); Program.formRef.Controls.Remove(sender); sender.Controls.Clear(); sender.Dispose(); }
public void animalAttack() { if (base.baseType == TileTypes.Grass) { TileOperators.changeTileAtLocation(this, base.baseType, Zone.Surface); } else if (base.baseType == TileTypes.Stone) { TileOperators.changeTileAtLocation(this, base.baseType, Zone.Cave); } }
private void HowToPlay_Load(object sender, EventArgs e) { int counter = 0; int tileSize = 32; int labelLength = 132; Dictionary <TileTypes, string> descriptions = new Dictionary <TileTypes, string>(); descriptions.Add(TileTypes.Grass, "Grass, You can walk on it"); descriptions.Add(TileTypes.Tree, "Trees, Cut these down with an axe"); descriptions.Add(TileTypes.Sticks, "Sticks, Collect these to craft tools"); descriptions.Add(TileTypes.Rocks, "Rocks, Collect these to craft tools"); descriptions.Add(TileTypes.Bush, "Bush, Collect berries for food from bushes"); descriptions.Add(TileTypes.Water, "Water, Build a bridge to cross it"); descriptions.Add(TileTypes.Bridge, "Bridges, Create these with a log"); descriptions.Add(TileTypes.Passive, "Cows, Kill these with a sword for food"); descriptions.Add(TileTypes.Hostile, "Tigers, Don't come to close, they will eat you"); descriptions.Add(TileTypes.Treasure, "Treasure, Dig up the relic with a spade"); descriptions.Add(TileTypes.Chest, "Chest, Contains a relic"); descriptions.Add(TileTypes.Home, "Home Village, Your humble abode"); foreach (TileTypes tileType in Enum.GetValues(typeof(TileTypes))) { if (tileType == TileTypes.Cave || tileType == TileTypes.Stone || tileType == TileTypes.Ravine || tileType == TileTypes.Player)//Ignore removed types and player tiles { continue; } Tile tileRef = TileOperators.extractControlFromType(tileType, Zone.Surface); Image image = tileRef.Image; Utils.nonAntialiasingPictureBox tileIcon = new Utils.nonAntialiasingPictureBox(); tileIcon.Image = image; tileIcon.BackColor = Color.Transparent; tileIcon.SizeMode = PictureBoxSizeMode.Zoom; tileIcon.Size = new Size(tileSize, tileSize); tileIcon.Location = new Point((tileSize + labelLength) * (counter / 5) + 10, (tileSize + 5) * (counter % 5) + 300); this.Controls.Add(tileIcon); tileIcon.BringToFront(); tileIcon.Show(); Label lblDescription = new Label(); lblDescription.Text = descriptions[tileType]; lblDescription.BackColor = Color.Transparent; lblDescription.ForeColor = Color.White; lblDescription.Size = new Size(labelLength, tileSize); lblDescription.TextAlign = ContentAlignment.MiddleCenter; lblDescription.Font = new Font("Times new Roman", 9, FontStyle.Italic); lblDescription.Location = new Point((tileSize + labelLength) * (counter / 5) + 10 + tileSize, (tileSize + 5) * (counter % 5) + 300); this.Controls.Add(lblDescription); lblDescription.BringToFront(); lblDescription.Show(); counter++; } }
//TODO Change the zone to cave if implemented private void buildBridge(Utils.MessageBox sender, bool result) { if (result && levelHandler.player.HasItem(ItemTypes.Log)) { TileOperators.changeTileAtLocation(this, TileTypes.Bridge, Zone.Surface); levelHandler.player.RemoveItem(ItemTypes.Log); levelHandler.player.callMove(); } sender.Hide(); Program.formRef.Controls.Remove(sender); sender.Controls.Clear(); sender.Dispose(); }
public void pickUp() { if (base.baseType == TileTypes.Grass) { TileOperators.changeTileAtLocation(this, base.baseType, Zone.Surface); } else if (base.baseType == TileTypes.Stone) { TileOperators.changeTileAtLocation(this, base.baseType, Zone.Cave); } levelHandler.player.CollectItem(ItemTypes.Rock); levelHandler.player.callMove(); }
private void cutDown(Utils.MessageBox sender, bool result) { if (result && levelHandler.player.HasItem(ItemTypes.Axe))//It is possible for the player to use the item before pressing yes. { TileOperators.changeTileAtLocation(this, base.baseType, Zone.Surface); levelHandler.player.RemoveItem(ItemTypes.Axe); levelHandler.player.CollectItem(ItemTypes.Log); levelHandler.player.callMove(); } sender.Hide(); Program.formRef.Controls.Remove(sender); sender.Controls.Clear(); sender.Dispose(); }
public override void playerAction() { if (path != null) { Point curLoc = TileOperators.getGridPosition(this); //Get the reversed path location int revPathLoc = (pathLoc + (reversed ? 1 : -1)) % path.Length; if (revPathLoc < 0) { revPathLoc = path.Length - 1; } AnimalMovementHandler.Request request = new AnimalMovementHandler.Request(new Point(curLoc.Y, curLoc.X), getMovementLocation(pathLoc, false), getMovementLocation(revPathLoc, true), new AnimalMovementHandler.movementHandlerCallBack(movementCallBack), new AnimalMovementHandler.movementHandlerDeathCallBack(animalAttack), 0); AnimalMovementHandler.requestMovement(request); } }
//Default Clicked On For Tiles That Are Walkable public virtual void ClickedOn(object sender, EventArgs e) { int tileSize = base.Size.Width; if (isInRange() && isWalkable && //Can Walk On It validActions.Length == 1) // Walking is the only valid option { Point pos = TileOperators.getGridPosition(this); int posX = pos.X; int posY = pos.Y; levelHandler.player.MovePlayer(posX, posY); levelHandler.player.callMove(); } }
//Builds the surface public Tile[,] buildLevelSurface(LevelContainerClass.levelInfo levelInformation) { //Create array to add tiles to Tile[,] controlArray; controlArray = new Tile[levelInformation.width, levelInformation.height]; int caveIndex = 0; // No longer used int tileSize = Math.Min(Program.formWidth, Program.formHeight) / Math.Max(levelInformation.width, levelInformation.height); //Set the tiles to be the size of the smallest dimension of the space it is in divided by the longest side of level //Loop every tile for (int x = 0; x < levelInformation.width; x++) { for (int y = 0; y < levelInformation.height; y++) { //Handle player seperately if (levelInformation.surface[x, y] == TileTypes.Player) { //Assume player is on grass controlArray[x, y] = TileOperators.extractControlFromType(TileTypes.Grass, Zone.Surface); //Create the player player = new Player(TileTypes.Grass); player.hiddenControl = controlArray[x, y]; player.BringToFront(); //Sets the playersdetails TileOperators.setTileDetails(player, tileSize, 0, 0); //Override the players location player.Location = new System.Drawing.Point(0, 0); } else { //Extract the tile at this location controlArray[x, y] = TileOperators.extractControlFromType(levelInformation.surface[x, y], Zone.Surface); //Set cave ID - Not used if (levelInformation.surface[x, y] == TileTypes.Cave) { Cave cave = (Cave)controlArray[x, y]; cave.SetId(levelInformation.surfaceCaveId[caveIndex]); caveIndex++; } } //Set details of the tile at current location TileOperators.setTileDetails(controlArray[x, y], tileSize, x, y); } } //Return initialised level return(controlArray); }
//Checks if the player can interact with the tile public bool isInRange() { Point curPos = TileOperators.getGridPosition(this); int curPosX = curPos.X; int curPosY = curPos.Y; Point playerPos = TileOperators.getGridPosition(levelHandler.player.hiddenControl); int playerPosX = playerPos.X; int playerPosY = playerPos.Y; if (Math.Abs(playerPosX - curPosX) > 1 || // X is more than one away Math.Abs(playerPosY - curPosY) > 1 || // Y is more than one away Math.Abs(playerPosX - curPosX) == Math.Abs(playerPosY - curPosY) // Not On a diagonal or the player's tile ) { return(false); } return(true); }
public override void ClickedOn(object sender, EventArgs e) { if (base.isInRange()) { if (levelHandler.player.HasItem(ItemTypes.Spade)) { Utils.MessageBox messageBox = new Utils.MessageBox(Program.formRef.ClientSize, global::TileGamePrototype.Properties.Resources.WoodTexture); Program.formRef.Controls.Add(messageBox); messageBox.BringToFront(); messageBox.ShowMessageBox("Do you wish to uncover the treasure?", new Utils.MessageBox.DialogResultCallBack(uncover)); } else { Point pos = TileOperators.getGridPosition(this); levelHandler.player.MovePlayer(pos.X, pos.Y); levelHandler.player.callMove(); } } }
private void attack(Utils.MessageBox sender, bool result) { if (result && levelHandler.player.HasItem(ItemTypes.Sword)) { levelHandler.player.RemoveItem(ItemTypes.Sword); levelHandler.player.CollectItem(ItemTypes.Meat); if (base.baseType == TileTypes.Grass) { TileOperators.changeTileAtLocation(this, base.baseType, Zone.Surface); } else if (base.baseType == TileTypes.Stone) { TileOperators.changeTileAtLocation(this, base.baseType, Zone.Cave); } levelHandler.player.callMove(); } sender.Hide(); Program.formRef.Controls.Remove(sender); sender.Controls.Clear(); sender.Dispose(); }
public void movementCallBack(bool reversed) { if (reversed) { this.reversed = !this.reversed; } Point loc = getMovementLocation(pathLoc, this.reversed); pathLoc += (!this.reversed) ? 1 : -1; if (pathLoc < 0) { pathLoc = path.Length - 1; } if (pathLoc >= path.Length) { pathLoc = 0; } if (reversed) { loc = getMovementLocation(pathLoc, this.reversed); } TileOperators.moveControlLocation(this, this.baseType, (this.baseType == TileTypes.Stone) ? Zone.Cave : Zone.Surface, loc); }
public Point getMovementLocation(int pathLocAlt, bool reversed) { Point loc = TileOperators.getGridPosition(this); int modifier = reversed ? 2 : 0; // Switches direction when going backward through the path if ((path[pathLocAlt] + modifier - 1) % 4 + 1 == 1) //Up { loc.Y--; } else if ((path[pathLocAlt] + modifier - 1) % 4 + 1 == 2)//Right { loc.X++; } else if ((path[pathLocAlt] + modifier - 1) % 4 + 1 == 3)//Down { loc.Y++; } else if ((path[pathLocAlt] + modifier - 1) % 4 + 1 == 4)//Left { loc.X--; } return(new Point(loc.Y, loc.X));//Needs Flipped }
public void attackNeighbouringTiles() { if (base.isInRange()) { levelHandler.requestPlayersBrutallyPainfulDeath(); return; } Point curLoc = TileOperators.getGridPosition(this); for (int i = -1; i <= 2; i += 2) { if (curLoc.Y + i < 0 || curLoc.Y + i >= levelHandler.currentLevelSurfaceArray.GetLength(0)) { continue; } Tile neighbour = levelHandler.currentLevelSurfaceArray[curLoc.Y + i, curLoc.X]; if (neighbour.GetType().ToString() == (TileOperators.extractControlFromType(TileTypes.Passive, Zone.Surface)).GetType().ToString()) { PassiveAnimal animal = (PassiveAnimal)neighbour; animal.animalAttack(); } } for (int i = -1; i <= 2; i += 2) { if (curLoc.X + i < 0 || curLoc.X + i >= levelHandler.currentLevelSurfaceArray.GetLength(1)) { continue; } Tile neighbour = levelHandler.currentLevelSurfaceArray[curLoc.Y, curLoc.X + i]; if (neighbour.GetType().ToString() == (TileOperators.extractControlFromType(TileTypes.Passive, Zone.Surface)).GetType().ToString()) { PassiveAnimal animal = (PassiveAnimal)neighbour; animal.animalAttack(); } } }
//Checks if the player has meet the requirements for the given objective public static bool meetsRequirements(ObjectiveTypes objective) { int countRequired = getObjectiveOccurances(levelHandler.objectives, objective); if (countRequired == 0) { return(true); } switch (objective) { case ObjectiveTypes.FindFood: for (int i = 0; i <= countRequired; i++) { if (levelHandler.player.HasItem(ItemTypes.Meat, i) && levelHandler.player.HasItem(ItemTypes.Berries, countRequired - i)) { return(true); } } return(false); case ObjectiveTypes.ReturnHome: //Shouldn't be handled by this, should be handled by the act of entering the village, as it cannot be done without all other objectives being complete if (levelHandler.player.hiddenControl.GetType().ToString() == TileOperators.extractControlFromType(TileTypes.Home, Zone.Surface).GetType().ToString()) { return(true); } else { return(false); } case ObjectiveTypes.CollectItem: Dictionary <ItemTypes, int> countPerItem = new Dictionary <ItemTypes, int>(); foreach (ItemTypes itemType in levelHandler.itemsToCollect) { if (countPerItem.ContainsKey(itemType)) { countPerItem[itemType]++; } else { countPerItem.Add(itemType, 1); } } foreach (ItemTypes itemType in Enum.GetValues(typeof(ItemTypes))) { //Check if the item has an entry in the dictionary int val; if (!countPerItem.TryGetValue(itemType, out val)) { continue; } if (!levelHandler.player.HasItem(itemType, val)) { return(false); } } return(true); case ObjectiveTypes.ObtainRelic: if (levelHandler.player.HasItem(ItemTypes.Relic, countRequired)) { return(true); } else { return(false); } default: return(false); } }
public void pickUp() { TileOperators.changeTileAtLocation(this, base.baseType, Zone.Surface); levelHandler.player.CollectItem(ItemTypes.Berries); levelHandler.player.callMove(); }
//Key down event private void GameForm_KeyDown(object sender, KeyEventArgs e) { //If message box is shown this will be disabled if (disableKeyPress) { return; } //Gets players location Point loc = TileOperators.getGridPosition(levelHandler.player.hiddenControl); //Up if (e.KeyCode == Keys.Up) { if (loc.Y > 0 && move) { levelHandler.currentLevelSurfaceArray[loc.Y - 1, loc.X].ClickedOn(this, EventArgs.Empty); } move = false; } //Down else if (e.KeyCode == Keys.Down) { if (loc.Y < levelHandler.currentLevelSurfaceArray.GetLength(0) - 1 && move) { levelHandler.currentLevelSurfaceArray[loc.Y + 1, loc.X].ClickedOn(this, EventArgs.Empty); } move = false; } //Left else if (e.KeyCode == Keys.Left) { if (loc.X > 0 && move) { levelHandler.currentLevelSurfaceArray[loc.Y, loc.X - 1].ClickedOn(this, EventArgs.Empty); } move = false; } //Right else if (e.KeyCode == Keys.Right) { if (loc.X < levelHandler.currentLevelSurfaceArray.GetLength(1) - 1 && move) { levelHandler.currentLevelSurfaceArray[loc.Y, loc.X + 1].ClickedOn(this, EventArgs.Empty); } move = false; } //Inventory Shortcut else if (e.KeyCode == Keys.I) { Inventory(null, EventArgs.Empty); } //Crafting shortcut else if (e.KeyCode == Keys.C) { Combine(null, EventArgs.Empty); } //Menu shortcut else if (e.KeyCode == Keys.M || e.KeyCode == Keys.Escape) { ReturnToMenu(null, EventArgs.Empty); } //Help shortcut else if (e.KeyCode == Keys.H) { Help(null, EventArgs.Empty); } //Restart level else if (e.KeyCode == Keys.R) { levelHandler.restartLevel(); } //Developer hack /*else * { * Program.NextLevel(); * }*/ }