/* * Process the taking of fire from the enemy */ public void TakingFire() { lock (pblock) { int p; String resp; ObjectMovement m; // loop through and take fire from Klingons based on their health for (int s = 0; s < starObjects.Count(); s++) { p = starObjects.ElementAt(s).Health; if (starObjects.ElementAt(s).Type == KLINGON && p > 0) { // disrupter fire from klingon ship p = GameUtility.HitPower(starObjects.ElementAt(s), game.SRS, (int)p); // create update on hit m = new ObjectMovement(-KLINGON, "F" + p + " point hit from Klingon at (" + (starObjects.ElementAt(s).Row + 1) + "," + (starObjects.ElementAt(s).Col + 1) + ")", starObjects.ElementAt(s).Row, starObjects.ElementAt(s).Col); moveObjects.Add(m); m = new ObjectMovement(-KLINGON, "F", starObjects.ElementAt(s).Row, starObjects.ElementAt(s).Col); moveObjects.Add(m); m = new ObjectMovement(-KLINGON, "F", starObjects.ElementAt(s).Row, starObjects.ElementAt(s).Col); moveObjects.Add(m); m = new ObjectMovement(KLINGON, "F", starObjects.ElementAt(s).Row, starObjects.ElementAt(s).Col); moveObjects.Add(m); resp = game.DamageControl.takingDamage(p); if (resp.Length > 0) { m = new ObjectMovement(0, "C" + resp, -1, -1); moveObjects.Add(m); } } } } }
/* * Create the list of movement animation actions * */ public int SetObjectMovement(int fromRow, int fromCol, List <Track> track, int distance) { // initialize everything int type = game.SRS.GetShortRangeSensors(fromRow, fromCol); int trackIndex = 0; int r, c, t; int dist = 0; bool done = false; bool animate = game.IsUsingAnimation(); int lastr = fromRow; int lastc = fromCol; int currentLoc = game.GameBoard.getMyLocation(); int gbLimit = game.GameBoard.GetSize() - 1; ObjectMovement m; // movement only works if there is a ship in the cell if (type == KLINGON || type == ENTERPRISE) { // If it's the enterprise, and distance is negative, we're // firing a torpedo down the listed track if (type == 4 && distance < 0) { // firing a torpedo! type = TORPEDO; distance = 99; if (!animate) { m = new ObjectMovement(0, "CTorpedo Track", 0, 0); moveObjects.Add(m); } } // move the object along the track, stopping if it runs into something while (!done) { r = track.ElementAt(trackIndex).Row; c = track.ElementAt(trackIndex).Col; if (r >= 0 && r < 10 && c >= 0 && c < 10) { if (r != fromRow || c != fromCol) { // we don't want to mess with starting location dist++; //get what's in the cell along this track t = game.SRS.GetShortRangeSensors(r, c); if (t > 0) { // there is something at this location, so the // track ends here and something may happen switch (type) { case ENTERPRISE: // enterprise ran into something, stop engines m = new ObjectMovement(0, "CMr Scot says, 'Engines shut down to prevent collision.'", -1, -1); moveObjects.Add(m); break; case TORPEDO: // torpedo ran into something, make it go away m = new ObjectMovement(t, "CChekov yells, 'Direct hit, Kiptan!'", r, c); moveObjects.Add(m); for (int i = 0; i < starObjects.Count(); i++) { if (starObjects.ElementAt(i).Row == r && starObjects.ElementAt(i).Col == c) { // deliver 76 = 125 hit points so that klingons USUALLY die starObjects.ElementAt(i).Health -= Dice.roll(50) + 75; // did we destroy it? if (starObjects.ElementAt(i).Health < 1) { m = new ObjectMovement(t, "D", r, c); moveObjects.Add(m); } } } break; } // track ends done = true; } else { // nothing found along the track (yet) so // continue the movement animation if (type == ENTERPRISE) { m = new ObjectMovement(ENTERPRISE, "R", game.SRS.GetMyRow(), game.SRS.GetMyCol()); moveObjects.Add(m); m = new ObjectMovement(ENTERPRISE, "A", r, c); moveObjects.Add(m); game.SRS.SetMyRow(r); game.SRS.SetMyCol(c); } else if (type != TORPEDO) { m = new ObjectMovement(type, "R", lastr, lastc); moveObjects.Add(m); m = new ObjectMovement(type, "A", r, c); moveObjects.Add(m); } else { m = new ObjectMovement(TORPEDO, "A", r, c); moveObjects.Add(m); moveObjects.Add(m); m = new ObjectMovement(TORPEDO, "R", r, c); moveObjects.Add(m); if (!animate) { m = new ObjectMovement(0, "C (" + (r + 1).ToString() + "," + (c + 1).ToString() + ")", 0, 0); moveObjects.Add(m); } } } lastr = r; lastc = c; } } else { // the track takes us out of the sector, torpedos just sail away // klingons will stop and the enterprise goes to a different sector // if we're not at the edge of the galaxy switch (type) { case ENTERPRISE: int lr, lc; int rfix = 0; int cfix = 0; // moving into other sector while (!done) { dist++; lr = currentLoc / game.GameBoard.GetSize(); lc = currentLoc % game.GameBoard.GetSize(); // are we trying to leave the galaxy? if (lr < 0 || lc < 0 || lr > gbLimit || lc > gbLimit) { m = new ObjectMovement(0, "CImpulse engines shut down at galactic border.", -1, -1); moveObjects.Add(m); done = true; } // continue to track through to the next sector(s) // rfix & cfix make sure the track appears to be in the grid // and when it leaves the grid, the sector location and fix // values are updated if (!done) { currentLoc += (r + rfix < 0 ? -game.GameBoard.GetSize() : (r + rfix >= 10 ? game.GameBoard.GetSize() : 0)); currentLoc += (c + cfix < 0 ? -1 : (c + cfix >= 10 ? 1 : 0)); rfix += (r + rfix >= 10 ? -10 : 0); rfix += (r + rfix < 0 ? 10 : 0); cfix += (c + cfix >= 10 ? -10 : 0); cfix += (c + cfix < 0 ? 10 : 0); // have we gone the requested distance? if (dist < distance) { // we're just calculating moves, not showing trackIndex++; r = (track.ElementAt(trackIndex).Row); c = (track.ElementAt(trackIndex).Col); } else { // we're done, so set up the Location command m = new ObjectMovement(currentLoc, "L", r + rfix, c + cfix); moveObjects.Add(m); done = true; } } } break; case TORPEDO: m = new ObjectMovement(0, "CYou watch the torpedo sailing out of the sector; a clean miss!", -1, -1); moveObjects.Add(m); done = true; break; } } trackIndex++; // we're done if we run out of track or we go the expected distance done = (done || trackIndex >= track.Count() || dist >= distance); } } // Impulse burns power and time if (type == ENTERPRISE) { game.GameBoard.StarDateAdd(((double)dist) * 0.1); game.AdjustEnergy(dist * -0.1); } return(dist); // actual distance traveled }