Skip to content

Instantly share code, notes, and snippets.

@TyGrze
Last active May 5, 2016 20:57
Show Gist options
  • Save TyGrze/440764fa602e3a12c8acd11d3ba0b96e to your computer and use it in GitHub Desktop.
Save TyGrze/440764fa602e3a12c8acd11d3ba0b96e to your computer and use it in GitHub Desktop.
A game like ruby warrior
class Player
def initialize(health, damage, position)
@health = health
@damage = damage
@position = position - 1
end
attr_reader :health, :damage, :position;
end
class Enemy
@@snakeID = 1;
@@golemID = 2;
@@snakeChar = "~";
@@golemChar = "§";
def initialize(position, id)
if id == @@snakeID
@ID = id
@health = 10
@position = position - 1
@char = @@snakeChar
@damage = 1;
elsif id == @@golemID
@ID = id
@health = 15
@position = position
@char = @@golemChar
@damage = 2;
end
end
attr_reader :health, :damage, :position, :char, :ID;
end
class Map
def initialize(size, player)
if size >= 20
@mapsize = 19;
else
@mapSize = size;
end
if player.position > size
player.position = 0;
end
@player = player;
@enemys = Array.new;
@spaces = Array.new;
end
def addEnemy(enemy)
@enemys << enemy
end
def makeMap()
print "╔"
for length in 0..@mapSize - 1
print "═"
end
puts "╗"
print "║"
for length in 0..@mapSize - 1
for enem in @enemys
if(length == enem.position)
@enemyAtThisPosition = true;
@enemyChar = enem.char;
else
@enemyAtThisPosition = false;
end
end
if(length == @player.position)
print "☼"
@spaces.push("player")
elsif @enemyAtThisPosition == true
print @enemyChar
@spaces << "enemy"
else
print " "
@spaces.push("Empty")
end
end
puts "║"
print "╚"
for length in 0..@mapSize - 1
print "═"
end
puts "╝"
print " "
for length in 0..@mapSize - 1
if length == 9
@count = 0;
print 1
elsif length > 9
@count += 1;
print 1
else
print length + 1;
end
end
puts ""
print " "
for i in 0..@count
print i;
end
#test
puts ""
p @spaces
end
end
player = Player.new(20, 3, 3);;
world = Map.new(19, player);
world.addEnemy(Enemy.new(1,1));
world.makeMap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment