-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tank-race-game] feat: add on-win pop-up
- Loading branch information
1 parent
8699843
commit 302480d
Showing
7 changed files
with
135 additions
and
8 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
ArkGameExample/games/TankRaceGame/CustomViews/TankWinCustomView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import UIKit | ||
|
||
class TankWinCustomView: UIViewController { | ||
|
||
var winner: String? | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
view.backgroundColor = UIColor(white: 0, alpha: 0.5) | ||
setupSubviews() | ||
} | ||
|
||
func setupSubviews() { | ||
// Container view | ||
let containerView = UIView() | ||
containerView.backgroundColor = .white | ||
containerView.layer.cornerRadius = 10 | ||
containerView.clipsToBounds = true | ||
view.addSubview(containerView) | ||
|
||
// Winner label | ||
let winnerLabel = UILabel() | ||
winnerLabel.text = "Winner: \(winner ?? "Unknown")" | ||
winnerLabel.textAlignment = .center | ||
winnerLabel.font = UIFont.boldSystemFont(ofSize: 24) | ||
containerView.addSubview(winnerLabel) | ||
|
||
// Back button | ||
let backButton = UIButton(type: .system) | ||
backButton.setTitle("Back", for: .normal) | ||
backButton.addTarget(self, action: #selector(backButtonTapped), for: .touchUpInside) | ||
containerView.addSubview(backButton) | ||
|
||
// Layout | ||
containerView.translatesAutoresizingMaskIntoConstraints = false | ||
NSLayoutConstraint.activate([ | ||
containerView.centerXAnchor.constraint(equalTo: view.centerXAnchor), | ||
containerView.centerYAnchor.constraint(equalTo: view.centerYAnchor), | ||
containerView.widthAnchor.constraint(equalToConstant: 300), | ||
containerView.heightAnchor.constraint(equalToConstant: 200) | ||
]) | ||
|
||
winnerLabel.translatesAutoresizingMaskIntoConstraints = false | ||
backButton.translatesAutoresizingMaskIntoConstraints = false | ||
NSLayoutConstraint.activate([ | ||
winnerLabel.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 20), | ||
winnerLabel.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 20), | ||
winnerLabel.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -20), | ||
|
||
backButton.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: -20), | ||
backButton.centerXAnchor.constraint(equalTo: containerView.centerXAnchor) | ||
]) | ||
} | ||
|
||
@objc func backButtonTapped() { | ||
dismiss(animated: true, completion: nil) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
ArkGameExample/games/TankRaceGame/Events/TankWinEvent.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Foundation | ||
|
||
struct TankWinEventData: ArkSerializableEventData { | ||
var name: String | ||
var tankId: Int | ||
} | ||
|
||
struct TankWinEvent: ArkSerializableEvent { | ||
static var id = UUID() | ||
var eventData: TankWinEventData | ||
var priority: Int? | ||
|
||
init(eventData: TankWinEventData, priority: Int? = nil) { | ||
self.eventData = eventData | ||
self.priority = priority | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters