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
def get_arrays
return @figure_wrapper, @figure_names, @sound_names
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
@navi = Memory_Game_Navigate.new
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
@navi.navigate
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
#@navigater = Memory_Game_Navigate.new
#@pic_ID1 = -1
#@pic_ID2 = -2
#end
#Ändert die angezeigten Bilder.
# TODO Tonvariante einpflegen
def change_card(pID1,pID2)
@navigater = Memory_Game_Navigate.new
@memo = Game_Memory.new
f_wrapper, f_names, s_names = $game_system.memory.get_arrays()
#@pID1,@pid2 = @naviagter.navigate(@pic_ID1, pic_ID2)
#pID1 = -1
#pID2 = -2
#zeigt die erste umgedeckte Karte an.
if pID1 != -1
@c = f_names[pID1]
@f_wrapper.map! {|x| x == pID1 ? @c : x}.flatter
memo.update_graphics()
end
#zeigt die zweite umgedeckte Karte an.
if pID2 != -2
@d = f_names[pID2]
@f_wrapper.map! {|x| x == pID1 ? @d : x}.flatter
memo.update_graphics()
end
if (pID1 != -1 && pID2 != -2)
#Wenn die Karten gleich sind!
if pID1 == pID2
Audio.se_play("Chime2", 80, 100)
pID1 = -1
pID2 = -2
@win +1
#Wenn die Karten ungleich sind!
else #(pID1 != pID2)
Audio.se_play("Buzzer2", 80, 100)
pic = "Grundkarte.png"
@f_wrapper.map! {|x| x == pID1 ? pic : x}.flatter
@f_wrapper.map! {|y| y == pID2 ? pic : x}.flatter
pID1 = -1
pID2 = -2
memo.update_graphics()
end
end
return pID1,pID2
end
#also, ich muss irgendwie die Variablen da oben nutzen um da die Namen der
#der Karten reinzuschreiben. Mit der ID arbeite ich dann um die Karten
#zu zeigen oder wieder das Deckblatt draufzulegen.
#ergo brauche ich noch ID Variablen.
#dann muss ich noch an die IDs der Karten kommen. Das müsste ich wohl über
#die Bewegung machen... die irgendwie weiter zählt. Geht man nach rechts
#halt + auf der x-Achse, geht man nach links - auf der x-Achse
#geht man nach oben - auf der y-Achse geht man nach unten + auf der y-Achse
#irgendwie muss ich den Spaß dann auch noch starten und symbolisieren
#wie man sich bewegt, ich würde ja gerne einen roten Rahmen um das Bild
#legen der dann da einfach auf dem aktuellen Standort auftaucht, nur wie?
#erstmal muss ich eh herausfinden wie ich Elemente in einem Array an einer
#bestimmten Stelle verändere.
end
# Hier findet die Navigation statt.
class Memory_Game_Navigate
def initialize
@cursor = Sprite.new
#Kommentar: Die meisten Sprites liegen im Z-Wert zwischen 0 und 300.
#Mit 500 solltest du auf jeden Fall auf der obersten Ebene sein, wodurch
#dein Cursor über allem steht.
@cursor.z = 500
@cursor.bitmap = Cache.picture("Zeiger.PNG")
@x_nav = 0
@y_nav = 0
@id = 0
@pic_ID1 = -1
@pic_ID2 = -2
@win = 0
end
def navigate
@pic_changer = Memory_Picture_Changer.new
@get_id = Game_Memory.new
# f_wrapper enthält die Deckblätter
# f_names enthält die Bilder
# s_names enthält die Sounds
f_wrapper, f_names, s_names = $game_system.memory.get_arrays()
#@pic_ID1,@pic_ID2 = @pic_changer.change_card(@pic_ID1,@pic_ID2)
@pic_ID1,@pic_ID2 = @pic_changer.change_card(@pID1,@pID2)
#@h = $game_system.memory.initialize(@figure_wrapper)
if Input.trigger?(:DOWN)
if @y_nav == 312
#Hier wird der Ton für den 2. Modus abgespielt.
move_error()
#Wert wird nicht vergrößert.
elsif
@y_nav = @y_nav + 104
@id = @id + 4
move_cursor()
end
end
if Input.trigger?(:LEFT)
if @x_nav == 0
move_error()
#Wert wird nich verkleinert.
elsif
@x_nav = @x_nav - 136
@id = @id - 1
move_cursor()
end
end
if Input.trigger?(:UP)
if @y_nav == 0
#Hier wird der Ton für den 2. Modus abgespielt.
move_error()
#Wert wird nicht verkleinert.
elsif
@y_nav = @y_nav - 104
@id = @id - 4
move_cursor()
end
end
if Input.trigger?(:RIGHT)
if @x_nav == 408
move_error()
#Wert wird nich vergrößert.
elsif
@x_nav = @x_nav + 136
@id = @id + 1
move_cursor()
end
end
if Input.trigger?(:C)
a = f_names[@id]
b = f_wrapper[@id]
#a = @figure_names.select[@id]
if b == "Grundkarte.png"
if @pic_ID1 == -1
$game_variables[10] = $game_variables[10] + 1
@pic_ID1 = @id
@pic_changer.change_card()
#change_card()
elsif @pic_ID2 == -2
$game_variables[10] = $game_variables[10] + 1
@pic_ID2 = @id
@pic_changer.change_card()
#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
return @pic_ID1, @pic_ID2
end
#Hier findet die Bewegung des Mauszeigers statt.
def move_cursor
@cursor.x = @x_nav
@cursor.y = @y_nav
end
#hier wird der Ton abegespielt wenn sich der Spieler nicht mehr bewegen kann.
def move_error
if $game_switches[2] == true
Audio.se_play("Earth6", 80, 100)
end
end
end
Sorry dass der Code erst jetzt kommt