/// <summary> /// Calling this function will add another sheep on the desktop, if MAX_SHEEP was not reached. /// </summary> public void AddSheep() { if (iSheeps < MAX_SHEEPS) { var newSheep = new FormPet(animations, xml); foreach (var sprite in xml.sprites) { newSheep.AddImage(sprite); } sheeps[iSheeps] = newSheep; sheeps[iSheeps].Show(xml.spriteWidth, xml.spriteHeight); AddDebugInfo(DEBUG_TYPE.info, "new pet..."); AddDebugInfo(DEBUG_TYPE.info, xml.sprites.Count.ToString() + " frames added"); // Start the animation of the pet sheeps[iSheeps].Play(true); iSheeps++; } else { AddDebugInfo(DEBUG_TYPE.warning, "max PETs reached"); } }
/// <summary> /// Close a single sheep on the desktop. /// </summary> /// <param name="sheep">The sheep-form to close.</param> public bool KillSheep(FormPet sheep) { bool bSheepRemoved = false; AddDebugInfo(DEBUG_TYPE.info, "Kill one sheep"); for (int i = 0; i < iSheeps; i++) { if (sheeps[i] == sheep) { sheeps[i].Kill(); for (int j = i; j < iSheeps - 1; j++) { sheeps[j] = sheeps[j + 1]; } iSheeps--; Application.DoEvents(); bSheepRemoved = true; break; } } /* * This will close application if all Sheeps are removed. But Maybe the user want see the try icon to add a sheep later. * Maybe in future you can choose 0 to 10 sheeps at startup, so this is commented out for the moment. * if (iSheeps <= 0) * { * timer1.Tag = "0"; * pi.Dispose(); * * timer1.Interval = 1100; * timer1.Enabled = true; * } */ return(bSheepRemoved); }