Warning, /games/kolorfill/src/qml/GameArea.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.0 0002 import QtQuick.Controls 2.0 0003 import "KolorFillUtils.js" as Utils 0004 0005 0006 Item { 0007 property int fillCounter: 0 0008 property int boardsize: 2 0009 property var colorList: [] 0010 property bool filled: false 0011 property var board: [] 0012 function fill(color,board) { 0013 var changed = Utils.fill(color,board) 0014 if (!changed) { 0015 return 0016 } 0017 gamearea.fillCounter++ 0018 gamearea.filled = Utils.checkWin(board) 0019 canvas.requestPaint() 0020 } 0021 function restart() { 0022 gamearea.board = Utils.createBoard(boardsize,colorList) 0023 gamearea.fillCounter = 0 0024 gamearea.filled = Utils.checkWin(board) 0025 canvas.requestPaint() 0026 } 0027 Canvas { 0028 anchors.fill: parent 0029 anchors.margins: 20 0030 anchors.bottomMargin: 120 0031 anchors.topMargin: 40 0032 id: canvas; 0033 onPaint: { 0034 var ctx = getContext("2d") 0035 ctx.fillRect(0,0,canvasSize.width, canvasSize.height) 0036 var number = gamearea.board.length 0037 var fieldheight = canvasSize.height / number 0038 var fieldwidth = canvasSize.width / number 0039 for(var i = 0; i < number ; i++) { 0040 for(var j = 0 ; j < number ; j++) { 0041 ctx.fillStyle = gamearea.board[i][j] 0042 ctx.fillRect(Math.ceil(i*fieldwidth), Math.ceil(j* fieldheight), Math.ceil(fieldwidth), Math.ceil( fieldheight)) 0043 } 0044 } 0045 } 0046 } 0047 Row { 0048 anchors.bottom: gamearea.bottom 0049 height: 100 0050 id: selector 0051 Repeater { 0052 model: gamearea.colorList 0053 Button { 0054 height: selector.height 0055 width: gamearea.width / gamearea.colorList.length 0056 enabled: !gamearea.filled 0057 onClicked: gamearea.fill(modelData, gamearea.board) 0058 Rectangle { 0059 anchors.margins: 5 0060 anchors.fill: parent 0061 color: modelData 0062 } 0063 } 0064 } 0065 } 0066 }