Mastermind Minigame for RPGVXA?

VTDraws

Filthy Point-&-Click casual
Veteran
Joined
Apr 17, 2017
Messages
56
Reaction score
9
First Language
English
Primarily Uses
RMMV
So I'm currently working on a point-and-click type adventure game and needed a small handful of minigames for it. I found a few that are rather nice, but then the one that I really wanted to work out is only for VX.
Would anyone either be able to translate this to VX Ace or make a new version for VX Ace? It doesn't seem like too complex of a script:
http://rmrk.net/index.php?topic=42143.0
 

VTDraws

Filthy Point-&-Click casual
Veteran
Joined
Apr 17, 2017
Messages
56
Reaction score
9
First Language
English
Primarily Uses
RMMV

VTDraws

Filthy Point-&-Click casual
Veteran
Joined
Apr 17, 2017
Messages
56
Reaction score
9
First Language
English
Primarily Uses
RMMV
Pbbbt bump again.
 

VTDraws

Filthy Point-&-Click casual
Veteran
Joined
Apr 17, 2017
Messages
56
Reaction score
9
First Language
English
Primarily Uses
RMMV
If someone can't help me script this, could anyone give me an event system for it? I can't seem to figure it out.
 

DarkEspeon

Veteran
Veteran
Joined
Apr 9, 2017
Messages
86
Reaction score
15
First Language
Russian
Primarily Uses
RMMV
God damn it, the guy has been waiting for 4 months, is there really no one who can help him?
 

TakeHomeTheCup

Veteran
Veteran
Joined
Oct 15, 2013
Messages
244
Reaction score
460
First Language
English
Primarily Uses
Do you have the images for the script? All the download links aren't working.
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,655
Reaction score
562
First Language
English
Primarily Uses
RMVXA
I was able to get some and photoshoped out three. Color 0, 2 and answer.
The blue and green need to switch numbers
 

Attachments

Last edited:

VTDraws

Filthy Point-&-Click casual
Veteran
Joined
Apr 17, 2017
Messages
56
Reaction score
9
First Language
English
Primarily Uses
RMMV
I was able to get some and photoshoped out three. Color 0, 2 and answer.
I appreciate any help, I could get the images if they're still needed.
 

TakeHomeTheCup

Veteran
Veteran
Joined
Oct 15, 2013
Messages
244
Reaction score
460
First Language
English
Primarily Uses
Well, this is my attempt.
Thanks to, @Roninator2 for the images.
Code:
#==============================================================================
#  Mastermind (VX)
#  Version: 1.0
#  Author: Zylos (rmrk.net)
#  Date: March 21, 2011
#------------------------------------------------------------------------------
#  Description:
#
#   This script sets up a classic Mastermind minigame, in which the player must
#   try to guess the secret sequence of colors that the opponent has chosen.
#   Each turn, the player selects a four piece sequence using six different
#   colors, and the opponent responds by giving the player black and white
#   pegs accordingly. A black peg means that the player has a right color piece
#   in the right position, while a white peg means that the player has a right
#   color piece but in the wrong position. The game ends when the player either
#   guesses correctly or has failed to figure it out after eight turns.
#
#------------------------------------------------------------------------------
#  Instructions:
#   
#     - Place this script in the materials section, above Main.
#
#     - Copy the game board and piece graphics to your game's pictures folder.
#       If you do not already have them, they can be found at:
#       http://rmrk.net/index.php/topic,42143.0.html
#
#     - Check the script options below these instructions to tweak the game's
#       appearance to your likings or change the winning and losing sounds.
#
#     - To start the minigame, simply call it with an event by using the
#       script command and entering "call_mastermind" without the quotation
#       marks. It'll automatically initiate the game.
#
#==============================================================================

module Mastermind_Options
    #============================================================================
    # EDITABLE REGION:
    #============================================================================
    
    Win_Lose = true                       # Show the Win Loss Ratio window
    Side = true                           # Show the side decoration graphic
    Black_Background = true              # Show a black background
    Game_Music = false                    # Plays a different BGM during game
    Game_BGM = ""              # BGM played during the game
    Win_Sound = ""            # Sound played when game is won
    Win_Sound_Type = ""                 # Type of sound Win_Sound is (ME/SE)
    Loss_Sound = ""          # Sound played when game is lost
    Loss_Sound_Type = ""                # Type of sound Loss_Sound is (ME/SE)
    
    #============================================================================
    # END EDITABLE REGION
    #============================================================================
end

#==============================================================================
# ** Game_System
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Adding the wins and losses variables to the game here.
#==============================================================================

class Game_System
    #--------------------------------------------------------------------------
    # * Public Instance Variables
    #--------------------------------------------------------------------------
    attr_accessor :wins                    # number of wins
    attr_accessor :losses                  # number of losses
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    alias_method :winlossratio, :initialize
    def initialize
        winlossratio
        @wins = 0
        @losses = 0
    end
end

#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Adding the mastermind command.
#==============================================================================

class Game_Interpreter
    #--------------------------------------------------------------------------
    # * Call Mastermind
    #--------------------------------------------------------------------------
    def call_mastermind
        SceneManager.call(Scene_Mastermind)
    end
end

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  Adding the change to Scene_Mastermind.
#==============================================================================

#~ class Scene_Map
#~ #--------------------------------------------------------------------------
#~ # * Execute Screen Switch
#~ #--------------------------------------------------------------------------
#~ alias kylos_mm_update_scene_change scene_change
#~ def kylos_mm_update_scene_change
#~ return if $game_player.moving?   
#~ if $game_temp.next_scene == "mastermind"
#~ call_mastermind
#~ else
#~ scene_change
#~ end
#~ end
#~ #--------------------------------------------------------------------------
#~ # * Switch to Mastermind
#~ #-------------------------------------------------------------------------- 
#~ def call_mastermind
#~ $game_temp.next_scene = nil
#~ $scene = Scene_Mastermind.new
#~ end
#~ end

#==============================================================================
# ** Window_MastermindRatio
#------------------------------------------------------------------------------
#  This window displays yours wins versus your losses in Mastermind.
#==============================================================================

class Window_MastermindRatio < Window_Base
    #--------------------------------------------------------------------------
    # * Object Initialization
    #     x : window X coordinate
    #     y : window Y coordinate
    #--------------------------------------------------------------------------
    def initialize(x, y)
        super(x, y, 135, 80)
        refresh
    end
    #--------------------------------------------------------------------------
    # * Refresh
    #--------------------------------------------------------------------------
    def refresh
        self.contents.clear
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 90, line_height, "Wins:")
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 90, line_height, $game_system.wins, 2)
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 90, line_height*2.6, "Losses:")
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 90, line_height*2.6, $game_system.losses, 2)
    end
end

class Window_MastermindCommand < Window_Command
    def initialize(x, y)
        super(x, y)
    end
    
    def process_handling
        
    end
    
    def make_command_list
        s1 = "Play game?"
        s2 = "Quit"
        add_command(s1, :s1)
        add_command(s2, :s2)
    end
    
end


class Window_MastermindCommand_Color < Window_Command
    def initialize(x, y)
        super(x, y)
    end
    
    def make_command_list
        s1 = "Red"
        s2 = "Orange"
        s3 = "Yellow"
        s4 = "Green"
        s5 = "Blue"
        s6 = "Purple"
        add_command(s1, :s1a)
        add_command(s2, :s2a)
        add_command(s3, :s3)
        add_command(s4, :s4)
        add_command(s5, :s5)
        add_command(s6, :s6)
    end
    
    def process_handling
        
    end
    
    def visible_line_number
        return 6
    end
    
end


#==============================================================================
# ** Scene_Mastermind
#------------------------------------------------------------------------------
#  This class performs the Mastermind screen processing.
#==============================================================================

