Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Commiting first time.

  • Loading branch information...
commit e4ecbf729519bab4ec5ea2db9bcfee80dcc3878c 0 parents
authored August 03, 2008
BIN  .DS_Store
Binary file not shown
16  Drug.rb
... ...
@@ -0,0 +1,16 @@
  1
+require 'game'
  2
+
  3
+class Drug
  4
+  
  5
+  TYPES = ["weed", "ecstacy", "shrooms", "oxycotin", "acid", "ruffy", "crack", "cocaine", "heroin", "crystal meth"]
  6
+  
  7
+  def can_be_sold?
  8
+    true
  9
+  end
  10
+  
  11
+  
  12
+  def self.display_price
  13
+    rand(500) + 10
  14
+  end
  15
+  
  16
+end
47  Game.rb
... ...
@@ -0,0 +1,47 @@
  1
+require 'player'
  2
+require 'drug'
  3
+require 'bank'
  4
+
  5
+class Game
  6
+  
  7
+  LOCATIONS = ["Las Vegas", "New York", "Miami", "Amsterdam", "Frankfurt", "El-Jazier"]
  8
+  
  9
+  def self.days
  10
+    30
  11
+  end
  12
+  
  13
+  def self.agent?
  14
+    rand(100) > 50
  15
+  end
  16
+  
  17
+  
  18
+  # 0 - 300 you're safe, no agents
  19
+  # 301 - 600 1 agent has spotted you, but you can run
  20
+  # 601 - 900 2 agents have spotted you, but you can fight, or run
  21
+  # 901 - 1200 you're being chased, can't run, can fight but will probably lose
  22
+  # 1201 - 1500 you're caught, no chance to win. 
  23
+  def self.random_agent
  24
+    chance = (rand(100) * 30) / 2 #mix it up a bit to make it more random
  25
+    case chance
  26
+    when (0..300)
  27
+      puts "There are no agents following you, but watch your back."
  28
+    when (301..600)
  29
+      puts "An agent has spotted you, but you ran away."
  30
+    when (601..900)
  31
+      puts "Two agents are hot on your trail."
  32
+      puts "You run from one, but you had to unleash your glok on the other one."
  33
+    when (901..1200)
  34
+      puts "The agent that has been following you wants to make a deal."
  35
+      puts "You lose $500.00"
  36
+    when (1201..1500)
  37
+      puts "You have been caught, there is no way out."
  38
+      puts "Sorry, game over."
  39
+      game_over
  40
+    end
  41
+  end
  42
+  
  43
+  def self.game_over
  44
+    exit
  45
+  end
  46
+  
  47
+end
151  Player.rb
... ...
@@ -0,0 +1,151 @@
  1
+require 'game'
  2
+
  3
+class Player
  4
+  attr_accessor :name, :drugs, :funds, :current_location, :days_remaining, :bank_account
  5
+  
  6
+  def initialize(name)
  7
+    @name = name
  8
+    @drugs = Hash.new
  9
+    @funds = 0
  10
+    @current_location = "Las Vegas"
  11
+    @days_remaining = Game.days
  12
+    @bank_account = Bank.new
  13
+  end
  14
+  
  15
+  # you can buy the drug if you have enough money for the qty of that drug
  16
+  def can_buy_drug?(price, qty)
  17
+    self.funds > (price * qty) 
  18
+  end
  19
+  
  20
+  # you can sell the drug if there is a market for it on the streets
  21
+  def can_sell_drug?(drug)
  22
+    drug.can_be_sold?
  23
+  end
  24
+  
  25
+  def add_to_drugs(drugs)
  26
+    drugs.each_pair do |drug, amount|
  27
+      if @drugs.has_key?(drug)
  28
+        @drugs[drug] += drugs[drug]
  29
+      else
  30
+        @drugs.update({drug => amount})
  31
+      end
  32
+    end
  33
+  end
  34
+  
  35
+  def remove_from_drugs(drugs)
  36
+    drugs.each_pair do |drug, amount|
  37
+      @drugs[drug] -= drugs[drug]
  38
+    end    
  39
+  end
  40
+  
  41
+  def buy_drugs
  42
+    puts "Select the number of the drug you want to buy."
  43
+    Drug::TYPES.each_with_index do |drug, select_number|
  44
+      @price = Drug.display_price
  45
+      max_amount = @funds / @price
  46
+      puts "#{select_number + 1}. #{drug} @ $#{@price} {#{max_amount}}\n"
  47
+    end
  48
+    drug_choice = gets.chomp
  49
+    drug = Drug::TYPES[drug_choice.to_i - 1]
  50
+    puts "How many?"
  51
