#==============================================================================
# Mastermind (VXA)
# Version: 2.0
# Author: Zylos
# Date: March 21, 2011
# Mod by Roninator2
# Updated 4 Sep 2020
#------------------------------------------------------------------------------
# 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:
#============================================================================
Side = true # Show the side decoration graphic
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)
Difficulty = 1 # switch used to set the difficulty
Colours = 1 # Values from 1 - 6 # variable used to set how many colours used
# value equals how many colors. 2 = 2 colors. Will exit if 0.
Lives = 2 # variable used to set how many chances (lives)
Win = 2 # switch turns on when player wins
Victory1 = "Congratulations! You passed the easiest level."
Victory2 = "Congratulations! You know how to tell colours apart."
Victory3 = "Congratulations! You are an average player"
Victory4 = "Congratulations! I'm almost impressed."
Victory5 = "Congratulations! But I'll get you next time."
Victory6 = "WOW! I never thought someone could win that challenge!"
# message shown after winning
# icons used for commands
ICONS = [1360,1361,1362,1363,1364,1376]
Use_Icons = true # whether or not to use icons
#============================================================================
# END EDITABLE REGION
#============================================================================
end
#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Adding the mastermind command.
#==============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# * Call Mastermind
#--------------------------------------------------------------------------
def call_mastermind
SceneManager.call(Scene_Mastermind)
end
end
#==============================================================================
# ** Window_MastermindRatio
#------------------------------------------------------------------------------
# This window displays yours wins versus your losses in Mastermind.
#==============================================================================
class Window_MastermindLives < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
# x : window X coordinate
# y : window Y coordinate
#--------------------------------------------------------------------------
def initialize(x, y)
super(x, y, 135, 100)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 90, line_height, "Lives")
self.contents.draw_text(4, 24, 90, line_height, "Remaining:")
self.contents.font.color = normal_color
self.contents.draw_text(14, 24, 90, line_height, $game_variables[Mastermind_Options::Lives], 2)
end
end
#==============================================================================
# ** Window_MastermindCommand_Color
#------------------------------------------------------------------------------
# This window displays your colors to use in the game.
#==============================================================================
class Window_MastermindCommand_Color < Window_Command
def initialize(x, y, ci)
@ci = []
@ci = Mastermind_Options::ICONS
super(x, y)
end
alias r2_MM_icon_draw_9274hv draw_item
def draw_item(index)
enabled = command_enabled?(index)
change_color(normal_color, enabled)
text = command_name(index)
if Mastermind_Options::Use_Icons == true
rect = item_rect(index)
draw_icon(@ci[index], rect.x + 10, rect.y, true)
rect.x += 40
rect.width -= 30
draw_text(rect, text, alignment)
else
r2_MM_icon_draw_9274hv(index)
end
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 window_width
return 200
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
if $game_variables[Mastermind_Options::Colours] == 0
error = "Colors are set to 0!"
$game_message.add(sprintf(error, @actor))
SceneManager.return
end
@colours = []
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
super
create_command_window_2
create_lives_window
@board_sprite = Sprite.new(Viewport.new(0, 0, 640, 480))
@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 = 260
@answer_sprite.y = -20
@answer_sprite.z = 10
if $game_switches[Mastermind_Options::Difficulty] == true
@hard_sprite = Sprite.new(Viewport.new(0, 0, 640, 480))
@hard_sprite.bitmap = Cache.picture("mm_hard")
@hard_sprite.x = 0
@hard_sprite.y = 0
@hard_sprite.z = 2
end
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
#--------------------------------------------------------------------------
# * Wait
#--------------------------------------------------------------------------
def wait(duration)
for i in 0...duration
Graphics.update
end
end
#--------------------------------------------------------------------------
# * Termination Processing
#--------------------------------------------------------------------------
def terminate
super
@board_sprite.dispose
@answer_sprite.dispose
@hard_sprite.dispose if $game_switches[Mastermind_Options::Difficulty] == true
@side_sprite.dispose if Mastermind_Options::Side == 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
def update
super
if @game_mode == "start"
$game_switches[Mastermind_Options::Win] == false
Sound.play_ok
cover_answer
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"[email hidden]_s)
@color_sprite[@color_index].x = 275 + (@guess_index * 35)
@color_sprite[@color_index].y = 415 - (@round_index * 40)
@color_sprite[@color_index].z = 2
@guess_index += 1
@color_index += 1
if @guess_index == 4
@game_mode = "peg"
@command_window_2.index = 0
wait(15)
check_colors
end
end
end
if Input.trigger?(:B)
if @guess_index == 0
Sound.play_cancel
@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"
Sound.play_cancel
SceneManager.return
elsif @game_mode == "lose"
Sound.play_cancel
wait(8)
if $game_variables[Mastermind_Options::Lives] > 0
@game_mode = "color"
$game_variables[Mastermind_Options::Lives] -= 1
for i in 0...@color_index
@color_sprite[i].dispose
end
for i in 0...@peg_index
@peg_sprite[i].dispose
end
@colours = []
wait(10)
cover_answer
else
Sound.play_cancel
SceneManager.return
end
elsif @game_mode == "win"
Sound.play_use_skill
case $game_variables[Mastermind_Options::Colours]
when 1
$game_message.add(sprintf(Mastermind_Options::Victory1, @actor))
when 2
$game_message.add(sprintf(Mastermind_Options::Victory2, @actor))
when 3
$game_message.add(sprintf(Mastermind_Options::Victory3, @actor))
when 4
$game_message.add(sprintf(Mastermind_Options::Victory4, @actor))
when 5
$game_message.add(sprintf(Mastermind_Options::Victory5, @actor))
when 6
$game_message.add(sprintf(Mastermind_Options::Victory6, @actor))
else
$game_message.add(sprintf("I give up", @actor))
end
$game_switches[Mastermind_Options::Win] = true
SceneManager.return
end
end
#--------------------------------------------------------------------------
# * Game Start
#--------------------------------------------------------------------------
def cover_answer
if $game_switches[Mastermind_Options::Difficulty] == true
@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 = 50 - (@answer_sprite.y)
@iindex = 0
RPG::ME.stop
RPG::SE.stop
for i in 0..3
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 = 275 + (i * 35)
@color_sprite[i].y = 45
@color_sprite[i].z = 2
@color_index += 1
wait(10)
end
while @distance > 0
@answer_sprite.y += 1
temp_answer = rand(6)
@color_sprite[@iindex].bitmap=Cache.picture("mm_color"+temp_answer.to_s)
@iindex += 1
if @iindex == 4
@iindex = 0
end
@distance = 35 - (@answer_sprite.y)
Sound.play_cursor
wait(2)
end
until @colours.size == $game_variables[Mastermind_Options::Colours]
pick = rand(6)
if [email protected]?(pick)
@colours << pick
end
end
for i in 0..3
count = @colours.size
number = rand(count)
setcolour = @colours[number]
@answer[i] = setcolour
@color_sprite[i].bitmap=Cache.picture("mm_color"+@answer[i].to_s)
@color_sprite[i].z = 2
end
open_command_window_2
open_lives_window
@game_mode = "color"
end
#--------------------------------------------------------------------------
# * Game End
#--------------------------------------------------------------------------
def uncover_answer
begin
@answer_sprite.y -= 1
wait(2)
end until @answer_sprite.y == -20
wait(60)
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 = 231
@peg_sprite[@peg_index].y = 412 - (@round_index * 40)
when 1
@peg_sprite[@peg_index].x = 245
@peg_sprite[@peg_index].y = 412 - (@round_index * 40)
when 2
@peg_sprite[@peg_index].x = 231
@peg_sprite[@peg_index].y = 426 - (@round_index * 40)
when 3
@peg_sprite[@peg_index].x = 245
@peg_sprite[@peg_index].y = 426 - (@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 = 231
@peg_sprite[@peg_index].y = 412 - (@round_index * 40)
when 1
@peg_sprite[@peg_index].x = 245
@peg_sprite[@peg_index].y = 412 - (@round_index * 40)
when 2
@peg_sprite[@peg_index].x = 231
@peg_sprite[@peg_index].y = 426 - (@round_index * 40)
when 3
@peg_sprite[@peg_index].x = 245
@peg_sprite[@peg_index].y = 426 - (@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 == 8 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
uncover_answer
close_command_window_2
close_lives_window
if $game_variables[Mastermind_Options::Lives] > 0
update
@lives.refresh
else
Sound.play_cancel
SceneManager.return
end
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
uncover_answer
else
@round_index += 1
@game_mode = "color"
end
end
#--------------------------------------------------------------------------
# * Create Command Window Two
#--------------------------------------------------------------------------
def create_command_window_2
@command_window_2 = Window_MastermindCommand_Color.new(0, 0, @ci)
@command_window_2.x = (200 - @command_window_2.width) / 2
@command_window_2.height = @command_window_2.fitting_height(6)
@command_window_2.y = 210
@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
@command_window_2.opacity = 255
end
#--------------------------------------------------------------------------
# * Close Command Window Two
#--------------------------------------------------------------------------
def close_command_window_2
@command_window_2.close
@command_window_2.active = false
@command_window_2.refresh
@command_window_2.opacity = 0
end
def create_lives_window
@lives = Window_MastermindLives.new(30, 30)
@lives.openness = 0
end
def close_lives_window
@lives.close
@lives.opacity = 0
end
def open_lives_window
@lives.open
@lives.opacity = 255
end
end