Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My own version #4

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
11d85db
Delete .DS_Store
May 11, 2015
33f1d37
Initial Commit
awbedell May 11, 2015
8d2455e
Initial Commit
awbedell May 11, 2015
749650c
Tests 1-12 pass
awbedell May 11, 2015
4999b00
Tests 1-19 pass
awbedell May 11, 2015
6195587
Tests 1-19 pass
awbedell May 11, 2015
c6ca4c9
Tests 1-23 working
awbedell May 11, 2015
edc1da2
Tests 1-25 working
awbedell May 11, 2015
483b8f1
Tests 1-29 working
awbedell May 11, 2015
f9aa6b1
Test 1-29 working
awbedell May 11, 2015
d8a4eab
Tests 1-30 working
awbedell May 11, 2015
28579a5
#31 modification, still not working
awbedell May 12, 2015
77f8d92
Game class
awbedell May 12, 2015
80621c6
Tests 1-31 working
awbedell May 12, 2015
c10ee0e
Test 31 optimized
awbedell May 12, 2015
de5af3c
Tests 1-31 working
awbedell May 12, 2015
ed573ae
Tests 1-39 working
awbedell May 12, 2015
1355d43
Fix inheritance
owenrham May 12, 2015
637db8f
Fix Inheritance
owenrham May 12, 2015
5bbd79c
Tests 1-40 working
awbedell May 12, 2015
fb634e9
Tests 1-40 working
awbedell May 12, 2015
4f76174
Tests 1-20 working
awbedell May 12, 2015
db9b5bf
Tests 1-41 working
awbedell May 12, 2015
19a1e42
Tests 1-42 working
awbedell May 12, 2015
1ef9f25
Initial Commit
awbedell May 13, 2015
cd0a7a2
Tests 1-42 working
awbedell May 13, 2015
c04e4bb
Tests 1-42 working
awbedell May 13, 2015
c13b86c
Tests 1-42 working
awbedell May 13, 2015
314aff3
Refactoring
awbedell May 13, 2015
1124526
refactoring
awbedell May 13, 2015
80c29f5
refactoring
awbedell May 13, 2015
643dc1a
My modified version initial commit
awbedell May 13, 2015
7ab33e9
refactoring
awbedell May 13, 2015
d819cfe
x and y coordinates are joined into one, hard mode implementation
awbedell May 13, 2015
ea23f6b
README added, minor refactoring
awbedell May 14, 2015
e90f41c
human grid updated
awbedell May 14, 2015
4e94024
Ships cannot go off the board
awbedell May 14, 2015
ad6c0a8
puts space between each turn
awbedell May 14, 2015
bc4c04a
minor refactoring
awbedell May 14, 2015
f301240
refactoring
awbedell May 14, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
68 changes: 17 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,29 @@

## Description

Write a program that plays the game of Battleship. In the first version, the user can act as Player 1, and the computer can act as Player 2.
Classic Battleship. Try to sink your opponent's ships!

## Objectives

After completing this assignment, you should...
Sink your opponent's ships.

* Understand the basics of control flow, variables, and methods in Ruby.
* Understand the basics of Object Oriented Programming.
* Understand the basic use cases of Git for single-developer projects.
* Understand the purpose of test suites and how they can assist in development.
* Understand how frustrating it would have been to try to check and debug this assignment without written tests!
* Be able to build a game-playing application that asks the user for input and provides output to the user.
* Be able to create a computer player that can act like a human (albeit not necessarily an intelligent one).
* Be able to write an program that can satisfy a test suite.
## Directions

## Deliverables
1. Initialize two players, either computer or human. For each human player, enter
a name. For each player, either computer or human, also enter the width and
height dimensions of the desired board side.

* **A Repository.** Fork this repository to your own github account.
* **A README.** Wipe out this README and write your own. It should tell readers how to play your version of the game.
* **Ruby Files.** You'll need a lot of these, and you'll be creating them from scratch. You should have one per class, plus at least one other to be executed from the command line to run the game.
* **A Playable Game.** When I clone your repository, I should be able to run your program and play through an entire game of Battleship. I should be able to win and to lose.
2. Initialize the game with two players as the arguments.

When you are finished, create a pull request.
3. Play will switch between players. On each player's turn, one shot may be
made at the other board. Enter a letter and a number that are within the range
of board size that was initialized. For example, if the board was initialized
with a height of 4, shots can only be made from A-D.

4. On each player's turn, two boards will be shown. First, the board that
displays the shots that player has already made. Hits are marked with a "+"
and misses are marked with a "-". The second board shows the player's own ships,
with hits marked with a "X" and un-hit ships marked with a "O".

## Normal Mode

Your task for this project, whether or not you choose to accept it, is to write a program that plays the game of Battleship. The user can act as Player 1, and the computer can act as Player 2. However, as you work through the assignment, you'll notice that you're also building it so that two humans could play each other (or two computer players, but that's not as much fun).

The rules of the game are given in the [Hasbro instructions](http://www.hasbro.com/common/instruct/battleship.pdf).

The major requirement of this project is for the TEST SUITE TO PASS. You are coding to the tests, and ideally, you're making them pass one at a time. As discussed in class, I would suggest making the first test pass USING THE SIMPLEST MEANS POSSIBLE. Then move on to the second test, the third test and so on. You should commit after each test passes.

Just to be clear, your computer player does not have to be smart. It just has to play until the game is finished.

Here's the unfortunately odd thing. READ THIS. If you're ever about to call `gets.chomp` in your code to prompt the user for his/her input, don't. Put the following code at the top of any file that needs to prompt the user:

```
def get_user_input
gets.chomp
end
```

This goes BEFORE you start defining your class. I know that looks stupid, and I apologize for it, but the test suite will only run if you ALWAYS ask for user input by calling `get_user_input` rather than `gets.chomp`. Sorry again.

## Hard Mode

This game currently only works for 9x9 grids, and for five ships with pre-set lengths. Add two optional parameters to `Grid.new` to allow the user to specify width and height of the board. Add one optional parameter to `Game.new` which is an array of integers. These integers define the lengths of the ships to be placed.

In addition to the above, add ten more (meaningful) tests to the test suite. Get them to pass!

## Nightmare Mode

You have two paths to choose from in Nightmare mode:

1. In addition to the above, modify your existing code to ask the user which type of game he/she would like to play: regular or SALVO. Allow the user to select and play either game.

2. Modify your computer player so that it makes intelligent moves. In other words, Normal Mode is satisfied if the computer fires randomly. Hard mode required the computer to fire with some meaning. It has to have a chance of winning.

Don't forget to modify the test suite to continue to pass!
5. Play will move back and forth until one player has sunk all ships of the
other player.
21 changes: 21 additions & 0 deletions battleship.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require './ship.rb'
require './player.rb'
require './human_player.rb'
require './computer_player.rb'
require './grid.rb'
require './game.rb'

#
# puts "Grid Width: "
# width = get_user_input.to_i
# puts "Grid Height: "
# height = get_user_input.to_i
# puts "Player1: "
# player1 = get_user_input
# puts "Player2: "
# player2 = get_user_input
#
# first_player = HumanPlayer.new(name: player1, width: width, height: height)
# second_player = HumanPlayer.new(name: player2, width: width, height: height)
# game = Game.new(first_player, second_player)
# game.play
Loading