+    drug_amount = gets.chomp
  52
+    decrease = (@price * drug_amount.to_i)
  53
+    if self.can_buy_drug?(@price, drug_amount.to_i)
  54
+      self.add_to_drugs({drug => drug_amount.to_i})
  55
+      @funds -= decrease
  56
+    else
  57
+      puts "You can't buy that many."
  58
+    end
  59
+  end
  60
+  
  61
+  def sell_drugs
  62
+    puts "Which of your drugs would you like to sell?"
  63
+    i = 0
  64
+    @drugs.each_pair do |drug, amount|
  65
+      @price = Drug.display_price
  66
+      puts "#{i + 1}. #{drug} x #{amount} @ $#{@price}.00ea.\n"
  67
+      i +=1
  68
+    end
  69
+    drug_choice = gets.chomp
  70
+    drug = @drugs.keys[i - 1]
  71
+    puts "How many?"
  72
+    drug_amount = gets.chomp
  73
+    if drug_amount.to_i <= @drugs[drug]
  74
+      self.remove_from_drugs({drug => drug_amount.to_i})
  75
+      increase = @price * drug_amount.to_i
  76
+      @funds += increase
  77
+    else
  78
+      puts "You can't sell more then #{@drugs[drug]} of #{drug}."
  79
+    end
  80
+  end
  81
+  
  82
+  def fly_to_city
  83
+    puts "Select the number of the city you want to fly to."
  84
+    Game::LOCATIONS.each_with_index do |city, select_number|
  85
+      next if current_location.eql?(city)
  86
+      puts "#{select_number + 1}. #{city}\n"
  87
+    end
  88
+    answer = gets.chomp
  89
+    self.current_location = Game::LOCATIONS[answer.to_i - 1]
  90
+    @days_remaining -= 1
  91
+  end
  92
+  
  93
+  def go_to_bank
  94
+    puts "*****************"
  95
+    puts "***** BANK ******"
  96
+    puts "*****************"
  97
+    puts "Welcome to the swiss bank exchange."
  98
+    puts "Choose an option."
  99
+    puts "1. Take out a loan."
  100
+    puts "2. Put money in savings."
  101
+    puts "3. Leave."
  102
+    answer = gets.chomp
  103
+    loop do
  104
+      case answer
  105
+      when "1"
  106
+        puts "How much?"
  107
+        amount = gets.chomp
  108
+        @funds += amount.to_i
  109
+        @bank_account.increase_loan(amount.to_i)
  110
+        break
  111
+      when "2"
  112
+        puts "How much?"
  113
+        amount = gets.chomp
  114
+        if amount.to_i > @funds
  115
+          puts "Sorry, you don't have that much money."
  116
+        else
  117
+          @funds -= amount.to_i
  118
+          @bank_account.increase_savings(amount.to_i)
  119
+          break
  120
+        end
  121
+      when "3"
  122
+        puts "Goodbye."
  123
+        break
  124
+      else
  125
+        puts "You have to select option 1, 2 or 3"
  126
+        answer = gets.chomp
  127
+      end
  128
+    end
  129
+  end
  130
+  
  131
+  def check_stats
  132
+    puts "**********************"
  133
+    puts "******* STATS ********"
  134
+    puts "**********************"
  135
+    puts "Stats for #{@name}"
  136
+    puts "Drugs:"
  137
+    @drugs.each { |k,v| puts "-#{k} x #{v}" }
  138
+    puts "Wallet: $#{@funds}.00"
  139
+    puts "Current Location: #{@current_location}"
  140
+    puts "Days remaining: #{@days_remaining}"
  141
+    puts "Total savings: #{@bank_account.savings_account}"
  142
+    puts "Total loans: #{@bank_account.loan_amount}"
  143
+  end
  144
+  
  145
+  def fight
  146
+  end
  147
+  
  148
+  def run
  149
+  end
  150
+  
  151
+end
36  bank.rb
... ...
@@ -0,0 +1,36 @@
  1
+require 'game'
  2
+
  3
+class Bank
  4
+  
  5
+  attr_accessor :loan_amount, :savings_account
  6
+  
  7
+  def initialize
  8
+    @loan_amount = 0
  9
+    @savings_account = 0
  10
+    @interest = 1.5
  11
+  end
  12
+  
  13
+  def increase_loan(amount)
  14
+    @loan_amount += amount
  15
+  end
  16
+  
  17
+  def decrease_loan(amount)
  18
+    @loan_amount -= amount
  19
+  end
  20
+  
  21
+  def increase_savings(amount)
  22
+    @savings_account += amount
  23
+  end
  24
+  
  25
+  def decrease_savings(amount)
  26
