RPGVX.net

  RPGVX.net => RPGVX.net Service => Archiv => Thema gestartet von: saschb2b am Juni 01, 2009, 14:15:44

Titel: (Tech) Tik Tak Toe Hilfe ^^
Beitrag von: saschb2b am Juni 01, 2009, 14:15:44
Hi ich habe einen Skript gefunden, welcher ein Tik Tak Toe game erlaubt.
################################################################################
##### M I N I - G A M E ########################################################
########## v1.0.0 ##############################################################
###############################   # O # X ######################################
############################### ######### ######################################
########## By: LB #############   # O # X ######################################
############################### ######### ######################################
############################### O #   # X ######################################
################################################################################

class Velha_Game < Scene_Base
  def initialize(var)
    @var = var
  end
  def start
    super
    create_menu_background
  end
  def post_start
    l = 544
    v = 4
    for i in 0...(544-416)/v
      l -= v
      Graphics.resize_screen(l,416)
    end
    @pos = [
    [1,2,3],
    [4,5,6],
    [7,8,9],
    [1,4,7],
    [2,5,8],
    [3,6,9],
    [1,5,9],
    [3,5,7]]
    @pos2 = [
    [1,5,9,3,7],
    [9,5,1,7,3],
    [3,5,7,1,9],
    [7,5,3,9,1],
    [1,9,5,4,8],
    [3,7,5,6,2]]
    @pos3 = [
    1,
    3,
    9,
    7]
    @jogou = []
    @jogada = 0
    @w = Window_Velha.new
  end
  def update
    super
    update_menu_background
    @w.update
    if Input.trigger?(Input::C) and @jogou[@w.index] == nil
      @jogada += 1
      @w.draw("O")
      @jogou[@w.index] = 1
      t = 0
      for i in 0...9
        t += 1 if @jogou != nil
      end
      if t != 9
        h = @w.index
        ia
        @w.draw("X")
        @jogou[@w.index] = 0
        @w.index = h
      end
    end
    for i in 0...2
      @v = i
      if f(1,2,3) or f(4,5,6) or f(7,8,9) or
         f(1,4,7) or f(2,5,8) or f(3,6,9) or
         f(1,5,9) or f(3,5,7)
        $game_variables[@var] = (@v == 0 ? 2 : 1)
        $scene = Scene_Map.new
      end
    end
    t = 0
    for i in 0...9
      t += 1 if @jogou != nil
    end
    if t == 9
      $game_variables[@var] = 3
      $scene = Scene_Map.new
    end
  end
  def ia
    for t in 0...2
      @v = t
      for i in 0...@pos.size
        a = @pos[0]
        b = @pos[1]
        c = @pos[2]
        if    (j(a) and j(b) and !j(c))
          next if @jogou[c-1] != nil
          @w.index = c-1
          return
        elsif (j(a) and !j(b) and j(c))
          next if @jogou[b-1] != nil
          @w.index = b-1
          return
        elsif (!j(a) and j(b) and j(c))
          next if @jogou[a-1] != nil
          @w.index = a-1
          return
        end
      end
    end
    if s != false
      @w.index = s-1
      return
    end
    @v = 1
    @w.index = 3
    if @jogada == 1
      for i in 0...4
        @w.index = 4 if j(@pos3)
      end
    end
    @v = 0
    return if @w.index == 4
    loop do
      @w.index = rand(9)
      next if @jogada == 1 and (@w.index == 1 or @w.index == 3 or @w.index == 5 or @w.index == 7)
      return if @jogou[@w.index] == nil
    end
  end
  def s
    for i in 0...6
      @v = 1
      a = j(@pos2[0]) and j(@pos2[1])
      @v = 0
      for h in 0...2
        r = @pos2[3+h] if a and j(@pos2[2]) and @jogou[@pos2[3+h]] == nil
      end
    end
    return (r == nil ? false : r)
  end
  def f(a,b,c)
    return (j(a) and j(b) and j(c))
  end
  def j(i)
    return @jogou[i-1] == @v
  end
  def terminate
    super
    Graphics.freeze
    @w.dispose
    perform_transition
    l = 416
    v = 4
    for i in 0...(544-416)/v
      l += v
      Graphics.resize_screen(l,416)
    end
    dispose_menu_background
  end
