daily pastebin goal
57%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*  Mark Beckingham
  2.         Assignment 5
  3.         Mark Beckingham Assihnment 5.cpp
  4. */
  5.  
  6. #include <iostream>
  7. #include <conio.h>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.     int cox;
  14.     int coy;
  15.     int targetx;
  16.     int targety;
  17.     int torps;
  18.  
  19.  
  20.     //Player one's turn
  21. p1:
  22.     system("CLS");
  23.     torps = 3;
  24.     cout << "Welcome to battleships." << endl;
  25.     cout << "Player 1 please select the co-ordinates for your ship." << endl;
  26.     cx:
  27.     cout << "X = ";
  28.     cin >> cox;
  29.  
  30.         if (cox > 10 || cox < 0)
  31.         {
  32.             cout << "The grid is 10 by 10, please select a co-ordinate within the grid" << endl;
  33.             cout << "" << endl;
  34.             goto cx;
  35.         }
  36.  
  37.         cy:
  38.         cout << "Y = ";
  39.         cin >> coy;
  40.  
  41.  
  42.     cout << "Player 1's turn over." << endl;
  43.     system("CLS");
  44.  
  45.  
  46.     //Player 2's turn
  47.     cout << "Player 2, take you're 1st guess" << endl;
  48. p2:
  49.  
  50.     cout << "You have " << torps << "left.";
  51.     cout << "Choose you're co-ordinates" << endl;
  52. p2x:
  53.     cout << "X = ";
  54.     cin >> targetx;
  55.         if (targetx > 10 || targetx < 0)
  56.         {
  57.             cout << "The grid is 10 by 10, please select a co-ordinate within the grid" << endl;
  58.             cout << "" << endl;
  59.             goto p2x;
  60.         }
  61.  
  62. p2y:
  63.     cout << "Y = ";
  64.     cin >> targety;
  65.             if (targety > 10 || targety < 0)
  66.         {
  67.             cout << "The grid is 10 by 10, please select a co-ordinate within the grid" << endl;
  68.             cout << "" << endl;
  69.             goto p2y;
  70.         }
  71.             if (targetx == cox || targety == coy)
  72.             {
  73.                 cout << "Congratulations! You sunk player one's battleship!" << endl;
  74.                 cout << "Press any key to play again" << endl;
  75.                 _getch();
  76.                 goto p1;
  77.             }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. }
RAW Paste Data
Top