RpgsLz
Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.

Script jogo da velha

3 participantes

Ir para baixo

Script jogo da velha Empty Script jogo da velha

Mensagem  P. R. da Silva Ter maio 19, 2009 9:40 pm

Explicação:


Bem o nome diz tudo esse é um script que cria um jogo da velha.

Screen:


Script jogo da velha 2ens56o

Utilização:


Colo o Script acima do Main
Para chama-lo crie um evento e coloque esse código num chamar script:
Código:
$scene = Tictactoe.new

Script:


Código:
######################################
# Jeu Tic-tac-toe fait par Seigneur Shadow - 21 Décembre 2006
# Version : 1.3
######################################
# $scene = Tictactoe.new
######################################

class Tictactoe

@@turn = "x"
@@font_name = "Arial"
@@font_size = 40

def initialize(menu_index = 0)
@menu_index = menu_index
end
######################
def main
@turnWindow = Turn_Window.new(@@turn)
@turnWindow.x = 450
@turnWindow.y = 370
setSquares
setMenu

Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end

Graphics.freeze
@command_window.dispose
@turnWindow.dispose

for x in 0..8
@sqr[x].dispose
end
end
######################
def update
@command_window.update
@turnWindow.update(@@turn)

for x in 0..8
@sqr[x].update
end

if @command_window.active
update_command
return
end
end

######################
def update_command
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
if Input.trigger?(Input::C)
case @command_window.index
when 0..8
$game_system.se_play($data_system.decision_se)
doAction(@command_window.index)
when 9
$game_system.se_play($data_system.decision_se)
$scene = Tictactoe.new
when 10
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
end
return
end
end
######################
def setMenu
s1 = "Acima - Esquerda"
s2 = "Acima - Meio"
s3 = "Acima - Direita"
s4 = "Centro - Esquerda"
s5 = "Centro - Meio"
s6 = "Centro - Direita"
s7 = "Abaixo - Esquerda"
s8 = "Abaixo - Meio"
s9 = "Abaixo - Direita"
s10 = "Recomeçar"
s11 = "Sair"
@command_window = Window_Command.new(175, [s1, s2, s3, s4, s5, s6,s7,s8,s9,s10,s11])
@command_window.index = @menu_index
@command_window.x = 440
end
######################
def setSquares
@sqr = []
for x in 0..2
@sqr[x] = Square.new(@@font_name,@@font_size)
@sqr[x].x = (x+1)*100
@sqr[x].y = 50
end

for x in 3..5
@sqr[x] = Square.new(@@font_name,@@font_size)
@sqr[x].x = (x-2)*100
@sqr[x].y = 150
end

for x in 6..8
@sqr[x] = Square.new(@@font_name,@@font_size)
@sqr[x].x = (x-5)*100
@sqr[x].y = 250
end

end
######################
def doAction(squareId)
if (@sqr[squareId].getOwner == "none")
@sqr[squareId].setOwner(@@turn)
verifyScore
else
$game_system.se_play($data_system.buzzer_se)
end
end
######################
def verifyScore
gameIsFinish = false
#check all --
for x in 0..2
if (@sqr[x*3].getOwner == @@turn && @sqr[x*3+1].getOwner == @@turn && @sqr[x*3+2].getOwner == @@turn)
print "O "+@@turn+" venceu !"
gameIsFinish = true
end
end

#check all |
for x in 0..2
if (@sqr[x].getOwner == @@turn && @sqr[x+3].getOwner == @@turn && @sqr[x+6].getOwner == @@turn)
print "O "+@@turn+" venceu !"
gameIsFinish = true
end
end

#check \
if (@sqr[0].getOwner == @@turn && @sqr[4].getOwner == @@turn && @sqr[8].getOwner == @@turn)
print "O "+@@turn+" venceu !"
gameIsFinish = true
end

#check /
if (@sqr[2].getOwner == @@turn && @sqr[4].getOwner == @@turn && @sqr[6].getOwner == @@turn)
print "O "+@@turn+" venceu !"
gameIsFinish = true
end

if noMoreSpace && !gameIsFinish
print "Velha!"
$scene = Scene_Restart.new
end