class Scene_Mastermind < Scene_MenuBase
    #--------------------------------------------------------------------------
    # * Start processing
    #--------------------------------------------------------------------------
    def start
        super
        if Mastermind_Options::Game_Music == true
            @last_bgm = RPG::BGM::last
            @last_bgs = RPG::BGS::last
            RPG::BGS.stop
            temp_sound = "Audio/BGM/" + Mastermind_Options::Game_BGM
            Audio.bgm_play(temp_sound, 100, 100)
        end
        @play_vocab = "Play game?"
        @cancel_vocab = "Quit"
        create_background if Mastermind_Options::Black_Background == false
        create_command_window
        create_command_window_2
        if Mastermind_Options::Win_Lose == true
            @winloss = Window_MastermindRatio.new(5.5, 10)
        end
        @board_sprite = Sprite.new(Viewport.new(0, 0, 544, 416))
        @board_sprite.bitmap = Cache.picture("mm_board")
        @board_sprite.x = 0
        @board_sprite.y = 0
        @board_sprite.z = 1
        @answer_sprite = Sprite.new
        @answer_sprite.bitmap = Cache.picture("mm_answer")
        @answer_sprite.x = 212
        @answer_sprite.y = -25
        @answer_sprite.z = 10
        if Mastermind_Options::Side == true
            @side_sprite = Sprite.new
            @side_sprite.bitmap = Cache.picture("mm_side")
            @side_sprite.x = 399 + (146 - @side_sprite.width) / 2
            @side_sprite.y = (416 - @side_sprite.height) / 2
            @side_sprite.z = 1
        end
        @color_sprite = []
        @peg_sprite = []
        @guess = []
        @guess_used = []
        @answer = []
        @answer_used = []
        @color_index = 0
        @peg_index = 0
        @game_mode = "start"
    end
    #--------------------------------------------------------------------------
    # * Post-Start Processing
    #--------------------------------------------------------------------------
    def post_start
        super
        open_command_window
    end
    #--------------------------------------------------------------------------
    # * Wait
    #--------------------------------------------------------------------------
    def wait(duration)
        for i in 0...duration
            Graphics.update
        end
    end
    #--------------------------------------------------------------------------
    # * Pre-termination Processing
    #--------------------------------------------------------------------------
    def pre_terminate
        super
        close_command_window
        close_command_window_2
    end
    #--------------------------------------------------------------------------
    # * Termination Processing
    #--------------------------------------------------------------------------
    def terminate
        super
        dispose_command_window
        @board_sprite.dispose
        @answer_sprite.dispose
        @side_sprite.dispose if Mastermind_Options::Side == true
        @winloss.dispose if Mastermind_Options::Win_Lose == true
        if @color_index != 0
            for i in 0...@color_index
                @color_sprite[i].dispose
            end
            for i in 0...@peg_index
                @peg_sprite[i].dispose
            end
        end
        if Mastermind_Options::Game_Music == true
            @last_bgm.play
            @last_bgs.play
        end
    end
    #--------------------------------------------------------------------------
    # * Frame Update
    #--------------------------------------------------------------------------
    def tests
        p 1
    end
    
    def update
        super
        #update_menu_background if Mastermind_Options::Black_Background == false
        @winloss.update if Mastermind_Options::Win_Lose == true
        if @game_mode == "start"
            if Input.press?(:C)
                case @command_window.index
                when 0
                    Sound.play_ok
                    close_command_window
                    cover_answer
                when 1
                    Sound.play_cancel
                    SceneManager.return
                end
            end
        elsif @game_mode == "color"
            if Input.trigger?(:C)
                if @guess_index != 4
                    Sound.play_ok
                    @go = @command_window_2.index
                    @guess[@guess_index] = @go
                    @color_sprite[@color_index] = Sprite.new
                    @color_sprite[@color_index].bitmap=Cache.picture("mm_color"+@go.to_s)
                    @color_sprite[@color_index].x = 228 + (@guess_index * 35)
                    @color_sprite[@color_index].y = 360 - (@round_index * 40)
                    @color_sprite[@color_index].z = 2
                    @guess_index += 1
                    @color_index += 1
                    if @guess_index == 4
                        @game_mode = "peg"
                        close_command_window_2
                        @command_window.index = 0
                        @command_window_2.index = 0
                        wait(15)
                        check_colors
                    end
                end
            end
            if Input.trigger?(:B)
                if @guess_index == 0
                    Sound.play_cancel
                    close_command_window_2
                    @play_vocab = "Continue"
                    @cancel_vocab = "Quit"
                    @command_window.index = 0
                    @command_window.dispose
                    create_command_window
                    open_command_window
                    @game_mode = "quit"
                else
                    case @guess_index
                    when 1
                        @guess[0] = -1
                    when 2
                        @guess[1] = -1
                    when 3
                        @guess[2] = -1
                    end
                    @guess_index -= 1
                    @color_index -= 1
                    Sound.play_cancel
                    @color_sprite[@color_index].dispose
                end
            end
        elsif @game_mode == "quit"
            if Input.press?(:C)
                case @command_window.index
                when 0
                    Sound.play_ok
                    close_command_window
                    open_command_window_2
                    @game_mode = "color"
                when 1
                    Sound.play_cancel
                    SceneManager.return
                end 
            end
        elsif @game_mode == "win" or @game_mode == "lose"
            if @command_window.openness == 255
                if Input.trigger?(:C)
                    case @command_window.index
                    when 0
                        Sound.play_ok
                        opac = 250
                        close_command_window
                        wait(8)
                        begin
                            opac -= 10
                            for i in 0...@color_index
                                @color_sprite[i].opacity = opac
                            end
                            for i in 0...@peg_index
                                @peg_sprite[i].opacity = opac
                            end
                            wait(2)
                        end until opac == 0
                        for i in 0...@color_index
                            @color_sprite[i].dispose
                        end
                        for i in 0...@peg_index
                            @peg_sprite[i].dispose
                        end
                        wait(10)
                        cover_answer
                    when 1
                        Sound.play_cancel
                        SceneManager.return
                    end
                end
            end
        end 
    end 
    #--------------------------------------------------------------------------
    # * Update Background for Menu Screen
    #--------------------------------------------------------------------------
    def update_menu_background
        #~ super
        #~ @menuback_sprite.tone.set(0, 0, 0, 128)
    end
    #--------------------------------------------------------------------------
    # * Game Start
    #--------------------------------------------------------------------------
    def cover_answer
        @round_index = 0
        @color_index = 0
        @peg_index = 0
        @guess[0] = -1
        @guess[1] = -1
        @guess[2] = -1
        @guess[3] = -1
        @guess_used[0] = false
        @guess_used[1] = false
        @guess_used[2] = false
        @guess_used[3] = false
        @guess_index = 0
        @answer[0] = -1
        @answer[1] = -1
        @answer[2] = -1
        @answer[3] = -1
        @answer_used[0] = false
        @answer_used[1] = false
        @answer_used[2] = false
        @answer_used[3] = false
        @peg_hole = 0
        @j = 0
        @k = 0   
        @distance = 19 - (@answer_sprite.y)
        @iindex = 0
        RPG::ME.stop
        RPG::SE.stop
        for i in 0...4
            Sound.play_cursor
            temp_answer = rand(5)
            @color_sprite[i] = Sprite.new
            @color_sprite[i].bitmap=Cache.picture("mm_color"+temp_answer.to_s)
            @color_sprite[i].x = 228 + (i * 35)
            @color_sprite[i].y = 29
            @color_sprite[i].z = 2
            @color_index += 1
            wait(10)
        end
        while @distance > 0
            @answer_sprite.y += 1
            temp_answer = rand(5)
            @color_sprite[@iindex].bitmap=Cache.picture("mm_color"+temp_answer.to_s)
            @iindex += 1
            if @iindex == 4
                @iindex = 0
            end
            @distance = 19 - (@answer_sprite.y)
            Sound.play_cursor
            wait(2)
        end
        for i in 0...4
            @answer[i] = rand(5)
            @color_sprite[i].bitmap=Cache.picture("mm_color"+@answer[i].to_s)
            @color_sprite[i].z = 2
        end
        open_command_window_2
        @game_mode = "color"
    end
    #--------------------------------------------------------------------------
    # * Game End
    #--------------------------------------------------------------------------
    def uncover_answer
        begin
            @answer_sprite.y -= 1
            wait(2)
        end until @answer_sprite.y == -25
        @play_vocab = "Rematch"
        @cancel_vocab = "Quit"
        @command_window.dispose
        create_command_window
        open_command_window 
    end
    #--------------------------------------------------------------------------
    # * Round End
    #--------------------------------------------------------------------------
    def check_colors
        for i in 0...4
            if @guess[i] == @answer[i]
                @guess_used[i] = true
                @answer_used[i] = true
                @peg_sprite[@peg_index] = Sprite.new
                @peg_sprite[@peg_index].bitmap = Cache.picture("mm_black")
                case @peg_hole
                when 0
                    @peg_sprite[@peg_index].x = 184
                    @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                when 1
                    @peg_sprite[@peg_index].x = 198
                    @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                when 2
                    @peg_sprite[@peg_index].x = 184
                    @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                when 3
                    @peg_sprite[@peg_index].x = 198
                    @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                end
                @peg_sprite[@peg_index].z = 2
                @peg_index += 1
                @peg_hole += 1
                if @peg_hole == 4
                    @game_mode = "win"
                end
            end
        end
        while @j <= 3
            if @j != @k
                if @guess[@j] == @answer[@k]
                    if @guess_used[@j] == false
                        if @answer_used[@k] == false
                            @guess_used[@j] = true
                            @answer_used[@k] = true
                            @peg_sprite[@peg_index] = Sprite.new
                            @peg_sprite[@peg_index].bitmap = Cache.picture("mm_white")
                            case @peg_hole
                            when 0
                                @peg_sprite[@peg_index].x = 184
                                @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                            when 1
                                @peg_sprite[@peg_index].x = 198
                                @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                            when 2
                                @peg_sprite[@peg_index].x = 184
                                @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                            when 3
                                @peg_sprite[@peg_index].x = 198
                                @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                            end
                            @peg_sprite[@peg_index].z = 2
                            @peg_index += 1
                            @peg_hole += 1
                        end
                    end
                end
            end
            @k += 1
            if @k == 4
                @j += 1
                @k = 0
            end
        end
        @guess[0] = -1
        @guess[1] = -1
        @guess[2] = -1
        @guess[3] = -1
        @guess_used[0] = false
        @guess_used[1] = false
        @guess_used[2] = false
        @guess_used[3] = false
        @guess_index = 0
        @answer_used[0] = false
        @answer_used[1] = false
        @answer_used[2] = false
        @answer_used[3] = false
        @peg_hole = 0
        @j = 0
        @k = 0
        wait(15)
        if @round_index == 7 and @game_mode != "win"
            @game_mode = "lose"
            if Mastermind_Options::Loss_Sound_Type == "SE"
                temp_sound = "Audio/SE/" + Mastermind_Options::Loss_Sound
                Audio.se_play(temp_sound, 100, 100)
            elsif Mastermind_Options::Loss_Sound_Type == "ME"
                temp_sound = "Audio/ME/" + Mastermind_Options::Loss_Sound       
                Audio.me_play(temp_sound, 100, 100)
            end
            $game_system.losses += 1
            @winloss.refresh if Mastermind_Options::Win_Lose == true
            uncover_answer
        elsif @game_mode == "win"
            if Mastermind_Options::Win_Sound_Type == "SE"
                temp_sound = "Audio/SE/" + Mastermind_Options::Win_Sound
                Audio.se_play(temp_sound, 100, 100)
            elsif Mastermind_Options::Win_Sound_Type == "ME"
                temp_sound = "Audio/ME/" + Mastermind_Options::Win_Sound       
                Audio.me_play(temp_sound, 100, 100)
            end
            $game_system.wins += 1
            @winloss.refresh if Mastermind_Options::Win_Lose == true
            uncover_answer
        else
            @round_index += 1
            open_command_window_2
            @game_mode = "color"
        end
    end
    #--------------------------------------------------------------------------
    # * Create Command Window
    #--------------------------------------------------------------------------
    def create_command_window
        @command_window = Window_MastermindCommand.new(0, 0)
        @command_window.x = (Graphics.width - @command_window.width) / 2
        @command_window.y = (Graphics.height - @command_window.height) / 2
        @command_window.height = @command_window.fitting_height(2)
        @command_window.refresh
        @command_window.openness = 0
    end
    #--------------------------------------------------------------------------
    # * Dispose of Command Window
    #--------------------------------------------------------------------------
    def dispose_command_window
        @command_window.dispose
        @command_window_2.dispose
    end
    #--------------------------------------------------------------------------
    # * Open Command Window
    #--------------------------------------------------------------------------
    def open_command_window
        @command_window.open
        @command_window.refresh
        @command_window.active = true
    end
    #--------------------------------------------------------------------------
    # * Close Command Window
    #--------------------------------------------------------------------------
    def close_command_window
        @command_window.close
        @command_window.refresh
        @command_window.active = false
    end
    #--------------------------------------------------------------------------
    # * Create Command Window Two
    #--------------------------------------------------------------------------
    def create_command_window_2
        @command_window_2 = Window_MastermindCommand_Color.new(0, 0)
        @command_window_2.x = (198 - @command_window_2.width) / 2
        @command_window_2.height = @command_window_2.fitting_height(6)
        if Mastermind_Options::Win_Lose == false
            @command_window_2.y = (Graphics.height - @command_window_2.height) / 2
        else
            @command_window_2.y = 210
        end
        @command_window_2.openness = 0
        @command_window_2.active = false
    end
    #--------------------------------------------------------------------------
    # * Open Command Window Two
    #--------------------------------------------------------------------------
    def open_command_window_2
        @command_window_2.open
        @command_window_2.active = true
        @command_window_2.refresh
    end
    #--------------------------------------------------------------------------
    # * Close Command Window Two
    #--------------------------------------------------------------------------
    def close_command_window_2
        @command_window_2.close
        @command_window_2.active = false
        @command_window_2.refresh
    end
end
 
Last edited:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,157
Reaction score
821
First Language
Hungarian
Primarily Uses
RMVXA
@TakeHomeTheCup
Please edit that and use code tags. Your code is messed up now.
I know exactly what's been changed to smileys, but someone without much scripting knowledge might not.
But that is really not the biggest issue, that would be the formatting. It hurts my eyes to see any code like this. :D
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,655
Reaction score
562
First Language
English
Primarily Uses
RMVXA
Apparently the answer graphic does not fit well. Here's a new one that should work.
mm_answer.png
 
Last edited:

VTDraws

Filthy Point-&-Click casual
Veteran
Joined
Apr 17, 2017
Messages
56
Reaction score
9
First Language
English
Primarily Uses
RMMV
Sorry for the late reply, I super appreciate the help with this! Now, I just have one last request... Is there any way we could code the game to not have repeating colors? Patterns with one color in more than one slot [like Green Green Orange Yellow] are infinitely harder to solve than patterns that only allow a color to appear once. [As opposed to Green Blue Orange Yellow].
I'm not sure if that could be coded, but it seems like it should be possible. Like as it's making the pattern, 'if _ has been used, use any other color' and then repeat until the fourth color so there's no repeats.
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,655
Reaction score
562
First Language
English
Primarily Uses
RMVXA
I adjusted the values to make it fit in a 640 x 480 screen.
If anybody is interested in that.
Code:
#==============================================================================
#  Mastermind (VX)
#  Version: 1.0
#  Author: Zylos (rmrk.net)
#  Date: March 21, 2011
#------------------------------------------------------------------------------
#  Description:
#
#   This script sets up a classic Mastermind minigame, in which the player must
#   try to guess the secret sequence of colors that the opponent has chosen.
#   Each turn, the player selects a four piece sequence using six different
#   colors, and the opponent responds by giving the player black and white
#   pegs accordingly. A black peg means that the player has a right color piece
#   in the right position, while a white peg means that the player has a right
#   color piece but in the wrong position. The game ends when the player either
#   guesses correctly or has failed to figure it out after eight turns.
#
#------------------------------------------------------------------------------
#  Instructions:
#   
#     - Place this script in the materials section, above Main.
#
#     - Copy the game board and piece graphics to your game's pictures folder.
#       If you do not already have them, they can be found at:
#       http://rmrk.net/index.php/topic,42143.0.html
#
#     - Check the script options below these instructions to tweak the game's
#       appearance to your likings or change the winning and losing sounds.
#
#     - To start the minigame, simply call it with an event by using the
#       script command and entering "call_mastermind" without the quotation
#       marks. It'll automatically initiate the game.
#
#==============================================================================

module Mastermind_Options
    #============================================================================
    # EDITABLE REGION:
    #============================================================================
    
    Win_Lose = true                       # Show the Win Loss Ratio window
    Side = true                           # Show the side decoration graphic
    Black_Background = true              # Show a black background
    Game_Music = false                    # Plays a different BGM during game
    Game_BGM = ""              # BGM played during the game
    Win_Sound = ""            # Sound played when game is won
    Win_Sound_Type = ""                 # Type of sound Win_Sound is (ME/SE)
    Loss_Sound = ""          # Sound played when game is lost
    Loss_Sound_Type = ""                # Type of sound Loss_Sound is (ME/SE)
    
    #============================================================================
    # END EDITABLE REGION
    #============================================================================
end

#==============================================================================
# ** Game_System
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Adding the wins and losses variables to the game here.
#==============================================================================

class Game_System
    #--------------------------------------------------------------------------
    # * Public Instance Variables
    #--------------------------------------------------------------------------
    attr_accessor :wins                    # number of wins
    attr_accessor :losses                  # number of losses
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    alias_method :winlossratio, :initialize
    def initialize
        winlossratio
        @wins = 0
        @losses = 0
    end
end

#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Adding the mastermind command.
#==============================================================================

class Game_Interpreter
    #--------------------------------------------------------------------------
    # * Call Mastermind
    #--------------------------------------------------------------------------
    def call_mastermind
        SceneManager.call(Scene_Mastermind)
    end
end

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  Adding the change to Scene_Mastermind.
#==============================================================================

#~ class Scene_Map
#~ #--------------------------------------------------------------------------
#~ # * Execute Screen Switch
#~ #--------------------------------------------------------------------------
#~ alias kylos_mm_update_scene_change scene_change
#~ def kylos_mm_update_scene_change
#~ return if $game_player.moving?   
#~ if $game_temp.next_scene == "mastermind"
#~ call_mastermind
#~ else
#~ scene_change
#~ end
#~ end
#~ #--------------------------------------------------------------------------
#~ # * Switch to Mastermind
#~ #--------------------------------------------------------------------------
#~ def call_mastermind
#~ $game_temp.next_scene = nil
#~ $scene = Scene_Mastermind.new
#~ end
#~ end

#==============================================================================
# ** Window_MastermindRatio
#------------------------------------------------------------------------------
#  This window displays yours wins versus your losses in Mastermind.
#==============================================================================

