Commit 7a378e5c by Julio Hermosa

Primera entrega del proyecto, contiene la versión para iOS de generala y el…

Primera entrega del proyecto, contiene la versión para iOS de generala y el archivo PDF con el desarrollo de los problemas s/ probabilidades planteados
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 Mobile Roshka on 4/9/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" : "dado-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" : "dado-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" : "dado-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" : "dado-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" : "dado-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" : "dado-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" : "universal",
"filename" : "dado-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>
//
// Dado.swift
// generala
//
// Created by Julio Hermosa on 4/9/20.
// Copyright © 2020 Mobile Roshka. All rights reserved.
//
import Foundation
class Dado{
//
var resultado = [Int]()//El array se carga al llamar a la función lanzarDado, con valores aleatorios del 1 al 6 (caras del dado). Cada posición de éste vector corresponde a un dado.
var valores: [Int: Int] = [1: 0, 2:0, 3:0, 4:0, 5:0, 6:0]//Diccionario con cada uno de los valores posibles de 'resultado', contabilizando las veces que se repiten los valores
//Para cargar los valores del array resultado de manera manual
//var resultado: [Int] = [1,2,3,5,4]
var resultadoOrdenado = [Int]()//Se ordena el array 'resultado' de manera creciente
//Los siguientes diccionarios resultan a realizar un filtro del diccionario de valores
var par = [Int:Int]() // Cantidad de pares y sus valores, se utiliza para la combinación 'Full'
var trio = [Int:Int]() // Valores que aparecen en 3 ocasiones
var poker = [Int:Int]() // Valores que aparecen en 4 ocasiones
var generala = [Int:Int]() // Valores que aparecen en 5 ocasiones
var retorno = "Nada" // Ninguna combinación
//Simulamos el lanzamiento de 5 dados, cuyos resultados se cargan en el array 'resultado' y en el diccionario de valores
func lanzarDado(){
//var resultado = [Int]()
//Cargamos los arrays de resultado
for index in 0...4{
resultado.append(Int.random(in: 1...6))
resultadoOrdenado.append(resultado[index])
}
//ordenamos el resultado
resultadoOrdenado.sort()
//Recorremos el array contabilizando repeticiones de valores
for i in 1...4 {
if valores[resultadoOrdenado[i]] == 0{
valores[resultadoOrdenado[i]]! += 1
}
if resultadoOrdenado[i] == resultadoOrdenado[i-1]{
valores[resultadoOrdenado[i]]! += 1
}
}
//filtramos el diccionario de valores segun su cantidad cargando en su combinación correspondiente
par = valores.filter { $0.value == 2}
trio = valores.filter { $0.value == 3}
poker = valores.filter { $0.value == 4}
generala = valores.filter { $0.value == 5}
//print (resultado)
//print (resultadoOrdenado)
}
//La función obtenerResultado devuelve el nombre de la combinación obtenida
func obtenerResultado()->String{
if trio.count == 1 && par.count == 1{
retorno = "Full"
}
if poker.count == 1{
retorno = "Poker"
}
if generala.count == 1{
retorno = "Generala"
}
let escaleraMenor: [Int] = [1, 2, 3, 4, 5]
let escalera: [Int] = [2, 3, 4, 5, 6]
let escaleraMayor: [Int] = [3, 4, 5, 6, 1]
if resultadoOrdenado == escaleraMenor || resultadoOrdenado == escalera || resultadoOrdenado == escaleraMayor{
retorno = "Escalera"
}
return retorno
}
//Removemos todos los valores obtenidos por el usuario para volver a jugar
func reiniciar(){
resultado.removeAll()
resultadoOrdenado.removeAll()
for index in 1...6 {
valores[index] = 0
}
retorno = "Nada"
}
}
<?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 Mobile Roshka on 4/9/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
// generala
//
// Created by Julio Hermosa on 4/9/20.
// Copyright © 2020 Mobile Roshka. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
//inicializamos un dado, del tipo Dado
var dado = Dado.init()
@IBOutlet weak var jugarBtn: UIButton!
//Se cargan las imagenes de los dados segun el resultado obtenido
@IBOutlet weak var dado1: UIImageView!
@IBOutlet weak var dado2: UIImageView!
@IBOutlet weak var dado3: UIImageView!
@IBOutlet weak var dado4: UIImageView!
@IBOutlet weak var dado5: UIImageView!
//Botón para iniciar juego, llama a la función jugar
@IBAction func jugarBtnAction(_ sender: Any) {
jugar()
}
@IBOutlet weak var resultadoLbl: UILabel!
//Función jugar, se realizan las operaciones de lanzamiento de los dados, carga de imagenes de los dados y se imprime si hay alguna combinación en el label resultadoLbl
func jugar(){
dado.lanzarDado() //Se carga el resultado de los lanzamientos
//print(dado.obtenerResultado())
resultadoLbl.text = dado.obtenerResultado()
dado1.image = UIImage(named: "dado-\(dado.resultado[0])")
dado2.image = UIImage(named: "dado-\(dado.resultado[1])")
dado3.image = UIImage(named: "dado-\(dado.resultado[2])")
dado4.image = UIImage(named: "dado-\(dado.resultado[3])")
dado5.image = UIImage(named: "dado-\(dado.resultado[4])")
dado.reiniciar()//Borramos todos los datos del usuario para que se pueda volver a jugar
}
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