mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-08 13:44:59 +00:00
Many more Rubocop-inspired code improvements
This commit is contained in:
@@ -174,7 +174,7 @@ class PokemonDuel
|
||||
PBMoveRoute::Forward
|
||||
])
|
||||
pbMessage(_INTL("Your attack was evaded!"))
|
||||
elsif (action == 0 || action == 1 || action == 2) && command == 3
|
||||
elsif [0, 1, 2].include?(action) && command == 3
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::ScriptAsync, "jumpForward"
|
||||
@@ -282,7 +282,7 @@ class PokemonDuel
|
||||
PBMoveRoute::Backward
|
||||
])
|
||||
pbMessage(_INTL("You evade the opponent's attack!"))
|
||||
elsif action == 3 && (command == 0 || command == 1 || command == 2)
|
||||
elsif action == 3 && [0, 1, 2].include?(command)
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::ScriptAsync, "jumpForward"
|
||||
|
||||
@@ -611,7 +611,7 @@ class TriadScreen
|
||||
|
||||
def maxCards
|
||||
numcards = @width * @height
|
||||
if numcards % 2 == 1
|
||||
if numcards.odd?
|
||||
numcards = numcards / 2 + 1
|
||||
else
|
||||
numcards = numcards / 2
|
||||
@@ -833,7 +833,7 @@ class TriadScreen
|
||||
end
|
||||
end
|
||||
# Sort by number of flips
|
||||
scores.sort! { |a, b| (b[3] == a[3]) ? rand(3) - 1 : b[3] <=> a[3] }
|
||||
scores.sort! { |a, b| (b[3] == a[3]) ? rand(-1..1) : b[3] <=> a[3] }
|
||||
scores = scores[0, opponentCards.length] # Get the best results
|
||||
if scores.length == 0
|
||||
@scene.pbDisplay(_INTL("{1} can't move somehow...", @opponentName))
|
||||
|
||||
@@ -193,7 +193,7 @@ class SlotMachineScene
|
||||
@sprites["light2"].src_rect.set(0, 26 * ((frame / timePerFrame) % 4), 96, 26)
|
||||
for i in 1..5
|
||||
if wonRow[i - 1]
|
||||
@sprites["row#{i}"].visible = ((frame / timePerFrame) % 2) == 0
|
||||
@sprites["row#{i}"].visible = (frame / timePerFrame).even?
|
||||
else
|
||||
@sprites["row#{i}"].visible = false
|
||||
end
|
||||
|
||||
@@ -44,7 +44,7 @@ class VoltorbFlip
|
||||
voltorbs += 1
|
||||
# Sets the value randomly to a 2 or 3 if the total is less than the max
|
||||
elsif total < @levelRanges[@level - 1][1]
|
||||
squareValues[i] = rand(2) + 2
|
||||
squareValues[i] = rand(2..3)
|
||||
total *= squareValues[i]
|
||||
end
|
||||
if total > (@levelRanges[@level - 1][1])
|
||||
@@ -387,11 +387,11 @@ class VoltorbFlip
|
||||
if @level < 8
|
||||
@level += 1
|
||||
pbMessage(_INTL("\\se[Voltorb Flip level up]Advanced to Game Lv. {1}!", @level.to_s))
|
||||
# if @firstRound
|
||||
if @firstRound
|
||||
# pbMessage(_INTL("Congratulations!"))
|
||||
# pbMessage(_INTL("You can receive even more Coins in the next game!"))
|
||||
@firstRound = false
|
||||
# end
|
||||
end
|
||||
end
|
||||
pbDisposeSpriteHash(@sprites)
|
||||
pbNewGame
|
||||
|
||||
@@ -78,8 +78,8 @@ class MiningGameCursor < BitmapSprite
|
||||
attr_accessor :hit
|
||||
attr_accessor :counter
|
||||
|
||||
ToolPositions = [[1, 0], [1, 1], [1, 1], [0, 0], [0, 0],
|
||||
[0, 2], [0, 2], [0, 0], [0, 0], [0, 2], [0, 2]] # Graphic, position
|
||||
TOOL_POSITIONS = [[1, 0], [1, 1], [1, 1], [0, 0], [0, 0],
|
||||
[0, 2], [0, 2], [0, 0], [0, 0], [0, 2], [0, 2]] # Graphic, position
|
||||
|
||||
def initialize(position = 0, mode = 0) # mode: 0=pick, 1=hammer
|
||||
@viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
|
||||
@@ -106,22 +106,23 @@ class MiningGameCursor < BitmapSprite
|
||||
|
||||
def update
|
||||
self.bitmap.clear
|
||||
x = 32 * (@position % MiningGameScene::BOARDWIDTH)
|
||||
y = 32 * (@position / MiningGameScene::BOARDWIDTH)
|
||||
x = 32 * (@position % MiningGameScene::BOARD_WIDTH)
|
||||
y = 32 * (@position / MiningGameScene::BOARD_WIDTH)
|
||||
if @counter > 0
|
||||
@counter -= 1
|
||||
toolx = x
|
||||
tooly = y
|
||||
i = 10 - (@counter / 2).floor
|
||||
if ToolPositions[i][1] == 1
|
||||
case TOOL_POSITIONS[i][1]
|
||||
when 1
|
||||
toolx -= 8
|
||||
tooly += 8
|
||||
elsif ToolPositions[i][1] == 2
|
||||
when 2
|
||||
toolx += 6
|
||||
end
|
||||
self.bitmap.blt(toolx, tooly, @toolbitmap.bitmap,
|
||||
Rect.new(96 * ToolPositions[i][0], 96 * @mode, 96, 96))
|
||||
if i < 5 && i % 2 == 0
|
||||
Rect.new(96 * TOOL_POSITIONS[i][0], 96 * @mode, 96, 96))
|
||||
if i < 5 && i.even?
|
||||
if @hit == 2
|
||||
self.bitmap.blt(x - 64, y, @hitsbitmap.bitmap, Rect.new(160 * 2, 0, 160, 160))
|
||||
else
|
||||
@@ -140,8 +141,8 @@ end
|
||||
|
||||
|
||||
class MiningGameScene
|
||||
BOARDWIDTH = 13
|
||||
BOARDHEIGHT = 10
|
||||
BOARD_WIDTH = 13
|
||||
BOARD_HEIGHT = 10
|
||||
ITEMS = [ # Item, probability, graphic x, graphic y, width, height, pattern
|
||||
[:DOMEFOSSIL, 20, 0, 3, 5, 4, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0]],
|
||||
[:HELIXFOSSIL, 5, 5, 3, 4, 4, [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]],
|
||||
@@ -238,9 +239,9 @@ class MiningGameScene
|
||||
@iron = []
|
||||
pbDistributeItems
|
||||
pbDistributeIron
|
||||
for i in 0...BOARDHEIGHT
|
||||
for j in 0...BOARDWIDTH
|
||||
@sprites["tile#{j + i * BOARDWIDTH}"] = MiningGameTile.new(32 * j, 64 + 32 * i)
|
||||
for i in 0...BOARD_HEIGHT
|
||||
for j in 0...BOARD_WIDTH
|
||||
@sprites["tile#{j + i * BOARD_WIDTH}"] = MiningGameTile.new(32 * j, 64 + 32 * i)
|
||||
end
|
||||
end
|
||||
@sprites["crack"] = MiningGameCounter.new(0, 4)
|
||||
@@ -258,7 +259,7 @@ class MiningGameScene
|
||||
for i in ITEMS
|
||||
ptotal += i[1]
|
||||
end
|
||||
numitems = 2 + rand(3)
|
||||
numitems = rand(2..4)
|
||||
tries = 0
|
||||
while numitems > 0
|
||||
rnd = rand(ptotal)
|
||||
@@ -268,8 +269,8 @@ class MiningGameScene
|
||||
if rnd < 0
|
||||
if pbNoDuplicateItems(ITEMS[i][0])
|
||||
while !added
|
||||
provx = rand(BOARDWIDTH - ITEMS[i][4] + 1)
|
||||
provy = rand(BOARDHEIGHT - ITEMS[i][5] + 1)
|
||||
provx = rand(BOARD_WIDTH - ITEMS[i][4] + 1)
|
||||
provy = rand(BOARD_HEIGHT - ITEMS[i][5] + 1)
|
||||
if pbCheckOverlaps(false, provx, provy, ITEMS[i][4], ITEMS[i][5], ITEMS[i][6])
|
||||
@items.push([i, provx, provy])
|
||||
numitems -= 1
|
||||
@@ -298,12 +299,12 @@ class MiningGameScene
|
||||
|
||||
def pbDistributeIron
|
||||
# Set iron to be buried (index in IRON, x coord, y coord)
|
||||
numitems = 4 + rand(3)
|
||||
numitems = rand(4..6)
|
||||
tries = 0
|
||||
while numitems > 0
|
||||
rnd = rand(IRON.length)
|
||||
provx = rand(BOARDWIDTH - IRON[rnd][2] + 1)
|
||||
provy = rand(BOARDHEIGHT - IRON[rnd][3] + 1)
|
||||
provx = rand(BOARD_WIDTH - IRON[rnd][2] + 1)
|
||||
provy = rand(BOARD_HEIGHT - IRON[rnd][3] + 1)
|
||||
if pbCheckOverlaps(true, provx, provy, IRON[rnd][2], IRON[rnd][3], IRON[rnd][4])
|
||||
@iron.push([rnd, provx, provy])
|
||||
numitems -= 1
|
||||
@@ -398,12 +399,12 @@ class MiningGameScene
|
||||
hittype = 2
|
||||
else
|
||||
for i in 0..2
|
||||
ytile = i - 1 + position / BOARDWIDTH
|
||||
next if ytile < 0 || ytile >= BOARDHEIGHT
|
||||
ytile = i - 1 + position / BOARD_WIDTH
|
||||
next if ytile < 0 || ytile >= BOARD_HEIGHT
|
||||
for j in 0..2
|
||||
xtile = j - 1 + position % BOARDWIDTH
|
||||
next if xtile < 0 || xtile >= BOARDWIDTH
|
||||
@sprites["tile#{xtile + ytile * BOARDWIDTH}"].layer -= pattern[j + i * 3]
|
||||
xtile = j - 1 + position % BOARD_WIDTH
|
||||
next if xtile < 0 || xtile >= BOARD_WIDTH
|
||||
@sprites["tile#{xtile + ytile * BOARD_WIDTH}"].layer -= pattern[j + i * 3]
|
||||
end
|
||||
end
|
||||
if @sprites["cursor"].mode == 1 # Hammer
|
||||
@@ -427,8 +428,8 @@ class MiningGameScene
|
||||
end
|
||||
|
||||
def pbIsItemThere?(position)
|
||||
posx = position % BOARDWIDTH
|
||||
posy = position / BOARDWIDTH
|
||||
posx = position % BOARD_WIDTH
|
||||
posy = position / BOARD_WIDTH
|
||||
for i in @items
|
||||
index = i[0]
|
||||
width = ITEMS[index][4]
|
||||
@@ -444,8 +445,8 @@ class MiningGameScene
|
||||
end
|
||||
|
||||
def pbIsIronThere?(position)
|
||||
posx = position % BOARDWIDTH
|
||||
posy = position / BOARDWIDTH
|
||||
posx = position % BOARD_WIDTH
|
||||
posy = position / BOARD_WIDTH
|
||||
for i in @iron
|
||||
index = i[0]
|
||||
width = IRON[index][2]
|
||||
@@ -471,7 +472,7 @@ class MiningGameScene
|
||||
pattern = ITEMS[index][6]
|
||||
for j in 0...height
|
||||
for k in 0...width
|
||||
layer = @sprites["tile#{@items[i][1] + k + (@items[i][2] + j) * BOARDWIDTH}"].layer
|
||||
layer = @sprites["tile#{@items[i][1] + k + (@items[i][2] + j) * BOARD_WIDTH}"].layer
|
||||
revealed = false if layer > 0 && pattern[k + j * width] > 0
|
||||
break if !revealed
|
||||
end
|
||||
@@ -550,22 +551,22 @@ class MiningGameScene
|
||||
end
|
||||
# Input
|
||||
if Input.trigger?(Input::UP) || Input.repeat?(Input::UP)
|
||||
if @sprites["cursor"].position >= BOARDWIDTH
|
||||
if @sprites["cursor"].position >= BOARD_WIDTH
|
||||
pbSEPlay("Mining cursor")
|
||||
@sprites["cursor"].position -= BOARDWIDTH
|
||||
@sprites["cursor"].position -= BOARD_WIDTH
|
||||
end
|
||||
elsif Input.trigger?(Input::DOWN) || Input.repeat?(Input::DOWN)
|
||||
if @sprites["cursor"].position < (BOARDWIDTH * (BOARDHEIGHT - 1))
|
||||
if @sprites["cursor"].position < (BOARD_WIDTH * (BOARD_HEIGHT - 1))
|
||||
pbSEPlay("Mining cursor")
|
||||
@sprites["cursor"].position += BOARDWIDTH
|
||||
@sprites["cursor"].position += BOARD_WIDTH
|
||||
end
|
||||
elsif Input.trigger?(Input::LEFT) || Input.repeat?(Input::LEFT)
|
||||
if @sprites["cursor"].position % BOARDWIDTH > 0
|
||||
if @sprites["cursor"].position % BOARD_WIDTH > 0
|
||||
pbSEPlay("Mining cursor")
|
||||
@sprites["cursor"].position -= 1
|
||||
end
|
||||
elsif Input.trigger?(Input::RIGHT) || Input.repeat?(Input::RIGHT)
|
||||
if @sprites["cursor"].position % BOARDWIDTH < (BOARDWIDTH - 1)
|
||||
if @sprites["cursor"].position % BOARD_WIDTH < (BOARD_WIDTH - 1)
|
||||
pbSEPlay("Mining cursor")
|
||||
@sprites["cursor"].position += 1
|
||||
end
|
||||
|
||||
@@ -190,13 +190,14 @@ class TilePuzzleScene
|
||||
ret.push(i)
|
||||
@angles.push(0)
|
||||
end
|
||||
if @game == 6
|
||||
case @game
|
||||
when 6
|
||||
@tiles = ret
|
||||
5.times do
|
||||
pbShiftLine([2, 4, 6, 8][rand(4)], rand(@boardwidth * @boardheight), false)
|
||||
end
|
||||
return @tiles
|
||||
elsif @game == 7
|
||||
when 7
|
||||
@tiles = ret
|
||||
5.times do
|
||||
pbRotateTile(rand(@boardwidth * @boardheight), false)
|
||||
@@ -213,11 +214,11 @@ class TilePuzzleScene
|
||||
ret[j] != @boardwidth * @boardheight - 1
|
||||
end
|
||||
end
|
||||
if @boardwidth % 2 == 1
|
||||
ret = pbShuffleTiles if num % 2 == 1
|
||||
if @boardwidth.odd?
|
||||
ret = pbShuffleTiles if num.odd?
|
||||
else
|
||||
ret = pbShuffleTiles if !((num % 2 == 0 && (@boardheight - (blank / @boardwidth)) % 2 == 1) ||
|
||||
(num % 2 == 1 && (@boardheight - (blank / @boardwidth)) % 2 == 0))
|
||||
ret = pbShuffleTiles if !((num.even? && (@boardheight - (blank / @boardwidth)).odd?) ||
|
||||
(num.odd? && (@boardheight - (blank / @boardwidth)).even?))
|
||||
end
|
||||
end
|
||||
if @game == 1 || @game == 2
|
||||
@@ -241,16 +242,15 @@ class TilePuzzleScene
|
||||
for i in 0...@boardwidth * @boardheight
|
||||
return i if @tiles[i] == @boardwidth * @boardheight - 1
|
||||
end
|
||||
return 0
|
||||
else
|
||||
return 0
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
def pbMoveCursor(pos, dir)
|
||||
if dir == 2
|
||||
case dir
|
||||
when 2
|
||||
pos += @boardwidth
|
||||
elsif dir == 4
|
||||
when 4
|
||||
if pos >= @boardwidth * @boardheight
|
||||
if pos % @boardwidth == (@boardwidth / 2).ceil
|
||||
pos = ((pos % (@boardwidth * @boardheight)) / @boardwidth) * @boardwidth + @boardwidth - 1
|
||||
@@ -264,7 +264,7 @@ class TilePuzzleScene
|
||||
pos -= 1
|
||||
end
|
||||
end
|
||||
elsif dir == 6
|
||||
when 6
|
||||
if pos >= @boardwidth * @boardheight
|
||||
if pos % @boardwidth == (@boardwidth / 2).ceil - 1
|
||||
pos = ((pos % (@boardwidth * @boardheight)) / @boardwidth) * @boardwidth
|
||||
@@ -278,7 +278,7 @@ class TilePuzzleScene
|
||||
pos += 1
|
||||
end
|
||||
end
|
||||
elsif dir == 8
|
||||
when 8
|
||||
pos -= @boardwidth
|
||||
end
|
||||
return pos
|
||||
@@ -286,21 +286,22 @@ class TilePuzzleScene
|
||||
|
||||
def pbCanMoveInDir?(pos, dir, swapping)
|
||||
return true if @game == 6 && swapping
|
||||
if dir == 2
|
||||
case dir
|
||||
when 2
|
||||
return false if (pos / @boardwidth) % @boardheight >= @boardheight - 1
|
||||
elsif dir == 4
|
||||
when 4
|
||||
if @game == 1 || @game == 2
|
||||
return false if pos >= @boardwidth * @boardheight && pos % @boardwidth == 0
|
||||
else
|
||||
return false if pos % @boardwidth == 0
|
||||
end
|
||||
elsif dir == 6
|
||||
when 6
|
||||
if @game == 1 || @game == 2
|
||||
return false if pos >= @boardwidth * @boardheight && pos % @boardwidth >= @boardwidth - 1
|
||||
else
|
||||
return false if pos % @boardwidth >= @boardwidth - 1
|
||||
end
|
||||
elsif dir == 8
|
||||
when 8
|
||||
return false if (pos / @boardwidth) % @boardheight == 0
|
||||
end
|
||||
return true
|
||||
@@ -376,8 +377,8 @@ class TilePuzzleScene
|
||||
movetile = pbMoveCursor(cursor, dir)
|
||||
@sprites["cursor"].visible = false
|
||||
@sprites["tile#{@tiles[cursor]}"].z = 1
|
||||
if dir == 2 || dir == 8 # Swap vertically
|
||||
swapTime = Graphics.frame_rate * 3 / 10
|
||||
swapTime = Graphics.frame_rate * 3 / 10
|
||||
if [2, 8].include?(dir) # Swap vertically
|
||||
distancePerFrame = (@tileheight.to_f / swapTime).ceil
|
||||
dist = (dir / 4).floor - 1
|
||||
swapTime.times do
|
||||
@@ -388,7 +389,6 @@ class TilePuzzleScene
|
||||
Input.update
|
||||
end
|
||||
else # Swap horizontally
|
||||
swapTime = Graphics.frame_rate * 3 / 10
|
||||
distancePerFrame = (@tilewidth.to_f / swapTime).ceil
|
||||
dist = dir - 5
|
||||
swapTime.times do
|
||||
@@ -411,7 +411,7 @@ class TilePuzzleScene
|
||||
# Get tiles involved
|
||||
tiles = []
|
||||
dist = 0
|
||||
if dir == 2 || dir == 8
|
||||
if [2, 8].include?(dir)
|
||||
dist = (dir / 4).floor - 1
|
||||
while (dist > 0 && cursor < (@boardwidth - 1) * @boardheight) ||
|
||||
(dist < 0 && cursor >= @boardwidth)
|
||||
@@ -441,7 +441,7 @@ class TilePuzzleScene
|
||||
Input.update
|
||||
end
|
||||
shiftTime = Graphics.frame_rate * 3 / 10
|
||||
if dir == 2 || dir == 8
|
||||
if [2, 8].include?(dir)
|
||||
distancePerFrame = (@tileheight.to_f / shiftTime).ceil
|
||||
shiftTime.times do
|
||||
for i in tiles
|
||||
|
||||
Reference in New Issue
Block a user