class Window_MastermindRatio < Window_Base
    #--------------------------------------------------------------------------
    # * Object Initialization
    #     x : window X coordinate
    #     y : window Y coordinate
    #--------------------------------------------------------------------------
    def initialize(x, y)
        super(x, y, 135, 80)
        refresh
    end
    #--------------------------------------------------------------------------
    # * Refresh
    #--------------------------------------------------------------------------
    def refresh
        self.contents.clear
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 90, line_height, "Wins:")
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 90, line_height, $game_system.wins, 2)
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 90, line_height*2.6, "Losses:")
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 90, line_height*2.6, $game_system.losses, 2)
    end
end

class Window_MastermindCommand < Window_Command
    def initialize(x, y)
        super(x, y)
    end
    
    def process_handling
        
    end
    
    def make_command_list
        s1 = "Play game?"
        s2 = "Quit"
        add_command(s1, :s1)
        add_command(s2, :s2)
    end
    
end


class Window_MastermindCommand_Color < Window_Command
    def initialize(x, y)
        super(x, y)
    end
    
    def make_command_list
        s1 = "Red"
        s2 = "Orange"
        s3 = "Yellow"
        s4 = "Green"
        s5 = "Blue"
        s6 = "Purple"
        add_command(s1, :s1a)
        add_command(s2, :s2a)
        add_command(s3, :s3)
        add_command(s4, :s4)
        add_command(s5, :s5)
        add_command(s6, :s6)
    end
    
    def process_handling
        
    end
    
    def visible_line_number
        return 6
    end
    
end


#==============================================================================
# ** Scene_Mastermind
#------------------------------------------------------------------------------
#  This class performs the Mastermind screen processing.
#==============================================================================

class Scene_Mastermind < Scene_MenuBase
    #--------------------------------------------------------------------------
    # * Start processing
    #--------------------------------------------------------------------------
    def start
        super
        if Mastermind_Options::Game_Music == true
            @last_bgm = RPG::BGM::last
            @last_bgs = RPG::BGS::last
            RPG::BGS.stop
            temp_sound = "Audio/BGM/" + Mastermind_Options::Game_BGM
            Audio.bgm_play(temp_sound, 100, 100)
        end
        @play_vocab = "Play game?"
        @cancel_vocab = "Quit"
        create_background if Mastermind_Options::Black_Background == false
        create_command_window
        create_command_window_2
        if Mastermind_Options::Win_Lose == true
            @winloss = Window_MastermindRatio.new(5.5, 10)
        end
        @board_sprite = Sprite.new(Viewport.new(0, 0, 640, 480))
        @board_sprite.bitmap = Cache.picture("mm_board")
        @board_sprite.x = 50
        @board_sprite.y = 32
        @board_sprite.z = 1
        @answer_sprite = Sprite.new
        @answer_sprite.bitmap = Cache.picture("mm_answer")
        @answer_sprite.x = 260
        @answer_sprite.y = 5
        @answer_sprite.z = 10
        if Mastermind_Options::Side == true
            @side_sprite = Sprite.new
            @side_sprite.bitmap = Cache.picture("mm_side")
            @side_sprite.x = 420 + (146 - @side_sprite.width) / 2
            @side_sprite.y = (480 - @side_sprite.height) / 2
            @side_sprite.z = 1
        end
        @color_sprite = []
        @peg_sprite = []
        @guess = []
        @guess_used = []
        @answer = []
        @answer_used = []
        @color_index = 0
        @peg_index = 0
        @game_mode = "start"
    end
    #--------------------------------------------------------------------------
    # * Post-Start Processing
    #--------------------------------------------------------------------------
    def post_start
        super
        open_command_window
    end
    #--------------------------------------------------------------------------
    # * Wait
    #--------------------------------------------------------------------------
    def wait(duration)
        for i in 0...duration
            Graphics.update
        end
    end
    #--------------------------------------------------------------------------
    # * Pre-termination Processing
    #--------------------------------------------------------------------------
    def pre_terminate
        super
        close_command_window
        close_command_window_2
    end
    #--------------------------------------------------------------------------
    # * Termination Processing
    #--------------------------------------------------------------------------
    def terminate
        super
        dispose_command_window
        @board_sprite.dispose
        @answer_sprite.dispose
        @side_sprite.dispose if Mastermind_Options::Side == true
        @winloss.dispose if Mastermind_Options::Win_Lose == true
        if @color_index != 0
            for i in 0...@color_index
                @color_sprite[i].dispose
            end
            for i in 0...@peg_index
                @peg_sprite[i].dispose
            end
        end
        if Mastermind_Options::Game_Music == true
            @last_bgm.play
            @last_bgs.play
        end
    end
    #--------------------------------------------------------------------------
    # * Frame Update
    #--------------------------------------------------------------------------
    def tests
        p 1
    end
    
    def update
        super
        #update_menu_background if Mastermind_Options::Black_Background == false
        @winloss.update if Mastermind_Options::Win_Lose == true
        if @game_mode == "start"
            if Input.press?(:C)
                case @command_window.index
                when 0
                    Sound.play_ok
                    close_command_window
                    cover_answer
                when 1
                    Sound.play_cancel
                    SceneManager.return
                end
            end
        elsif @game_mode == "color"
            if Input.trigger?(:C)
                if @guess_index != 4
                    Sound.play_ok
                    @go = @command_window_2.index
                    @guess[@guess_index] = @go
                    @color_sprite[@color_index] = Sprite.new
                    @color_sprite[@color_index].bitmap=Cache.picture("mm_color"+@go.to_s)
                    @color_sprite[@color_index].x = 278 + (@guess_index * 35)
                    @color_sprite[@color_index].y = 390 - (@round_index * 40)
                    @color_sprite[@color_index].z = 2
                    @guess_index += 1
                    @color_index += 1
                    if @guess_index == 4
                        @game_mode = "peg"
                        close_command_window_2
                        @command_window.index = 0
                        @command_window_2.index = 0
                        wait(15)
                        check_colors
                    end
                end
            end
            if Input.trigger?(:B)
                if @guess_index == 0
                    Sound.play_cancel
                    close_command_window_2
                    @play_vocab = "Continue"
                    @cancel_vocab = "Quit"
                    @command_window.index = 0
                    @command_window.dispose
                    create_command_window
                    open_command_window
                    @game_mode = "quit"
                else
                    case @guess_index
                    when 1
                        @guess[0] = -1
                    when 2
                        @guess[1] = -1
                    when 3
                        @guess[2] = -1
                    end
                    @guess_index -= 1
                    @color_index -= 1
                    Sound.play_cancel
                    @color_sprite[@color_index].dispose
                end
            end
        elsif @game_mode == "quit"
            if Input.press?(:C)
                case @command_window.index
                when 0
                    Sound.play_ok
                    close_command_window
                    open_command_window_2
                    @game_mode = "color"
                when 1
                    Sound.play_cancel
                    SceneManager.return
                end
            end
        elsif @game_mode == "win" or @game_mode == "lose"
            if @command_window.openness == 255
                if Input.trigger?(:C)
                    case @command_window.index
                    when 0
                        Sound.play_ok
                        opac = 250
                        close_command_window
                        wait(8)
                        begin
                            opac -= 10
                            for i in 0...@color_index
                                @color_sprite[i].opacity = opac
                            end
                            for i in 0...@peg_index
                                @peg_sprite[i].opacity = opac
                            end
                            wait(2)
                        end until opac == 0
                        for i in 0...@color_index
                            @color_sprite[i].dispose
                        end
                        for i in 0...@peg_index
                            @peg_sprite[i].dispose
                        end
                        wait(10)
                        cover_answer
                    when 1
                        Sound.play_cancel
                        SceneManager.return
                    end
                end
            end
        end
    end
    #--------------------------------------------------------------------------
    # * Update Background for Menu Screen
    #--------------------------------------------------------------------------
    def update_menu_background
        #~ super
        #~ @menuback_sprite.tone.set(0, 0, 0, 128)
    end
    #--------------------------------------------------------------------------
    # * Game Start
    #--------------------------------------------------------------------------
    def cover_answer
        @round_index = 0
        @color_index = 0
        @peg_index = 0
        @guess[0] = -1
        @guess[1] = -1
        @guess[2] = -1
        @guess[3] = -1
        @guess_used[0] = false
        @guess_used[1] = false
        @guess_used[2] = false
        @guess_used[3] = false
        @guess_index = 0
        @answer[0] = -1
        @answer[1] = -1
        @answer[2] = -1
        @answer[3] = -1
        @answer_used[0] = false
        @answer_used[1] = false
        @answer_used[2] = false
        @answer_used[3] = false
        @peg_hole = 0
        @j = 0
        @k = 0   
        @distance = 50 - (@answer_sprite.y)
        @iindex = 0
        RPG::ME.stop
        RPG::SE.stop
        for i in 0...4
            Sound.play_cursor
            temp_answer = rand(5)
            @color_sprite[i] = Sprite.new
            @color_sprite[i].bitmap=Cache.picture("mm_color"+temp_answer.to_s)
            @color_sprite[i].x = 278 + (i * 35)
            @color_sprite[i].y = 60
            @color_sprite[i].z = 2
            @color_index += 1
            wait(10)
        end
        while @distance > 0
            @answer_sprite.y += 1
            temp_answer = rand(5)
            @color_sprite[@iindex].bitmap=Cache.picture("mm_color"+temp_answer.to_s)
            @iindex += 1
            if @iindex == 4
                @iindex = 0
            end
            @distance = 50 - (@answer_sprite.y)
            Sound.play_cursor
            wait(2)
        end
        for i in 0...4
            @answer[i] = rand(5)
            @color_sprite[i].bitmap=Cache.picture("mm_color"+@answer[i].to_s)
            @color_sprite[i].z = 2
        end
        open_command_window_2
        @game_mode = "color"
    end
    #--------------------------------------------------------------------------
    # * Game End
    #--------------------------------------------------------------------------
    def uncover_answer
        begin
            @answer_sprite.y -= 1
            wait(2)
        end until @answer_sprite.y == 5
        @play_vocab = "Rematch"
        @cancel_vocab = "Quit"
        @command_window.dispose
        create_command_window
        open_command_window
    end
    #--------------------------------------------------------------------------
    # * Round End
    #--------------------------------------------------------------------------
    def check_colors
        for i in 0...4
            if @guess[i] == @answer[i]
                @guess_used[i] = true
                @answer_used[i] = true
                @peg_sprite[@peg_index] = Sprite.new
                @peg_sprite[@peg_index].bitmap = Cache.picture("mm_black")
                case @peg_hole
                when 0
                    @peg_sprite[@peg_index].x = 234
                    @peg_sprite[@peg_index].y = 388 - (@round_index * 40)
                when 1
                    @peg_sprite[@peg_index].x = 248
                    @peg_sprite[@peg_index].y = 388 - (@round_index * 40)
                when 2
                    @peg_sprite[@peg_index].x = 234
                    @peg_sprite[@peg_index].y = 402 - (@round_index * 40)
                when 3
                    @peg_sprite[@peg_index].x = 248
                    @peg_sprite[@peg_index].y = 402 - (@round_index * 40)
                end
                @peg_sprite[@peg_index].z = 2
                @peg_index += 1
                @peg_hole += 1
                if @peg_hole == 4
                    @game_mode = "win"
                end
            end
        end
        while @j <= 3
            if @j != @k
                if @guess[@j] == @answer[@k]
                    if @guess_used[@j] == false
                        if @answer_used[@k] == false
                            @guess_used[@j] = true
                            @answer_used[@k] = true
                            @peg_sprite[@peg_index] = Sprite.new
                            @peg_sprite[@peg_index].bitmap = Cache.picture("mm_white")
                            case @peg_hole
                            when 0
                                @peg_sprite[@peg_index].x = 234
                                @peg_sprite[@peg_index].y = 388 - (@round_index * 40)
                            when 1
                                @peg_sprite[@peg_index].x = 248
                                @peg_sprite[@peg_index].y = 388 - (@round_index * 40)
                            when 2
                                @peg_sprite[@peg_index].x = 234
                                @peg_sprite[@peg_index].y = 402 - (@round_index * 40)
                            when 3
                                @peg_sprite[@peg_index].x = 248
                                @peg_sprite[@peg_index].y = 402 - (@round_index * 40)
                            end
                            @peg_sprite[@peg_index].z = 2
                            @peg_index += 1
                            @peg_hole += 1
                        end
                    end
                end
            end
            @k += 1
            if @k == 4
                @j += 1
                @k = 0
            end
        end
        @guess[0] = -1
        @guess[1] = -1
        @guess[2] = -1
        @guess[3] = -1
        @guess_used[0] = false
        @guess_used[1] = false
        @guess_used[2] = false
        @guess_used[3] = false
        @guess_index = 0
        @answer_used[0] = false
        @answer_used[1] = false
        @answer_used[2] = false
        @answer_used[3] = false
        @peg_hole = 0
        @j = 0
        @k = 0
        wait(15)
        if @round_index == 7 and @game_mode != "win"
            @game_mode = "lose"
            if Mastermind_Options::Loss_Sound_Type == "SE"
                temp_sound = "Audio/SE/" + Mastermind_Options::Loss_Sound
                Audio.se_play(temp_sound, 100, 100)
            elsif Mastermind_Options::Loss_Sound_Type == "ME"
                temp_sound = "Audio/ME/" + Mastermind_Options::Loss_Sound       
                Audio.me_play(temp_sound, 100, 100)
            end
            $game_system.losses += 1
            @winloss.refresh if Mastermind_Options::Win_Lose == true
            uncover_answer
        elsif @game_mode == "win"
            if Mastermind_Options::Win_Sound_Type == "SE"
                temp_sound = "Audio/SE/" + Mastermind_Options::Win_Sound
                Audio.se_play(temp_sound, 100, 100)
            elsif Mastermind_Options::Win_Sound_Type == "ME"
                temp_sound = "Audio/ME/" + Mastermind_Options::Win_Sound       
                Audio.me_play(temp_sound, 100, 100)
            end
            $game_system.wins += 1
            @winloss.refresh if Mastermind_Options::Win_Lose == true
            uncover_answer
        else
            @round_index += 1
            open_command_window_2
            @game_mode = "color"
        end
    end
    #--------------------------------------------------------------------------
    # * Create Command Window
    #--------------------------------------------------------------------------
    def create_command_window
        @command_window = Window_MastermindCommand.new(0, 0)
        @command_window.x = (Graphics.width - @command_window.width) / 2
        @command_window.y = (Graphics.height - @command_window.height) / 2
        @command_window.height = @command_window.fitting_height(2)
        @command_window.refresh
        @command_window.openness = 0
    end
    #--------------------------------------------------------------------------
    # * Dispose of Command Window
    #--------------------------------------------------------------------------
    def dispose_command_window
        @command_window.dispose
        @command_window_2.dispose
    end
    #--------------------------------------------------------------------------
    # * Open Command Window
    #--------------------------------------------------------------------------
    def open_command_window
        @command_window.open
        @command_window.refresh
        @command_window.active = true
    end
    #--------------------------------------------------------------------------
    # * Close Command Window
    #--------------------------------------------------------------------------
    def close_command_window
        @command_window.close
        @command_window.refresh
        @command_window.active = false
    end
    #--------------------------------------------------------------------------
    # * Create Command Window Two
    #--------------------------------------------------------------------------
    def create_command_window_2
        @command_window_2 = Window_MastermindCommand_Color.new(0, 0)
        @command_window_2.x = (200 - @command_window_2.width) / 2
        @command_window_2.height = @command_window_2.fitting_height(6)
        if Mastermind_Options::Win_Lose == false
            @command_window_2.y = (Graphics.height - @command_window_2.height) / 2
        else
            @command_window_2.y = 210
        end
        @command_window_2.openness = 0
        @command_window_2.active = false
    end
    #--------------------------------------------------------------------------
    # * Open Command Window Two
    #--------------------------------------------------------------------------
    def open_command_window_2
        @command_window_2.open
        @command_window_2.active = true
        @command_window_2.refresh
    end
    #--------------------------------------------------------------------------
    # * Close Command Window Two
    #--------------------------------------------------------------------------
    def close_command_window_2
        @command_window_2.close
        @command_window_2.active = false
        @command_window_2.refresh
    end
