class Eschaton::Game

Attributes

beanie_status[RW]

400 5-megaton warheads total, disbursed

combatants[RW]

400 5-megaton warheads total, disbursed

Public Class Methods

new(name: "Eschaton", beanie_status: 'Normal Game Conditions') click to toggle source
# File lib/eschaton/game.rb, line 13
def initialize(name: "Eschaton", beanie_status: 'Normal Game Conditions')
        @beanie_status = beanie_status
        @combatants = [Combatant.new(:amnat), Combatant.new(:sovwar), Combatant.new(:redchi), 
                                                                 Combatant.new(:irlibsyr), Combatant.new(:southaf), Combatant.new(:indpak)]
        # status can change to 'cessation of hostilities'
        # and 'utter global crisis'
end

Public Instance Methods

control_combatant() click to toggle source

initializes player control of random Combatant. A bit hacky, yes

# File lib/eschaton/game.rb, line 26
def control_combatant
        @playercombatant = @combatants.delete_at(rand(@combatants.length))
        puts "\nFor this game of Eschaton, you've been designated to be represent #{@playercombatant.nation}. (press Enter)\n "
        @playercombatant.nation.prepend '*'
end
finalstats() click to toggle source
# File lib/eschaton/game.rb, line 163
def finalstats
        @combatants << @playercombatant
        accuracy_rankings = @combatants.sort {|a,b| b.accuracy <=> a.accuracy }
        mvl = accuracy_rankings.first
        if mvl.accuracy = 1
                puts "Most Valuable Lobber: #{mvl.nation} with #{mvl.accuracy} direct hit!\n "
        else
                puts "Most Valuable Lobber: #{mvl.nation} with #{mvl.accuracy} direct hits!\n "
        end
        sleep(1.5)

        @combatants.each {|c| c.scoretotal } # calculates the INDDIR/SUFDDIR ratio for a final score.

        score_rankings = @combatants.sort {|a,b| b.score <=> a.score}
        puts "Final Rankings:\n"
        puts " "
        ranknum = 1
        score_rankings.each do |c|
                puts "#{ranknum} #{c.nation}:"
                puts "Total Infliction of Death, Destruction and Incapacitation of Response(INDDIR): #{c.inddir}"
                puts "Total Suffering of Death, Destruction and Incapacitation of Response(SUFDDIR): #{c.sufddir}"
                puts "Direct Hits: #{c.accuracy}"
                c.each_hit_target do |t|
                        puts "Total INDDIR from striking #{t.name}s: #{t.ptvalue}"
                end
                c.target_stats
                print_score(c)
                ranknum += 1
        end
                puts score_rankings.first.nation + ' wins! (press Enter to continue)'
                gets
                @playercombatant.nation[0] = ''
end
play(rounds) click to toggle source

gameplay

# File lib/eschaton/game.rb, line 45
def play(rounds)

        1.upto(rounds) do |r|
                puts "\nRound #{r}\n "

                puts "Which Combatant will you attack?"
                puts @combatants.map{|x| x.nation }.sort.join(', ')

                puts ' '

                # This loop cycles through the @combatants array for a match between the user's input
                # and each Combatant's nation abbreviation. If match found, we store the Combatant in
                # the @target variable. If no match, we ask user to try again.

                loop do
                        target = gets.chomp.upcase

                        puts ' '

                        if @combatants.any? { |i| i.nation == target }
                                @target = @combatants.find {|x| x.nation == target }
                                GameMaster.spasex(@playercombatant, @target)
                                sleep(2)
                                break
                        else
                                puts "Please enter the name of a Combatant:"
                                puts @combatants.map{|x| x.nation }.sort.join(', ')
                                puts ' '
                        end
                end


                # puts "Enter an nuclear attack sequence:"

                # loop do

                #   puts "LOB [Nuclear Attack]"
                #   puts "SACPOP [Strike Against Civilian Population]"
                #   puts "MIRV [Multiple Independent Reetry Vehicle]\n "

                #   attack = gets.chomp.upcase

                #   puts ' '

                #   case attack
                #   when "LOB"
                #           GameMaster.spasex(@playercombatant, @target)
                #           break
                #   when "SACPOP"
                #           @playercombatant.sacpop(@target)
                #           break
                #   when "MIRV"
                #           @playercombatant.mirv(@target)
                #           break
                #   else
                #           puts "Error: Incorrect Attack Sequence"
                #   end
                # end

                # sleep(2)

                @combatants.each do |c|

                        # clone the @combatant array without the current Combatant
                        combatantsclone = @combatants.reject { |x| x.nation == c.nation }
                        combatantsclone << @playercombatant # add @playercombatant to array of attackable Combatants

                        opp = combatantsclone.sample


                        GameMaster.spasex(c, opp)

                        combatantsclone.reject! { |x| x.nation == @playercombatant.nation} #removes @playercombatant again
                        sleep(2)
                end

                # if @combatants.all? {|c| c.defcon == 1 }
                #   @beanie_status = 'Utter Global Crisis'
                #   puts "\nEvery Combatant has entered DEFCON 1. Otis P. Lord has donned the Red Beanie. #{@beanie_status.upcase}.\n "
                #   sleep(2)
                # end

                if @combatants.all? {|c| c.megatonnage == 0}
                        @beanie_status = 'Cessation of Hostilities'
                        puts "\nIt appears the Global supply of Nuclear Weapons has been depleted. Otis P. Lord has donned the White Beanie. #{@beanie_status}.\n "
                end

        end
        puts "END OF GAME".center(30, ".")
        puts "\npress Enter to calculate results\n "
        gets
        puts "\nEndStat calculating results...\n "
        sleep(2)
        3.times do
                puts "calculating...\n " 
                sleep(1)
        end
        puts " "
        finalstats
end
print_score(combatant) click to toggle source

statistics