<commit_before>//
//  RummyScene.swift
//  Deckstravaganza
//
//  Created by <NAME> on 10/26/15.
//  Copyright © 2015 University of Florida. All rights reserved.
//

import Foundation
import SpriteKit

class RummyCardSprite: SKSpriteNode {
    
    // Properties
    let frontTexture: SKTexture
    let backTexture: SKTexture
    var faceUp: Bool
    var card: Card
    var touchesBeganClosure: (RummyCardSprite)->Void
    var touchesMovedClosure: (RummyCardSprite)->Void
    var touchesEndedClosure: (RummyCardSprite)->Void
    
    // required to prevent crashing
    required init(coder aDecoder: NSCoder) {
        fatalError("NSCoding not supported")
    }
    
    // initializer sets the card value and references the gamescene being used
    init(card: Card, touchesBeganClosure: (RummyCardSprite)->Void, touchesMovedClosure: (RummyCardSprite)->Void, touchesEndedClosure: (RummyCardSprite)->Void) {
        self.card = card
        
        self.frontTexture = SKTexture(image: card.getCardFace(Deck.DeckFronts.Default)!)
        self.backTexture = SKTexture(image: card.getCardBack(Deck.DeckBacks.Default)!)
        
        self.touchesBeganClosure = touchesBeganClosure
        self.touchesMovedClosure = touchesMovedClosure
        self.touchesEndedClosure = touchesEndedClosure
        
        self.faceUp = false
        
        super.init(texture: backTexture, color: UIColor.blackColor(), size: backTexture.size())
        self.userInteractionEnabled = true
        self.name = "\(card.getRank())\(card.getSuit())"
    }
    
    // flips of card by changing the tecture
    func flipCardOver() {
        if faceUp {
            self.texture = self.backTexture
            self.faceUp = false
        } else {
            self.texture = self.frontTexture
            self.faceUp = true
        }
    }
    
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        for _ in touches {
            touchesBeganClosure(self)
        }
    }
    
    //    override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
    //        touchesMovedClosure(self)
    //        for touch in touches {
    //            let location = touch.locationInNode(scene!)
    //            let touchedNode = nodeAtPoint(location)
    //            touchedNode.position = location
    //        }
    //    }
    
    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        for _ in touches {
            touchesEndedClosure(self)
        }
    }
}

class RummyScene: SKScene {
    let GameScene: GameSceneViewController
    let RummyGame: Rummy
    
    var cardSize = CGSize(width: 0, height: 0)
    
    var deckLocation = CGPoint(x: 0,y: 0)
    var wastePileLocation = CGPoint(x: 0, y: 0)
    var handLocations = [CGPoint(x: 0,y: 0)]
    var countLocations = [CGPoint(x: 0, y: 0)]
    var meldLocation = CGPoint(x: 0,y: 0)
    
    var isWinner = false
    var isPlayerTurn = false
    
    var cardCountNodeArray: [SKLabelNode] = []
    var scoreboardNodes: [SKNode] = []
    
    var buttonsOnScreen = [GameViewControllerButton]()
    
