Microsoft Small Basic

Program Listing: FVD421-5
' DoubutsuShogi v0.8 - Copyright (c) 2011 Nonki Takahashi
'
' History
' 2010/01/25 v0.1 Created (440 lines)
' 2010/02/03 v0.2 Created GameRecord_ class (595 lines FVD421)
' 2010/02/11 v0.3 Made animation for piece move (805 lines FVD421-0)
' 2010/02/16 v0.4 Created captured piece move (936 lines FVD421-1)
' 2010/02/23 v0.5 Bug fix for Human_ etc (1049 lines FVD421-2)
' 2010/02/24 v0.6 Created new controls (1339 lines FVD421-3)
' 2010/02/27 v0.7 Bug fix for Game_ etc (1401 lines FVD421-4)
' 2010/03/05 v0.8 Replay implementation and debug (1359 lines FVD421-5)
'
' Reference
' [1] 北岡, 藤田: "どうぶつしょうぎのほん", 2010, 幻冬舎エデュケーション
' (Kitaoka, Fujita: "Doubutsu Shogi No Hon", 2010, Gentosha Education)
' [2] 北岡, 藤田: "どうぶつしょうぎ あそびかたBOOK", 2009, 幻冬舎エデュケーション
' (Kitaoka, Fujita: "Doubutsu Shogi Asobikata Book", 2009, Gentosha Education)
'
' Naming convention
' class Xxx_
' label lXxx
' constant XXX
' variable type integer iXxx
' variable type real rXxx
' variable type string sXxx
' variable type url uXxx
' variable type char cXxx
' variable type boolean bXxx
' variable type object oXxx
'
' Constant
VERSION = 0.8
SPACE = 0
CHICK1 = 1
HEN1 = 2
ELEPHANT1 = 3
GIRAFFE1 = 4
LION1 = 5
CHICK2 = 6
HEN2 = 7
ELEPHANT2 = 8
GIRAFFE2 = 9
LION2 = 10
A = 1
B = 2
C = 3
CA = 4
CB = 5
CC = 6
CD = 7
DIRMIN = 0
TOPLEFT = 0
TOP = 1
TOPRIGHT = 2
LEFT = 3
CENTER = 4
RIGHT = 5
BOTTOMLEFT = 6
BOTTOM = 7
BOTTOMRIGHT = 8
DIRMAX = 8
FOREST = 1
SKY = 2
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
REPLAY = "4" ' Webdings replay mark for replay button
'
' Main
GraphicsWindow.Height = 540
GraphicsWindow.Width = 780
Game_Init()
Board_Init()
Console_Init()
GameRecord_Init()
While "True"
Board_New()
Board_Draw()
GameRecord_New()
GameRecord_Draw()
Console_AskFirstTurn()
Console_ShowTurn()
' yoroshiku onegai shimasu - best regards (?)
sMessage = "よろしく" + CRLF + "おねがい" + CRLF + "します"
iX = 500
iY = 250
Console_ShowBalloon()
'
Game_Loop() ' play game
'
' arigatou gozaimashita - thank you
sMessage = "ありがとう" + CRLF + "ございました"
iX = 500
iY = 250
Console_ShowBalloon()
Console_ShowReplayButton()
Console_ShowNewGameButton()
Console_bReplay = "True"
While Console_bReplay
Console_bNewGame = "False"
Console_bReplay = "False"
bButtonNotClicked = "True"
Controls.ButtonClicked = Console_OnButtonClicked
While bButtonNotClicked
Program.Delay(200)
EndWhile
Controls.ButtonClicked = Console_DoNothing
If Console_bReplay Then
GameRecord_Replay()
EndIf
EndWhile
Console_HideReplayButton()
Console_HideNewGameButton()
EndWhile
'
' Board | Initialization
' out: Board_iCols, Board_iRows - number of ro (number of file and rank)
' out: Board_iX0, Board_iY0, Board_iX1, Board_iY1 - board coordinate
' out: Board_idX, Board_idY - cell width and height (delta)
' out: iOffsetX, iOffsetY - offset between cell and piece
' out: Captured_iCols, Captured_iRows - number of ro for captured piece slot
' out: Captured_iX0, Captured_iY0, Captured_iX1, Captured_iY1 - captured slot coordinate
' out: uBoard - url of board image bitmap
' out: Board_sCol[], Board_sRow[] - cell name sign
' out: uCell[][] - url of cell image bitmap
' out: uPiece[] - url of piece image bitmap
' out: idCol[], idRow[] - nine direction delta
Sub Board_Init
Board_iCols = 3
Board_iRows = 4
Board_iX0 = 50
Board_iY0 = 100
Board_idX = 100
Board_idY = 100
Board_iX1 = Board_iX0 + Board_idX * Board_iCols
Board_iY1 = Board_iY0 + Board_idY * Board_iRows
iOffsetX = 10
iOffsetY = 10
Captured_iCols = 4
Captured_iRows = 2
Captured_idX = Board_idX / 2
Captured_idY = Board_idY / 2
Captured_iX0 = Board_iX1
Captured_iX1 = Captured_iX0 + Captured_idX * Captured_iCols
Captured_iY0 = Board_iY0
Captured_iY1 = Captured_iY0 + Captured_idY * Captured_iRows
Captured_iY3 = Board_iY1
Captured_iY2 = Captured_iY3 - Captured_idY * Captured_iRows
uFolder = "http://homepage2.nifty.com/nobukit/smallbasic.files/"
uBoard = uFolder + "Board300.png"
Board_sCol[A] = "A"
Board_sCol[B] = "B"
Board_sCol[C] = "C"
Board_sRow[1] = "1"
Board_sRow[2] = "2"
Board_sRow[3] = "3"
Board_sRow[4] = "4"
uCell[A][1] = uFolder + "A1.png"
uCell[B][1] = uFolder + "B1.png"
uCell[C][1] = uFolder + "C1.png"
uCell[A][2] = uFolder + "A2.png"
uCell[B][2] = uFolder + "B2.png"
uCell[C][2] = uFolder + "C2.png"
uCell[A][3] = uFolder + "A3.png"
uCell[B][3] = uFolder + "B3.png"
uCell[C][3] = uFolder + "C3.png"
uCell[A][4] = uFolder + "A4.png"
uCell[B][4] = uFolder + "B4.png"
uCell[C][4] = uFolder + "C4.png"
'
uPiece[LION1] = uFolder + "Lion1t.png"
uPiece[GIRAFFE1] = uFolder + "Giraffe1t.png"
uPiece[ELEPHANT1] = uFolder + "Elephant1t.png"
uPiece[CHICK1] = uFolder + "Chick1t.png"
uPiece[HEN1] = uFolder + "Hen1t.png"
uPiece[LION2] = uFolder + "Lion2t.png"
uPiece[GIRAFFE2] = uFolder + "Giraffe2t.png"
uPiece[ELEPHANT2] = uFolder + "Elephant2t.png"
uPiece[CHICK2] = uFolder + "Chick2t.png"
uPiece[HEN2] = uFolder + "Hen2t.png"
'
' TOPLEFT=0 (-1, -1) TOP=1 (0, -1) TOPRIGHT=2 (1, -1)
' LEFT=3 (-1, 0) CENTER=4 (0,0) RIGHT=5 (1, 0)
' BOTTOMLEFT=6 (-1, 1) BOTTOM=7 (0, 1) BOTTOMRIGHT=8 (1, 1)
idCol = "1=0;2=1;5=1;8=1;7=0;6=-1;3=-1;0=-1;4=0;"
idRow = "1=-1;2=-1;5=0;8=1;7=1;6=1;3=0;0=-1;4=0;"