end
 

TakeHomeTheCup

Veteran
Veteran
Joined
Oct 15, 2013
Messages
244
Reaction score
460
First Language
English
Primarily Uses
@TDraws
Try this then:
Code:
#==============================================================================
#  Mastermind (VX)
#  Version: 1.0
#  Author: Zylos (rmrk.net)
#  Date: March 21, 2011
#------------------------------------------------------------------------------
#  Description:
#
#   This script sets up a classic Mastermind minigame, in which the player must
#   try to guess the secret sequence of colors that the opponent has chosen.
#   Each turn, the player selects a four piece sequence using six different
#   colors, and the opponent responds by giving the player black and white
#   pegs accordingly. A black peg means that the player has a right color piece
#   in the right position, while a white peg means that the player has a right
#   color piece but in the wrong position. The game ends when the player either
#   guesses correctly or has failed to figure it out after eight turns.
#
#------------------------------------------------------------------------------
#  Instructions:
#   
#     - Place this script in the materials section, above Main.
#
#     - Copy the game board and piece graphics to your game's pictures folder.
#       If you do not already have them, they can be found at:
#       http://rmrk.net/index.php/topic,42143.0.html
#
#     - Check the script options below these instructions to tweak the game's
#       appearance to your likings or change the winning and losing sounds.
#
#     - To start the minigame, simply call it with an event by using the
#       script command and entering "call_mastermind" without the quotation
#       marks. It'll automatically initiate the game.
#
#==============================================================================

module Mastermind_Options
    #============================================================================
    # EDITABLE REGION:
    #============================================================================
    
    Win_Lose = true                       # Show the Win Loss Ratio window
    Side = true                           # Show the side decoration graphic
    Black_Background = true              # Show a black background
    Game_Music = false                    # Plays a different BGM during game
    Game_BGM = ""              # BGM played during the game
    Win_Sound = ""            # Sound played when game is won
    Win_Sound_Type = ""                 # Type of sound Win_Sound is (ME/SE)
    Loss_Sound = ""          # Sound played when game is lost
    Loss_Sound_Type = ""                # Type of sound Loss_Sound is (ME/SE)
    
    #============================================================================
    # END EDITABLE REGION
    #============================================================================
end

#==============================================================================
# ** Game_System
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Adding the wins and losses variables to the game here.
#==============================================================================

class Game_System
    #--------------------------------------------------------------------------
    # * Public Instance Variables
    #--------------------------------------------------------------------------
    attr_accessor :wins                    # number of wins
    attr_accessor :losses                  # number of losses
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    alias_method :winlossratio, :initialize
    def initialize
        winlossratio
        @wins = 0
        @losses = 0
    end
end

#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Adding the mastermind command.
#==============================================================================

class Game_Interpreter
    #--------------------------------------------------------------------------
    # * Call Mastermind
    #--------------------------------------------------------------------------
    def call_mastermind
        SceneManager.call(Scene_Mastermind)
    end
end

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  Adding the change to Scene_Mastermind.
#==============================================================================

#~ class Scene_Map
#~ #--------------------------------------------------------------------------
#~ # * Execute Screen Switch
#~ #--------------------------------------------------------------------------
#~ alias kylos_mm_update_scene_change scene_change
#~ def kylos_mm_update_scene_change
#~ return if $game_player.moving?   
#~ if $game_temp.next_scene == "mastermind"
#~ call_mastermind
#~ else
#~ scene_change
#~ end
#~ end
#~ #--------------------------------------------------------------------------
#~ # * Switch to Mastermind
#~ #-------------------------------------------------------------------------- 
#~ def call_mastermind
#~ $game_temp.next_scene = nil
#~ $scene = Scene_Mastermind.new
#~ end
#~ end

#==============================================================================
# ** Window_MastermindRatio
#------------------------------------------------------------------------------
#  This window displays yours wins versus your losses in Mastermind.
#==============================================================================

class Window_MastermindRatio < Window_Base
    #--------------------------------------------------------------------------
    # * Object Initialization
    #     x : window X coordinate
    #     y : window Y coordinate
    #--------------------------------------------------------------------------
    def initialize(x, y)
        super(x, y, 135, 80)
        refresh
    end
    #--------------------------------------------------------------------------
    # * Refresh
    #--------------------------------------------------------------------------
    def refresh
        self.contents.clear
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 90, line_height, "Wins:")
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 90, line_height, $game_system.wins, 2)
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 90, line_height*2.6, "Losses:")
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 90, line_height*2.6, $game_system.losses, 2)
    end
end

class Window_MastermindCommand < Window_Command
    def initialize(x, y)
        super(x, y)
    end
    
    def process_handling
        
    end
    
    def make_command_list
        s1 = "Play game?"
        s2 = "Quit"
        add_command(s1, :s1)
        add_command(s2, :s2)
    end
    
end


class Window_MastermindCommand_Color < Window_Command
    def initialize(x, y)
        super(x, y)
    end
    
    def make_command_list
        s1 = "Red"
        s2 = "Orange"
        s3 = "Yellow"
        s4 = "Green"
        s5 = "Blue"
        s6 = "Purple"
        add_command(s1, :s1a)
        add_command(s2, :s2a)
        add_command(s3, :s3)
        add_command(s4, :s4)
        add_command(s5, :s5)
        add_command(s6, :s6)
    end
    
    def process_handling
        
    end
    
    def visible_line_number
        return 6
    end
    
end


#==============================================================================
# ** Scene_Mastermind
#------------------------------------------------------------------------------
#  This class performs the Mastermind screen processing.
#==============================================================================

