Last active
December 17, 2017 14:40
-
-
Save CodePint/24eea7a630d0bd6be0a9bb6719065b39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##Turn based ruby game | |
=begin | |
GOAL | |
Write a simple game that allows the user and the computer to take turns selecting moves to use against each other. | |
Both the computer and the player should start out at the same amount of health (such as 100), | |
and should be able to choose between the three moves: | |
The first move should do moderate damage and has a small range (such as 18-25). | |
The second move should have a large range of damage | |
and can deal high or low damage (such as 10-35). | |
The third move should heal whoever casts it a moderate amount, similar to the first move. | |
After each move, a message should be printed out that tells the user what just | |
happened, and how much health the user and computer have. | |
Once the user or the computer's health reaches 0, the game should end. | |
SUBGOALS | |
When someone is defeated, make sure the game prints out that their health has reached 0, and not a negative number. | |
When the computer's health reaches a set amount (such as 35%), increase it's chance to cast heal. | |
Give each move a name. | |
- Create player/ai | |
- create health and attack | |
- create game_loop | |
- add dice roles | |
- add attacks and hp system | |
player need to be able to attack AI and vice versa | |
=end | |
#superclass for player and ai subclasses | |
class Character | |
attr_accessor :name, :description, :attacks, :max_hp, :hp | |
def initialize(name, description, max_hp) | |
@name = name | |
@description = description | |
@attacks = attacks | |
@max_hp | |
@hp = max_hp | |
end | |
def attacks_hashes | |
{"Power attack" => 50, | |
"Quick attack" => 20, | |
"Multi attack" => 5} | |
end | |
def heal_hashes | |
{"Minor heal" => 15, | |
"Risky heal" => 50, | |
"Multi heal" => 5} | |
end | |
end | |
#linebreak shortcut method | |
def line_break(text="*", n=30) | |
puts text * n | |
end | |
#player controlled class | |
class Player < Character | |
attr_accessor :choice | |
def attack_or_heal | |
puts "Attack | Heal " | |
@choice = attack_or_heal | |
att_heal = gets.chomp.capitalize | |
loop do | |
if att_heal == "Attack" | |
puts "lets attack them! " | |
return attack_choice | |
break | |
else att_heal == "Heal" | |
puts "lets heal up!" | |
return heal_choice | |
break | |
end | |
end | |
end | |
def attack_choice | |
loop do | |
puts attacks_hashes | |
line_break | |
puts "which attack move should we use? " | |
attack = gets.chomp | |
if attack == attacks_hashes.keys[0] | |
puts "you have selected #{attacks_hashes.keys[0]} " | |
return attacks_hashes.keys[0] | |
break | |
elsif attack == attacks_hashes.keys[1] | |
puts "you have selected #{attacks_hashes.keys[1]} " | |
return attacks_hashes.keys[1] | |
break | |
else attack == attacks_hashes.keys[2] | |
puts "you have selected #{attacks_hashes.keys[2]} " | |
return attacks_hashes.keys[2] | |
break | |
end | |
end | |
end | |
def heal_choice | |
loop do | |
puts heal_hashes | |
line_break | |
puts "which healing move should we use? " | |
heal = gets.chomp | |
if heal == heal_hashes.keys[0] | |
puts "you have selected #{heal_hashes.keys[0]} " | |
return heal_hashes.keys[0] | |
break | |
elsif attack == attacks_hashes.keys[1] | |
puts "you have selected #{heal_hashes.keys[1]} " | |
return heal_hashes.keys[1] | |
break | |
else attack == attacks_hashes.keys[2] | |
puts "you have selected #{heal_hashes.keys[2]} " | |
return heal_hashes.keys[2] | |
break | |
@choice01 = attack_or_heal | |
end | |
end | |
end | |
end | |
def moves | |
end | |
# computer controlled class | |
class AI < Character | |
def attack_choice | |
puts "attack choice" | |
end | |
end | |
player_01 = Player.new("player1", "player 1 descript", "100") | |
#puts player_01.inspect | |
attack_or_heal | |
ai_01 = AI.new("AI 01", "AI 01 descript", "101") | |
#puts ai_01.inspect | |
player_01.attack_or_heal | |
puts "this is an instance choice" | |
puts player_01.choice |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment