//Level selected private void naPicLevel_Click(object sender, EventArgs e) { //Get reference to picture box Utils.nonAntialiasingPictureBox level = (Utils.nonAntialiasingPictureBox)sender; //Extract level number from last two letters of picture ax's name int levelNumber = extractLevelNumberFromName(level.Name); //Checks it is a valid level if (levelNumber > Program.numberOfLevels) { //Tell the user the level is not availible lblTitle.Text = "Coming Soon!"; lblTitle.Refresh(); System.Threading.Thread.Sleep(1000); lblTitle.Text = "Select the level you wish to play"; lblTitle.Refresh(); return; } //Change title to say loading level lblTitle.Text = "Loading Level..."; lblTitle.Refresh(); //Opens level and loads game window if (!Program.SelectLevel(levelNumber - 1)) { //Tell the user they have not completed the previous levels lblTitle.Text = "Complete the previous levels first"; lblTitle.Refresh(); System.Threading.Thread.Sleep(1000); lblTitle.Text = "Select the level you wish to play"; lblTitle.Refresh(); return; } Program.formRef.Show(); this.Hide(); }
//Set details for items used in crafting private void setItemSelectInfo(Utils.nonAntialiasingPictureBox naPicRef, Point Location, string name, Item item) { naPicRef.Location = Location; naPicRef.Size = new Size(itemSelectSize, itemSelectSize); naPicRef.SizeMode = PictureBoxSizeMode.Zoom; naPicRef.BackColor = Color.Transparent; naPicRef.Name = name; naPicRef.Image = item.sprite; naPicRef.Click += new System.EventHandler(itemSelectClickedOn); }
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++; } }
//Load up tools at top private void CraftingWindow_Load(object sender, EventArgs e) { Utils.nonAntialiasingPictureBox naPicSwordSelect = new Utils.nonAntialiasingPictureBox(); setItemSelectInfo(naPicSwordSelect, new Point(40, 60), "SwordSelect", ItemOperators.extractControlFromType(ItemTypes.Sword)); Utils.nonAntialiasingPictureBox naPicSpadeSelect = new Utils.nonAntialiasingPictureBox(); setItemSelectInfo(naPicSpadeSelect, new Point(40 + (itemSelectSize + 32), 60), "SpadeSelect", ItemOperators.extractControlFromType(ItemTypes.Spade)); Utils.nonAntialiasingPictureBox naPicAxeSelect = new Utils.nonAntialiasingPictureBox(); setItemSelectInfo(naPicAxeSelect, new Point(40 + (itemSelectSize + 32) * 2, 60), "AxeSelect", ItemOperators.extractControlFromType(ItemTypes.Axe)); this.Controls.Add(naPicSwordSelect); this.Controls.Add(naPicSpadeSelect); this.Controls.Add(naPicAxeSelect); }
private void MenuScreen_Load(object sender, EventArgs e) { Utils.nonAntialiasingPictureBox background = new Utils.nonAntialiasingPictureBox(); background.BackgroundImage = this.BackgroundImage; background.Location = new Point(0, 0); background.Size = this.ClientSize; this.Controls.Add(background); background.BringToFront(); Label lblGender = new Label(); lblGender.Text = "Are You"; lblGender.BackColor = Color.Transparent; lblGender.ForeColor = Color.White; lblGender.Size = new Size(200, 60); lblGender.TextAlign = ContentAlignment.MiddleCenter; lblGender.Font = new Font("Times new Roman", 32, FontStyle.Bold); lblGender.Location = new Point((this.ClientSize.Width / 2) - (lblGender.Size.Width / 2), (this.ClientSize.Height / 2) - (lblGender.Size.Height / 2)); this.Controls.Add(lblGender); lblGender.BringToFront(); lblGender.Show(); Button btnFemale = new Button(); btnFemale.Text = "Female"; btnFemale.Font = new Font("Times new Roman", 24, FontStyle.Bold); btnFemale.Size = new Size(130, 50); btnFemale.Location = new Point((this.ClientSize.Width / 2) + (btnFemale.Size.Width / 4), (this.ClientSize.Height / 2) - (lblGender.Size.Height / 2) + (lblGender.Height)); this.Controls.Add(btnFemale); btnFemale.BringToFront(); btnFemale.Show(); btnFemale.TabStop = false; btnFemale.Click += btnFemale_Click; Button btnMale = new Button(); btnMale.Text = "Male"; btnMale.Font = new Font("Times new Roman", 24, FontStyle.Bold); btnMale.Size = btnFemale.Size; btnMale.Location = new Point((this.ClientSize.Width / 2) - (btnMale.Size.Width) - (btnMale.Size.Width / 4), (this.ClientSize.Height / 2) - (lblGender.Size.Height / 2) + (lblGender.Height)); this.Controls.Add(btnMale); btnMale.BringToFront(); btnMale.Show(); btnMale.TabStop = false; btnMale.Click += btnMale_Click; background.Tag = "Gender"; lblGender.Tag = "Gender"; btnMale.Tag = "Gender"; btnFemale.Tag = "Gender"; }
//Adds footer button to form private void addFooterButton(string name, int distanceAlong, Image image, System.EventHandler eventHandler) { //Add footer button Utils.nonAntialiasingPictureBox naPicRef = new Utils.nonAntialiasingPictureBox(); naPicRef.Name = name; this.Controls.Add(naPicRef); naPicRef.Parent = this.lblFooter; naPicRef.Location = new Point(distanceAlong, 5); naPicRef.Size = new Size(footerHeight - 10, footerHeight - 10); naPicRef.Image = image; naPicRef.SizeMode = PictureBoxSizeMode.Zoom; naPicRef.BackColor = Color.Transparent; naPicRef.Click += eventHandler; naPicRef.Show(); }
//Displays inventory private void InventoryWindow_Load(object sender, EventArgs e) { //Maximum number of items in inventory is 100 /*if (levelHandler.player.inventory.Count == 0) * { * this.lblEmpty.Show(); * return; * } * int number = 0; * int numberX = 10; * int size = 34; * foreach (Item item in levelHandler.player.inventory) * { * int x = 16 + (size + 16) * (number % numberX); * int y = 16 + (size + 16) * (number / numberX); * Utils.nonAntialiasingPictureBox naPicRef = new Utils.nonAntialiasingPictureBox(); * this.Controls.Add(naPicRef); * naPicRef.Location = new Point(x, y); * naPicRef.Size = new Size(size, size); * naPicRef.Image = item.sprite; * naPicRef.SizeMode = PictureBoxSizeMode.Zoom; * naPicRef.BackColor = Color.Transparent; * naPicRef.Show(); * number++; * }*/ int size = 120; int numberX = 4; int index = 0; //Loop through each item and get how many of that item the player has foreach (ItemTypes item in Enum.GetValues(typeof(ItemTypes))) { if (item == ItemTypes.Relic && levelHandler.relic == null) { continue; } int number = 0; //Calculate how many of that item the player has while (levelHandler.player.HasItem(item, number + 1)) { number++; } //Get coordinates at which to set it int x = 10 + (size + 4) * (index % numberX); int y = 10 + (size + 4) * (index / numberX); Utils.nonAntialiasingPictureBox naPicRef = new Utils.nonAntialiasingPictureBox(); this.Controls.Add(naPicRef); naPicRef.Location = new Point(x, y); naPicRef.Size = new Size(size, size); naPicRef.Image = ItemOperators.extractControlFromType(item).sprite; naPicRef.SizeMode = PictureBoxSizeMode.Zoom; naPicRef.BackColor = Color.Transparent; naPicRef.Show(); System.Windows.Forms.Label lblCount = new System.Windows.Forms.Label(); this.Controls.Add(lblCount); lblCount.Parent = naPicRef; lblCount.Location = new Point(naPicRef.Width - (size / 2), naPicRef.Height - (size / 6)); lblCount.Size = new Size(size / 2, size / 6); lblCount.Text = number.ToString(); lblCount.Font = new Font("Times New Roman", 12, lblCount.Font.Style); lblCount.TextAlign = ContentAlignment.MiddleRight; lblCount.ForeColor = Color.White; lblCount.BackColor = Color.Transparent; lblCount.Show(); index++; } }
//Checks private void itemSelectClickedOn(object sender, EventArgs e) { //Console.WriteLine("Item Selected"); //Get reference to item or tool being selected Utils.nonAntialiasingPictureBox itemSelected = (Utils.nonAntialiasingPictureBox)sender; //Add new 'items required' if tool is clicked on if (itemSelected.Name.Contains("Select")) { toolToCraft = itemSelected; List <ItemTypes> required = extractRequiredItems(itemSelected.Name); int multiplier = 0; itemInSlots = 0; //Remove previous 'items required' for (int i = this.Controls.Count - 1; i >= 0; i--) { Control control = this.Controls[i]; if (control.Name.Contains("Collect") || control.Name.Contains("Craft")) { this.Controls.Remove(control); } } //Add new items required foreach (ItemTypes itemType in required) { Item item = ItemOperators.extractControlFromType(itemType); Utils.nonAntialiasingPictureBox itemReq = new Utils.nonAntialiasingPictureBox(); setItemSelectInfo(itemReq, new Point(40 + (itemSelectSize + 32) * multiplier /*algebra - YEAH!*/, lblRequiredItemsTitle.Bottom + 10), itemType.ToString() + "ToCollect", item); multiplier++; this.Controls.Add(itemReq); } } //Moves item to crafting 'equation' if player has it else if (itemSelected.Name.Contains("ToCollect")) { ItemTypes itemType = extractRequiredItemType(itemSelected.Name); int spot = (itemSelected.Location.X - 40) / (itemSelectSize + 32); if (levelHandler.player.HasItem(itemType)) { itemSelected.Hide(); itemSelected.Location = new Point(60 + (140 * spot), 220); itemSelected.Size = new Size(75, 75); itemSelected.Show(); itemInSlots++; itemSelected.Name = itemType.ToString() + "Collected"; //Show output tool if 'equation' is complete if (itemInSlots >= 2) { lblClickHere.Show(); ItemTypes selectedToolType = extractItemToCraft(toolToCraft.Name); Item tool = ItemOperators.extractControlFromType(selectedToolType); Utils.nonAntialiasingPictureBox itemCrafted = new Utils.nonAntialiasingPictureBox(); setItemSelectInfo(itemCrafted, new Point(375, 220), selectedToolType.ToString() + "ToCraft", tool); itemCrafted.Size = new Size(75, 75); itemCrafted.Click += collectItem; this.Controls.Add(itemCrafted); } } } //Move tool out of equation else if (itemSelected.Name.Contains("Collected")) { lblClickHere.Hide(); ItemTypes itemType = extractRequiredItemType(itemSelected.Name); int spot = (itemSelected.Location.X - 60) / 140; itemSelected.Hide(); itemSelected.Location = new Point(40 + (itemSelectSize + 32) * spot, lblRequiredItemsTitle.Bottom + 10); itemSelected.Size = new Size(itemSelectSize, itemSelectSize); itemSelected.Show(); itemInSlots--; itemSelected.Name = itemType.ToString() + "ToCollect"; //Remove equation output if there for (int i = this.Controls.Count - 1; i >= 0; i--) { Control control = this.Controls[i]; if (control.Name.Contains("Craft")) { control.Click -= collectItem; this.Controls.Remove(control); } } } }