Commit 11e01ed6 by Julio Hermosa

Se agrega la tarea2 correspondiente al poker versión swift.

parent 7a378e5c
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:poker.xcodeproj">
</FileRef>
</Workspace>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "AD75538F-44D9-4077-A86B-D0C9F689EB7A"
type = "1"
version = "2.0">
</Bucket>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>poker.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
//
// AppDelegate.swift
// poker
//
// Created by Mobile Roshka on 4/13/20.
// Copyright © 2020 Mobile Roshka. All rights reserved.
//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "poker-C.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "poker-D.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "poker-E.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "poker-T.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "poker-logo.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
//
// Carta.swift
// poker
//
// Created by Mobile Roshka on 4/13/20.
// Copyright © 2020 Mobile Roshka. All rights reserved.
//
import Foundation
struct Carta{
var valor = Int()
//var nombre = String()
var palo = Palo.self
//var palo = String()
enum Palo: Int{
case E = 1
case T = 2
case C = 3
case D = 4
}
}
class Baraja{
// var enMesa = [String]()
var valor = [Int]()
var valoresOrdenados = [Int]()
var palo = [String]()
var nombreCarta = [String]()
var nombreJugada = "Carta alta"
private let escalera: [Int] = [1, 10, 11, 12, 13]
//función para extraer 5 cartas y guardar la información en arrays con los valores, el palo y el nombre de la carta en caso de ser A, J, Q y K
func extraerCartas()/*->[String]*/{
let carta = Carta.init()
//recorremos un array de 5 elementos (cada una de las cartas extraídas)
for index in 0...4{
//se elige al azar el palo segun el enum de palo
var paloCarta = carta.palo.init(rawValue: .random(in: 1...4))
//se guarda en el array los valores de la carta y el palo
valor.append(Int.random(in: 1...13))
palo.append("\(paloCarta!)")
//se recorre por los elementos anteriores para determinar si se repitió la carta y si es así escojemos otra
for i in 0..<index{
if valor[index] == valor[i] && palo[index] == palo[i]{
valor.removeLast()
palo.removeLast()
valor.append(Int.random(in: 1...13))
paloCarta = carta.palo.init(rawValue: Int.random(in: 1...4))
palo.append("\(paloCarta!)")
}
}
// se carga en el array auxiliar, que luego se ordenará
valoresOrdenados.append(valor[index])
//se carga en el array el nombre de la carta, 1: A, 11:J, 12:Q y 13:K
switch valor[index] {
case 1:
nombreCarta.append("A"/*+"\(paloCarta!)"*/)
case 11:
nombreCarta.append("J"/*+"\(paloCarta!)"*/)
case 12:
nombreCarta.append("Q"/*+"\(paloCarta!)"*/)
case 13:
nombreCarta.append("K"/*+"\(paloCarta!)"*/)
default:
nombreCarta.append("\(valor[index])"/*+"\(paloCarta!)"*/)
}
}
valoresOrdenados.sort()
return //nombreCarta
}
//devuelve un string con el nombre de la jugada segun la combinación de cartas
func jugadas()->String{
var contSecuencia = 1
var contPalosIguales = 1
var diccionarioCantidad: [Int: Int] = [1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0]
diccionarioCantidad[valoresOrdenados[0]]! += 1
for index in 1...4{
if valoresOrdenados[index] == valoresOrdenados[index-1]+1{
contSecuencia += 1
}
if palo[index] == palo[index-1]{
contPalosIguales += 1
}
if diccionarioCantidad[valoresOrdenados[index]] == 0{
diccionarioCantidad[valoresOrdenados[index]]! += 1
}
if valoresOrdenados[index] == valoresOrdenados[index - 1]{
diccionarioCantidad[valoresOrdenados[index]]! += 1
}
}
if contPalosIguales == 5{
nombreJugada = "Color"
}
if contSecuencia == 5{
nombreJugada = "Escalera"
}
if valoresOrdenados == escalera{
nombreJugada = "Escalera"
}
if nombreJugada == "Escalera" && contPalosIguales == 5 {
nombreJugada = "Escalera Color"
}
let poker = diccionarioCantidad.filter{ $0.value == 4}
let trio = diccionarioCantidad.filter{ $0.value == 3}
let par = diccionarioCantidad.filter{ $0.value == 2}
if par.count == 1{
nombreJugada = "Par"
}
if par.count == 2{
nombreJugada = "Par doble"
}
if trio.count == 1{
nombreJugada = "Trio"
}
if par.count == 1 && trio.count == 1{
nombreJugada = "Full"
}
if poker.count == 1 {
nombreJugada = "Poker"
}
return nombreJugada
}
//eliminamos todas las modificaciones para empezar de nuevo el juego
func barajarCartas(){
valor.removeAll()
palo.removeAll()
valoresOrdenados.removeAll()
nombreCarta.removeAll()
nombreJugada = "Carta alta"
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
//
// SceneDelegate.swift
// poker
//
// Created by Mobile Roshka on 4/13/20.
// Copyright © 2020 Mobile Roshka. All rights reserved.
//
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
}
func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
}
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}
func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}
func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}
func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}
}
//
// ViewController.swift
// poker
//
// Created by Julio Hermosa on 4/13/20.
// Copyright © 2020 Mobile Roshka. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
//var carta:Carta = Carta.init()
var baraja:Baraja = Baraja()
@IBOutlet weak var resultadoObtenido: UILabel!
@IBOutlet weak var valorCarta1: UILabel!
@IBOutlet weak var valorCarta2: UILabel!
@IBOutlet weak var valorCarta3: UILabel!
@IBOutlet weak var valorCarta4: UILabel!
@IBOutlet weak var valorCarta5: UILabel!
@IBOutlet weak var imagenCarta1: UIImageView!
@IBOutlet weak var imagenCarta2: UIImageView!
@IBOutlet weak var imagenCarta3: UIImageView!
@IBOutlet weak var imagenCarta4: UIImageView!
@IBOutlet weak var imagenCarta5: UIImageView!
@IBOutlet weak var jugarBtn: UIButton!
@IBAction func jugarAction(_ sender: Any) {
jugar()
}
//llamamos a las funciones relativas al juego de la clase baraja (extraer cartas, obtener la jugada y volver a barajar las cartas)
func jugar(){
baraja.extraerCartas()
resultadoObtenido.text = baraja.jugadas()
//cargamos los valores del array en los labels de las cartas
valorCarta1.text = baraja.nombreCarta[0]
valorCarta2.text = baraja.nombreCarta[1]
valorCarta3.text = baraja.nombreCarta[2]
valorCarta4.text = baraja.nombreCarta[3]
valorCarta5.text = baraja.nombreCarta[4]
//segun el nombre de la imagen mostramos su palo
imagenCarta1.image = UIImage(named: "poker-\(baraja.palo[0])")
imagenCarta2.image = UIImage(named: "poker-\(baraja.palo[1])")
imagenCarta3.image = UIImage(named: "poker-\(baraja.palo[2])")
imagenCarta4.image = UIImage(named: "poker-\(baraja.palo[3])")
imagenCarta5.image = UIImage(named: "poker-\(baraja.palo[4])")
baraja.barajarCartas()
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment