Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Mark Beckingham
- Assignment 5
- Mark Beckingham Assihnment 5.cpp
- */
- #include <iostream>
- #include <conio.h>
- using namespace std;
- int main()
- {
- int cox;
- int coy;
- int targetx;
- int targety;
- int torps;
- //Player one's turn
- p1:
- system("CLS");
- torps = 3;
- cout << "Welcome to battleships." << endl;
- cout << "Player 1 please select the co-ordinates for your ship." << endl;
- cx:
- cout << "X = ";
- cin >> cox;
- if (cox > 10 || cox < 0)
- {
- cout << "The grid is 10 by 10, please select a co-ordinate within the grid" << endl;
- cout << "" << endl;
- goto cx;
- }
- cy:
- cout << "Y = ";
- cin >> coy;
- cout << "Player 1's turn over." << endl;
- system("CLS");
- //Player 2's turn
- cout << "Player 2, take you're 1st guess" << endl;
- p2:
- cout << "You have " << torps << "left.";
- cout << "Choose you're co-ordinates" << endl;
- p2x:
- cout << "X = ";
- cin >> targetx;
- if (targetx > 10 || targetx < 0)
- {
- cout << "The grid is 10 by 10, please select a co-ordinate within the grid" << endl;
- cout << "" << endl;
- goto p2x;
- }
- p2y:
- cout << "Y = ";
- cin >> targety;
- if (targety > 10 || targety < 0)
- {
- cout << "The grid is 10 by 10, please select a co-ordinate within the grid" << endl;
- cout << "" << endl;
- goto p2y;
- }
- if (targetx == cox || targety == coy)
- {
- cout << "Congratulations! You sunk player one's battleship!" << endl;
- cout << "Press any key to play again" << endl;
- _getch();
- goto p1;
- }
- }
Add Comment
Please, Sign In to add comment