Commit 64fd0057 by Nicolas Gauna

first commit

parents
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:Generala.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"?>
<!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>Generala.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
//
// AppDelegate.swift
// Generala
//
// Created by Nicolas Gauna on 4/13/20.
// Copyright © 2020 Nicolas Gauna. 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" : "universal",
"filename" : "1.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" : "2.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" : "3.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" : "4.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" : "5.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" : "6.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"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
<?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>
//
// Generala.swift
// Generala
//
// Created by Nicolas Gauna on 4/13/20.
// Copyright © 2020 Nicolas Gauna. All rights reserved.
//
import Foundation
class Generala { //Esta es mi clase Generala
var jugadaResultante : String = ""
func jugada(dados:String) -> String{
if(generala(dadosTirados: dados)){ jugadaResultante = "generala"}
if(poker(dadosTirados: dados)){ jugadaResultante = "poker"}
if(full(dadosTirados: dados)){ jugadaResultante = "full"}
if(escalera(dadosTirados: dados)){ jugadaResultante = "escalera" }
if(invalido(dadosTirados: dados)){ jugadaResultante = "invalido"}
if(jugadaResultante == ""){jugadaResultante = "Nada"}
return jugadaResultante
}
func generala (dadosTirados:String) -> Bool{
//1. GENERALA
//Todos los dados, con el mismo valor. Ejemplo: 55555
switch dadosTirados {
case "11111", "22222", "33333", "44444", "55555", "66666" : //Si es igual a uno de estos casos
return true //retornamos true
default:
return false //Si no es igual retornamos false
}
}
func poker(dadosTirados:String) -> Bool{
//2. PÓKER
//Cuatro dados con el mismo valor. Ejemplo: 55553
var bool : Bool = false
var vec : [Int] = [0,0,0,0,0,0,0]
for caracter in dadosTirados{
switch caracter {
case "1" : vec[1] += 1
case "2" : vec[2] += 1
case "3" : vec[3] += 1
case "4" : vec[4] += 1
case "5" : vec[5] += 1
case "6" : vec[6] += 1
default : vec[0] += 1
}
}
for i in 1...6{
if (vec[i] == 4) { bool = true }
}
return bool
}
func full(dadosTirados:String) -> Bool{
//3. FULL
//Tres dados con el mismo valor y los otros dos, de un mismo valor
//Ejemplo: 55533
var bool : Bool = false
var temp : Int
var vec : [Int] = [0,0,0,0,0,0,0]
for caracter in dadosTirados{
switch caracter {
case "1" : vec[1] += 1
case "2" : vec[2] += 1
case "3" : vec[3] += 1
case "4" : vec[4] += 1
case "5" : vec[5] += 1
case "6" : vec[6] += 1
default : vec[0] += 1
}
}
for i in 1...6{
if (vec[i] == 3) {
temp = i
for a in 1...6{
if (vec[a] == 2 && vec[a] != temp) { bool = true }
}
}
}
return bool
}
func escalera(dadosTirados:String) -> Bool{
//4. ESCALERA
//Los dados, en secuencia:
// a) 12345
// b) 23456
// c) 34561
let dado = String(dadosTirados.sorted())
switch dado {
case "12345", "23456", "34561", "45612","56123", "61234" :
return true
default:
return false
}
}
func invalido(dadosTirados:String) -> Bool{
//6. INVALIDO
//Hay algún valor inválido en los dados ingresados.
var bool : Bool = false
for caracter in dadosTirados{
if (caracter > "6") { bool = true } else {bool = false}
}
return bool
}
}
<?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
// Generala
//
// Created by Nicolas Gauna on 4/13/20.
// Copyright © 2020 Nicolas Gauna. 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
// Generala
//
// Created by Nicolas Gauna on 4/13/20.
// Copyright © 2020 Nicolas Gauna. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var imgView1: UIImageView!
@IBOutlet weak var imgView2: UIImageView!
@IBOutlet weak var imgView3: UIImageView!
@IBOutlet weak var imgView4: UIImageView!
@IBOutlet weak var imgView5: UIImageView!
@IBOutlet weak var lblResultado: UILabel!
@IBOutlet weak var txtFieldDado: UITextField!
var resultadoDado: String = ""
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func aleatorio()->String{
var rand = 0
while (rand == 0) {
rand = Int(arc4random_uniform(6)) // numero random en base a 10
//let rand2 = Int(arc4random()) // numero random
}
return String(rand)
}
@IBAction func generala(_ sender: Any) {
var numerosParaLasImagenes = ["","","","",""]
if (txtFieldDado.text == "" || txtFieldDado.text == resultadoDado){
txtFieldDado.text = ""
for i in 0...4{
let numeroAleatorio = aleatorio()
txtFieldDado.text?.append(numeroAleatorio)
numerosParaLasImagenes[i] = numeroAleatorio
}
} else {
var cont = 0
var cont2 = ["","","","",""]
if(txtFieldDado.text!.count > 5 || txtFieldDado.text!.count < 5){
lblResultado.text = ""
return
}
for caracter in txtFieldDado.text!{
cont2[cont] = String(caracter)
cont += 1
}
for i in 0...4{ numerosParaLasImagenes[i] = cont2[i]}
}
imgView1.image = UIImage(named: "\(numerosParaLasImagenes[0]).jpg")
imgView2.image = UIImage(named: "\(numerosParaLasImagenes[1]).jpg")
imgView3.image = UIImage(named: "\(numerosParaLasImagenes[2]).jpg")
imgView4.image = UIImage(named: "\(numerosParaLasImagenes[3]).jpg")
imgView5.image = UIImage(named: "\(numerosParaLasImagenes[4]).jpg")
resultadoDado = String(txtFieldDado.text!)
let generala = Generala()
let tipoJugada = generala.jugada(dados: resultadoDado)
lblResultado.text = tipoJugada
print("\(resultadoDado) - \(tipoJugada)")
}
}
File added
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