Skip to content

Commit

Permalink
Tab == 2 spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Benzi committed Jun 23, 2019
1 parent b456307 commit dfb7baf
Show file tree
Hide file tree
Showing 12 changed files with 977 additions and 981 deletions.
248 changes: 122 additions & 126 deletions TetraVex/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,139 +11,135 @@ import TetraVexKit

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

var currentGameModel : TVGameModel = TVGameModel()
var currentGamePieces : [[TVPieceModel]]?

//MARK: - Resizing board
func setBoardSize(width: Int, height: Int) {
currentGameModel.boardWidth = width
currentGameModel.boardHeight = height
}
/*
* Reminder, First Responder actions have to marked with @IBAction
* to appear in the Interface Builder.
*/

var currentGameModel : TVGameModel = TVGameModel()
var currentGamePieces : [[TVPieceModel]]?

var optionMenu: NSMenuItem? {
return NSApplication.shared.mainMenu?
.item(withTitle: "Options")
}

//MARK: - Resizing board
func setBoardSize(width: Int, height: Int) {
currentGameModel.boardWidth = width
currentGameModel.boardHeight = height
}

// MARK: Board size menu manipulation
var sizeSubMenu: NSMenuItem? {
return optionMenu?.submenu?.item(withTitle: "Size")
}

@IBAction func setBoardTo2x2(sender: Any?) {
setBoardSize(width: 2, height: 2)
let sm = sizeSubMenu?.submenu
sm?.item(withTitle: "2x2")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "3x3")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "4x4")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "5x5")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "6x6")?.state = NSControl.StateValue(rawValue: 0)
}

@IBAction func setBoardTo3x3(sender: Any?) {
setBoardSize(width: 3, height: 3)
let sm = sizeSubMenu?.submenu
sm?.item(withTitle: "2x2")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "3x3")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "4x4")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "5x5")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "6x6")?.state = NSControl.StateValue(rawValue: 0)
}

@IBAction func setBoardTo4x4(sender: Any?) {
setBoardSize(width: 4, height: 4)
let sm = sizeSubMenu?.submenu
sm?.item(withTitle: "2x2")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "3x3")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "4x4")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "5x5")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "6x6")?.state = NSControl.StateValue(rawValue: 0)
}

@IBAction func setBoardTo5x5(sender: Any?) {
setBoardSize(width: 5, height: 5)
let sm = sizeSubMenu?.submenu
sm?.item(withTitle: "2x2")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "3x3")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "4x4")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "5x5")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "6x6")?.state = NSControl.StateValue(rawValue: 0)
}

@IBAction func setBoardTo6x6(sender: Any?) {
setBoardSize(width: 6, height: 6)
let sm = sizeSubMenu?.submenu
sm?.item(withTitle: "2x2")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "3x3")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "4x4")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "5x5")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "6x6")?.state = NSControl.StateValue(rawValue: 1)
}
@IBAction func setBoardTo2x2(sender: Any?) {
setBoardSize(width: 2, height: 2)
let sm = sizeSubMenu?.submenu
sm?.item(withTitle: "2x2")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "3x3")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "4x4")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "5x5")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "6x6")?.state = NSControl.StateValue(rawValue: 0)
}

@IBAction func setBoardTo3x3(sender: Any?) {
setBoardSize(width: 3, height: 3)
let sm = sizeSubMenu?.submenu
sm?.item(withTitle: "2x2")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "3x3")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "4x4")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "5x5")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "6x6")?.state = NSControl.StateValue(rawValue: 0)
}

//MARK: - Changing range of digits
func setNumberOfDigits(num :Int) {
currentGameModel.currentNumberDigits = num
}
@IBAction func setBoardTo4x4(sender: Any?) {
setBoardSize(width: 4, height: 4)
let sm = sizeSubMenu?.submenu
sm?.item(withTitle: "2x2")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "3x3")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "4x4")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "5x5")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "6x6")?.state = NSControl.StateValue(rawValue: 0)
}

@IBAction func setBoardTo5x5(sender: Any?) {
setBoardSize(width: 5, height: 5)
let sm = sizeSubMenu?.submenu
sm?.item(withTitle: "2x2")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "3x3")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "4x4")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "5x5")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "6x6")?.state = NSControl.StateValue(rawValue: 0)
}

@IBAction func setBoardTo6x6(sender: Any?) {
setBoardSize(width: 6, height: 6)
let sm = sizeSubMenu?.submenu
sm?.item(withTitle: "2x2")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "3x3")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "4x4")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "5x5")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "6x6")?.state = NSControl.StateValue(rawValue: 1)
}


//MARK: - Changing range of digits
func setNumberOfDigits(num :Int) {
currentGameModel.currentNumberDigits = num
}