EndSub
'
' Board | New
' out: Board_iCell[][] - game board, captured piece slot
' out: Board_iNumCaptured[] - 0
Sub Board_New
GraphicsWindow.PenColor = "DarkOrange"
GraphicsWindow.BrushColor = "DarkOrange"
GraphicsWindow.PenWidth = 2
GraphicsWindow.FontSize = 20 ' middle
GraphicsWindow.DrawImage(uBoard, Board_iX0, Board_iY0)
For iCol = 0 To Board_iCols
Dotted_iX0 = Board_iX0 + iCol * Board_idX
Dotted_iY0 = Board_iY0
Dotted_iX1 = Board_iX0 + iCol * Board_idX
Dotted_iY1 = Board_iY1
Graphics_DrawDottedLine()
If iCol > 0 Then
GraphicsWindow.DrawText(Board_iX0 + iCol * Board_idX - Board_idX / 2 - 5, Board_iY0 - Board_idY / 3, Board_sCol[iCol])
EndIf
EndFor
For iRow = 0 To Board_iRows
Dotted_iX0 = Board_iX0
Dotted_iY0 = Board_iY0 + iRow * Board_idY
Dotted_iX1 = Board_iX1
Dotted_iY1 = Board_iY0 + iRow * Board_idY
Graphics_DrawDottedLine()
If iRow > 0 Then
GraphicsWindow.DrawText(Board_iX0 - Board_idX / 4, Board_iY0 + iRow * Board_idY - Board_idY / 2 - 10, Board_sRow[iRow])
EndIf
EndFor
For iRow = 1 To 4
For iCol = A To CD
Board_iCell[iCol][iRow] = SPACE
EndFor
EndFor
Board_iCell[A][1] = GIRAFFE2
Board_iCell[B][1] = LION2
Board_iCell[C][1] = ELEPHANT2
Board_iCell[B][2] = CHICK2
Board_iCell[B][3] = CHICK1
Board_iCell[A][4] = ELEPHANT1
Board_iCell[B][4] = LION1
Board_iCell[C][4] = GIRAFFE1
' captured by FOREST, SKY
Board_iNumCaptured[FOREST] = 0
Board_iNumCaptured[SKY] = 0
EndSub
'
' Board | Move
' in: iFromCol, iFromRow, iPiece - piece and the position
' in: bPromote - promote chick to chicken
' in: iToCol, iToRow - to position
' in: iTurn - current turn FOREST or SKY
Sub Board_Move
iCase = 0
If iFromCol > Board_iCols Then ' from captured
' check iFromCol, iFromRow are in captured slot
If iFromCol < CA Or iFromCol > CD Then
iCase = 1
Goto lOutOfBounds
ElseIf iTurn = FOREST And (iFromRow < 3 Or iFromRow > 4) Then
iCase = 2
Goto lOutOfBounds
ElseIf iTurn = SKY And (iFromRow < 1 Or iFromRow > 2) Then
iCase = 3
Goto lOutOfBounds
EndIf
Else
' check iFromCol, iFromRow, iToCol, iToCol are in board
If iFromCol < 1 Or iFromCol > Board_iCols Or iFromRow < 1 Or iFromRow > Board_iRows Then
iCase = 4
Goto lOutOfBounds
EndIf
EndIf
iPiece = Board_iCell[iFromCol][iFromRow]
If iToCol < 1 Or iToCol > Board_iCols Or iToRow < 1 Or iToRow > Board_iRows Then
iCase = 5
Goto lOutOfBounds
EndIf
If iPiece > (iTurn - 1) * 5 And iPiece < 6 + (iTurn - 1) * 5 Then
' iPiece is a member of iTurn team
If iFromCol > Board_iCols And Board_iCell[iToCol][iToRow] = SPACE Then
' iToCol, iToRow is movable position for captured iPiece
Goto lMatch
EndIf
For iDir = DIRMIN To DIRMAX ' nine directions
If idCol[iDir] = iToCol - iFromCol And idRow[iDir] = iToRow - iFromRow And Game_bCanMove[iPiece][iDir] Then
' iToCol, iToRow is movable position for iPiece
Goto lMatch
EndIf
EndFor
Sound.PlayChime()
iCase = 6
Goto lExit
EndIf
lMatch:
' check phisically possible move if necessary
If Game_bCapture Then
iCaptured = Board_iCell[iToCol][iToRow]
Else
iCaptured = SPACE
EndIf
If Game_bIsPossibleMove Then
iCol = iFromCol
iRow = iFromRow
If iFromCol > Board_iCols Then ' from captured
Board_RemoveCaptured()
Else
Board_iCell[iCol][iRow] = SPACE
Board_DrawCell()
If bPromote And iPiece = CHICK1 Then
iPiece = HEN1
ElseIf bPromote And iPiece = CHICK2 Then
iPiece = HEN2
EndIf
EndIf
iCol = iToCol
iRow = iToRow
Board_iCell[iCol][iRow] = iPiece
Board_DrawCell()
If bPromote Then
sMessage = "パワーアップ!" ' power up!
iX = Board_iX0 + iCol * Board_idX - 20
iY = Board_iY0 + (iRow - 1) * Board_idY + 20
Console_ShowBalloon()
EndIf
EndIf
If Game_bCapture Then
iOpposite = iTurn * 10 - 15
iCaptured = iCaptured + iOpposite
If iCaptured = HEN1 Or iCaptured = HEN2 Then
iCaptured = iCaptured - 1 ' convert HEN to CHICK
EndIf
Board_AddCaptured()
EndIf
Goto lExit
lOutOfBounds:
Sound.PlayChime()
lExit:
If iCase > 0 Then
TextWindow.WriteLine("Error: case = " + iCase)
EndIf
EndSub
'
' Board | Draw
Sub Board_Draw
iCol = B ' lion in sky
iRow = 1
Board_DrawCell()
iRow = 4 ' lion in forest
Board_DrawCell()
iCol = C ' elephant in sky
iRow = 1
Board_DrawCell()
iCol = A ' elephant in forest
iRow = 4
Board_DrawCell()
iRow = 1 ' giraffe in sky
Board_DrawCell()
iCol = C ' giraffe in forest
iRow = 4
Board_DrawCell()
iCol = B ' chick in sky
iRow = 2
Board_DrawCell()
iRow = 3 ' chick in forest
Board_DrawCell()
For iRow = 1 To 4
For iCol = CA To CD
Board_DrawCaptured()
EndFor
EndFor
EndSub
'
' Board | Draw cell
' in: iCol, iRow - cell index
Sub Board_DrawCell
If Board_iCell[iCol][iRow] = SPACE Then
GraphicsWindow.DrawImage(uCell[iCol][iRow], Board_iX0 + (iCol - 1) * Board_idX + 2, Board_iY0 + (iRow - 1) * Board_idY + 2)
Else
GraphicsWindow.DrawImage(uPiece[Board_iCell[iCol][iRow]], Board_iX0 + (iCol - 1) * Board_idX + iOffsetX, Board_iY0 + (iRow - 1) * Board_idY + iOffsetY)
Sound.PlayClickAndWait()
EndIf
EndSub
'
' Board | Draw captured piece
' in: iCol, iRow - index FOREST team or SKY team
Sub Board_DrawCaptured
iX = Captured_iX0 + (iCol - CA) * Captured_idX
If iRow = 3 Or iRow = 4 Then ' forest team
iY = Captured_iY2 + (iRow - 3) * Captured_idY
Else ' sky team
iY = Captured_iY0 + (iRow - 1) * Captured_idY
EndIf
If Board_iCell[iCol][iRow] = SPACE Then
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillRectangle(iX + 1, iY + 1, 48, 48)
Else
GraphicsWindow.DrawResizedImage(uPiece[Board_iCell[iCol][iRow]], iX + iOffsetX / 2, iY + iOffsetY / 2, 42, 42)
Sound.PlayClickAndWait()
EndIf
EndSub
'
' Board | Get iCol, iRow from iTeam, iNum
Sub Board_GetColRowFromTeamNum
iCol = Math.Floor((iNum - 1) / 2) + CA
If iTeam = FOREST Then
iRow = Math.Remainder(iNum, 2) + 3
Else
iRow = Math.Remainder((iNum - 1), 2) + 1
EndIf
EndSub
'
' Board | Get iTeam, iNum from iCol, iRow
Sub Board_GetTeamNumFromColRow
If iRow = 1 Or iRow = 2 Then
iTeam = SKY
iNum = (iCol - CA) * 2 + Math.Remainder((iRow - 1), 2) + 1
ElseIf iRow = 3 Or iRow = 4 Then
iTeam = FOREST
iNum = (iCol - CA) * 2 + Math.Remainder(iRow, 2) + 1
EndIf
EndSub
'
' Board | Add captured piece
' in: iCaptured - captured piece
' work: iTeam, iNum - captured slot another index
' out: iCol, iRow - captured slot index
Sub Board_AddCaptured
If iCaptured <= LION1 Then
iTeam = FOREST
Else
iTeam = SKY
EndIf
iNum = Board_iNumCaptured[iTeam]
iNum = iNum + 1
Board_iNumCaptured[iTeam] = iNum
Board_GetColRowFromTeamNum()
Board_iCell[iCol][iRow] = iCaptured
Board_DrawCaptured()
EndSub
'
' Board | Remove captured piece
' in: iCol, iRow - captured slot index
' out: iPiece - removed piece
Sub Board_RemoveCaptured
Stack.PushValue("board", iCol)
Stack.PushValue("board", iRow)
Board_GetTeamNumFromColRow()
If iNum > Board_iNumCaptured[iTeam] Then
TextWindow.WriteLine("Remove: iNum out of bounds (iTeam = " + iTeam + ", iNum = " + iNum + ")")
Goto lRemoveError
EndIf
iPiece = Board_iCell[iCol][iRow]
Board_GetColRowFromTeamNum()
For iNum = iNum To Board_iNumCaptured[iTeam] - 1
iCol1 = Math.Floor(iNum / 2) + CA
If iTeam = FOREST Then
iRow1 = Math.Remainder((iNum - 1), 2) + 3
Else ' iTeam = SKY
iRow1 = Math.Remainder(iNum, 2) + 1
EndIf
Board_iCell[iCol][iRow] = Board_iCell[iCol1][iRow1]
Board_DrawCaptured()
iCol = iCol1
iRow = iRow1
EndFor
Board_iCell[iCol][iRow] = SPACE
Board_DrawCaptured()
Board_iNumCaptured[iTeam] = Board_iNumCaptured[iTeam] - 1
lRemoveError:
iRow = Stack.PopValue("board")
iCol = Stack.PopValue("board")
EndSub
'
' Board | Hide captured piece
' in: iCol, iRow - captured slot index
' out: iPiece - hidden piece
Sub Board_HideCaptured
Board_GetTeamNumFromColRow()
If iNum > Board_iNumCaptured[iTeam] Then
TextWindow.WriteLine("Hide: iNum out of bounds (iTeam = " + iTeam + ", iNum = " + iNum + ")")
Goto lHideError
EndIf
iPiece = Board_iCell[iCol][iRow]
Board_iCell[iCol][iRow] = SPACE
Board_DrawCaptured()
Board_iCell[iCol][iRow] = iPiece
lHideError:
EndSub
'
' Console | Initialization
' out: sTitle - game title
' out: sColor - game title color
' out: sTurnForest - string for turn forest
' out: sForestColor - forest color
' out: sTurnSky - string for turn sky
' out: sSkyColor - sky color
' out: sForestWin - string for forest win
' out: sSkyWin - string for sky win
' out: sDraw - string for draw
' out: sDrawColor - draw color
' out: oBalloon - balloon shape object
Sub Console_Init
' show title
TextWindow.Write("どうぶつしょうぎ ") ' doubutsu shogi
sTitle[1] = "ど" ' do
sTitle[2] = "う" ' u
sTitle[3] = "ぶ" ' bu
sTitle[4] = "つ" ' tsu
sTitle[5] = "し" ' sho
sTitle[6] = "ょ"
sTitle[7] = "う" ' u
sTitle[8] = "ぎ" ' gi
sColor[1] = "Red"
sColor[2] = "Gold"
sColor[3] = "Blue"
sColor[4] = "Orange"
sColor[5] = "DeepPink"
sColor[6] = "DeepSkyBlue"
sColor[7] = "Purple"
sColor[8] = "SeaGreen"
GraphicsWindow.FontSize = 30 ' large
For i = 1 To 8
GraphicsWindow.BrushColor = sColor[i]
GraphicsWindow.DrawText(Board_iX0 + (i - 1) * 38, Board_iY0 - Board_idY * 4 / 5, sTitle[i])
EndFor
' show version
TextWindow.WriteLine("バージョン " + VERSION) ' version
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontSize = 20 ' middle
GraphicsWindow.DrawText(Board_iX1 + Board_idX * 1.5, Board_iY0 -Board_idY * 4 / 5, "バージョン " + VERSION)
' for turn
sTurnForest = "森チームの番" ' turn of forest team
sForestColor = "YellowGreen"
sTurnSky = "空チームの番" ' turn of sky team
sSkyColor = "DeepSkyBlue"
' for result
sForestWin = "森チームの勝ち" ' forest team wins
sSkyWin = "空チームの勝ち" ' sky team wins
sDraw = "引き分け" ' draw
sDrawColor = "Orange"
' for balloon
uBalloon = uFolder + "balloon.png"
oBalloon = Shapes.AddImage(uBalloon)
Shapes.HideShape(oBalloon)
Shapes.Zoom(oBalloon, 0.6, 0.6)
Record_iX0 = Captured_iX1 + 4
Console_CreateReplayButton()
Console_CreateNewGameButton()
EndSub
'
' Console | Create replay button
' out: oReplay - replay button object
Sub Console_CreateReplayButton
sFontName = GraphicsWindow.FontName
GraphicsWindow.FontName = "Webdings"
oReplay = Controls.AddButton(REPLAY, Record_iX0, Board_iY1 - 38)
GraphicsWindow.FontName = sFontName
Controls.SetSize(oReplay, 30, 36)
Controls.HideControl(oReplay)
EndSub
'
' Console | Show replay button
' in: oReplay - replay button object
Sub Console_ShowReplayButton
Controls.ShowControl(oReplay)
Console_bReplay = "False"
bButtonNotClicked = "True"
EndSub
'
' Console | Hide replay button
' in: oReplay - replay button object
Sub Console_HideReplayButton
Controls.HideControl(oReplay)
EndSub
'
' Console | Create new game button
' out: oNewGame - new game button object
Sub Console_CreateNewGameButton
' from start
oNewGame = Controls.AddButton("はじめから", Record_iX0 + 38, Board_iY1 - 38)
Controls.HideControl(oNewGame)
EndSub
'
' Console | Show new game button
' in: oNewGame - new game button object
Sub Console_ShowNewGameButton
Controls.ShowControl(oNewGame)
bButtonNotClicked = "True"
Console_bNewGame = "False"
EndSub
'
' Console | Hide new game button
' in: oNewGame - new game button object
Sub Console_HideNewGameButton
Controls.HideControl(oNewGame)
EndSub
'
' Console | On button clicked
Sub Console_OnButtonClicked
If Controls.LastClickedButton = oReplay Then
Console_bReplay = "True"
bButtonNotClicked = "False"
ElseIf Controls.LastClickedButton = oNewGame Then
Console_bNewGame = "True"
bButtonNotClicked = "False"
EndIf
EndSub
'
' Console | Show turn
' in: iTurn - turn FOREST or SKY
Sub Console_ShowTurn
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillRectangle(Board_iX1 + 10, Board_iY0 + Board_idY, 150, Board_idY * 2)
GraphicsWindow.FontBold = "False"
If iTurn = FOREST Then
RoundRect_iR = 7
RoundRect_iX = Board_iX1 + 10
RoundRect_iY = Board_iY0 + Board_idY * 2
RoundRect_iWidth = 130
RoundRect_iHeight = 40
GraphicsWindow.BrushColor = sForestColor
Graphics_FillRoundRect()
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(RoundRect_iX + RoundRect_iR - 2, RoundRect_iY + RoundRect_iR, sTurnForest)
Else ' iTurn = SKY
RoundRect_iR = 7
RoundRect_iX = Board_iX1 + 10
RoundRect_iY = Board_iY0 + Board_idY
RoundRect_iWidth = 130
RoundRect_iHeight = 40
GraphicsWindow.BrushColor = sSkyColor
Graphics_FillRoundRect()
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(RoundRect_iX + RoundRect_iR - 2, RoundRect_iY + RoundRect_iR, sTurnSky)
EndIf
GraphicsWindow.FontBold = "True"
EndSub
'
' Console | Show game result
' in: Game_iWinner - winner FOREST or SKY
Sub Console_ShowGameResult
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillRectangle(Board_iX1 + 10, Board_iY0 + Board_idY, 150, Board_idY * 2)
GraphicsWindow.FontBold = "False"
If Game_iWinner = FOREST Then
RoundRect_iR = 7
RoundRect_iX = Board_iX1 + 10
RoundRect_iY = Board_iY0 + Board_idY * 2
RoundRect_iWidth = 150
RoundRect_iHeight = 40
GraphicsWindow.BrushColor = sForestColor
Graphics_FillRoundRect()
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(RoundRect_iX + RoundRect_iR - 2, RoundRect_iY + RoundRect_iR, sForestWin)
TextWindow.WriteLine(sForestWin)
ElseIf Game_iWinner = SKY Then
RoundRect_iR = 7
RoundRect_iX = Board_iX1 + 10
RoundRect_iY = Board_iY0 + Board_idY
RoundRect_iWidth = 150
RoundRect_iHeight = 40
GraphicsWindow.BrushColor = sSkyColor
Graphics_FillRoundRect()
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(RoundRect_iX + RoundRect_iR - 2, RoundRect_iY + RoundRect_iR, sSkyWin)
TextWindow.WriteLine(sSkyWin)
Else ' draw
RoundRect_iR = 7
RoundRect_iX = Board_iX1 + 10
RoundRect_iY = Board_iY0 + Board_idY * 1.5
RoundRect_iWidth = 130
RoundRect_iHeight = 40
GraphicsWindow.BrushColor = sSkyColor
Graphics_FillRoundRect()
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(RoundRect_iX + RoundRect_iR - 2, RoundRect_iY + RoundRect_iR, sDraw)
TextWindow.WriteLine(sDraw)
EndIf
GraphicsWindow.FontBold = "True"
EndSub
'
' Console | Ask first turn
' out: iTurn - FOREST or SKY
Sub Console_AskFirstTurn
sMessageBoxColor = "SaddleBrown"
GraphicsWindow.BrushColor = sMessageBoxColor
GraphicsWindow.PenColor = sMessageBoxColor
oMessageBox = Shapes.AddRectangle(300, 200)
Shapes.HideShape(oMessageBox)
iX = 240
iY = 175
Shapes.Move(oMessageBox, iX + 4, iY)
Shapes.SetOpacity(oMessageBox, 75)
'
GraphicsWindow.BrushColor = "White"
oMessageTitle = Shapes.AddText("どちらから?") ' from which?
Shapes.HideShape(oMessageTitle)
Shapes.Move(oMessageTitle, iX + 96, iY + 20)
'
Forest_iX0 = iX + 60
Forest_iX1 = Forest_iX0 + 80
Forest_iY0 = iY + 60
Forest_iY1 = Forest_iY0 + 120
'
oIcon1 = Shapes.AddImage(uCell[B][4])
Shapes.HideShape(oIcon1)
Shapes.Zoom(oIcon1, 0.8, 0.8)
Shapes.Move(oIcon1, Forest_iX0, Forest_iY0)
'
oText1 = Shapes.AddText("森チーム") ' forest team
Shapes.HideShape(oText1)
Shapes.Move(oText1, Forest_iX0, Forest_iY0 + 90)
'
Sky_iX0 = iX + 170
Sky_iX1 = Sky_iX0 + 80
Sky_iY0 = Forest_iY0
Sky_iY1 = Forest_iY1
'
oIcon2 = Shapes.AddImage(uCell[B][1])
Shapes.HideShape(oIcon2)
Shapes.Zoom(oIcon2, 0.8, 0.8)
Shapes.Move(oIcon2, Sky_iX0, Sky_iY0)
'
oText2 = Shapes.AddText("空チーム") ' sky team
Shapes.HideShape(oText2)
Shapes.Move(oText2, Sky_iX0, Sky_iY0 + 90)
'
Shapes.ShowShape(oMessageBox)
Shapes.ShowShape(oMessageTitle)
Shapes.ShowShape(oIcon1)
Shapes.ShowShape(oText1)
Shapes.ShowShape(oIcon2)
Shapes.ShowShape(oText2)
bOutOfBounds = "True"
While bOutOfBounds
GraphicsWindow.MouseDown = Console_OnMouseDown
bNotClicked = "True"
While bNotClicked
Program.Delay(200)
EndWhile
GraphicsWindow.MouseDown = Console_DoNothing
Console_CheckMouseClick()
EndWhile
Shapes.Remove(oMessageTitle)
Shapes.Remove(oIcon1)
Shapes.Remove(oText1)
Shapes.Remove(oIcon2)
Shapes.Remove(oText2)
Shapes.Remove(oMessageBox)
If iTurn = FOREST Then
TextWindow.WriteLine("先攻:森チーム") ' first turn: forest team
Else
TextWindow.WriteLine("先攻:空チーム") ' first turn: sky team
EndIf
EndSub
'
' Console | On mouse down
' out: iMX, iMY - mouse position
' out: bNotClicked - clear because clicked
Sub Console_OnMouseDown
iMX = GraphicsWindow.MouseX
iMY = GraphicsWindow.MouseY
bNotClicked = "False"
EndSub
'
' Console | Do nothing
Sub Console_DoNothing
EndSub
'
' Console | Check mouse click (which icon is selected)
' out: bOutOfBounds - selection failed
' out: iTurn - selected first turn FOREST or SKY
Sub Console_CheckMouseClick
If iMX >= Forest_iX0 And iMX <= Forest_iX1 And iMY >= Forest_iY0 And iMY <= Forest_iY1 Then
bOutOfBounds = "False"
iTurn = FOREST
ElseIf iMX >= Sky_iX0 And iMX <= Sky_iX1 And iMY >= Sky_iY0 And iMY <= Sky_iY1 Then
bOutOfBounds = "False"
iTurn = SKY
Else
bOutOfBounds = "True"
EndIf
EndSub
'
' Console | Show balloon
' in: sMessage - message in the balloon
' in: iX, iY - point of balloon root
Sub Console_ShowBalloon
' show balloon
GraphicsWindow.BrushColor = "Black"
oMessage = Shapes.AddText(sMessage)
Shapes.HideShape(oMessage)
Shapes.Move(oBalloon, iX, iY - 84)
Shapes.ShowShape(oBalloon)
Console_CountCRLF()
Shapes.Move(oMessage, iX + 72, iY - (iCRLF + 1) * 12)
Shapes.ShowShape(oMessage)
' wait a moment
Program.Delay(800)
' remove balloon
Shapes.Remove(oMessage)
Shapes.HideShape(oBalloon)
EndSub
'
' Console | Count CR+LF (carriage return, line feed)
' in: sMessage - message in the balloon
' in: iCRLF - number of CR+LF
Sub Console_CountCRLF
iPtr = 1
iDelta = 1
iCRLF = 0
While iDelta > 0
iDelta = Text.GetIndexOf(Text.GetSubTextToEnd(sMessage, iPtr), CRLF)
If iDelta > 0 Then
iCRLF = iCRLF + 1
iPtr = iPtr + iDelta + 1
EndIf
EndWhile
EndSub
'
' Game | Initialization
' out: Game_bCanMove[][] ' piece move ability
Sub Game_Init
Game_bCanMove = "5=1\=True\;2\=True\;5\=True\;8\=True\;7\=True\;6\=True\;3\=True\;0\=True\;4\=True\;;4=1\=True\;2\=False\;5\=True\;8\=False\;7\=True\;6\=False\;3\=True\;0\=False\;4\=True\;;3=1\=False\;2\=True\;5\=False\;8\=True\;7\=False\;6\=True\;3\=False\;0\=True\;4\=True\;;2=1\=True\;2\=True\;5\=True\;8\=False\;7\=True\;6\=False\;3\=True\;0\=True\;4\=True\;;1=1\=True\;2\=False\;5\=False\;8\=False\;7\=False\;6\=False\;3\=False\;0\=False\;4\=True\;;10=1\=True\;2\=True\;5\=True\;8\=True\;7\=True\;6\=True\;3\=True\;0\=True\;4\=True\;;9=1\=True\;2\=False\;5\=True\;8\=False\;7\=True\;6\=False\;3\=True\;0\=False\;4\=True\;;8=1\=False\;2\=True\;5\=False\;8\=True\;7\=False\;6\=True\;3\=False\;0\=True\;4\=True\;;7=1\=True\;2\=False\;5\=True\;8\=True\;7\=True\;6\=True\;3\=True\;0\=False\;4\=True\;;6=1\=False\;2\=False\;5\=False\;8\=False\;7\=True\;6\=False\;3\=False\;0\=False\;4\=True\;;"
EndSub
'
' Game | Loop while in game
Sub Game_Loop
Game_bInGame = "True"
GameRecord_FirstTurn()
While Game_bInGame
' Odd turn
Human_Move() ' player HUMAN
Board_Move()
GameRecord_Move()
Game_Judge()
iTurn = 3 - iTurn
Console_ShowTurn()
If Game_bInGame Then
' Even turn
Human_Move() ' player HUMAN
Board_Move()
GameRecord_Move()
Game_Judge()
iTurn = 3 - iTurn
Console_ShowTurn()
EndIf
EndWhile
Console_ShowGameResult()
EndSub
'
' Game | Judge
' in: iToCol, iToRow - last moved piece cell
' out: Game_bInGame - in game flag
' out: Game_bDraw - draw flag
' out: Game_iWinner - winner FOREST or SKY
Sub Game_Judge
Game_bInGame = "True"
Game_bDraw = "False"
Game_iWinner = SPACE
' Check draw (with 3 times of same board pattern)
Game_CheckSennichite()
If bSennichite Then
sMessage = "同じ場面が" + CRLF + "3回なので" + CRLF + "引き分け" ' draw
Console_ShowBalloon()
Game_bInGame = "False"
Game_bDraw = "True"
Else
Game_CheckCaught()
' Check catch
If bCaught Then
sMessage = "キャッチ!" ' catch!
iX = Board_iX0 + iToCol * Board_idX - 20
iY = Board_iY0 + (iToRow - 1) * Board_idY + 20
Console_ShowBalloon()
Game_bInGame = "False"
Else
' Check try (legal or illegal)
Game_CheckTried()
If bTried Then
sMessage = "トライ!" ' try!
iX = Board_iX0 + iCol * Board_idX - 20
iY = Board_iY0 + (iRow - 1) * Board_idY + 20
Console_ShowBalloon()
Game_bInGame = "False"
ElseIf bTryFailed Then
sMessage = "トライ失敗!" ' try failed!
iX = Board_iX0 + iCol * Board_idX - 20
iY = Board_iY0 + (iRow - 1) * Board_idY + 20
Console_ShowBalloon()
Game_bInGame = "False"
EndIf
EndIf
EndIf
EndSub
'
' Game | Check sennichite
' out: bSennichite - sennichite flag
Sub Game_CheckSennichite
' Check draw (with 3 times of same board pattern)
bSennichite = "False"
EndSub
'
' Game | Check caught lion
' in: iCaptured - captured piece
' in: iTurn - turn FOREST or SKY
' out: bCaught - caught lion flag
' out: Game_iWinner - winner FOREST or SKY
Sub Game_CheckCaught
' Check catch
bCaught = "False"
If iCaptured = LION1 Or iCaptured = LION2 Then
Game_iWinner = iTurn
bCaught = "True"
EndIf
EndSub
'
' Game | Check lion tried
' in: iTurn - turn FOREST or SKY
' out: bTried - lion tried flag
' out: bTryFailed - lion try failed flag
' out: Game_iWinner - winner FOREST or SKY
Sub Game_CheckTried
' Check catch
bTried = "False"
bTryFailed = "False"
For iCol = A To C
iRow = 1
If Board_iCell[iCol][iRow] = LION1 Then
Game_CheckNoMark()
If bNoMark Then
bTried = "True"
Game_iWinner = iTurn
Else
bTryFailed = "True"
Game_iWinner = 3 - iTurn
EndIf
Goto lExitTried
EndIf
iRow = 4
If Board_iCell[iCol][iRow] = LION2 Then
Game_CheckNoMark()
If bNoMark Then
bTried = "True"
Game_iWinner = iTurn
Else
bTryFailed = "True"
Game_iWinner = 3 - iTurn
EndIf
Goto lExitTried
EndIf
EndFor
lExitTried:
EndSub
'
' Game | Check point (iCol,iRow) is no mark
' in: iTurn - turn FOREST or SKY
' in: iCol, iRow - point to check
' out: bNoMark - flag (iCol, iRow) is no mark
Sub Game_CheckNoMark
bNoMark = "True"
For iDir = DIRMIN To DIRMAX
If iDir <> CENTER Then
iAdjCol = iCol + idCol[iDir] ' adjacent cell column to check
iAdjRow = iRow + idRow[iDir] ' adjacent cell row to check
If iAdjCol >= 1 And iAdjCol <= Board_iCols And iAdjRow >= 1 And iAdjRow <= Board_iRows Then
iCheck = Board_iCell[iAdjCol][iAdjRow]
If iCheck > (2 - iTurn) * 5 And iCheck < 6 + (2 - iTurn) * 5 Then
' opposite team piece found
Game_CalcOpposite() ' calc iOpposite from iDir
If Game_bCanMove[iCheck][iOpposite] Then
bNoMark = "False"
EndIf
EndIf
EndIf
EndIf
EndFor
EndSub
'
' Game | Calculate opposite direction
' in: iDir - original direction
' out: iOpposite - opposite direction
Sub Game_CalcOpposite
iOpposite = 8 - iDir
EndSub
'
' Game | Is movable piece?
' in: iCol, iRow - next move
' in: iTurn - turn forest or sky
' out: Game_bIsMovablePiece - is movable
' out: iPiece - piece if movable
' out: iFromCol, iFromRow - position of the piece
Sub Game_IsMovablePiece
iPiece = Board_iCell[iCol][iRow]
Game_bIsMovablePiece = "False"
If iPiece > (iTurn - 1) * 5 And iPiece < 6 + (iTurn - 1) * 5 Then
iFromCol = iCol
iFromRow = iRow
If iFromCol > Board_iCols Then ' from captured
Game_bIsMovablePiece = "True"
Goto lExitMovable
EndIf
' iPiece is a member of iTurn team and
For iDir = DIRMIN To DIRMAX ' nine directions
If Game_bCanMove[iPiece][iDir] Then
iToCol = iFromCol + idCol[iDir]
iToRow = iFromRow + idRow[iDir]
iToPiece = Board_iCell[iToCol][iToRow]
If iToPiece = SPACE Or (iToPiece > (2 - iTurn) * 5 And iToPiece < 6 + (2 - iTurn) * 5) Then
' iToCol, iToRow is movable position for iPiece
Game_bIsMovablePiece = "True"
EndIf
EndIf
EndFor
EndIf
lExitMovable:
EndSub
'
' Game | Is possible move?
' in: iFromCol, iFromRow - piece position
' in: iToCol, iToRow - next move
' in: iPiece - piece to move
' out: Game_bIsPossibleMove - flag if possible move
' out: Game_bCapture - flag if capture
Sub Game_IsPossibleMove
If iFromCol > Board_iCols Then ' from captured
If Board_iCell[iToCol][iToRow] = SPACE Then
Game_bIsPossibleMove = "True"
Game_bCapture = "False"
Else
Game_bIsPossibleMove = "False"
Game_bCapture = "False"
EndIf
Else ' not from captured
iDirCol = iToCol - iFromCol
iDirRow = iToRow - iFromRow
Game_bIsPossibleMove = "False"
Game_bCapture = "False"
If iDirCol >= -1 And iDirCol <= 1 And iDirRow >= -1 And iDirRow <= 1 Then
iDir = (iDirRow + 1) * 3 + (iDirCol + 1)
If Game_bCanMove[iPiece][iDir] Then
' iToCol, iToRow is movable position for iPiece
If Board_iCell[iToCol][iToRow] = SPACE Then
Game_bIsPossibleMove = "True"
Game_bCapture = "False"
ElseIf Board_iCell[iToCol][iToRow] > (2 - iTurn) * 5 And Board_iCell[iToCol][iToRow] < 6 + (2 - iTurn) * 5 Then
' opposite team piece already exists ... capture it
Game_bIsPossibleMove = "True"
Game_bCapture = "True"
EndIf
EndIf
EndIf
EndIf
' check promotion
bPromote = "False"
If Game_bIsPossibleMove And (iPiece = CHICK1 And iToRow = 1) Or (iPiece = CHICK2 And iToRow = 4) Then
bPromote = "True" ' power up!
EndIf
EndSub
'
' Game record | Initialization
Sub GameRecord_Init
sPiece[LION1] = "ライオン"
sPiece[ELEPHANT1] = "ぞう"
sPiece[GIRAFFE1] = "きりん"
sPiece[HEN1] = "ニワトリ"
sPiece[CHICK1] = "ひよこ"
sPiece[LION2] = "ライオン"
sPiece[ELEPHANT2] = "ぞう"
sPiece[GIRAFFE2] = "きりん"
sPiece[HEN2] = "ニワトリ"
sPiece[CHICK2] = "ひよこ"
EndSub
'
' Game record | New game
Sub GameRecord_New
GameRecord_iNum = 0
iLine = 1
EndSub
'
' Game record | Draw
Sub GameRecord_Draw
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillRectangle(Record_iX0, Board_iY0, 160, Board_idY * 4)
For iRec = 1 To GameRecord_iNum
sTo = Board_sCol[GameRecord_iToCol[iRec]] + Board_sRow[GameRecord_iToRow[iRec]]
iPiece = GameRecord_iPiece[iRec]
GameRecord_DrawLine()
EndFor
EndSub
'
' Game record | Draw line
' in: iPiece - moved piece
' in: sTo - cell the piece move to
' in: iRec - number of record
' in: iLine - draw line
' out: sLine - last record
Sub GameRecord_DrawLine
If iLine <= 12 Then
If Math.Remainder(iRec, 2) = FOREST Then
GraphicsWindow.BrushColor = sForestColor
Else
GraphicsWindow.BrushColor = sSkyColor
EndIf
GraphicsWindow.FillEllipse(Record_iX0, Board_iY0 + (iLine - 1) * 30 + 2, 24, 24)
GraphicsWindow.BrushColor = "Black"
sMove = sTo + " " + sPiece[iPiece]
sLine = iRec + " " + sMove
If iRec < 10 Then
GraphicsWindow.DrawText(Record_iX0 + 5, Board_iY0 + (iLine - 1) * 30, iRec)
Else
GraphicsWindow.FontSize = 16 ' small
GraphicsWindow.DrawText(Record_iX0 + 2, Board_iY0 + (iLine - 1) * 30 + 4, iRec)
GraphicsWindow.FontSize = 20 ' middle
EndIf
GraphicsWindow.DrawText(Record_iX0 + 28, Board_iY0 + (iLine - 1) * 30, sMove)
iLine = iLine + 1
Else
GameRecord_Scroll()
iLine = 12
GameRecord_DrawLine()
EndIf
EndSub
'
' Game record | Scroll
Sub GameRecord_Scroll
Stack.PushValue("scroll", iPiece)
Stack.PushValue("scroll", sTo)
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillRectangle(Record_iX0, Board_iY0, 160, Board_idY * 4)
iLine = 1
While iLine < 12
Stack.PushValue("scroll", iRec)
iRec = iRec - 12 + iLine
iPiece = GameRecord_iPiece[iRec]
iToCol = GameRecord_iToCol[iRec]
iToRow = GameRecord_iToRow[iRec]
sTo = Board_sCol[iToCol] + Board_sRow[iToRow]
GameRecord_DrawLine()
iRec = Stack.PopValue("scroll")
EndWhile
sTo = Stack.PopValue("scroll")
iPiece = Stack.PopValue("scroll")
EndSub
'
' Game record | FirstTurn
' in: iTurn - first turn FOREST or SKY
Sub GameRecord_FirstTurn
GameRecord_iFirstTurn = iTurn
EndSub
'
' Game record | Move
Sub GameRecord_Move
iRec = GameRecord_iNum + 1
GameRecord_iPiece[iRec] = iPiece
GameRecord_iFromCol[iRec] = iFromCol
GameRecord_iFromRow[iRec] = iFromRow
GameRecord_iToCol[iRec] = iToCol
GameRecord_iToRow[iRec] = iToRow
GameRecord_iNum = iRec
sTo = Board_sCol[iToCol] + Board_sRow[iToRow]
GameRecord_DrawLine()
TextWindow.WriteLine(sLine)
EndSub
'
' Game record | Replay
Sub GameRecord_Replay
iTurn = GameRecord_iFirstTurn
Board_New()
Board_Draw()
Console_ShowTurn()
For iRec = 1 To GameRecord_iNum
iPiece = GameRecord_iPiece[iRec]
iCol = GameRecord_iFromCol[iRec]
iRow = GameRecord_iFromRow[iRec]
Game_IsMovablePiece()
If Game_bIsMovablePiece Then
iFromCol = iCol
iFromRow = iRow
iToCol = GameRecord_iToCol[iRec]
iToRow = GameRecord_iToRow[iRec]
Game_IsPossibleMove()
If Game_bIsPossibleMove Then
Board_Move()
EndIf
EndIf
iTurn = 3 - iTurn
Console_ShowTurn()
Program.Delay(1000)
EndFor
Game_Judge()
Console_ShowGameResult()
EndSub
'
' Graphics | Draw dotted line
' in: Dotted_iX0, Dotted_iY0 - line start point
' in: Dotted_iX1, Dotted_iY1 - line end point
Sub Graphics_DrawDottedLine
iLen = 10
iSqX = (Dotted_iX1 - Dotted_iX0) * (Dotted_iX1 - Dotted_iX0)
iSqY = (Dotted_iY1 - Dotted_iY0) * (Dotted_iY1 - Dotted_iY0)
For rLen = 0 To Math.SquareRoot(iSqX + iSqY) - iLen Step iLen * 2
rRatio = rLen / Math.SquareRoot(iSqX + iSqY)
iDX0 = Dotted_iX0 + rRatio * (Dotted_iX1 - Dotted_iX0)
iDY0 = Dotted_iY0 + rRatio * (Dotted_iY1 - Dotted_iY0)
rRatio = (rLen + iLen) / Math.SquareRoot(iSqX + iSqY)
iDX1 = Dotted_iX0 + rRatio * (Dotted_iX1 - Dotted_iX0)
iDY1 = Dotted_iY0 + rRatio * (Dotted_iY1 - Dotted_iY0)
GraphicsWindow.DrawLine(iDX0, iDY0, iDX1, iDY1)
EndFor
EndSub
'
' Graphics | Fill round rectangle
' in: RoundRect_iX, RoundRect_iY - left top point
' in: RoundRect_iWidth, RoundRect_iHeight - width and height
' in: RoundRect_iR - corner radius
Sub Graphics_FillRoundRect
GraphicsWindow.FillRectangle(RoundRect_iX + RoundRect_iR, RoundRect_iY, RoundRect_iWidth - RoundRect_iR * 2, RoundRect_iHeight)
GraphicsWindow.FillRectangle(RoundRect_iX, RoundRect_iY + RoundRect_iR, RoundRect_iWidth, RoundRect_iHeight - RoundRect_iR * 2)
GraphicsWindow.FillEllipse(RoundRect_iX, RoundRect_iY, RoundRect_iR * 2, RoundRect_iR * 2)
GraphicsWindow.FillEllipse(RoundRect_iX + RoundRect_iWidth - RoundRect_iR * 2, RoundRect_iY, RoundRect_iR * 2, RoundRect_iR * 2)
GraphicsWindow.FillEllipse(RoundRect_iX, RoundRect_iY + RoundRect_iHeight - RoundRect_iR * 2, RoundRect_iR * 2, RoundRect_iR * 2)
GraphicsWindow.FillEllipse(RoundRect_iX + RoundRect_iWidth - RoundRect_iR * 2, RoundRect_iY + RoundRect_iHeight - RoundRect_iR * 2, RoundRect_iR * 2, RoundRect_iR * 2)
EndSub
'
' Player HUMAN | Move
' out: iPiece - piece to move
' out: iFromCol, iFromRow - piece position in board
' out: iToCol, iToRow - position to move
Sub Human_Move
lRetry:
' get movable piece as iPiece and get the position
While "True"
Human_bOutOfBoard = "True"
While Human_bOutOfBoard
GraphicsWindow.MouseDown = Human_OnMouseDown
Human_bNotClicked = "True"
While Human_bNotClicked
Program.Delay(200)
EndWhile
GraphicsWindow.MouseDown = Human_DoNothing
Human_GetPosition()
EndWhile
Game_IsMovablePiece()
If Game_bIsMovablePiece Then
Goto lMovablePiece
Else
sMessage = "ちがうよ" ' can't
iX = Board_iX0 + iCol * Board_idX - 20
iY = Board_iY0 + (iRow - 1) * Board_idY + 20
Console_ShowBalloon()
EndIf
EndWhile
lMovablePiece:
' erase the piece
If iFromCol > Board_iCols Then ' from captured
Board_HideCaptured()
Else
Stack.PushValue("human", iPiece)
iPiece = SPACE
iToCol = iCol
iToRow = iRow
Board_iCell[iFromCol][iFromRow] = SPACE
Board_DrawCell()
iPiece = Stack.PopValue("human")
Board_iCell[iFromCol][iFromRow] = iPiece
EndIf
' Set the piece as shape for mouse animation
oPiece = Shapes.AddImage(uPiece[iPiece])
Shapes.HideShape(oPiece)
If iFromCol > Board_iCols Then ' from captured
Shapes.Move(oPiece, Human_iMX - 40, Human_iMY - 40)
Else
Shapes.Move(oPiece, Board_iX0 + iOffsetX + (iFromCol - 1) * Board_idX , Board_iY0 + iOffsetY + (iFromRow - 1) * Board_idY)
EndIf
Shapes.ShowShape(oPiece)
GraphicsWindow.MouseMove = Human_OnMouseMove
' Get possible move
While "True"
Human_bOutOfBoard = "True"
While Human_bOutOfBoard Or iCol > Board_iCols
GraphicsWindow.MouseDown = Human_OnMouseDown
Human_bNotClicked = "True"
While Human_bNotClicked
Program.Delay(200)
EndWhile
GraphicsWindow.MouseDown = Human_DoNothing
Human_GetPosition()
EndWhile
iToCol = iCol
iToRow = iRow
If (iFromCol = iToCol And iFromRow = iToRow) Or (iFromCol > C And iToCol > C) Then
' return piece on the same cell and retry
Shapes.Remove(oPiece)
GraphicsWindow.MouseMove = Human_DoNothing
iCol = iFromCol
iRow = iFromRow
If iCol < CA Then
Board_DrawCell()
Else
Board_DrawCaptured()
EndIf
Goto lRetry
EndIf
Game_IsPossibleMove()
If Game_bIsPossibleMove Then
Goto lPossibleMove
Else
sMessage = "ちがうよ" ' can't
iX = Board_iX0 + iCol * Board_idX - 20
iY = Board_iY0 + (iRow - 1) * Board_idY + 20
Console_ShowBalloon()
EndIf
EndWhile
lPossibleMove:
Shapes.Remove(oPiece)
GraphicsWindow.MouseMove = Human_DoNothing
EndSub
'
' Player HUMAN | Get board position from mouse position
' work: bInCaptured - next piece from captured slot
' out: iCol, iRow - next move position
' out: Human_bOutOfBoard - mouse clicked out of board / captured slot
Sub Human_GetPosition
iCol = Math.Floor((Human_iMX - Board_iX0) / Board_idX) + 1
iRow = Math.Floor((Human_iMY - Board_iY0) / Board_idY) + 1
Human_bOutOfBoard = "False"
If iCol < 1 Or iCol > Board_iCols Or iRow < 1 Or iRow > Board_iRows Then
bInCaptured = "True"
iCol = Math.Floor((Human_iMX - Captured_iX0) / Captured_idX) + 1
iRow = Math.Floor((Human_iMY - Captured_iY0) / Captured_idY) + 1
iTeam = SKY
iNum = (iCol - 1) * 2 + iRow
If iCol < 1 Or iCol > Captured_iCols Or iRow < 1 Or iRow > Captured_iRows Then
iRow = Math.Floor((Human_iMY - Captured_iY2) / Captured_idY) + 1
iTeam = FOREST
iNum = (iCol - 1) * 2 + (3 - iRow)
If iCol < 1 Or iCol > Captured_iCols Or iRow < 1 Or iRow > Captured_iRows Then
bInCaptured = "False"
Human_bOutOfBoard = "True"
EndIf
EndIf
Else
bInCaptured = "False"
EndIf
If bInCaptured Then
iCol = iCol + CA - 1
If iTeam = FOREST Then
iRow = iRow + 2
EndIf
EndIf
EndSub
'
' Player HUMAN | Get mouse position
' out: Human_iMX, Human_iMY - clicked mouse position
' out: Human_bNotClicked - flag
' GraphicsWindow.MouseDown = Human_DoNothing
Sub Human_OnMouseDown
Human_iMX = GraphicsWindow.MouseX
Human_iMY = GraphicsWindow.MouseY
Human_bNotClicked = "False"
EndSub
'
' Player HUMAN | Move piece with mouse
Sub Human_OnMouseMove
Shapes.Move(oPiece, GraphicsWindow.MouseX - 40, GraphicsWindow.MouseY - 40)
EndSub
'
' Player HUMAN | Do nothing
Sub Human_DoNothing
EndSub