From 4a9475dae1139cd7378257476140a9f03af54e2b Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 10 Jul 2016 23:42:01 -0400 Subject: [PATCH 1/4] proposal --- proposal.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 proposal.txt diff --git a/proposal.txt b/proposal.txt new file mode 100644 index 0000000..6ac144c --- /dev/null +++ b/proposal.txt @@ -0,0 +1,6 @@ +Aly Milich + + For my final project I would like to make a battleship game. The rules will be very similar to the classic board game except the user will be able to customize their level and how large/small they would like the board to be. The easier the level, the more ships will be placed on the board (for a higher probability of hitting the ships). Depending on how much time it takes to code the basic parts of the game, I may have the board write to an external file, but I most likely will just print the board and the computer's moves. + This project will use a lot of arrays and conditional statements. The board will be a 2D array and the conditional statements will represent different scenarios, for example if the user hits a ship. It will also use functions so, instead of rewriting what happens when a ship is hit, I can just call a function to change the score/lives. The entire game will be in a loop while the user has ships left. + I would like to make this project because Battleship is a popular game and I think that it combines many of the topics we have covered. I have made many games in the past in Java but this would be my first of this type and in C. + I plan on using the standard input/output library as well as to check if certain conditions are met (like hitting a ship) and to choose random spots to place the ship. These are the only ones I can think of now but I may have to add more as I go. From 48e2b2de149c629e9eb8a62215612feac9989c2f Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 15 Jul 2016 14:51:27 -0400 Subject: [PATCH 2/4] executable --- battleship | Bin 0 -> 13056 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 battleship diff --git a/battleship b/battleship new file mode 100755 index 0000000000000000000000000000000000000000..4b64d7e209df185ef2891458cf27211266087d73 GIT binary patch literal 13056 zcmeHNeQ+DcbzcDdvOYl4v1M8IR9DxGX*YyLiIOS1sR4dS2M;965@|b4Xb=KG0ucxx zz(Jxs8e0xTCn!u?)5cR~S|yx`lW}K~iQ1+eO(r%e%R{EA|Bzd|Ri_`LW^9+V>{gyA zlC0K3e{XLea5#dk+fM%DVsLNYZ{K_S_U+!@?%h7!AK2k^I0PrB_-#R4y1^?U^D2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Z< zXop&m(|*gEY^ Date: Fri, 15 Jul 2016 14:52:15 -0400 Subject: [PATCH 3/4] final project code --- battleship.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 battleship.c diff --git a/battleship.c b/battleship.c new file mode 100644 index 0000000..6b6434b --- /dev/null +++ b/battleship.c @@ -0,0 +1,104 @@ +#include +#include +#include + +/*battleship game + @author Aly Milich + */ + +int main(){ + + int lives=5, xchoice, ychoice, score, boardsize, ships = 4, compxarr[4], compyarr[4]; + + printf("Welcome to Battleship.\n"); + printf("Please input the size of your board (i.e. enter 4 for a 4x4 board)\n"); + + scanf("%d", &boardsize); + + //create board + char board[boardsize][boardsize]; + + int i, j; + + //print board, googled how to do this and found a solution on Stack Overflow + for(i =0; i0 && ships >0){ + + //update board before next turn + for(i=0; i boardsize || ychoice > boardsize){ + printf("Those coordinates are invalid. Please choose values less than or equal to %d\n", boardsize); + printf("Input the row you would like to guess.\n"); + scanf("%d", &xchoice); + + printf("Input the column you would like to guess.\n"); + scanf("%d", &ychoice); + } + + //check if user hit a ship (if guess is in compx or compy arrays. I tried to do this with a loop and it ended up looping the entire thing and causing lives to decrease by 4 with each guess so i just wrote out the possibilities + if(xchoice-1 == compxarr[0]|| xchoice-1 == compxarr[1]||xchoice-1 == compxarr[2]||xchoice-1 == compxarr[3] && ychoice-1 == compyarr[0] || ychoice-1 == compyarr[1] || ychoice-1 == compyarr[2] || ychoice-1 == compyarr[3]){ + printf("You hit a ship!\n"); + ships--; + score++; + printf("There are %d ships left to find.\n", ships); + printf("Score: %d\n", score); + board[xchoice-1][ychoice-1] = 'S'; + } + else{ + printf("You missed.\n"); + lives--; + printf("You have %d lives left.\n", lives); + board[xchoice-1][ychoice-1] = 'X'; + } + + //user wins if they sink all of the ships + if(ships == 0){ + for(i=0; i Date: Fri, 15 Jul 2016 14:52:40 -0400 Subject: [PATCH 4/4] README for final project --- README.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 README.txt diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..6f1e3b2 --- /dev/null +++ b/README.txt @@ -0,0 +1,5 @@ +Aly Milich Final Project README + +This game of Battleship was designed and coded by Aly Milich for the Columbia High School Summer Program 2016. The player is meant to create the size of their board and attempt to sink the 4 battleships randomly placed by the opponent (the computer). After entering the coordinates of the player's guess, the spot on the board will either change to a 'X', indicating a miss, or a 'S', indicating a hit. The player, which starts with 5 lives, will lose 1 life for each miss and gain 1 point for each hit. The game ends either when the player loses all of its lives or all of the ships are hit. For a more challenging game, the player can make the board larger and for an easier game, the player should choose a smaller board size. + +The game does not include ships of varying sizes as was suggested after submitting the proposal because I wanted to make sure the basic parts of the game worked before adding on extra aspects. I thought it would be an interesting twist to allow the user to select the board size even though the ships are only one size. Another difference is that the user does not place his or her own ships and instead is only attacking the computer. I was having some issues implementing this aspect and wanted to finish in time so I had to leave it out. It is a little different than a classic game of battleship but still a lot of fun to play!