// MARK: Number of digits menu manipulation
// MARK: Number of digits menu manipulation
var numberOfDigitsSubMenu: NSMenuItem? {
return optionMenu?.submenu?.item(withTitle: "Digits")
}
@IBAction func setNumberOfDigitsTo6(sender: Any?) {
setNumberOfDigits(num: 5)
let sm = numberOfDigitsSubMenu?.submenu
sm?.item(withTitle: "6")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "7")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "8")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "9")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "10")?.state = NSControl.StateValue(rawValue: 0)
}

@IBAction func setNumberOfDigitsTo7(sender: Any?) {
setNumberOfDigits(num: 6)
let sm = numberOfDigitsSubMenu?.submenu
sm?.item(withTitle: "6")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "7")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "8")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "9")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "10")?.state = NSControl.StateValue(rawValue: 0)
}

@IBAction func setNumberOfDigitsTo8(sender: Any?) {
setNumberOfDigits(num: 7)
let sm = numberOfDigitsSubMenu?.submenu
sm?.item(withTitle: "6")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "7")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "8")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "9")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "10")?.state = NSControl.StateValue(rawValue: 0)
}
@IBAction func setNumberOfDigitsTo6(sender: Any?) {
setNumberOfDigits(num: 5)
let sm = numberOfDigitsSubMenu?.submenu
sm?.item(withTitle: "6")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "7")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "8")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "9")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "10")?.state = NSControl.StateValue(rawValue: 0)
}

@IBAction func setNumberOfDigitsTo9(sender: Any?) {
setNumberOfDigits(num: 8)
let sm = numberOfDigitsSubMenu?.submenu
sm?.item(withTitle: "6")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "7")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "8")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "9")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "10")?.state = NSControl.StateValue(rawValue: 0)
}

@IBAction func setNumberOfDigitsTo10(sender: Any?) {
setNumberOfDigits(num: 9)
let sm = numberOfDigitsSubMenu?.submenu
sm?.item(withTitle: "6")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "7")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "8")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "9")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "10")?.state = NSControl.StateValue(rawValue: 1)
}
@IBAction func setNumberOfDigitsTo7(sender: Any?) {
setNumberOfDigits(num: 6)
let sm = numberOfDigitsSubMenu?.submenu
sm?.item(withTitle: "6")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "7")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "8")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "9")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "10")?.state = NSControl.StateValue(rawValue: 0)
}

@IBAction func setNumberOfDigitsTo8(sender: Any?) {
setNumberOfDigits(num: 7)
let sm = numberOfDigitsSubMenu?.submenu
sm?.item(withTitle: "6")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "7")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "8")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "9")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "10")?.state = NSControl.StateValue(rawValue: 0)
}

@IBAction func setNumberOfDigitsTo9(sender: Any?) {
setNumberOfDigits(num: 8)
let sm = numberOfDigitsSubMenu?.submenu
sm?.item(withTitle: "6")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "7")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "8")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "9")?.state = NSControl.StateValue(rawValue: 1)
sm?.item(withTitle: "10")?.state = NSControl.StateValue(rawValue: 0)
}

@IBAction func setNumberOfDigitsTo10(sender: Any?) {
setNumberOfDigits(num: 9)
let sm = numberOfDigitsSubMenu?.submenu
sm?.item(withTitle: "6")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "7")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "8")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "9")?.state = NSControl.StateValue(rawValue: 0)
sm?.item(withTitle: "10")?.state = NSControl.StateValue(rawValue: 1)
}


@IBAction func setTextStyleToDigits(sender: Any?) {
Expand Down Expand Up @@ -180,15 +176,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {

controller.setTextStyle(to: .greekSymbols)
}
//MARK: - Game actions
@IBAction func newGame(sender: Any?) {
let pg = TVPuzzleGenerator(width: currentGameModel.boardWidth, height: currentGameModel.boardHeight, rangeOfNumbers: 0...currentGameModel.currentNumberDigits)
currentGamePieces = pg.solvedBoard
let pv : TVGameViewController = NSApplication.shared.mainWindow?.contentViewController as! TVGameViewController
pv.solvedBoard = currentGamePieces
pv.newBoard(currentGameModel.boardWidth, height: currentGameModel.boardHeight)
}

//MARK: - Game actions
@IBAction func newGame(sender: Any?) {
let pg = TVPuzzleGenerator(width: currentGameModel.boardWidth, height: currentGameModel.boardHeight, rangeOfNumbers: 0...currentGameModel.currentNumberDigits)
currentGamePieces = pg.solvedBoard
let pv : TVGameViewController = NSApplication.shared.mainWindow?.contentViewController as! TVGameViewController
pv.solvedBoard = currentGamePieces
pv.newBoard(currentGameModel.boardWidth, height: currentGameModel.boardHeight)

}

}
Loading

0 comments on commit dfb7baf

Please sign in to comment.