    init(gameScene : GameSceneViewController, game: Rummy, size: CGSize) {
        
        self.GameScene = gameScene
        self.RummyGame = game
        
        super.init(size: size)
        
        // initializes the various CGPoints and CGSizes used by gamescene
        self.cardSize = CGSize(width: self.scene!.size.width/11, height: self.scene!.size.height/5)
        
        // Sets the location for where the deck and waste pile are located in the frame
        self.deckLocation = CGPoint(x: self.scene!.frame.minX + 2*cardSize.width, y: self.scene!.frame.midY)
        self.wastePileLocation = CGPoint(x: self.scene!.frame.minX + 2.1*cardSize.width + cardSize.width , y: self.scene!.frame.midY)
        
        // Sets the location for where the melds should be location
        self.meldLocation = CGPoint(x: self.scene!.frame.midX - cardSize.width, y: self.scene!.frame.maxY - 1.75*cardSize.height)
        
        // Sets the locations of where the players' hands begin
        switch RummyGame.playersHands.count {
        case 2:
            self.handLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height/3)]
            self.countLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height)]
        case 3:
            self.handLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width/3, y: self.frame.midY), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height/3)]
            self.countLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width, y: self.frame.midY), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height)]
        case 4:
            self.handLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width/3, y: self.frame.midY), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height/3),CGPoint(x: self.frame.minX+cardSize.width/3, y: self.frame.midY)]
            self.countLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width, y: self.frame.midY), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height),CGPoint(x: self.frame.minX+cardSize.width, y: self.frame.midY)]
        case 5:
            self.handLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width/3, y: self.frame.midY-cardSize.height), CGPoint(x: self.frame.maxX-cardSize.width/3, y: self.frame.midY+cardSize.height), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height/3),CGPoint(x: self.frame.minX+cardSize.width/3, y: self.frame.midY+cardSize.height)]
            self.countLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width, y: self.frame.midY-cardSize.height), CGPoint(x: self.frame.maxX-cardSize.width, y: self.frame.midY+cardSize.height), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height),CGPoint(x: self.frame.minX+cardSize.width, y: self.frame.midY+cardSize.height)]
        case 6:
            self.handLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width/3, y: self.frame.midY-cardSize.height), CGPoint(x: self.frame.maxX-cardSize.width/3, y: self.frame.midY+cardSize.height), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height/3),CGPoint(x: self.frame.minX+cardSize.width/3, y: self.frame.midY+cardSize.height),CGPoint(x: self.frame.minX+cardSize.width/3, y: self.frame.midY-cardSize.height)]
            self.countLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width, y: self.frame.midY-cardSize.height), CGPoint(x: self.frame.maxX-cardSize.width, y: self.frame.midY+cardSize.height), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height),CGPoint(x: self.frame.minX+cardSize.width, y: self.frame.midY+cardSize.height),CGPoint(x: self.frame.minX+cardSize.width, y: self.frame.midY-cardSize.height)]
        default:
            break
        }
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func didMoveToView(view: SKView) {
        backgroundColor = UIColor.blueColor()
        if self.RummyGame.deck.numberOfCards() == 52{
            print(self.RummyGame.round,self.RummyGame.roundScores)
            addDealButton()
        } else {
            print(self.RummyGame.round,self.RummyGame.roundScores)
        }
    }
    
    
    // MARK: Function that add buttons to the scene
    func startRound() {
        self.shuffle()
        self.deal()
        
        // Must first deal the cards, use a GameViewButton to deal
        //addDealButton()
        
        for player in RummyGame.players {
            setUserInteractionEnabledPlayerHand(false, player: player)
        }
    }
    
    func addDealButton() {
        let dealButton = GameViewControllerButton(defaultButtonImage: "start_game_image", buttonAction: startRound)
        dealButton.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))
        dealButton.size = CGSize(width: 300, height: 200)
        self.addChild(dealButton)
        
    }
    
    func addMeldButton() {
        let meldButton = GameViewControllerButton(defaultButtonImage: "MeldButtonImg", buttonAction: meld)
        meldButton.size = CGSize(width: 100, height: 75)
        meldButton.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))
        meldButton.zPosition = 100
        self.addChild(meldButton)
        buttonsOnScreen.append(meldButton)
        
    }
    
    func addDiscardButton() {<commit_msg>resolved is where continuing game was re-dealing cards<commit_after>//
//  RummyScene.swift
//  Deckstravaganza
//
//  Created by <NAME> on 10/26/15.
//  Copyright © 2015 University of Florida. All rights reserved.
//

import Foundation
import SpriteKit

class RummyCardSprite: SKSpriteNode {
    
    // Properties
    let frontTexture: SKTexture
    let backTexture: SKTexture
    var faceUp: Bool
    var card: Card
    var touchesBeganClosure: (RummyCardSprite)->Void
    var touchesMovedClosure: (RummyCardSprite)->Void
    var touchesEndedClosure: (RummyCardSprite)->Void
    
    // required to prevent crashing
    required init(coder aDecoder: NSCoder) {
        fatalError("NSCoding not supported")
    }
    
    // initializer sets the card value and references the gamescene being used
    init(card: Card, touchesBeganClosure: (RummyCardSprite)->Void, touchesMovedClosure: (RummyCardSprite)->Void, touchesEndedClosure: (RummyCardSprite)->Void) {
        self.card = card
        
        self.frontTexture = SKTexture(image: card.getCardFace(Deck.DeckFronts.Default)!)
        self.backTexture = SKTexture(image: card.getCardBack(Deck.DeckBacks.Default)!)
        
        self.touchesBeganClosure = touchesBeganClosure
        self.touchesMovedClosure = touchesMovedClosure
        self.touchesEndedClosure = touchesEndedClosure
        
        self.faceUp = false
        
        super.init(texture: backTexture, color: UIColor.blackColor(), size: backTexture.size())
        self.userInteractionEnabled = true
        self.name = "\(card.getRank())\(card.getSuit())"
    }
    
    // flips of card by changing the tecture
    func flipCardOver() {
        if faceUp {
            self.texture = self.backTexture
            self.faceUp = false
        } else {
            self.texture = self.frontTexture
            self.faceUp = true
        }
    }
    
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        for _ in touches {
            touchesBeganClosure(self)
        }
    }
    
    //    override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
    //        touchesMovedClosure(self)
    //        for touch in touches {
    //            let location = touch.locationInNode(scene!)
    //            let touchedNode = nodeAtPoint(location)
    //            touchedNode.position = location
    //        }
    //    }
    
    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        for _ in touches {
            touchesEndedClosure(self)
        }
    }
}

class RummyScene: SKScene {
    let GameScene: GameSceneViewController
    let RummyGame: Rummy
    
    var cardSize = CGSize(width: 0, height: 0)
    
    var deckLocation = CGPoint(x: 0,y: 0)
    var wastePileLocation = CGPoint(x: 0, y: 0)
    var handLocations = [CGPoint(x: 0,y: 0)]
    var countLocations = [CGPoint(x: 0, y: 0)]
    var meldLocation = CGPoint(x: 0,y: 0)
    