if gameIsFinish
$scene = Scene_Restart.new
elsif (@@turn == "x")
@@turn = "o"
else @@turn = "x"
end
end
######################
def noMoreSpace
for x in 0..8
if (@sqr[x].getOwner == "none")
return false
end
end
return true
end
######################
end

#----------------------------------------------------------------------
#Squares
#----------------------------------------------------------------------
class Square < Window_Base

def initialize(fontName,fontSize)
@owner = "none"

super(0, 0, 100,100)
self.contents = Bitmap.new(width-32, height-32)
self.contents.font.name = fontName
self.contents.font.size = fontSize
refresh
end

def refresh
self.contents.clear
if (@owner == "x")
self.contents.font.color = text_color(2)
self.contents.draw_text(22, 15, 100, 32, "X")
elsif (@owner == "o")
self.contents.font.color = text_color(1)
self.contents.draw_text(22, 15, 100, 32, "O")
end
end

def update
refresh
end
#############
def setOwner(newOwner)
@owner = newOwner
end
#############
def getOwner
return @owner
end
#############
end

#----------------------------------------------------------------------
#Turn Window
#----------------------------------------------------------------------
class Turn_Window < Window_Base

def initialize(turn)
super(0, 0, 165,64)
self.contents = Bitmap.new(width-32, height-32)
self.contents.font.name = "Arial"
self.contents.font.size = 30
refresh(turn)
end

def refresh(turn)
self.contents.clear
if (turn == "x")
self.contents.font.color = text_color(2)
self.contents.draw_text(0,0,100,32,"Jogador1: X")
elsif
self.contents.font.color = text_color(1)
self.contents.draw_text(0,0,100,32,"Jogador2: O")
end
end

def update(turn)
refresh(turn)
end
end
#----------------------------------------------------------------------
#scene restart
#----------------------------------------------------------------------
class Scene_Restart

@@font_name = "Georgia"
@@font_size = 40

def initialize(menu_index = 0)
@menu_index = menu_index
end
######################
def main
setMenu

Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end

Graphics.freeze
@command_window.dispose
end
######################
def update
@command_window.update

if @command_window.active
update_command
return
end
end
######################
def update_command
if Input.trigger?(Input::C)
case @command_window.index
when 0
$game_system.se_play($data_system.decision_se)
$scene = Tictactoe.new
when 1
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
end
return
end
end
######################
def setMenu
s1 = "Recomeçar"
s2 = "Sair"
@command_window = Window_Command.new(180, [s1, s2])
@command_window.index = @menu_index
@command_window.x = 250
@command_window.y = 200
end
end

Créditos:


Criado por: Seigneur Shadow
Traduzido por: P. R. da Silva
P. R. da Silva
P. R. da Silva

Mensagens : 2
Creditos : 303
Reputação : 3
Data de inscrição : 19/05/2009
Idade : 30
Localização : Itanhaém

Ir para o topo Ir para baixo

Script jogo da velha Empty Excelente Nota 10!

Mensagem  Lz-Admin Qui maio 21, 2009 9:54 pm

Gostei muito do topico,Script e vai ajudar Bastante no meu rpg(Colocarei seu nome nos creditos).

A contribuição do Administrador P.R Silva vai ser muito importante para o Forum!.
Script jogo da velha Kuran10
Lz-Admin
Lz-Admin
Admin

Mensagens : 32
Creditos : 100000007
Reputação : 0
Data de inscrição : 29/04/2009
Idade : 43
Localização : Juazeiro

https://forumlz.directorioforuns.com

Ir para o topo Ir para baixo

Script jogo da velha Empty Re: Script jogo da velha

Mensagem  Saraiva-kun Dom maio 24, 2009 2:49 am

Muito legal, é a versão atualizada, e bem eficiente e relaxante. Valeu por disponibilizar.
Saraiva-kun
Saraiva-kun

Mensagens : 5
Creditos : 15
Reputação : 9
Data de inscrição : 14/05/2009
Idade : 28
Localização : Soul Socyet

http://saraiva-kun.blogspot.com/

Ir para o topo Ir para baixo

Script jogo da velha Empty Re: Script jogo da velha

Mensagem  Conteúdo patrocinado


Conteúdo patrocinado


Ir para o topo Ir para baixo

Ir para o topo


 
Permissões neste sub-fórum
Não podes responder a tópicos