-------------------------------------------------------------------------------- PROGRAM BOMBARDMENT -------------------------------------------------------------------------------- LANGUAGES TO IMPLEMENT IN -------------------------------------------------------------------------------- # LANGUAGE IDE -- --------- ---------------------------------------------- 01 Ada GNAT Studio 02 BASIC GW-BASIC 03 C\C++ Visual Studio 2019 04 C# Visual Studio 2019 05 Lua ZeroBrane Studio 06 Pascal Turbo Pascal 07 Python Idle -------------------------------------------------------------------------------- GLOBAL VARIABLES -------------------------------------------------------------------------------- YourGrid(ARRAY OF INTEGERS) your side, 25 slots EnemyGrid(ARRAY OF INTEGERS) enemy side, 25 slots Outposts(ARRAY OF 2 INTEGERS) number of outposts for each side -------------------------------------------------------------------------------- METHODS/FUNCTIONS -------------------------------------------------------------------------------- DisplayRules -------------------------------------------------------------------------------- ACCEPT : NONE RETURN : NONE LOGIC : display the rules as YOU ARE ON A BATTLEFIELD WITH 4 PLATOONS AND YOU HAVE 25 OUTPOSTS AVAILABLE WHERE THEY MAY BE PLACED. YOU CAN ONLY PLACE ONE PLATOON AT ANY ONE OUTPOST. THE COMPUTER DOES THE SAME WITH ITS FOUR PLATOONS. [BLANK LINE] THE OBJECT OF THE GAME IS TO FIRE MISSILES AT THE OUTPOSTS OF THE COMPUTER. IT WILL DO THE SAME TO YOU. THE ONE WHO DESTROYS ALL FOUR OF THE ENEMY'S PLATOONS FIRST IS THE WINNER. [BLANK LINE] GOOD LUCK...AND TELL US WHERE YOU WANT THE BODIES SENT. [BLANK LINE] -------------------------------------------------------------------------------- CheckWinner -------------------------------------------------------------------------------- ACCEPT : NONE RETURN : INTEGER LOGIC : if Outposts(1) = 0 return 2 (computer won) if Outposts(2) = 0 return 1 (player won) otherwise return 0 (no one has one yet) -------------------------------------------------------------------------------- DisplayYourGrid -------------------------------------------------------------------------------- ACCEPT : NONE RETURN : NONE LOGIC : display ======================= YOUR GRID ======================= X | 1 | 2 | 3 | 4 | 5 | Y |---+---+---+---+---| loop x from 1 to 5 set gStart = (x -1) * 5 set gEnd = x * 5 set displayLine = "[x] |" loop g from gStart to gEnd - 1 if YourGrid(g) = -1 add " X |" to displayLine if YourGrid(g) = 1 add " O |" to displayLine else add " |" to displayLine display the displayLine display " |---+---+---+---+---|" -------------------------------------------------------------------------------- DisplayEnemyGrid -------------------------------------------------------------------------------- ACCEPT : NONE RETURN : NONE LOGIC : display ======================= ENEMY GRID ======================= X | 1 | 2 | 3 | 4 | 5 | Y |---+---+---+---+---| loop x from 1 to 5 set gStart = (x -1) * 5 set gEnd = x * 5 set displayLine = "[x] |" loop g from gStart to gEnd - 1 if EnemyGrid(g) = -1 add " X |" to displayLine if EnemyGrid(g) = 1 add " |" to displayLine else add " |" to displayLine display the displayLine display " |---+---+---+---+---|" -------------------------------------------------------------------------------- ClearGrids -------------------------------------------------------------------------------- ACCEPT : NONE RETURN : NONE LOGIC : loop g from 0 to 24 YourGrid(g) = 0 EnemyGrid(g) = 0 -------------------------------------------------------------------------------- SetOutposts -------------------------------------------------------------------------------- ACCEPT : NONE RETURN : NONE LOGIC : set Outposts(1) = 4 (these are how many you have) set outpost to 0 loop o from 0 to 4 DisplayYourGrid set outpostSet = FALSE loop while outpostSet = FALSE display PLACE YOUR OUTPOST #[o + 1] set x = GetIntInput("X") if x < 1 or x > 5 display X MUST BE BETWEEN 1 AND 5. else set y = GetIntInput("Y") if y < 1 or y > 5 display Y MUST BE BETWEEN 1 AND 5. else set outpost = ((y -1) * 5) + (x -1) if YourGrid(outpost) = 0 then set outpostSet = TRUE else display YOU ALREADY HAVE AN OUTPOST THERE. end if end if end if end loop YourGrid(outpost) = 1 end loop -------------------------------------------------------------------------------- ComputerSetOutposts -------------------------------------------------------------------------------- ACCEPT : NONE RETURN : NONE LOGIC : set Outposts(2) = 4 (these are how many enemy has) set outpost to 0 loop o from 0 to 4 set outpostSet = FALSE loop while outpostSet = FALSE set outpost = GenerateRandomNumber(0, 24, false) if EnemyGrid(outpost) = 0 then set outpostSet = TRUE end if end loop EnemyGrid(outpost) = 1 end loop -------------------------------------------------------------------------------- ComputerTurn -------------------------------------------------------------------------------- ACCEPT : NONE RETURN : NONE LOGIC : display MY TURN... set loc = 0 set x = 0 set y = 0 set gotLoc = FALSE loop while gotLoc = FALSE set x = GenerateRandomNumber(1, 5, false) set y = GenerateRandomNumber(1, 5, false) set loc = ((y - 1) * 5) + (x -1) if YourGrid(loc) > -1 then set gotLoc = TRUE end if end loop display ..........BOOM! if YourGrid(loc) = 0 display I MISSED YOU, YOU DIRTY RAT. I PICKED LOCATION ([x],[y]). else display I GOT YOU. IT WON'T BE LONG NOW! OUTPOST AT ([x],[y]) WAS HIT. YourGrid(loc) = -1 Outposts(1) decrease by 1 if Outposts(1) = 3 display YOU ONLY HAVE THREE OUTPOSTS LEFT. if Outposts(1) = 2 display YOU ONLY HAVE TWO OUTPOSTS LEFT. if Outposts(1) = 1 display YOU ONLY HAVE ONE OUTPOST LEFT. if Outposts(1) = 0 display YOU ARE DEAD! YOU HAVE NO OUTPOSTS LEFT. end if -------------------------------------------------------------------------------- FireMissile -------------------------------------------------------------------------------- ACCEPT : NONE RETURN : NONE LOGIC : set x = 0 set y = 0 set gotLoc = FALSE display WHERE DO YOU WANT TO FIRE YOUR MISSILE? loop while gotLoc = FALSE set x = GetIntInput("X") if x < 1 or x > 5 then display PLEASE ENTER A NUMBER BETWEEN 1 AND 5. else set gotLoc = TRUE end if end loop set gotLoc = FALSE loop while gotLoc = FALSE set y = GetIntInput("Y") if y < 1 or y > 5 then display PLEASE ENTER A NUMBER BETWEEN 1 AND 5 else set gotLoc = TRUE end if end loop set loc = ((y -1) * 5) + (x - 1) display ..........BOOM! if EnemyGrid(loc) = -1 display YOU FOOL, YOU ALREADY ATTACKED THERE! else if EnemyGrid(loc) = 0 display HA HA, YOU MISSED! else display YOU GOT ONE OF MY OUTPOSTS! EnemyGrid(loc) = -1 Outposts(2) decreases by 1 if Outposts(2) = 3 display ONE DOWN, THREE TO GO. if Outposts(2) = 2 display TWO DOWN, TWO TO GO. if Outposts(2) = 1 display THREE DOWN, ONE TO GO. if Outposts(2) = 0 display YOU GOT THEM ALL. -------------------------------------------------------------------------------- GAME LOOP VARIABLES -------------------------------------------------------------------------------- turn(INTEGER) turn number -------------------------------------------------------------------------------- Main Logic -------------------------------------------------------------------------------- display *** BOMBARDMENT : [LANGUAGE] *** set turn = 0 if AskToSeeTheRules = TRUE then DisplayRules set Running to TRUE loop while Running = TRUE call ClearGrids call ComputerSetOutposts call SetOutposts set GameOver = FALSE display ---------- LET THE WAR BEGIN ---------- loop while GameOver = FALSE display ----------------------- TURN #[turn + 1] ----------------------- PRESS [ENTER] TO BEGIN YOUR TURN get input if turn MOD 2 = 0 call DisplayYourGrid call DisplayEnemyGrid call FireMissile else call ComputerTurn end if set winner = CheckWinner if winner = 0 then increment turn by 1 else call DisplayYourGrid call DisplayEnemyGrid if winner = 1 then display "YOU WIN!!!" else display "TOO BAD, BETTER LUCK NEXT TIME." end if set GameOver = TRUE end if end loop display "*** GAME OVER ***" set Running = AskToPlayAgain end loop display THANKS FOR PLAYING! --------------------------------------------------------------------------------