+    @savings_account -= amount
  27
+  end
  28
+  
  29
+  def add_daily_interest
  30
+    dividend = @savings_account * @interest
  31
+    @savings_account += dividend
  32
+    loan = @loan_amount * @interest
  33
+    @loan_amount += loan
  34
+  end
  35
+  
  36
+end
51  dopewars.rb
... ...
@@ -0,0 +1,51 @@
  1
+require "game"
  2
+
  3
+puts "Dopewars v1.0"
  4
+puts "press 'S' to continue or any (other) key to quit."
  5
+@game = Game.new
  6
+answer = gets.chomp
  7
+if answer.downcase.eql?('s')
  8
+  puts "Welcome new drug dealer, what is your name?"
  9
+  name = gets.chomp
  10
+  @player = Player.new(name)
  11
+  puts "Nice to meet you #{@player.name}. Here is $500.00 and some weed to get you started."
  12
+  sleep 2
  13
+  @player.add_to_drugs({"weed" => 5})
  14
+  @player.funds += 500
  15
+  puts "Now that you have that, there is one more thing you will need."
  16
+  sleep 2
  17
+  puts "Here is a special plane ticket, and boarding pass."
  18
+  sleep 2
  19
+  puts "This will allow you to travel to one of 6 special cities."
  20
+  sleep 2
  21
+  puts "You may also need this bag to carry stuff in. You have 30 days."
  22
+  sleep 3
  23
+  while @player.days_remaining > 0
  24
+    puts "What would you like to do?"
  25
+    puts "1. Buy drugs\n2. Sell drugs\n3. Fly to a new city\n4. Go to the bank.\n5. Check stats."
  26
+    puts "Select your option:"
  27
+    option = gets.chomp
  28
+    case option
  29
+    when 1.to_s
  30
+      @player.buy_drugs
  31
+    when 2.to_s
  32
+      @player.sell_drugs
  33
+    when 3.to_s
  34
+      @player.fly_to_city
  35
+    when 4.to_s
  36
+      @player.go_to_bank
  37
+    when 5.to_s
  38
+      @player.check_stats
  39
+    else
  40
+      puts "You must select a number 1 through 4"
  41
+    end
  42
+    
  43
+    @player.days_remaining -= 1
  44
+    @player.bank_account.add_daily_interest
  45
+    if Game.agent?
  46
+      Game.random_agent
  47
+    end
  48
+  end
  49
+  
  50
+  puts "You've done it. You're now gangsta!"
  51
+end
62  dopewars.txt
... ...
@@ -0,0 +1,62 @@
  1
+notes for "dope wars" game:
  2
+
  3
+Overview:
  4
+You are a drug dealer. Your goal is to buy and sell drugs and make money without being caught.
  5
+You have 30 days to fly around the world making your purchases and selling your product. 
  6
+
  7
+This is a one player game, as the player, your goal is to beat your previous score. 
  8
+You lose only if you get caught, or if you owe any money. 
  9
+
  10
+Simple economy. Drug value is, to some degree, determined randomly by the day (1..30).
  11
+
  12
+Objects:
  13
+	The player (you)
  14
+	drugs
  15
+	weapons
  16
+	bags
  17
+	federal agents - DEA
  18
+	cities
  19
+	bank
  20
+	
  21
+Game play:
  22
+There are 6 cities located around the world.
  23
+	1. Las Vegas
  24
+	2. New York
  25
+	3. Miami
  26
+	4. Amsterdam
  27
+	5. Frankfurt
  28
+	6. El-Jazier
  29
+	
  30
+The city you are in dictates what drugs are available.
  31
+
  32
+There are 10 types of drugs
  33
+	1. weed
  34
+	2. heroine
  35
+	3. cocaine
  36
+	4. ecstasy
  37
+	5. shrooms
  38
+	6. ruffy
  39
+	7. acid
  40
+	8. crack
  41
+	9. oxycotin
  42
+	10. crystal meth
  43
+	
  44
+There are 3 weapons
  45
+	1. Brass knuckles
  46
+	2. Knife
  47
+	3. Gun
  48
+	
  49
+There are random federal agents
  50
+	1. they carry weapons
  51
+	2. they can arrest you
  52
+
  53
+There is 1 bank
  54
+	1. you can borrow
  55
+	2. you can save
  56
+	3. gains interest at 1.5% a day
  57
+
  58
+There are 3 bags
  59
+	1. small back pack - holds 50 drugs and 1 weapon
  60
+	2. briefcase - holds 100 drugs and 1 weapon
  61
+	3. large case - holds 500 drugs and 2 weapons
  62
+

0 notes on commit e4ecbf7

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