class Scene_Mastermind < Scene_MenuBase
    #--------------------------------------------------------------------------
    # * Start processing
    #--------------------------------------------------------------------------
    def start
        super
        if Mastermind_Options::Game_Music == true
            @last_bgm = RPG::BGM::last
            @last_bgs = RPG::BGS::last
            RPG::BGS.stop
            temp_sound = "Audio/BGM/" + Mastermind_Options::Game_BGM
            Audio.bgm_play(temp_sound, 100, 100)
        end
        @play_vocab = "Play game?"
        @cancel_vocab = "Quit"
        create_background if Mastermind_Options::Black_Background == false
        create_command_window
        create_command_window_2
        if Mastermind_Options::Win_Lose == true
            @winloss = Window_MastermindRatio.new(5.5, 10)
        end
        @board_sprite = Sprite.new(Viewport.new(0, 0, 544, 416))
        @board_sprite.bitmap = Cache.picture("mm_board")
        @board_sprite.x = 0
        @board_sprite.y = 0
        @board_sprite.z = 1
        @answer_sprite = Sprite.new
        @answer_sprite.bitmap = Cache.picture("mm_answer")
        @answer_sprite.x = 212
        @answer_sprite.y = -25
        @answer_sprite.z = 10
        if Mastermind_Options::Side == true
            @side_sprite = Sprite.new
            @side_sprite.bitmap = Cache.picture("mm_side")
            @side_sprite.x = 399 + (146 - @side_sprite.width) / 2
            @side_sprite.y = (416 - @side_sprite.height) / 2
            @side_sprite.z = 1
        end
        @color_sprite = []
        @peg_sprite = []
        @guess = []
        @guess_used = []
        @answer = []
        @answer_used = []
        @color_index = 0
        @peg_index = 0
        @game_mode = "start"
    end
    #--------------------------------------------------------------------------
    # * Post-Start Processing
    #--------------------------------------------------------------------------
    def post_start
        super
        open_command_window
    end
    #--------------------------------------------------------------------------
    # * Wait
    #--------------------------------------------------------------------------
    def wait(duration)
        for i in 0...duration
            Graphics.update
        end
    end
    #--------------------------------------------------------------------------
    # * Pre-termination Processing
    #--------------------------------------------------------------------------
    def pre_terminate
        super
        close_command_window
        close_command_window_2
    end
    #--------------------------------------------------------------------------
    # * Termination Processing
    #--------------------------------------------------------------------------
    def terminate
        super
        dispose_command_window
        @board_sprite.dispose
        @answer_sprite.dispose
        @side_sprite.dispose if Mastermind_Options::Side == true
        @winloss.dispose if Mastermind_Options::Win_Lose == true
        if @color_index != 0
            for i in 0...@color_index
                @color_sprite[i].dispose
            end
            for i in 0...@peg_index
                @peg_sprite[i].dispose
            end
        end
        if Mastermind_Options::Game_Music == true
            @last_bgm.play
            @last_bgs.play
        end
    end
    #--------------------------------------------------------------------------
    # * Frame Update
    #--------------------------------------------------------------------------
    def tests
        p 1
    end
    
    def update
        super
        #update_menu_background if Mastermind_Options::Black_Background == false
        @winloss.update if Mastermind_Options::Win_Lose == true
        if @game_mode == "start"
            if Input.press?(:C)
                case @command_window.index
                when 0
                    Sound.play_ok
                    close_command_window
                    cover_answer
                when 1
                    Sound.play_cancel
                    SceneManager.return
                end
            end
        elsif @game_mode == "color"
            if Input.trigger?(:C)
                if @guess_index != 4
                    Sound.play_ok
                    @go = @command_window_2.index
                    @guess[@guess_index] = @go
                    @color_sprite[@color_index] = Sprite.new
                    @color_sprite[@color_index].bitmap=Cache.picture("mm_color"+@go.to_s)
                    @color_sprite[@color_index].x = 228 + (@guess_index * 35)
                    @color_sprite[@color_index].y = 360 - (@round_index * 40)
                    @color_sprite[@color_index].z = 2
                    @guess_index += 1
                    @color_index += 1
                    if @guess_index == 4
                        @game_mode = "peg"
                        close_command_window_2
                        @command_window.index = 0
                        @command_window_2.index = 0
                        wait(15)
                        check_colors
                    end
                end
            end
            if Input.trigger?(:B)
                if @guess_index == 0
                    Sound.play_cancel
                    close_command_window_2
                    @play_vocab = "Continue"
                    @cancel_vocab = "Quit"
                    @command_window.index = 0
                    @command_window.dispose
                    create_command_window
                    open_command_window
                    @game_mode = "quit"
                else
                    case @guess_index
                    when 1
                        @guess[0] = -1
                    when 2
                        @guess[1] = -1
                    when 3
                        @guess[2] = -1
                    end
                    @guess_index -= 1
                    @color_index -= 1
                    Sound.play_cancel
                    @color_sprite[@color_index].dispose
                end
            end
        elsif @game_mode == "quit"
            if Input.press?(:C)
                case @command_window.index
                when 0
                    Sound.play_ok
                    close_command_window
                    open_command_window_2
                    @game_mode = "color"
                when 1
                    Sound.play_cancel
                    SceneManager.return
                end 
            end
        elsif @game_mode == "win" or @game_mode == "lose"
            if @command_window.openness == 255
                if Input.trigger?(:C)
                    case @command_window.index
                    when 0
                        Sound.play_ok
                        opac = 250
                        close_command_window
                        wait(8)
                        begin
                            opac -= 10
                            for i in 0...@color_index
                                @color_sprite[i].opacity = opac
                            end
                            for i in 0...@peg_index
                                @peg_sprite[i].opacity = opac
                            end
                            wait(2)
                        end until opac == 0
                        for i in 0...@color_index
                            @color_sprite[i].dispose
                        end
                        for i in 0...@peg_index
                            @peg_sprite[i].dispose
                        end
                        wait(10)
                        cover_answer
                    when 1
                        Sound.play_cancel
                        SceneManager.return
                    end
                end
            end
        end 
    end 
    #--------------------------------------------------------------------------
    # * Update Background for Menu Screen
    #--------------------------------------------------------------------------
    def update_menu_background
        #~ super
        #~ @menuback_sprite.tone.set(0, 0, 0, 128)
    end
    #--------------------------------------------------------------------------
    # * Game Start
    #--------------------------------------------------------------------------
    def cover_answer
        @used_colors = [0, 1, 2, 3, 4]
        @round_index = 0
        @color_index = 0
        @peg_index = 0
        @guess[0] = -1
        @guess[1] = -1
        @guess[2] = -1
        @guess[3] = -1
        @guess_used[0] = false
        @guess_used[1] = false
        @guess_used[2] = false
        @guess_used[3] = false
        @guess_index = 0
        @answer[0] = -1
        @answer[1] = -1
        @answer[2] = -1
        @answer[3] = -1
        @answer_used[0] = false
        @answer_used[1] = false
        @answer_used[2] = false
        @answer_used[3] = false
        @peg_hole = 0
        @j = 0
        @k = 0   
        @distance = 19 - (@answer_sprite.y)
        @iindex = 0
        RPG::ME.stop
        RPG::SE.stop
        for i in 0...4
            Sound.play_cursor
            temp_answer = rand(5)
            @color_sprite[i] = Sprite.new
            @color_sprite[i].bitmap=Cache.picture("mm_color"+temp_answer.to_s)
            @color_sprite[i].x = 228 + (i * 35)
            @color_sprite[i].y = 29
            @color_sprite[i].z = 2
            @color_index += 1
            wait(10)
        end
        while @distance > 0
            @answer_sprite.y += 1
            temp_answer = rand(5)
            @color_sprite[@iindex].bitmap=Cache.picture("mm_color"+temp_answer.to_s)
            @iindex += 1
            if @iindex == 4
                @iindex = 0
            end
            @distance = 19 - (@answer_sprite.y)
            Sound.play_cursor
            wait(2)
        end
        for i in 0...4
            @answer[i] = @used_colors[rand(@used_colors.size)]
            @used_colors.delete(@answer[i])
            @color_sprite[i].bitmap=Cache.picture("mm_color"+@answer[i].to_s)
            @color_sprite[i].z = 2
        end
        open_command_window_2
        @game_mode = "color"
    end
    #--------------------------------------------------------------------------
    # * Game End
    #--------------------------------------------------------------------------
    def uncover_answer
        begin
            @answer_sprite.y -= 1
            wait(2)
        end until @answer_sprite.y == -25
        @play_vocab = "Rematch"
        @cancel_vocab = "Quit"
        @command_window.dispose
        create_command_window
        open_command_window 
    end
    #--------------------------------------------------------------------------
    # * Round End
    #--------------------------------------------------------------------------
    def check_colors
        for i in 0...4
            if @guess[i] == @answer[i]
                @guess_used[i] = true
                @answer_used[i] = true
                @peg_sprite[@peg_index] = Sprite.new
                @peg_sprite[@peg_index].bitmap = Cache.picture("mm_black")
                case @peg_hole
                when 0
                    @peg_sprite[@peg_index].x = 184
                    @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                when 1
                    @peg_sprite[@peg_index].x = 198
                    @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                when 2
                    @peg_sprite[@peg_index].x = 184
                    @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                when 3
                    @peg_sprite[@peg_index].x = 198
                    @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                end
                @peg_sprite[@peg_index].z = 2
                @peg_index += 1
                @peg_hole += 1
                if @peg_hole == 4
                    @game_mode = "win"
                end
            end
        end
        while @j <= 3
            if @j != @k
                if @guess[@j] == @answer[@k]
                    if @guess_used[@j] == false
                        if @answer_used[@k] == false
                            @guess_used[@j] = true
                            @answer_used[@k] = true
                            @peg_sprite[@peg_index] = Sprite.new
                            @peg_sprite[@peg_index].bitmap = Cache.picture("mm_white")
                            case @peg_hole
                            when 0
                                @peg_sprite[@peg_index].x = 184
                                @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                            when 1
                                @peg_sprite[@peg_index].x = 198
                                @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                            when 2
                                @peg_sprite[@peg_index].x = 184
                                @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                            when 3
                                @peg_sprite[@peg_index].x = 198
                                @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                            end
                            @peg_sprite[@peg_index].z = 2
                            @peg_index += 1
                            @peg_hole += 1
                        end
                    end
                end
            end
            @k += 1
            if @k == 4
                @j += 1
                @k = 0
            end
        end
        @guess[0] = -1
        @guess[1] = -1
        @guess[2] = -1
        @guess[3] = -1
        @guess_used[0] = false
        @guess_used[1] = false
        @guess_used[2] = false
        @guess_used[3] = false
        @guess_index = 0
        @answer_used[0] = false
        @answer_used[1] = false
        @answer_used[2] = false
        @answer_used[3] = false
        @peg_hole = 0
        @j = 0
        @k = 0
        wait(15)
        if @round_index == 7 and @game_mode != "win"
            @game_mode = "lose"
            if Mastermind_Options::Loss_Sound_Type == "SE"
                temp_sound = "Audio/SE/" + Mastermind_Options::Loss_Sound
                Audio.se_play(temp_sound, 100, 100)
            elsif Mastermind_Options::Loss_Sound_Type == "ME"
                temp_sound = "Audio/ME/" + Mastermind_Options::Loss_Sound       
                Audio.me_play(temp_sound, 100, 100)
            end
            $game_system.losses += 1
            @winloss.refresh if Mastermind_Options::Win_Lose == true
            uncover_answer
        elsif @game_mode == "win"
            if Mastermind_Options::Win_Sound_Type == "SE"
                temp_sound = "Audio/SE/" + Mastermind_Options::Win_Sound
                Audio.se_play(temp_sound, 100, 100)
            elsif Mastermind_Options::Win_Sound_Type == "ME"
                temp_sound = "Audio/ME/" + Mastermind_Options::Win_Sound       
                Audio.me_play(temp_sound, 100, 100)
            end
            $game_system.wins += 1
            @winloss.refresh if Mastermind_Options::Win_Lose == true
            uncover_answer
        else
            @round_index += 1
            open_command_window_2
            @game_mode = "color"
        end
    end
    #--------------------------------------------------------------------------
    # * Create Command Window
    #--------------------------------------------------------------------------
    def create_command_window
        @command_window = Window_MastermindCommand.new(0, 0)
        @command_window.x = (Graphics.width - @command_window.width) / 2
        @command_window.y = (Graphics.height - @command_window.height) / 2
        @command_window.height = @command_window.fitting_height(2)
        @command_window.refresh
        @command_window.openness = 0
    end
    #--------------------------------------------------------------------------
    # * Dispose of Command Window
    #--------------------------------------------------------------------------
    def dispose_command_window
        @command_window.dispose
        @command_window_2.dispose
    end
    #--------------------------------------------------------------------------
    # * Open Command Window
    #--------------------------------------------------------------------------
    def open_command_window
        @command_window.open
        @command_window.refresh
        @command_window.active = true
    end
    #--------------------------------------------------------------------------
    # * Close Command Window
    #--------------------------------------------------------------------------
    def close_command_window
        @command_window.close
        @command_window.refresh
        @command_window.active = false
    end
    #--------------------------------------------------------------------------
    # * Create Command Window Two
    #--------------------------------------------------------------------------
    def create_command_window_2
        @command_window_2 = Window_MastermindCommand_Color.new(0, 0)
        @command_window_2.x = (198 - @command_window_2.width) / 2
        @command_window_2.height = @command_window_2.fitting_height(6)
        if Mastermind_Options::Win_Lose == false
            @command_window_2.y = (Graphics.height - @command_window_2.height) / 2
        else
            @command_window_2.y = 210
        end
        @command_window_2.openness = 0
        @command_window_2.active = false
    end
    #--------------------------------------------------------------------------
    # * Open Command Window Two
    #--------------------------------------------------------------------------
    def open_command_window_2
        @command_window_2.open
        @command_window_2.active = true
        @command_window_2.refresh
    end
    #--------------------------------------------------------------------------
    # * Close Command Window Two
    #--------------------------------------------------------------------------
    def close_command_window_2
        @command_window_2.close
        @command_window_2.active = false
        @command_window_2.refresh
    end
end
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,655
Reaction score
562
First Language
English
Primarily Uses
RMVXA
Tried it. Works
 

VTDraws

Filthy Point-&-Click casual
Veteran
Joined
Apr 17, 2017
Messages
56
Reaction score
9
First Language
English
Primarily Uses
RMMV
Thank you. Sorry to keep adding things, but another question. Would it be possible to have a difficulty level? [just Simple/Hard] The only difference would be that Simple has two extra guesses [for a total of 10 guesses] and hard would be 8. [the default] I understand this would require a lot of location tweaking [for pictures] and a new board graphic, just figured I'd toss it out there.
 

TakeHomeTheCup

Veteran
Veteran
Joined
Oct 15, 2013
Messages
244
Reaction score
460
First Language
English
Primarily Uses
In order to change the board size, the screen size may have to change, or the size of the circles and other game pieces. We could probably also try to scroll the image, though I'm not sure how well that will work.
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,655
Reaction score
562
First Language
English
Primarily Uses
RMVXA
My apologies to the MOD's, it won't allow me to post this all together.
@VTDraws
Code:
#==============================================================================
#  Mastermind (VX)
#  Version: 1.0
#  Author: Zylos (rmrk.net)
#  Date: March 21, 2011
#------------------------------------------------------------------------------
#  Description:
#
#   This script sets up a classic Mastermind minigame, in which the player must
#   try to guess the secret sequence of colors that the opponent has chosen.
#   Each turn, the player selects a four piece sequence using six different
#   colors, and the opponent responds by giving the player black and white
#   pegs accordingly. A black peg means that the player has a right color piece
#   in the right position, while a white peg means that the player has a right
#   color piece but in the wrong position. The game ends when the player either
#   guesses correctly or has failed to figure it out after eight turns.
#
#------------------------------------------------------------------------------
#  Instructions:
#  
#     - Place this script in the materials section, above Main.
#
#     - Copy the game board and piece graphics to your game's pictures folder.
#       If you do not already have them, they can be found at:
#       http://rmrk.net/index.php/topic,42143.0.html
#
#     - Check the script options below these instructions to tweak the game's
#       appearance to your likings or change the winning and losing sounds.
#
#     - To start the minigame, simply call it with an event by using the
#       script command and entering "call_mastermind" without the quotation
#       marks. It'll automatically initiate the game.
#
#==============================================================================

module Mastermind_Options
    #============================================================================
    # EDITABLE REGION:
    #============================================================================
   
    Win_Lose = true                       # Show the Win Loss Ratio window
    Side = true                           # Show the side decoration graphic
    Black_Background = true              # Show a black background
    Game_Music = false                    # Plays a different BGM during game
    Game_BGM = ""              # BGM played during the game
    Win_Sound = ""            # Sound played when game is won
    Win_Sound_Type = ""                 # Type of sound Win_Sound is (ME/SE)
    Loss_Sound = ""          # Sound played when game is lost
    Loss_Sound_Type = ""                # Type of sound Loss_Sound is (ME/SE)
   
    #============================================================================
    # END EDITABLE REGION
    #============================================================================
end

#==============================================================================
# ** Game_System
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Adding the wins and losses variables to the game here.
#==============================================================================

class Game_System
    #--------------------------------------------------------------------------
    # * Public Instance Variables
    #--------------------------------------------------------------------------
    attr_accessor :wins                    # number of wins
    attr_accessor :losses                  # number of losses
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    alias_method :winlossratio, :initialize
    def initialize
        winlossratio
        @wins = 0
        @losses = 0
    end
end

#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Adding the mastermind command.
#==============================================================================

class Game_Interpreter
    #--------------------------------------------------------------------------
    # * Call Mastermind
    #--------------------------------------------------------------------------
    def call_mastermind
        SceneManager.call(Scene_Mastermind)
    end
end

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  Adding the change to Scene_Mastermind.
#==============================================================================

#~ class Scene_Map
#~ #--------------------------------------------------------------------------
#~ # * Execute Screen Switch
#~ #--------------------------------------------------------------------------
#~ alias kylos_mm_update_scene_change scene_change
#~ def kylos_mm_update_scene_change
#~ return if $game_player.moving?  
#~ if $game_temp.next_scene == "mastermind"
#~ call_mastermind
#~ else
#~ scene_change
#~ end
#~ end
#~ #--------------------------------------------------------------------------
#~ # * Switch to Mastermind
#~ #--------------------------------------------------------------------------
#~ def call_mastermind
#~ $game_temp.next_scene = nil
#~ $scene = Scene_Mastermind.new
#~ end
#~ end

