cursetank 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/cursetank +3 -0
- data/cursetank.gemspec +19 -0
- data/lib/cursetank/tank_objects/basic_fish.rb +47 -0
- data/lib/cursetank/tank_objects/bubble.rb +48 -0
- data/lib/cursetank/tank_objects/plant.rb +100 -0
- data/lib/cursetank/tank_objects/tank_object.rb +35 -0
- data/lib/cursetank/version.rb +3 -0
- data/lib/cursetank.rb +92 -0
- metadata +61 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Josh Skeen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Cursetank
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'cursetank'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install cursetank
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/cursetank
ADDED
data/cursetank.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "cursetank/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "cursetank"
|
7
|
+
gem.version = Cursetank::VERSION
|
8
|
+
gem.platform = Gem::Platform::RUBY
|
9
|
+
gem.authors = ["Josh Skeen"]
|
10
|
+
gem.email = ["josh@joshskeen.com"]
|
11
|
+
gem.description = %q{CurseTank - a curses-based ASCII fishtank, for all your fishtank simulation needs!}
|
12
|
+
gem.summary = %q{CurseTank - a curses-based ASCII fishtank, for all your fishtank simulation needs}
|
13
|
+
gem.homepage = "http://github.com/mutexkid/cursetank"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split("\n")
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#####
|
2
|
+
##### cursetank!
|
3
|
+
#####
|
4
|
+
require 'cursetank/tank_objects/tank_object'
|
5
|
+
module Cursetank
|
6
|
+
class BasicFish < TankObject
|
7
|
+
|
8
|
+
def initialize(args={})
|
9
|
+
super(args)
|
10
|
+
@height = 1
|
11
|
+
@width = 5
|
12
|
+
@swin = @win.subwin(@height, @width, 0, 0)
|
13
|
+
@color = args.fetch(:color, 1)
|
14
|
+
@speed = args.fetch(:speed, 0.1)
|
15
|
+
end
|
16
|
+
|
17
|
+
def frames
|
18
|
+
["><_'>",
|
19
|
+
"><_\">"
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
def frames_reverse
|
24
|
+
["<'_><",
|
25
|
+
"<\"_><"
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
29
|
+
def draw
|
30
|
+
set_direction
|
31
|
+
@frame += @speed
|
32
|
+
@frame = 0 if @frame > @maxframes - 1
|
33
|
+
@swin.setpos(0, 0)
|
34
|
+
@swin.move(@pos_y, @pos_x)
|
35
|
+
frame = frames[@frame.round.to_i]
|
36
|
+
frame = frames_reverse[@frame.round.to_i] if @dir_right == -1
|
37
|
+
@swin.attron(Curses.color_pair(@color)){
|
38
|
+
@swin.addstr(frame)
|
39
|
+
}
|
40
|
+
change_row = rand(100)
|
41
|
+
@pos_y += @speed * @dir_down if change_row == 7
|
42
|
+
@pos_x += @speed * @dir_right
|
43
|
+
@swin.refresh()
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#####
|
2
|
+
##### cursetank!
|
3
|
+
#####
|
4
|
+
require 'cursetank/tank_objects/tank_object'
|
5
|
+
module Cursetank
|
6
|
+
class Bubble < TankObject
|
7
|
+
|
8
|
+
def initialize(args={})
|
9
|
+
super(args)
|
10
|
+
@height = 2
|
11
|
+
@width = 3
|
12
|
+
@pos_x = args.fetch(:pos_x)
|
13
|
+
@pos_y = @win.maxy - @height - rand(1..20)
|
14
|
+
@swin = @win.subwin(@height, @width, 0, 0)
|
15
|
+
@color = args.fetch(:color, 1)
|
16
|
+
@speed = 0.2
|
17
|
+
@frame = rand(0..frames.length - 1)
|
18
|
+
@bubbles = args.fetch(:bubbles)
|
19
|
+
end
|
20
|
+
|
21
|
+
def frames
|
22
|
+
[".O
|
23
|
+
o *",
|
24
|
+
".
|
25
|
+
..o",
|
26
|
+
".o
|
27
|
+
."
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
def draw
|
32
|
+
@frame += @speed
|
33
|
+
@frame = 0 if @frame > @maxframes - 1
|
34
|
+
@swin.setpos(0, 0)
|
35
|
+
@swin.move(@pos_y, @pos_x)
|
36
|
+
frame = frames[@frame.round.to_i]
|
37
|
+
@swin.attron(Curses.color_pair(@color)){
|
38
|
+
@swin.addstr(frame)
|
39
|
+
}
|
40
|
+
@swin.refresh()
|
41
|
+
@pos_y += @speed * -1
|
42
|
+
|
43
|
+
@bubbles.delete(self) if @pos_y <= 0
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#####
|
2
|
+
##### cursetank!
|
3
|
+
#####
|
4
|
+
require 'cursetank/tank_objects/tank_object'
|
5
|
+
module Cursetank
|
6
|
+
class Plant < TankObject
|
7
|
+
|
8
|
+
MAX_PLANT_HEIGHT = 14
|
9
|
+
|
10
|
+
def initialize(args={})
|
11
|
+
super(args)
|
12
|
+
@height = args.fetch(:plant_height, 14)
|
13
|
+
@width = 5
|
14
|
+
@swin = @win.subwin(@height, @width, 0, 0)
|
15
|
+
@pos_y = @win.maxy - @height
|
16
|
+
@speed = 0.1
|
17
|
+
@frame = rand(0..frames.length - 1)
|
18
|
+
end
|
19
|
+
|
20
|
+
def frames
|
21
|
+
["
|
22
|
+
(.
|
23
|
+
)
|
24
|
+
.(
|
25
|
+
)
|
26
|
+
.(
|
27
|
+
)..
|
28
|
+
(
|
29
|
+
(.
|
30
|
+
)
|
31
|
+
.(
|
32
|
+
)
|
33
|
+
.(
|
34
|
+
)..
|
35
|
+
(",
|
36
|
+
"
|
37
|
+
.(
|
38
|
+
)
|
39
|
+
(.
|
40
|
+
)
|
41
|
+
.(
|
42
|
+
)
|
43
|
+
(.
|
44
|
+
.(
|
45
|
+
)
|
46
|
+
(.
|
47
|
+
)
|
48
|
+
.(
|
49
|
+
)
|
50
|
+
(.",
|
51
|
+
"
|
52
|
+
(.
|
53
|
+
. )
|
54
|
+
(
|
55
|
+
)
|
56
|
+
(.
|
57
|
+
)
|
58
|
+
(.
|
59
|
+
.
|
60
|
+
.)
|
61
|
+
(
|
62
|
+
)
|
63
|
+
(.
|
64
|
+
)
|
65
|
+
(.",
|
66
|
+
"
|
67
|
+
(.
|
68
|
+
)
|
69
|
+
.(
|
70
|
+
)
|
71
|
+
(.
|
72
|
+
.)
|
73
|
+
(.
|
74
|
+
(.
|
75
|
+
)
|
76
|
+
.(
|
77
|
+
)
|
78
|
+
(.
|
79
|
+
.)
|
80
|
+
(."
|
81
|
+
]
|
82
|
+
end
|
83
|
+
|
84
|
+
def draw
|
85
|
+
@swin.setpos(0, 0)
|
86
|
+
@swin.move(@pos_y, @pos_x)
|
87
|
+
@frame += @speed
|
88
|
+
@frame = 0 if @frame > @maxframes - 1
|
89
|
+
@swin.setpos(0, 0)
|
90
|
+
@swin.move(@pos_y, @pos_x)
|
91
|
+
frame = frames[@frame.round.to_i]
|
92
|
+
|
93
|
+
@swin.attron(Curses.color_pair(2)){
|
94
|
+
@swin.addstr(frame)
|
95
|
+
}
|
96
|
+
@swin.refresh()
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#####
|
2
|
+
##### cursetank!
|
3
|
+
#####
|
4
|
+
#base class for tank objects
|
5
|
+
module Cursetank
|
6
|
+
class TankObject
|
7
|
+
|
8
|
+
def initialize(args={})
|
9
|
+
@frame = 0
|
10
|
+
@win = args.fetch(:window)
|
11
|
+
@pos_x = args.fetch(:pos_x, 0)
|
12
|
+
@pos_y = args.fetch(:pos_y, 0)
|
13
|
+
@dir_right = args.fetch(:dir_right, 1)
|
14
|
+
@dir_down = args.fetch(:dir_down, 1)
|
15
|
+
@maxframes = frames.length
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_direction
|
19
|
+
@dir_right = -1 if @swin.begx >= @win.maxx - 10
|
20
|
+
@dir_right = 1 if @swin.begx <= 5
|
21
|
+
@dir_down = -1 if @swin.begy >= @win.maxy - 10
|
22
|
+
@dir_down = 1 if @swin.begy <= 5
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def frames
|
27
|
+
[]
|
28
|
+
end
|
29
|
+
|
30
|
+
def draw
|
31
|
+
raise Exception("draw method not implemented!")
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
data/lib/cursetank.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require "cursetank/version"
|
2
|
+
require 'cursetank/tank_objects/basic_fish'
|
3
|
+
require 'cursetank/tank_objects/bubble'
|
4
|
+
require 'cursetank/tank_objects/plant'
|
5
|
+
|
6
|
+
require 'curses'
|
7
|
+
|
8
|
+
module Cursetank
|
9
|
+
include Curses
|
10
|
+
class Cursetank
|
11
|
+
def initialize
|
12
|
+
setup_curses
|
13
|
+
@win = Curses::Window.new(0, 0, 0, 0)
|
14
|
+
main
|
15
|
+
end
|
16
|
+
|
17
|
+
def main
|
18
|
+
@plantlife_back = setup_plantlife
|
19
|
+
@fishes = setup_fishes
|
20
|
+
@plantlife_front = setup_plantlife
|
21
|
+
@bubbles = []
|
22
|
+
loop do
|
23
|
+
@plantlife_back.each do | p |
|
24
|
+
p.draw
|
25
|
+
end
|
26
|
+
@fishes.each do | f |
|
27
|
+
f.draw
|
28
|
+
end
|
29
|
+
@plantlife_front.each do | p |
|
30
|
+
p.draw
|
31
|
+
end
|
32
|
+
generate_bubbles
|
33
|
+
@bubbles.each do | b |
|
34
|
+
b.draw
|
35
|
+
end
|
36
|
+
sleep(1.0/15.0)
|
37
|
+
@win.clear
|
38
|
+
@win.refresh
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def generate_bubbles
|
45
|
+
chance = rand(30)
|
46
|
+
if chance == 29
|
47
|
+
rand_x = rand(150)
|
48
|
+
@bubbles << Bubble.new({window: @win, pos_x: rand_x, bubbles: @bubbles })
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def setup_plantlife
|
53
|
+
plantlife = []
|
54
|
+
plantcount = rand(4..10)
|
55
|
+
plantcount.times do | p |
|
56
|
+
rand_x = rand(150)
|
57
|
+
plant_height = rand(1..Plant::MAX_PLANT_HEIGHT)
|
58
|
+
plantlife << Plant.new({window: @win, pos_x: rand_x, plant_height: plant_height})
|
59
|
+
end
|
60
|
+
plantlife
|
61
|
+
end
|
62
|
+
|
63
|
+
def setup_fishes
|
64
|
+
fishes = []
|
65
|
+
fishcount = rand(10..50)
|
66
|
+
fishcount.times do | i |
|
67
|
+
rand_x = rand(50)
|
68
|
+
rand_y = rand(50)
|
69
|
+
rand_speed = rand(0.1..1.5)
|
70
|
+
rand_color = rand(1..3)
|
71
|
+
rand_dir = rand(2)%2 ? -1 : 1
|
72
|
+
fishes << BasicFish.new({window: @win, dir_right: rand_dir, pos_x: rand_x, pos_y: rand_y, speed:rand_speed, color: rand_color})
|
73
|
+
end
|
74
|
+
fishes
|
75
|
+
end
|
76
|
+
|
77
|
+
def setup_curses
|
78
|
+
Curses.init_screen()
|
79
|
+
Curses.start_color()
|
80
|
+
Curses.use_default_colors()
|
81
|
+
Curses.noecho
|
82
|
+
Curses.cbreak
|
83
|
+
Curses.curs_set(0)
|
84
|
+
Curses.init_pair(1, Curses::COLOR_CYAN, Curses::COLOR_BLACK)
|
85
|
+
Curses.init_pair(2, Curses::COLOR_GREEN, Curses::COLOR_BLACK)
|
86
|
+
Curses.init_pair(3, Curses::COLOR_RED, Curses::COLOR_BLACK)
|
87
|
+
Curses.init_pair(4, Curses::COLOR_MAGENTA, Curses::COLOR_BLACK)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cursetank
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josh Skeen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-28 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: CurseTank - a curses-based ASCII fishtank, for all your fishtank simulation
|
15
|
+
needs!
|
16
|
+
email:
|
17
|
+
- josh@joshskeen.com
|
18
|
+
executables:
|
19
|
+
- cursetank
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- .gitignore
|
24
|
+
- Gemfile
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/cursetank
|
29
|
+
- cursetank.gemspec
|
30
|
+
- lib/cursetank.rb
|
31
|
+
- lib/cursetank/tank_objects/basic_fish.rb
|
32
|
+
- lib/cursetank/tank_objects/bubble.rb
|
33
|
+
- lib/cursetank/tank_objects/plant.rb
|
34
|
+
- lib/cursetank/tank_objects/tank_object.rb
|
35
|
+
- lib/cursetank/version.rb
|
36
|
+
homepage: http://github.com/mutexkid/cursetank
|
37
|
+
licenses: []
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.8.24
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: CurseTank - a curses-based ASCII fishtank, for all your fishtank simulation
|
60
|
+
needs
|
61
|
+
test_files: []
|