battles.rb
1 require "io/console" 2 3 # Helper Functions {{ 4 5 # Pause Function 6 def pause(show_prompt=true) 7 if show_prompt 8 print "Press any key to continue..." 9 end 10 STDOUT.flush 11 _ = STDIN.getch 12 puts "" 13 end 14 15 # Clear Screen 16 def cls 17 # yoinked from stack overflow lol (yes i still use stack overflow, i hate ai) 18 system("clear") || system("cls") 19 end 20 21 # Choice Function (essentially a menu select tool) 22 def choice(prompt="", choices=["y", "n"]) 23 print prompt 24 STDOUT.flush 25 print "[" 26 STDOUT.flush 27 28 i = 0 29 while i < choices.size do 30 print choices[i].upcase 31 STDOUT.flush 32 if i + 1 != choices.length 33 print "," 34 STDOUT.flush 35 end 36 i = i + 1 37 end 38 print "]?" 39 STDOUT.flush 40 41 input = "" 42 43 exitloop = false 44 while !exitloop do 45 input = STDIN.getch 46 47 i = 0 48 while i < choices.size 49 if input == choices[i] 50 exitloop = true 51 end 52 i = i + 1 53 end 54 end 55 puts input.upcase 56 57 input.downcase 58 end 59 60 # Input Function (based on "set /p") 61 def setp(prompt="") 62 print prompt 63 STDOUT.flush 64 input = gets.chomp 65 66 input # returns input 67 end 68 69 # Placeholder Function 70 def placeholder_helper 71 puts "Looks like this part isn't finished. Check back later on a newer version." 72 puts "" 73 pause 74 end 75 76 # }} 77 78 $playerhealth = 30 79 $playermaxhealth = 30 80 81 def mainbattlescreen(enemydata) 82 health = enemydata[:health] 83 maxhealth = enemydata[:maxhealth] 84 85 cls 86 puts "You started a battle with #{enemydata[:name]}!" 87 puts "" 88 puts "Place holder sprite" 89 90 while true do 91 puts "" 92 puts "Enemy Health: #{health}/#{maxhealth}" 93 puts "Health: #{$playerhealth}/#{$playermaxhealth}" 94 puts "" 95 puts "1: Attack 2: Defend" 96 puts "3: Items 4: Run" 97 guh = choice "", %w[1 2 3 4] 98 99 if guh == "1" 100 elsif guh == "2" 101 elsif guh == "3" 102 elsif guh == "4" 103 end 104 end 105 end 106 107 def main 108 data = { 109 # basic data 110 111 name: "placeholder", 112 health: 10, 113 maxhealth: 10, 114 115 # damage range 116 117 damage: 1, 118 maxdamage: 3, 119 } 120 121 mainbattlescreen data 122 end 123 124 main