#==============================================================================
# ** Window_MastermindRatio
#------------------------------------------------------------------------------
#  This window displays yours wins versus your losses in Mastermind.
#==============================================================================

class Window_MastermindRatio < Window_Base
    #--------------------------------------------------------------------------
    # * Object Initialization
    #     x : window X coordinate
    #     y : window Y coordinate
    #--------------------------------------------------------------------------
    def initialize(x, y)
        super(x, y, 135, 80)
        refresh
    end
    #--------------------------------------------------------------------------
    # * Refresh
    #--------------------------------------------------------------------------
    def refresh
        self.contents.clear
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 90, line_height, "Wins:")
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 90, line_height, $game_system.wins, 2)
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 90, line_height*2.6, "Losses:")
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 90, line_height*2.6, $game_system.losses, 2)
    end
end

class Window_MastermindCommand < Window_Command
    def initialize(x, y)
        super(x, y)
    end
   
    def process_handling
       
    end
   
    def make_command_list
        s1 = "Play Normal Game?"
        s2 = "Play Hard Game?"
        s3 = "Quit"
        add_command(s1, :s1)
        add_command(s2, :s2)
        add_command(s3, :s3)
    end
   
end


class Window_MastermindCommand_Color < Window_Command
    def initialize(x, y)
        super(x, y)
    end
   
    def make_command_list
        s1 = "Red"
        s2 = "Orange"
        s3 = "Yellow"
        s4 = "Green"
        s5 = "Blue"
        s6 = "Purple"
        add_command(s1, :s1a)
        add_command(s2, :s2a)
        add_command(s3, :s3a)
        add_command(s4, :s4)
        add_command(s5, :s5)
        add_command(s6, :s6)
    end
   
    def process_handling
       
    end
   
    def visible_line_number
        return 6
    end
   
end


#==============================================================================
# ** Scene_Mastermind
#------------------------------------------------------------------------------
#  This class performs the Mastermind screen processing.
#==============================================================================

class Scene_Mastermind < Scene_MenuBase
    #--------------------------------------------------------------------------
    # * Start processing
    #--------------------------------------------------------------------------
    def start
        super
        if Mastermind_Options::Game_Music == true
            @last_bgm = RPG::BGM::last
            @last_bgs = RPG::BGS::last
            RPG::BGS.stop
            temp_sound = "Audio/BGM/" + Mastermind_Options::Game_BGM
            Audio.bgm_play(temp_sound, 100, 100)
        end
        @playe_vocab = "Play Normal Game?"
        @playh_vocab = "Play Hard Game?"
        @cancel_vocab = "Quit"
        create_background if Mastermind_Options::Black_Background == false
        create_command_window
        create_command_window_2
        if Mastermind_Options::Win_Lose == true
            @winloss = Window_MastermindRatio.new(5.5, 10)
        end
        @board_sprite = Sprite.new(Viewport.new(0, 0, 544, 416))
        @board_sprite.bitmap = Cache.picture("mm_board")
        @board_sprite.x = 0
        @board_sprite.y = 0
        @board_sprite.z = 1
        @answer_sprite = Sprite.new
        @answer_sprite.bitmap = Cache.picture("mm_answer")
        @answer_sprite.x = 212
        @answer_sprite.y = -25
        @answer_sprite.z = 10
        @hard_sprite = Sprite.new(Viewport.new(0, 0, 544, 416))
        @hard_sprite.bitmap = Cache.picture("mm_hard")
        @hard_sprite.x = 0
        @hard_sprite.y = 0
        @hard_sprite.z = 2
        if Mastermind_Options::Side == true
            @side_sprite = Sprite.new
            @side_sprite.bitmap = Cache.picture("mm_side")
            @side_sprite.x = 399 + (146 - @side_sprite.width) / 2
            @side_sprite.y = (416 - @side_sprite.height) / 2
            @side_sprite.z = 1
        end
        @color_sprite = []
        @peg_sprite = []
        @guess = []
        @guess_used = []
        @answer = []
        @answer_used = []
        @color_index = 0
        @peg_index = 0
        @game_mode = "start"
    end
    #--------------------------------------------------------------------------
    # * Post-Start Processing
    #--------------------------------------------------------------------------
    def post_start
        super
        open_command_window
    end
    #--------------------------------------------------------------------------
    # * Wait
    #--------------------------------------------------------------------------
    def wait(duration)
        for i in 0...duration
            Graphics.update
        end
    end
    #--------------------------------------------------------------------------
    # * Pre-termination Processing
    #--------------------------------------------------------------------------
    def pre_terminate
        super
        close_command_window
        close_command_window_2
    end
    #--------------------------------------------------------------------------
    # * Termination Processing
    #--------------------------------------------------------------------------
    def terminate
        super
        dispose_command_window
        @board_sprite.dispose
        @answer_sprite.dispose
        @hard_sprite.dispose
        @side_sprite.dispose if Mastermind_Options::Side == true
        @winloss.dispose if Mastermind_Options::Win_Lose == true
        if @color_index != 0
            for i in 0...@color_index
                @color_sprite[i].dispose
            end
            for i in 0...@peg_index
                @peg_sprite[i].dispose
            end
        end
        if Mastermind_Options::Game_Music == true
            @last_bgm.play
            @last_bgs.play
        end
    end
    #--------------------------------------------------------------------------
    # * Frame Update
    #--------------------------------------------------------------------------
    # def tests
        # p 1
    # end
    def easy_terminate
        @hard_sprite.dispose
    end
   
    def update
        super
        #update_menu_background if Mastermind_Options::Black_Background == false
        @winloss.update if Mastermind_Options::Win_Lose == true
        if @game_mode == "start"
            if Input.press?(:C)
                case @command_window.index
                when 0
                    Sound.play_ok
                    close_command_window
                    cover_answer
                    easy_terminate
                when 1
                    Sound.play_ok
                    close_command_window
                    cover_answer
                when 2
                    Sound.play_cancel
                    SceneManager.return
                end
            end
        elsif @game_mode == "color"
            if Input.trigger?(:C)
                if @guess_index != 4
                    Sound.play_ok
                    @go = @command_window_2.index
                    @guess[@guess_index] = @go
                    @color_sprite[@color_index] = Sprite.new
                    @color_sprite[@color_index].bitmap=Cache.picture("mm_color"+@go.to_s)
                    @color_sprite[@color_index].x = 228 + (@guess_index * 35)
                    @color_sprite[@color_index].y = 360 - (@round_index * 40)
                    @color_sprite[@color_index].z = 2
                    @guess_index += 1
                    @color_index += 1
                    if @guess_index == 4
                        @game_mode = "peg"
                        close_command_window_2
                        @command_window.index = 0
                        @command_window_2.index = 0
                        wait(15)
                        check_colors
                    end
                end
            end
            if Input.trigger?(:B)
                if @guess_index == 0
                    Sound.play_cancel
                    close_command_window_2
                    @playe_vocab = "Continue"
                    @playh_vocab = "Continue"
                    @cancel_vocab = "Quit"
                    @command_window.index = 0
                    @command_window.dispose
                    create_command_window
                    open_command_window
                    @game_mode = "quit"
                else
                    case @guess_index
                    when 1
                        @guess[0] = -1
                    when 2
                        @guess[1] = -1
                    when 3
                        @guess[2] = -1
                    end
                    @guess_index -= 1
                    @color_index -= 1
                    Sound.play_cancel
                    @color_sprite[@color_index].dispose
                end
            end
        elsif @game_mode == "quit"
            if Input.press?(:C)
                case @command_window.index
                when 0
                    Sound.play_ok
                    close_command_window
                    open_command_window_2
                    @game_mode = "color"
                when 1
                    Sound.play_ok
                    close_command_window
                    open_command_window_2
                    @game_mode = "color"
                when 2
                    Sound.play_cancel
                    SceneManager.return
                end
            end
        elsif @game_mode == "win" or @game_mode == "lose"
            if @command_window.openness == 255
                if Input.trigger?(:C)
                    case @command_window.index
                    when 0
                        Sound.play_ok
                        opac = 250
                        close_command_window
                        wait(8)
                        begin
                            opac -= 10
                            for i in 0...@color_index
                                @color_sprite[i].opacity = opac
                            end
                            for i in 0...@peg_index
                                @peg_sprite[i].opacity = opac
                            end
                            wait(2)
                        end until opac == 0
                        for i in 0...@color_index
                            @color_sprite[i].dispose
                        end
                        for i in 0...@peg_index
                            @peg_sprite[i].dispose
                        end
                        wait(10)
                        cover_answer
                        easy_terminate
                    when 1
                        Sound.play_ok
                        opac = 250
                        close_command_window
                        wait(8)
                        begin
                            opac -= 10
                            for i in 0...@color_index
                                @color_sprite[i].opacity = opac
                            end
                            for i in 0...@peg_index
                                @peg_sprite[i].opacity = opac
                            end
                            wait(2)
                        end until opac == 0
                        for i in 0...@color_index
                            @color_sprite[i].dispose
                        end
                        for i in 0...@peg_index
                            @peg_sprite[i].dispose
                        end
                        wait(10)
                        cover_answer
                        easy_terminate
                        @hard_sprite = Sprite.new(Viewport.new(0, 0, 544, 416))
                        @hard_sprite.bitmap = Cache.picture("mm_hard")
                        @hard_sprite.x = 0
                        @hard_sprite.y = 0
                        @hard_sprite.z = 2
                    when 2
                        Sound.play_cancel
                        SceneManager.return
                    end
                end
            end
        end
    end
    #--------------------------------------------------------------------------
    # * Update Background for Menu Screen
    #--------------------------------------------------------------------------
    def update_menu_background
        #~ super
        #~ @menuback_sprite.tone.set(0, 0, 0, 128)
    end
    #--------------------------------------------------------------------------
    # * Game Start
    #--------------------------------------------------------------------------
    def cover_answer
      if @command_window.index == 1
        @round_index = 2
      else
        @round_index = 0
      end
        @color_index = 0
        @peg_index = 0
        @guess[0] = -1
        @guess[1] = -1
        @guess[2] = -1
        @guess[3] = -1
        @guess_used[0] = false
        @guess_used[1] = false
        @guess_used[2] = false
        @guess_used[3] = false
        @guess_index = 0
        @answer[0] = -1
        @answer[1] = -1
        @answer[2] = -1
        @answer[3] = -1
        @answer_used[0] = false
        @answer_used[1] = false
        @answer_used[2] = false
        @answer_used[3] = false
        @peg_hole = 0
        @j = 0
        @k = 0  
        @distance = 19 - (@answer_sprite.y)
        @iindex = 0
        RPG::ME.stop
        RPG::SE.stop
        for i in 0...4
            Sound.play_cursor
            temp_answer = rand(5)
            @color_sprite[i] = Sprite.new
            @color_sprite[i].bitmap=Cache.picture("mm_color"+temp_answer.to_s)
            @color_sprite[i].x = 228 + (i * 35)
            @color_sprite[i].y = 29
            @color_sprite[i].z = 2
            @color_index += 1
            wait(10)
        end
        while @distance > 0
            @answer_sprite.y += 1
            temp_answer = rand(5)
            @color_sprite[@iindex].bitmap=Cache.picture("mm_color"+temp_answer.to_s)
            @iindex += 1
            if @iindex == 4
                @iindex = 0
            end
            @distance = 19 - (@answer_sprite.y)
            Sound.play_cursor
            wait(2)
        end
        for i in 0...4
            @answer[i] = rand(5)
            @color_sprite[i].bitmap=Cache.picture("mm_color"+@answer[i].to_s)
            @color_sprite[i].z = 2
        end
        open_command_window_2
        @game_mode = "color"
    end
    #--------------------------------------------------------------------------
    # * Game End
    #--------------------------------------------------------------------------
    def uncover_answer
        begin
            @answer_sprite.y -= 1
            wait(2)
        end until @answer_sprite.y == -25
        @playe_vocab = "Try Harder"
        @playh_vocab = "Rematch"
        @cancel_vocab = "Quit"
        @command_window.dispose
        create_command_window
        open_command_window
    end
    #--------------------------------------------------------------------------
    # * Round End
    #--------------------------------------------------------------------------
    def check_colors
        for i in 0...4
            if @guess[i] == @answer[i]
                @guess_used[i] = true
                @answer_used[i] = true
                @peg_sprite[@peg_index] = Sprite.new
                @peg_sprite[@peg_index].bitmap = Cache.picture("mm_black")
                case @peg_hole
                when 0
                    @peg_sprite[@peg_index].x = 184
                    @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                when 1
                    @peg_sprite[@peg_index].x = 198
                    @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                when 2
                    @peg_sprite[@peg_index].x = 184
                    @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                when 3
                    @peg_sprite[@peg_index].x = 198
                    @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                end
                @peg_sprite[@peg_index].z = 2
                @peg_index += 1
                @peg_hole += 1
                if @peg_hole == 4
                    @game_mode = "win"
                end
            end
        end
        while @j <= 3
            if @j != @k
                if @guess[@j] == @answer[@k]
                    if @guess_used[@j] == false
                        if @answer_used[@k] == false
                            @guess_used[@j] = true
                            @answer_used[@k] = true
                            @peg_sprite[@peg_index] = Sprite.new
                            @peg_sprite[@peg_index].bitmap = Cache.picture("mm_white")
                            case @peg_hole
                            when 0
                                @peg_sprite[@peg_index].x = 184
                                @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                            when 1
                                @peg_sprite[@peg_index].x = 198
                                @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                            when 2
                                @peg_sprite[@peg_index].x = 184
                                @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                            when 3
                                @peg_sprite[@peg_index].x = 198
                                @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                            end
                            @peg_sprite[@peg_index].z = 2
                            @peg_index += 1
                            @peg_hole += 1
                        end
                    end
                end
            end
            @k += 1
            if @k == 4
                @j += 1
                @k = 0
            end
        end
        @guess[0] = -1
        @guess[1] = -1
        @guess[2] = -1
        @guess[3] = -1
        @guess_used[0] = false
        @guess_used[1] = false
        @guess_used[2] = false
        @guess_used[3] = false
        @guess_index = 0
        @answer_used[0] = false
        @answer_used[1] = false
        @answer_used[2] = false
        @answer_used[3] = false
        @peg_hole = 0
        @j = 0
        @k = 0
        wait(15)
        if @round_index == 7 and @game_mode != "win"
            @game_mode = "lose"
            if Mastermind_Options::Loss_Sound_Type == "SE"
                temp_sound = "Audio/SE/" + Mastermind_Options::Loss_Sound
                Audio.se_play(temp_sound, 100, 100)
            elsif Mastermind_Options::Loss_Sound_Type == "ME"
                temp_sound = "Audio/ME/" + Mastermind_Options::Loss_Sound      
                Audio.me_play(temp_sound, 100, 100)
            end
            $game_system.losses += 1
            @winloss.refresh if Mastermind_Options::Win_Lose == true
            uncover_answer
        elsif @game_mode == "win"
            if Mastermind_Options::Win_Sound_Type == "SE"
                temp_sound = "Audio/SE/" + Mastermind_Options::Win_Sound
                Audio.se_play(temp_sound, 100, 100)
            elsif Mastermind_Options::Win_Sound_Type == "ME"
                temp_sound = "Audio/ME/" + Mastermind_Options::Win_Sound      
                Audio.me_play(temp_sound, 100, 100)
            end
            $game_system.wins += 1
            @winloss.refresh if Mastermind_Options::Win_Lose == true
            uncover_answer
        else
            @round_index += 1
            open_command_window_2
            @game_mode = "color"
        end
    end
    #--------------------------------------------------------------------------
    # * Create Command Window
    #--------------------------------------------------------------------------
    def create_command_window
        @command_window = Window_MastermindCommand.new(0, 0)
        @command_window.x = (Graphics.width - @command_window.width) / 2
        @command_window.y = (Graphics.height - @command_window.height) / 2
        @command_window.height = @command_window.fitting_height(3)
        @command_window.refresh
        @command_window.openness = 0
    end
    #--------------------------------------------------------------------------
    # * Dispose of Command Window
    #--------------------------------------------------------------------------
    def dispose_command_window
        @command_window.dispose
        @command_window_2.dispose
    end
    #--------------------------------------------------------------------------
    # * Open Command Window
    #--------------------------------------------------------------------------
    def open_command_window
        @command_window.open
        @command_window.refresh
        @command_window.active = true
    end
    #--------------------------------------------------------------------------
    # * Close Command Window
    #--------------------------------------------------------------------------
    def close_command_window
        @command_window.close
        @command_window.refresh
        @command_window.active = false
    end
    #--------------------------------------------------------------------------
    # * Create Command Window Two
    #--------------------------------------------------------------------------
    def create_command_window_2
        @command_window_2 = Window_MastermindCommand_Color.new(0, 0)
        @command_window_2.x = (198 - @command_window_2.width) / 2
        @command_window_2.height = @command_window_2.fitting_height(6)
        if Mastermind_Options::Win_Lose == false
            @command_window_2.y = (Graphics.height - @command_window_2.height) / 2
        else
            @command_window_2.y = 210
        end
        @command_window_2.openness = 0
        @command_window_2.active = false
    end
    #--------------------------------------------------------------------------
    # * Open Command Window Two
    #--------------------------------------------------------------------------
    def open_command_window_2
        @command_window_2.open
        @command_window_2.active = true
        @command_window_2.refresh
    end
    #--------------------------------------------------------------------------
    # * Close Command Window Two
    #--------------------------------------------------------------------------
    def close_command_window_2
        @command_window_2.close
        @command_window_2.active = false
        @command_window_2.refresh
    end
