Und da melde ich mich wieder ^^
Es sind ein paar neue Probleme aufgetaucht.
Das erste und größste Problem, ich weiß nicht wie ich gescheit meine beiden Klassen "Memory_Picture_Changer" und "Memory_Game_Navigate" starten soll.
Dadurch weiß ich natürlich auch noch nicht, ob das was ich mir gedacht habe so überhaupt funktioniert....
Auch habe ich noch eine Frage, kann man eigentlich ein Bild hier noch über die anderen Bilder legen?
Damit man z.B. einen Rahmen immer über eine Karte legen kann, oder einen Mauszeiger um zu sehen wo man eigentlich ist.
Wenn schon jemand Lust hat sich das "Grauen" anzuschauen, bitte schön XD
Code:class Game_Memory
# hier kommen alle Attribute rein die dein Spiel so hat
# filenames of the pictures of your cards
attr_accessor :figure_names
def initialize
#Deckkarten
@figure_wrapper = [
"Grundkarte.png", "Grundkarte.png", #1
"Grundkarte.png", "Grundkarte.png", #2
"Grundkarte.png", "Grundkarte.png", #3
"Grundkarte.png", "Grundkarte.png", #4
"Grundkarte.png", "Grundkarte.png", #5
"Grundkarte.png", "Grundkarte.png", #6
"Grundkarte.png", "Grundkarte.png", #7
"Grundkarte.png", "Grundkarte.png", #8
]
#Bilderkarten
@figure_names = [
"Spinne1.png", "Spinne1.png",
"Spinne2.png", "Spinne2.png",
"Spinne3.png", "Spinne3.png",
"Spinne4.png", "Spinne4.png",
"Spinne5.png", "Spinne5.png",
"Spinne6.png", "Spinne6.png",
"Spinne7.png", "Spinne7.png",
"Spinne8.png", "Spinne8.png",
].shuffle
#Sounds für die Tonvariante
@sound_names = [
"Up1", "Up1", #1
"Thunder3", "Thunder3", #2
"Sword4", "Sword4", #3
"Switch2", "Switch2", #4
"Stare", "Stare", #5
"Shop", "Shop", #6
"Saint9", "Saint9", #7
"Miss", "Miss" #8
].shuffle
@positions = [
0, 0,
136, 0,
272, 0,
408, 0,
#
0, 104,
136, 104,
272, 104,
408, 104,
#
#0, 208,
#136, 208,
#272, 208,
#408, 208,
#
#0, 312,
#136, 312,
#272, 312,
#408, 312
]
# number of cards horizontal
@max_number_of_cols = 4
# size of cards
@card_width = 136
@card_height = 104
# distance between cards
@margin = 0
# number of possible moves
@move = 32
# number of right pairs found. Win at 8
# change in def change_card for your game
@win = 0
p @figure_names
p @positions
end
# returns x, y coordinates as well as the image name of
# the card with the given index
def get_card index
[card_x(index), card_y(index), card_image(index)]
end
# return all cards
def get_cards
# create a new array with elements
# for all indizes from 0 upto @positions.size
(0...@positions.size).map do |index|
# each element contains the result value of
# get_card
get_card index
end
end
# x coordinate for a given card index
def card_x index
col_num = index % @max_number_of_cols
col_num * (@card_width + @margin)
end
# y coordinate for a given card index
def card_y index
row_num = index / @max_number_of_cols
row_num * (@card_height+@margin)
end
# filename of card image
def card_image index
#@figure_names[index]
@figure_wrapper [index]
#@figure_names[@positions[index]]
end
# number of different figures/cards
def number_of_pictures
#p "number_of_pictures"
@figure_names.size
end
# add 2 cards for each figure into the field
# shuffle the positions of all cards
def shuffle_cards
#p "shuffle_cards"
@positions.clear
# this loop is invoked as often as the number
# of different cards
number_of_pictures.times do |picture_id|
# for each invocation, two cards are added
# into the array
@positions << picture_id << picture_id
end
# shuffle the array at the end
@positions.shuffle!
end
end
class Game_System
# füge Memory als Attribut hinzu
attr_accessor :memory
end
# Erbebt von Scene_Base
class Scene_Memory < Scene_Base
def initialize_graphics
#for each card in the game
@card_sprites = $game_system.memory.get_cards.map do |x, y, image|
# create a new sprite
sprite = Sprite.new
# set its graphic and coordinates
sprite.bitmap = Cache.picture(image)
sprite.x, sprite.y = x, y
# and "return" the sprite into the array
sprite
end
end
def update_graphics
#update attributes of all sprites
@card_sprites.each_with_index do |sprite, index|
x, y, image = $game_system.memory.get_card(index)
sprite.bitmap = Cache.picture(image)
sprite.x, sprite.y = x,y
end
end
def dispose_graphics
@card_sprites.each do |sprite|
sprite.dispose
end
end
#-------------------------------------------------------------------------------
# überschreibt terminate Scene_Base
#-------------------------------------------------------------------------------
def terminate
super
dispose_graphics
end
#-------------------------------------------------------------------------------
# überschreibt update Scene_Base
#-------------------------------------------------------------------------------
def update
super
update_graphics
end
#-------------------------------------------------------------------------------
# Überschreibt start von Scene_Base
#-------------------------------------------------------------------------------
def start #(start)
super
initialize_graphics
update
end
end
#-------------------------------------------------------------------------------
# Hier findet das Verändern der Deckbilder statt.
# Ich sollte nach gleichen Namen schauen und wenn diese gleich sind, wird das
# Deckblatt entgültig entfernt.
#-------------------------------------------------------------------------------
class Memory_Picture_Changer
def initialize
@pic_ID1 = -1
@pic_ID2 = -2
p "wupi"
end
#Ändert die angezeigten Bilder.
# TODO Tonvariante einpflegen
def change_card
#zeigt die erste umgedeckte Karte an.
if @pic_ID1 != -1
a = @figure_names.select[@pic_ID1]
#ersetzen des Bildes an Stelle @pic_ID1 durch a
@figure_wrapper.map! {|x| x == @pic_ID1 ? a : x}.flatter
update_graphics()
end
#zeigt die zweite umgedeckte Karte an.
if @pic_ID2 != -2
b = @figure_names.select[@pic_ID2]
@figure_wrapper.map! {|y| y == @pic_ID1 ? b : y}.flatter
update_graphics()
end
if (@pic_ID1 != -1 && @pic_ID2 != -2)
#Wenn die Karten gleich sind!
if @pic1 == @pic2
Audio.se_play("Chime2", 80, 100)
@pic_ID1 = -1
@pic_ID2 = -2
@win +1
#Wenn die Karten ungleich sind!
else #(@pic1 != @pic2)
Audio.se_play("Buzzer2", 80, 100)
pic = "Grundkarte.png"
@figure_wrapper.map! {|x| x == @pic_ID1 ? pic : x}.flatter
@figure_wrapper.map! {|y| y == @pic_ID2 ? pic : y}.flatter
@pic_ID1 = -1
@pic_ID2 = -2
update_graphics()
end
end
end
end
# Hier findet die Navigation statt.
class Memory_Game_Navigate
def navigate
@x_nav = 0
@y_nav = 0
@id = 0
if Input.trigger?(:DOWN)
if @y_nav == 312
#Hier wird der Ton für den 2. Modus abgespielt.
if $game_switches[2] == true
Audio.se_play("Earth6", 80, 100)
end
#Wert wird nicht vergrößert.
elsif
@y_nav = @y_nax + 104
@id = @id + 4
end
end
if Input.trigger?(:LEFT)
if @x_nav == 0
if $game_switches[2] == true
Audio.se_play("Earth6", 80, 100)
end
#Wert wird nich verkleinert.
elsif
@x_nav = @x_nav - 136
@id = @id - 1
end
end
if Input.trigger?(:UP)
if @y_nav == 0
#Hier wird der Ton für den 2. Modus abgespielt.
if $game_switches[2] == true
Audio.se_play("Earth6", 80, 100)
end
#Wert wird nicht verkleinert.
elsif
@y_nav = @y_nax - 104
@id = @id - 4
end
end
if Input.trigger?(:RIGHT)
if @x_nav == 408
if $game_switches[2] == true
Audio.se_play("Earth6", 80, 100)
end
#Wert wird nich vergrößert.
elsif
@x_nav = @x_nav + 136
@id = @id + 1
end
end
if Input.trigger?(:C)
a = @figure_names.select[@id]
if a == "Grundkarte"
if @pic_ID1 == -1
@pic_ID1 = @id
$game_variables[10] = $game_variables[10] + 1
change_card()
elsif @pic_ID == -2
@pic_ID2 = @id
$game_variables[10] = $game_variables[10] + 1
change_card()
end
else
#Falls der Spieler blind ist, wird hier ein Signal abgespielt
#sonst wird in beiden Fällen die Variable für die Züge
#hochgezählt.
if $game_switches[2] == true
Audio.se_play("Buzzer1", 80, 100)
end
$game_variables[10] = $game_variables[10] + 1
end
end
end
end