end
class Window_Velha < Window_Selectable
  def initialize
    super(0, 0, 416, 416, 32)
    @item_max = 9
    @column_max = 3
    self.index = 0
    self.contents.font.size = 50
  end
  def draw(symbol)
      a = (416-32)/3
      x = define_x(a)
      y = define_y(a)
    self.contents.draw_text(x,y+((a-50)/2),a,50,symbol.to_s,1)
  end
  def define_x(a)
    case @index
    when 0,3,6
      x = a*0
    when 1,4,7
      x = a*1
    when 2,5,8
      x = a*2
    end
    return x
  end
  def define_y(a)
    case @index
    when 0,1,2
      y = a*0
    when 3,4,5
      y = a*1
    when 6,7,8
      y = a*2
    end
    return y
  end
  def update_cursor
    if @index < 0
      self.cursor_rect.empty
    else
      a = (416-32)/3
      x = define_x(a)
      y = define_y(a)
      self.cursor_rect.set(x, y, a, a)
    end
  end
end

Nun der Skript funktioniert so ganz gut nur, wie bekomme ich raus wer gewonnen hat?

Könnte mir vll. jemand so etwas machen?
Dachte es kann ca. so aussehen:
A1 ist oben links hier im Bsp.
if((A1 == X & A2 == X & A3 == X) oder
    (B1 == X & B2 == X & B3 == X) oder
    (B1 == X & B2 == X & B3 == X) oder
    (A1 == X & B2 == X & C3 == X) oder
    (A3 == X & B2 == X & C1 == X))
{
// X hat gewonnen
variable[10] +1;
}
elseif((A1 == O & A2 == O & A3 == O) oder
    (B1 == O & B2 == O & B3 == O) oder
    (B1 == O & B2 == O & B3 == O) oder
    (A1 == O & B2 == O & C3 == O) oder
    (A3 == O & B2 == O & C1 == O))
{
// O hat gewonnen
variable[11] +1;
}
// Und Unentschieden weiß ich nicht wie man das ausdrücken könnte

Da ich nur c# kann ist es mit der Syntax von Ruby für mich ziemlich schwer,
also bitte greift mir unter die Arme. Danke ^^
Titel: Re: Tik Tak Toe Hilfe ^^
Beitrag von: Ðeity am Juni 01, 2009, 15:16:39
Hi.
Ich hoffe es klappt so wie es soll :D
Im script, änderst du in der 13 Zeile;
    @var = var
zu
    @var = 1#Die rote Nummer = Variable die du haben willst
Nun ist es ziemmlich simpel, hast du das Spiel gewonen, ändert sich die variable zu 1. Bei einer Niederlage, wird sie zu 2 und bei Unentschieden zu 3. Dieses kannst du ganz einfach abrufen durch z.B.;
Conditional Branch (Variable = 1 oder Script($game_variables[1] = 1) etc.
Jetzt kanst du im Spiel guken, wer gewonen hat die Darstellung, würde ich sagen musst du dann in einer Nachricht oder mit Show Picture anzeigen oder, du bist soweit mit RGSS, dass du eine Message anzeigen lassen kannst.^^
MfG
Deity
Titel: Re: Tik Tak Toe Hilfe ^^
Beitrag von: saschb2b am Juni 01, 2009, 15:25:34
XD das ist viel einfacher als das, was ich mir gedacht habe.
Danke
Titel: Re: Tik Tak Toe Hilfe ^^
Beitrag von: Ðeity am Juni 01, 2009, 15:27:18
Simply the Best viel Glück mit RGSS :D und keine ursache
MfG
Deity
SimplePortal 2.3.3 © 2008-2010, SimplePortal