end
 

Attachments

Last edited:

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,655
Reaction score
562
First Language
English
Primarily Uses
RMVXA
Code:
#==============================================================================
#  Mastermind (VX)
#  Version: 1.0
#  Author: Zylos (rmrk.net)
#  Date: March 21, 2011
#------------------------------------------------------------------------------
#  Description:
#
#   This script sets up a classic Mastermind minigame, in which the player must
#   try to guess the secret sequence of colors that the opponent has chosen.
#   Each turn, the player selects a four piece sequence using six different
#   colors, and the opponent responds by giving the player black and white
#   pegs accordingly. A black peg means that the player has a right color piece
#   in the right position, while a white peg means that the player has a right
#   color piece but in the wrong position. The game ends when the player either
#   guesses correctly or has failed to figure it out after eight turns.
#
#------------------------------------------------------------------------------
#  Instructions:
#   
#     - Place this script in the materials section, above Main.
#
#     - Copy the game board and piece graphics to your game's pictures folder.
#       If you do not already have them, they can be found at:
#       http://rmrk.net/index.php/topic,42143.0.html
#
#     - Check the script options below these instructions to tweak the game's
#       appearance to your likings or change the winning and losing sounds.
#
#     - To start the minigame, simply call it with an event by using the
#       script command and entering "call_mastermind" without the quotation
#       marks. It'll automatically initiate the game.
#
#==============================================================================

module Mastermind_Options
    #============================================================================
    # EDITABLE REGION:
    #============================================================================
    
    Win_Lose = true                       # Show the Win Loss Ratio window
    Side = true                           # Show the side decoration graphic
    Black_Background = true              # Show a black background
    Game_Music = false                    # Plays a different BGM during game
    Game_BGM = ""              # BGM played during the game
    Win_Sound = ""            # Sound played when game is won
    Win_Sound_Type = ""                 # Type of sound Win_Sound is (ME/SE)
    Loss_Sound = ""          # Sound played when game is lost
    Loss_Sound_Type = ""                # Type of sound Loss_Sound is (ME/SE)
    
    #============================================================================
    # END EDITABLE REGION
    #============================================================================
end

#==============================================================================
# ** Game_System
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Adding the wins and losses variables to the game here.
#==============================================================================

class Game_System
    #--------------------------------------------------------------------------
    # * Public Instance Variables
    #--------------------------------------------------------------------------
    attr_accessor :wins                    # number of wins
    attr_accessor :losses                  # number of losses
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    alias_method :winlossratio, :initialize
    def initialize
        winlossratio
        @wins = 0
        @losses = 0
    end
end

#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Adding the mastermind command.
#==============================================================================

class Game_Interpreter
    #--------------------------------------------------------------------------
    # * Call Mastermind
    #--------------------------------------------------------------------------
    def call_mastermind
        SceneManager.call(Scene_Mastermind)
    end
end

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  Adding the change to Scene_Mastermind.
#==============================================================================

#~ class Scene_Map
#~ #--------------------------------------------------------------------------
#~ # * Execute Screen Switch
#~ #--------------------------------------------------------------------------
#~ alias kylos_mm_update_scene_change scene_change
#~ def kylos_mm_update_scene_change
#~ return if $game_player.moving?   
#~ if $game_temp.next_scene == "mastermind"
#~ call_mastermind
#~ else
#~ scene_change
#~ end
#~ end
#~ #--------------------------------------------------------------------------
#~ # * Switch to Mastermind
#~ #--------------------------------------------------------------------------
#~ def call_mastermind
#~ $game_temp.next_scene = nil
#~ $scene = Scene_Mastermind.new
#~ end
#~ end

#==============================================================================
# ** Window_MastermindRatio
#------------------------------------------------------------------------------
#  This window displays yours wins versus your losses in Mastermind.
#==============================================================================

class Window_MastermindRatio < Window_Base
    #--------------------------------------------------------------------------
    # * Object Initialization
    #     x : window X coordinate
    #     y : window Y coordinate
    #--------------------------------------------------------------------------
    def initialize(x, y)
        super(x, y, 135, 80)
        refresh
    end
    #--------------------------------------------------------------------------
    # * Refresh
    #--------------------------------------------------------------------------
    def refresh
        self.contents.clear
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 90, line_height, "Wins:")
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 90, line_height, $game_system.wins, 2)
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 90, line_height*2.6, "Losses:")
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 90, line_height*2.6, $game_system.losses, 2)
    end
end

class Window_MastermindCommand < Window_Command
    def initialize(x, y)
        super(x, y)
    end
    
    def process_handling
        
    end
    
    def make_command_list
        s1 = "Play Normal Game?"
        s2 = "Play Hard Game?"
        s3 = "Quit"
        add_command(s1, :s1)
        add_command(s2, :s2)
        add_command(s3, :s3)
    end
    
end


class Window_MastermindCommand_Color < Window_Command
    def initialize(x, y)
        super(x, y)
    end
    
    def make_command_list
        s1 = "Red"
        s2 = "Orange"
        s3 = "Yellow"
        s4 = "Green"
        s5 = "Blue"
        s6 = "Purple"
        add_command(s1, :s1a)
        add_command(s2, :s2a)
        add_command(s3, :s3a)
        add_command(s4, :s4)
        add_command(s5, :s5)
        add_command(s6, :s6)
    end
    
    def process_handling
        
    end
    
    def visible_line_number
        return 6
    end
    
end


#==============================================================================
# ** Scene_Mastermind
#------------------------------------------------------------------------------
#  This class performs the Mastermind screen processing.
#==============================================================================

