Skip to content

Commit

Permalink
Implementing city logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea committed Nov 6, 2011
1 parent 8b9b51c commit d4db11c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 14 additions & 0 deletions lib/vimcity/city.rb
Expand Up @@ -5,6 +5,20 @@ class City
def initialize(coins=1000, population=100)
@coins = coins
@population = population
@population_cap = 0
@money_per_second = 1
@people_per_second = 1
@happiness = 1
end

def update
@coins+=@money_per_second
if @population < @population_cap
@population+=@people_per_second*@happiness
@population=@population.round
end
@happiness-=0.001
@happiness = 0.001 if @happiness < 0
end

end
13 changes: 7 additions & 6 deletions lib/vimcity/vim_city_game.rb
Expand Up @@ -79,7 +79,8 @@ def start_game

elsif input == 'r'
VIM::message("receive p")
if @insert_mode && @current_building
if @insert_mode && @current_building
@city.coins+=1000
failure = false
@last_chars.each do |row|
failure = true if row != "."*@current_building.width
Expand All @@ -94,6 +95,7 @@ def start_game
end

update_status_bar
@city.update()
wait 80
end
end
Expand Down Expand Up @@ -127,7 +129,6 @@ def init_cursor

def update_status_bar
VIM::evaluate("genutils#MoveCursorToWindow(1)")
@city.coins +=1
@status_buffer[1] = " "*@width
print_to_buffer(@status_buffer, 1, 0, "Money: #{@city.coins}c")
print_to_buffer(@status_buffer, 1, 18, "Population: #{@city.population}")
Expand All @@ -143,12 +144,12 @@ def update_cursor(x,y)
print_area_to_buffer(@main_buffer, c[0], c[1], @last_chars)

c[0] += y
c[0] = 1 if c[1] < 1
c[0] = @map.height+2-cursor_height if c[1]+cursor_height >= @map.height+2
c[0] = 1 if c[0] < 1
c[0] = @map.height+2-cursor_height if c[0]+cursor_height >= @map.height+2

c[1] += x
c[1] = @map.offset if c[2] < @map.offset
c[1] = @map.width-(@map.offset)-cursor_width+2 if c[2]+cursor_width >= (@map.width+@map.offset+1)
c[1] = @map.offset if c[1] < @map.offset
c[1] = @map.width-(@map.offset)-cursor_width+2 if c[1]+cursor_width >= (@map.width+@map.offset+1)

set_cursor_pos(c[0], c[1])

Expand Down

0 comments on commit d4db11c

Please sign in to comment.