    var isWinner = false
    var isPlayerTurn = false
    
    var cardCountNodeArray: [SKLabelNode] = []
    var scoreboardNodes: [SKNode] = []
    
    var buttonsOnScreen = [GameViewControllerButton]()
    
    init(gameScene : GameSceneViewController, game: Rummy, size: CGSize) {
        
        self.GameScene = gameScene
        self.RummyGame = game
        
        super.init(size: size)
        
        // initializes the various CGPoints and CGSizes used by gamescene
        self.cardSize = CGSize(width: self.scene!.size.width/11, height: self.scene!.size.height/5)
        
        // Sets the location for where the deck and waste pile are located in the frame
        self.deckLocation = CGPoint(x: self.scene!.frame.minX + 2*cardSize.width, y: self.scene!.frame.midY)
        self.wastePileLocation = CGPoint(x: self.scene!.frame.minX + 2.1*cardSize.width + cardSize.width , y: self.scene!.frame.midY)
        
        // Sets the location for where the melds should be location
        self.meldLocation = CGPoint(x: self.scene!.frame.midX - cardSize.width, y: self.scene!.frame.maxY - 1.75*cardSize.height)
        
        // Sets the locations of where the players' hands begin
        switch RummyGame.playersHands.count {
        case 2:
            self.handLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height/3)]
            self.countLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height)]
        case 3:
            self.handLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width/3, y: self.frame.midY), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height/3)]
            self.countLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width, y: self.frame.midY), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height)]
        case 4:
            self.handLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width/3, y: self.frame.midY), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height/3),CGPoint(x: self.frame.minX+cardSize.width/3, y: self.frame.midY)]
            self.countLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width, y: self.frame.midY), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height),CGPoint(x: self.frame.minX+cardSize.width, y: self.frame.midY)]
        case 5:
            self.handLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width/3, y: self.frame.midY-cardSize.height), CGPoint(x: self.frame.maxX-cardSize.width/3, y: self.frame.midY+cardSize.height), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height/3),CGPoint(x: self.frame.minX+cardSize.width/3, y: self.frame.midY+cardSize.height)]
            self.countLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width, y: self.frame.midY-cardSize.height), CGPoint(x: self.frame.maxX-cardSize.width, y: self.frame.midY+cardSize.height), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height),CGPoint(x: self.frame.minX+cardSize.width, y: self.frame.midY+cardSize.height)]
        case 6:
            self.handLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width/3, y: self.frame.midY-cardSize.height), CGPoint(x: self.frame.maxX-cardSize.width/3, y: self.frame.midY+cardSize.height), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height/3),CGPoint(x: self.frame.minX+cardSize.width/3, y: self.frame.midY+cardSize.height),CGPoint(x: self.frame.minX+cardSize.width/3, y: self.frame.midY-cardSize.height)]
            self.countLocations = [CGPoint(x: self.frame.midX,y: self.frame.minY+cardSize.height/3),CGPoint(x: self.frame.maxX-cardSize.width, y: self.frame.midY-cardSize.height), CGPoint(x: self.frame.maxX-cardSize.width, y: self.frame.midY+cardSize.height), CGPoint(x: self.frame.midX, y: self.frame.maxY-cardSize.height),CGPoint(x: self.frame.minX+cardSize.width, y: self.frame.midY+cardSize.height),CGPoint(x: self.frame.minX+cardSize.width, y: self.frame.midY-cardSize.height)]
        default:
            break
        }
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func didMoveToView(view: SKView) {
        backgroundColor = UIColor.blueColor()
        if self.RummyGame.deck.numberOfCards() == 52{
            print(self.RummyGame.round,self.RummyGame.roundScores)
            addDealButton()
        } else {
            print(self.RummyGame.round,self.RummyGame.roundScores)
        }
    }
    
    
    // MARK: Function that add buttons to the scene
    func startRound() {
        self.shuffle()
        self.deal()
        
        for player in RummyGame.players {
            setUserInteractionEnabledPlayerHand(false, player: player)
        }
    }
    
    func addDealButton() {
        let dealButton = GameViewControllerButton(defaultButtonImage: "start_game_image", buttonAction: startRound)
        dealButton.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))
        dealButton.size = CGSize(width: 300, height: 200)
        self.addChild(dealButton)
        
    }
    
    func addMeldButton() {
        let meldButton = GameViewControllerButton(defaultButtonImage: "MeldButtonImg", buttonAction: meld)
        meldButton.size = CGSize(width: 100, height: 75)
        meldButton.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))
        meldButton.zPosition = 100
        self.addChild(meldButton)
        buttonsOnScreen.append(meldButton)
        
    }
    
    func addDiscardButton() {
{'fraction_non_alphanumeric': 0.12393561500851508, 'fraction_numerical': 0.008460143932318849, 'mean_word_length': 2.8600508905852418, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4603506', 'n_tokens_mistral': 6311, 'n_tokens_neox': 6104, 'n_words': 1104}