class Scene_Mastermind < Scene_MenuBase
    #--------------------------------------------------------------------------
    # * Start processing
    #--------------------------------------------------------------------------
    def start
        super
        if Mastermind_Options::Game_Music == true
            @last_bgm = RPG::BGM::last
            @last_bgs = RPG::BGS::last
            RPG::BGS.stop
            temp_sound = "Audio/BGM/" + Mastermind_Options::Game_BGM
            Audio.bgm_play(temp_sound, 100, 100)
        end
        @playe_vocab = "Play Normal Game?"
        @playh_vocab = "Play Hard Game?"
        @cancel_vocab = "Quit"
        create_background if Mastermind_Options::Black_Background == false
        create_command_window
        create_command_window_2
        if Mastermind_Options::Win_Lose == true
            @winloss = Window_MastermindRatio.new(5.5, 10)
        end
        @board_sprite = Sprite.new(Viewport.new(0, 0, 544, 416))
        @board_sprite.bitmap = Cache.picture("mm_board")
        @board_sprite.x = 0
        @board_sprite.y = 0
        @board_sprite.z = 1
        @answer_sprite = Sprite.new
        @answer_sprite.bitmap = Cache.picture("mm_answer")
        @answer_sprite.x = 212
        @answer_sprite.y = -25
        @answer_sprite.z = 10
        @hard_sprite = Sprite.new(Viewport.new(0, 0, 544, 416))
        @hard_sprite.bitmap = Cache.picture("mm_hard")
        @hard_sprite.x = 0
        @hard_sprite.y = 0
        @hard_sprite.z = 2
        if Mastermind_Options::Side == true
            @side_sprite = Sprite.new
            @side_sprite.bitmap = Cache.picture("mm_side")
            @side_sprite.x = 399 + (146 - @side_sprite.width) / 2
            @side_sprite.y = (416 - @side_sprite.height) / 2
            @side_sprite.z = 1
        end
        @color_sprite = []
        @peg_sprite = []
        @guess = []
        @guess_used = []
        @answer = []
        @answer_used = []
        @color_index = 0
        @peg_index = 0
        @game_mode = "start"
    end
    #--------------------------------------------------------------------------
    # * Post-Start Processing
    #--------------------------------------------------------------------------
    def post_start
        super
        open_command_window
    end
    #--------------------------------------------------------------------------
    # * Wait
    #--------------------------------------------------------------------------
    def wait(duration)
        for i in 0...duration
            Graphics.update
        end
    end
    #--------------------------------------------------------------------------
    # * Pre-termination Processing
    #--------------------------------------------------------------------------
    def pre_terminate
        super
        close_command_window
        close_command_window_2
    end
    #--------------------------------------------------------------------------
    # * Termination Processing
    #--------------------------------------------------------------------------
    def terminate
        super
        dispose_command_window
        @board_sprite.dispose
        @answer_sprite.dispose
        @hard_sprite.dispose
        @side_sprite.dispose if Mastermind_Options::Side == true
        @winloss.dispose if Mastermind_Options::Win_Lose == true
        if @color_index != 0
            for i in 0...@color_index
                @color_sprite[i].dispose
            end
            for i in 0...@peg_index
                @peg_sprite[i].dispose
            end
        end
        if Mastermind_Options::Game_Music == true
            @last_bgm.play
            @last_bgs.play
        end
    end
    #--------------------------------------------------------------------------
    # * Frame Update
    #--------------------------------------------------------------------------
    # def tests
        # p 1
    # end
    def easy_terminate
        @hard_sprite.dispose
    end
    
    def update
        super
        #update_menu_background if Mastermind_Options::Black_Background == false
        @winloss.update if Mastermind_Options::Win_Lose == true
        if @game_mode == "start"
            if Input.press?(:C)
                case @command_window.index
                when 0
                    Sound.play_ok
                    close_command_window
                    cover_answer
                    easy_terminate
                when 1
                    Sound.play_ok
                    close_command_window
                    cover_answer
                when 2
                    Sound.play_cancel
                    SceneManager.return
                end
            end
        elsif @game_mode == "color"
            if Input.trigger?(:C)
                if @guess_index != 4
                    Sound.play_ok
                    @go = @command_window_2.index
                    @guess[@guess_index] = @go
                    @color_sprite[@color_index] = Sprite.new
                    @color_sprite[@color_index].bitmap=Cache.picture("mm_color"+@go.to_s)
                    @color_sprite[@color_index].x = 228 + (@guess_index * 35)
                    @color_sprite[@color_index].y = 360 - (@round_index * 40)
                    @color_sprite[@color_index].z = 2
                    @guess_index += 1
                    @color_index += 1
                    if @guess_index == 4
                        @game_mode = "peg"
                        close_command_window_2
                        @command_window.index = 0
                        @command_window_2.index = 0
                        wait(15)
                        check_colors
                    end
                end
            end
            if Input.trigger?(:B)
                if @guess_index == 0
                    Sound.play_cancel
                    close_command_window_2
                    @playe_vocab = "Continue"
                    @playh_vocab = "Continue"
                    @cancel_vocab = "Quit"
                    @command_window.index = 0
                    @command_window.dispose
                    create_command_window
                    open_command_window
                    @game_mode = "quit"
                else
                    case @guess_index
                    when 1
                        @guess[0] = -1
                    when 2
                        @guess[1] = -1
                    when 3
                        @guess[2] = -1
                    end
                    @guess_index -= 1
                    @color_index -= 1
                    Sound.play_cancel
                    @color_sprite[@color_index].dispose
                end
            end
        elsif @game_mode == "quit"
            if Input.press?(:C)
                case @command_window.index
                when 0
                    Sound.play_ok
                    close_command_window
                    open_command_window_2
                    @game_mode = "color"
                when 1
                    Sound.play_ok
                    close_command_window
                    open_command_window_2
                    @game_mode = "color"
                when 2
                    Sound.play_cancel
                    SceneManager.return
                end
            end
        elsif @game_mode == "win" or @game_mode == "lose"
            if @command_window.openness == 255
                if Input.trigger?(:C)
                    case @command_window.index
                    when 0
                        Sound.play_ok
                        opac = 250
                        close_command_window
                        wait(8)
                        begin
                            opac -= 10
                            for i in 0...@color_index
                                @color_sprite[i].opacity = opac
                            end
                            for i in 0...@peg_index
                                @peg_sprite[i].opacity = opac
                            end
                            wait(2)
                        end until opac == 0
                        for i in 0...@color_index
                            @color_sprite[i].dispose
                        end
                        for i in 0...@peg_index
                            @peg_sprite[i].dispose
                        end
                        wait(10)
                        cover_answer
                        easy_terminate
                    when 1
                        Sound.play_ok
                        opac = 250
                        close_command_window
                        wait(8)
                        begin
                            opac -= 10
                            for i in 0...@color_index
                                @color_sprite[i].opacity = opac
                            end
                            for i in 0...@peg_index
                                @peg_sprite[i].opacity = opac
                            end
                            wait(2)
                        end until opac == 0
                        for i in 0...@color_index
                            @color_sprite[i].dispose
                        end
                        for i in 0...@peg_index
                            @peg_sprite[i].dispose
                        end
                        wait(10)
                        cover_answer
                        easy_terminate
                        @hard_sprite = Sprite.new(Viewport.new(0, 0, 544, 416))
                        @hard_sprite.bitmap = Cache.picture("mm_hard")
                        @hard_sprite.x = 0
                        @hard_sprite.y = 0
                        @hard_sprite.z = 2
                    when 2
                        Sound.play_cancel
                        SceneManager.return
                    end
                end
            end
        end
    end
    #--------------------------------------------------------------------------
    # * Update Background for Menu Screen
    #--------------------------------------------------------------------------
    def update_menu_background
        #~ super
        #~ @menuback_sprite.tone.set(0, 0, 0, 128)
    end
    #--------------------------------------------------------------------------
    # * Game Start
    #--------------------------------------------------------------------------
    def cover_answer
        @used_colors = [0, 1, 2, 3, 4]
      if @command_window.index == 1
        @round_index = 2
      else
        @round_index = 0
      end
        @color_index = 0
        @peg_index = 0
        @guess[0] = -1
        @guess[1] = -1
        @guess[2] = -1
        @guess[3] = -1
        @guess_used[0] = false
        @guess_used[1] = false
        @guess_used[2] = false
        @guess_used[3] = false
        @guess_index = 0
        @answer[0] = -1
        @answer[1] = -1
        @answer[2] = -1
        @answer[3] = -1
        @answer_used[0] = false
        @answer_used[1] = false
        @answer_used[2] = false
        @answer_used[3] = false
        @peg_hole = 0
        @j = 0
        @k = 0   
        @distance = 19 - (@answer_sprite.y)
        @iindex = 0
        RPG::ME.stop
        RPG::SE.stop
        for i in 0...4
            Sound.play_cursor
            temp_answer = rand(5)
            @color_sprite[i] = Sprite.new
            @color_sprite[i].bitmap=Cache.picture("mm_color"+temp_answer.to_s)
            @color_sprite[i].x = 228 + (i * 35)
            @color_sprite[i].y = 29
            @color_sprite[i].z = 2
            @color_index += 1
            wait(10)
        end
        while @distance > 0
            @answer_sprite.y += 1
            temp_answer = rand(5)
            @color_sprite[@iindex].bitmap=Cache.picture("mm_color"+temp_answer.to_s)
            @iindex += 1
            if @iindex == 4
                @iindex = 0
            end
            @distance = 19 - (@answer_sprite.y)
            Sound.play_cursor
            wait(2)
        end
        for i in 0...4
            @answer[i] = @used_colors[rand(@used_colors.size)]
            @used_colors.delete(@answer[i])
            @color_sprite[i].bitmap=Cache.picture("mm_color"+@answer[i].to_s)
            @color_sprite[i].z = 2
        end
        open_command_window_2
        @game_mode = "color"
    end
    #--------------------------------------------------------------------------
    # * Game End
    #--------------------------------------------------------------------------
    def uncover_answer
        begin
            @answer_sprite.y -= 1
            wait(2)
        end until @answer_sprite.y == -25
        @playe_vocab = "Try Harder"
        @playh_vocab = "Rematch"
        @cancel_vocab = "Quit"
        @command_window.dispose
        create_command_window
        open_command_window
    end
    #--------------------------------------------------------------------------
    # * Round End
    #--------------------------------------------------------------------------
    def check_colors
        for i in 0...4
            if @guess[i] == @answer[i]
                @guess_used[i] = true
                @answer_used[i] = true
                @peg_sprite[@peg_index] = Sprite.new
                @peg_sprite[@peg_index].bitmap = Cache.picture("mm_black")
                case @peg_hole
                when 0
                    @peg_sprite[@peg_index].x = 184
                    @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                when 1
                    @peg_sprite[@peg_index].x = 198
                    @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                when 2
                    @peg_sprite[@peg_index].x = 184
                    @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                when 3
                    @peg_sprite[@peg_index].x = 198
                    @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                end
                @peg_sprite[@peg_index].z = 2
                @peg_index += 1
                @peg_hole += 1
                if @peg_hole == 4
                    @game_mode = "win"
                end
            end
        end
        while @j <= 3
            if @j != @k
                if @guess[@j] == @answer[@k]
                    if @guess_used[@j] == false
                        if @answer_used[@k] == false
                            @guess_used[@j] = true
                            @answer_used[@k] = true
                            @peg_sprite[@peg_index] = Sprite.new
                            @peg_sprite[@peg_index].bitmap = Cache.picture("mm_white")
                            case @peg_hole
                            when 0
                                @peg_sprite[@peg_index].x = 184
                                @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                            when 1
                                @peg_sprite[@peg_index].x = 198
                                @peg_sprite[@peg_index].y = 358 - (@round_index * 40)
                            when 2
                                @peg_sprite[@peg_index].x = 184
                                @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                            when 3
                                @peg_sprite[@peg_index].x = 198
                                @peg_sprite[@peg_index].y = 372 - (@round_index * 40)
                            end
                            @peg_sprite[@peg_index].z = 2
                            @peg_index += 1
                            @peg_hole += 1
                        end
                    end
                end
            end
            @k += 1
            if @k == 4
                @j += 1
                @k = 0
            end
        end
        @guess[0] = -1
        @guess[1] = -1
        @guess[2] = -1
        @guess[3] = -1
        @guess_used[0] = false
        @guess_used[1] = false
        @guess_used[2] = false
        @guess_used[3] = false
        @guess_index = 0
        @answer_used[0] = false
        @answer_used[1] = false
        @answer_used[2] = false
        @answer_used[3] = false
        @peg_hole = 0
        @j = 0
        @k = 0
        wait(15)
        if @round_index == 7 and @game_mode != "win"
            @game_mode = "lose"
            if Mastermind_Options::Loss_Sound_Type == "SE"
                temp_sound = "Audio/SE/" + Mastermind_Options::Loss_Sound
                Audio.se_play(temp_sound, 100, 100)
            elsif Mastermind_Options::Loss_Sound_Type == "ME"
                temp_sound = "Audio/ME/" + Mastermind_Options::Loss_Sound       
                Audio.me_play(temp_sound, 100, 100)
            end
            $game_system.losses += 1
            @winloss.refresh if Mastermind_Options::Win_Lose == true
            uncover_answer
        elsif @game_mode == "win"
            if Mastermind_Options::Win_Sound_Type == "SE"
                temp_sound = "Audio/SE/" + Mastermind_Options::Win_Sound
                Audio.se_play(temp_sound, 100, 100)
            elsif Mastermind_Options::Win_Sound_Type == "ME"
                temp_sound = "Audio/ME/" + Mastermind_Options::Win_Sound       
                Audio.me_play(temp_sound, 100, 100)
            end
            $game_system.wins += 1
            @winloss.refresh if Mastermind_Options::Win_Lose == true
            uncover_answer
        else
            @round_index += 1
            open_command_window_2
            @game_mode = "color"
        end
    end
    #--------------------------------------------------------------------------
    # * Create Command Window
    #--------------------------------------------------------------------------
    def create_command_window
        @command_window = Window_MastermindCommand.new(0, 0)
        @command_window.x = (Graphics.width - @command_window.width) / 2
        @command_window.y = (Graphics.height - @command_window.height) / 2
        @command_window.height = @command_window.fitting_height(3)
        @command_window.refresh
        @command_window.openness = 0
    end
    #--------------------------------------------------------------------------
    # * Dispose of Command Window
    #--------------------------------------------------------------------------
    def dispose_command_window
        @command_window.dispose
        @command_window_2.dispose
    end
    #--------------------------------------------------------------------------
    # * Open Command Window
    #--------------------------------------------------------------------------
    def open_command_window
        @command_window.open
        @command_window.refresh
        @command_window.active = true
    end
    #--------------------------------------------------------------------------
    # * Close Command Window
    #--------------------------------------------------------------------------
    def close_command_window
        @command_window.close
        @command_window.refresh
        @command_window.active = false
    end
    #--------------------------------------------------------------------------
    # * Create Command Window Two
    #--------------------------------------------------------------------------
    def create_command_window_2
        @command_window_2 = Window_MastermindCommand_Color.new(0, 0)
        @command_window_2.x = (198 - @command_window_2.width) / 2
        @command_window_2.height = @command_window_2.fitting_height(6)
        if Mastermind_Options::Win_Lose == false
            @command_window_2.y = (Graphics.height - @command_window_2.height) / 2
        else
            @command_window_2.y = 210
        end
        @command_window_2.openness = 0
        @command_window_2.active = false
    end
    #--------------------------------------------------------------------------
    # * Open Command Window Two
    #--------------------------------------------------------------------------
    def open_command_window_2
        @command_window_2.open
        @command_window_2.active = true
        @command_window_2.refresh
    end
    #--------------------------------------------------------------------------
    # * Close Command Window Two
    #--------------------------------------------------------------------------
    def close_command_window_2
        @command_window_2.close
        @command_window_2.active = false
        @command_window_2.refresh
    end
end
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Yet another gaming question, i'm currently playing Last of Us 2 and want to get another game to play next but can't decide between Ghost of Tsushima, Miles Morales & Jedi Fallen Order. After the latest mandalorian i AM on a star wars kick, but i also LOVED the last spiderman game that prequels Miles Morales. Ghost of Tsushima is the bottom of my list but i heard it was AWESOME. Just want a good story & fun gameplay.
I checked out Genshin Impact gameplay out of curiosity. I can't believe it's available as a mobile game too. Smooth animation, great music, and stellar sound effects (the ambient sounds are pretty detailed).

I'm flabbergasted to see games have becoming more and more advanced. Maybe also because I'm oblivious to current trend for a long time, it almost feel like I'm being sent into distant future. xD
xDRAGOONx wrote on WaywardMartian's profile.
Your artwork is amazing!!!
:ewat:
Stream will be live shortly with a session of the Interactive Text Adventure! Feel free to drop by!
I should finish the cat video I'm editing and finish the indesign stuff. So far only 1 is done and 4 to go

Forum statistics

Threads
105,663
Messages
1,015,362
Members
137,338
Latest member
greatgamegal
Top