Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Classes established. Still working on game methods

  • Loading branch information...
commit f399a1872cbe53c8538b747675721931d0cf433e 1 parent 7915a91
Adam Scott authored
BIN  .DS_Store
Binary file not shown
10 README.md
Source Rendered
@@ -2,21 +2,25 @@ Overview
2 2 ========
3 3 A Ruby command line game based on widely popular series of children's books. The game is from a second-person point of view, with the reader assuming the role of the protagonist and making choices that determine the main character's actions and the plot's outcome.
4 4
  5 +Story loosely based on "The Cave of Time" book. See a [graph of the paths](http://www.codinghorror.com/.a/6a0120a85dcdae970b0163057f849b970d-pi).
  6 +
5 7
6 8 Features
7 9 ========
8   - - user inputs name, gender and weapon of choice - all used throughout the game
  10 + - game instructions run when game starts
  11 + - user inputs name and gender - all used throughout the game
9 12 - user presented with "forks in the road" where you must choose with path to take
10   - - random starting point
11 13 - "forks in the road" saved in a csv file
12   - - ability to add new "forks in the road"
13 14 - each path has an assigned number of points
14 15 - total score tabulated at the end
15 16
16 17 Future Features
17 18 ===============
  19 +- ability to add new "forks in the road"
  20 +- add user carrying a weapon of choice (selected at the beginning of the game)
18 21 - top scores save to csv file (scores command shows top scores)
19 22 - ASCII art integrated
  23 +- make this a Ruby gem
20 24
21 25 Dependencies
22 26 ============
11 Rakefile
... ... @@ -0,0 +1,11 @@
  1 +#!/usr/bin/env ruby
  2 +# -*- ruby -*-
  3 +
  4 +require 'rake/testtask'
  5 +
  6 +Rake::TestTask.new do |t|
  7 + t.libs << 'test'
  8 +end
  9 +
  10 +desc "Run tests"
  11 +task :default => :test
30 cyoa.rb
... ... @@ -1,30 +0,0 @@
1   -def instructions
2   - puts ""
3   - puts "Welcome to the game of".center(80)
4   - puts " _____ _ ____ __ _____ _
5   - |_ _| |__ ___ / ___|__ ___ _____ ___ / _| |_ _(_)_ __ ___ ___
6   - | | | '_ \\ / _ \\ | | / _` \\ \\ / / _ \\ / _ \\| |_ | | | | '_ ` _ \\ / _ \\
7   - | | | | | | __/ | |___ (_| |\\ V / __/ | (_) | _| | | | | | | | | | __/
8   - |_| |_| |_|\\___| \\____\\__,_| \\_/ \\___| \\___/|_| |_| |_|_| |_| |_|\\___|"
9   - puts ""
10   - puts "~~~~ A Choose Your Own Adventure Game ~~~~".center(80)
11   - puts "This is a game where you choose what happens next in the story. It all depends on the choices you make. How does the story end? Only you can find out! And the best part is that you can start over and go ahead until you've had not one but many incredibly daring experiences!\n\n"
12   - puts "Each step of the way you'll pick which path you take by typing the corresponding number and pressing Enter.\n\n"
13   - puts "To get started, type 'start'"
14   -end
15   -
16   -def prompt(*args)
17   - print(*args)
18   - gets
19   -end
20   -
21   -instructions
22   -
23   -#prompt for start
24   -start = prompt
25   -if prompt == "start"
26   - puts "Please type 'start'"
27   - prompt
28   -end
29   -
30   -puts "This is stop one"
BIN  doc/.DS_Store
Binary file not shown
9 lib/cyoa.rb
... ... @@ -0,0 +1,9 @@
  1 +require_relative 'game'
  2 +
  3 +
  4 +go = Game.new
  5 +# go.instructions
  6 +# go.get_user_name
  7 +# go.clear_screen
  8 +go.load_next(1)
  9 +
18 lib/fork.rb
... ... @@ -1,7 +1,21 @@
1 1 class Fork
2   - def initialize
3   - end
4 2
  3 + attr_reader :id, :story, :path1, :path2, :finish
  4 +
  5 + def initialize(id,story,path1,path2,finish)
  6 + @id = id
  7 + @story = story
  8 + @path1 = path1
  9 + @path2 = path2
  10 + @finish = finish
  11 + end
5 12
  13 + def end?
  14 + if @finish == true
  15 + true
  16 + else
  17 + false
  18 + end
  19 + end
6 20
7 21 end
14 lib/forkslist.csv
... ... @@ -0,0 +1,14 @@
  1 +id,story,path1,path2,finish
  2 +1,"You are hiking in Snake Canyon when you find yourself lost in the strange, dimly lit Cave of Time. Gradually you can make out two passageways. One curves downward to the right; the other leads upward to the left. It occurs to you that the one leading down may go to the past and the one leading up may go to the future. Which way will you choose?\nType '1' for the tunnel leading down\nType '2' for the tunnel leading up",4,5,false
  3 +4,"Door 8 or 10",8,10,false
  4 +5,"Door 6 or 16",6,16,false
  5 +6,"Door 22 or 114",22,114,false
  6 +8,"Door 17 or 18",17,18,false
  7 +10,"Door 20 or 21",20,21,false
  8 +17,"Door 26 or 28",26,28,false
  9 +18,"Door 29 or 30",29,30,false
  10 +20,"Door 93 or 93",93,93,false
  11 +21,"Door 33 or 35",33,35,false
  12 +22,"Door 36 or 37",36,37,false
  13 +114,"Door 61 or 61",61,61,false
  14 +
53 lib/game.rb
... ... @@ -0,0 +1,53 @@
  1 +require_relative 'story'
  2 +
  3 +class Game
  4 +
  5 + def initialize
  6 + @maingame = Story.new
  7 + end
  8 +
  9 + def instructions
  10 + puts ""
  11 + puts "Welcome to the game of".center(80)
  12 + puts " _____ _ ____ __ _____ _
  13 + |_ _| |__ ___ / ___|__ ___ _____ ___ / _| |_ _(_)_ __ ___ ___
  14 + | | | '_ \\ / _ \\ | | / _` \\ \\ / / _ \\ / _ \\| |_ | | | | '_ ` _ \\ / _ \\
  15 + | | | | | | __/ | |___ (_| |\\ V / __/ | (_) | _| | | | | | | | | | __/
  16 + |_| |_| |_|\\___| \\____\\__,_| \\_/ \\___| \\___/|_| |_| |_|_| |_| |_|\\___|"
  17 + puts ""
  18 + puts "~~~~ A Choose Your Own Adventure Game ~~~~".center(80)
  19 + puts "\nThis is a game where you choose what happens next in the story. It all depends on the choices you make. How does the story end? Only you can find out! And the best part is that you can start over and go ahead until you've had not one but many incredibly daring experiences!\n\n"
  20 + puts "Each step of the way you'll pick which path you take by typing the corresponding number and pressing Enter.\n\n"
  21 + puts "To get started, type your name."
  22 + end
  23 +
  24 + #prompt helper
  25 + def prompt(*args)
  26 + print(*args)
  27 + gets
  28 + end
  29 +
  30 + def get_user_name
  31 + name = gets
  32 + puts "Hello #{name}"
  33 + end
  34 +
  35 + def load_next(id)
  36 + item = @maingame.get_fork(id)
  37 + while item.finish == "false"
  38 + puts item.story
  39 + route = gets
  40 + next_fork = item.path(gets)
  41 + puts next_fork
  42 + item = @maingame.get_fork(next_fork)
  43 + end
  44 + puts "\e[H\e[2J"
  45 + puts "Game Over!"
  46 +
  47 + end
  48 +
  49 + def clear_screen
  50 + puts "\e[H\e[2J"
  51 + end
  52 +
  53 +end
20 lib/story.rb
... ... @@ -0,0 +1,20 @@
  1 +require 'csv'
  2 +require_relative 'fork'
  3 +
  4 +
  5 +class Story
  6 +
  7 + attr_reader :all_forks
  8 +
  9 + def initialize
  10 + @all_forks = {}
  11 + CSV.foreach("./lib/forkslist.csv", :headers => true) do |row|
  12 + @all_forks[row[0]] = Fork.new(row[0],row[1],row[2],row[3],row[4])
  13 + end
  14 + end
  15 +
  16 + def get_fork(id)
  17 + @all_forks[id.to_s]
  18 + end
  19 +
  20 +end
BIN  test/.DS_Store
Binary file not shown
11 test/game.rb
... ... @@ -0,0 +1,11 @@
  1 +require 'test/unit'
  2 +require 'cyoa'
  3 +
  4 +class GameTest < Test::Unit::Testcase
  5 +
  6 + def test_01_print_instructions
  7 +
  8 + end
  9 +
  10 +
  11 +end
34 test/test_fork.rb
... ... @@ -0,0 +1,34 @@
  1 +require 'test/unit'
  2 +require 'fork'
  3 +
  4 +class ForkTest < Test::Unit::TestCase
  5 +
  6 + def test_01_fork_has_ID
  7 + item = Fork.new(12,"abcd",2,3,false)
  8 + assert_equal(12,item.id)
  9 + end
  10 +
  11 + def test_02_fork_has_story
  12 + item = Fork.new(12,"abcd",2,3,false)
  13 + assert_equal("abcd",item.story)
  14 + end
  15 +
  16 + def test_03_fork_has_path1
  17 + item = Fork.new(12,"abcd",2,3,false)
  18 + assert_equal(2,item.path1)
  19 + end
  20 +
  21 + def test_04_fork_has_path2
  22 + item = Fork.new(12,"abcd",2,3,false)
  23 + assert_equal(3,item.path2)
  24 + end
  25 +
  26 + def test_05_fork_is_end?
  27 + item = Fork.new(12,"abcd",2,3,false)
  28 + item2 = Fork.new(12,"abcd",2,3,true)
  29 + assert_equal(false,item.end?)
  30 + assert_equal(true,item2.end?)
  31 + end
  32 +
  33 +
  34 +end
11 test/test_game.rb
... ... @@ -0,0 +1,11 @@
  1 +require 'test/unit'
  2 +require 'game'
  3 +
  4 +class GameTest < Test::Unit::TestCase
  5 +
  6 + def test_01_test
  7 + assert_equal(1,1)
  8 + end
  9 +
  10 +
  11 +end
23 test/test_story.rb
... ... @@ -0,0 +1,23 @@
  1 +require 'test/unit'
  2 +require 'story'
  3 +
  4 +class StoryTest < Test::Unit::TestCase
  5 +
  6 + def test_01_find_fork
  7 + item = Story.new
  8 + assert_equal(Fork,item.get_fork(2).class)
  9 + end
  10 +
  11 + def test_02_get_fork_story
  12 + item = Story.new
  13 + item = item.get_fork(3)
  14 + assert_equal("ghij",item.story)
  15 + end
  16 +
  17 + def test_03_get_fork_story
  18 + item = Story.new
  19 + item = item.get_fork(2)
  20 + assert_equal("4",item.path1)
  21 + end
  22 +
  23 +end

0 comments on commit f399a18

Please sign in to comment.
Something went wrong with that request. Please try again.