var myString = "Hello world! - swift.jsrun.net"
print(myString)
var GameOver = false
var beginTimestamp : Int = 0
let GamePeriod = 20
var TimeCost = 0
func getcurrentTimeStamp() -> Int [
let now = DateC
let timelnterval : Timelnterval = now
timeIntervalsince1970
return Int(timelnterval)
func timeElapseO) (
TimerscheduledTimer(withTimelnterval: 0.5,repeats: true) ((timer) in
let timestamp = self.getCurrentTimeStamp0
let pastPeriod = timestamp - self.
beginTimestamp
let countDown = self,GamePerioc
pastperlod
self,TimeCost = pastPeriod
f countDown <= 0 elf GameOver
self GameOver
et tipsLabel = self.view.v Tag(1001)as. UILabe
tiosLabel,text=游戏结束 共消耗时间(selfmeCost)秒
linvalidateO
et tiosLabel = selfview.yi WitnTag(1002)as! UILabel
DispatchQueue.main.async
tipsLabel.text="您消耗\(pastPeriod)秒 倒时(countDown
音效 计时戏结案
@objc func buttonCheckMusicTimer( sender: UiButton)
if GameOver freturn
et tlosLaber – selfview.viewwithTag(1001)as! uTLabel
var tag = sender.tag
if tag >= 5000 (
tag- 5000
else if tag= 400,0
tao 4000
et row = Int (tag / cols)
let col = taa - cols * row
——IrOW.CO
ot
0=(TOW.CO
errorCords = reserved
if result.count >=1(
sender.backgroundColor = red
let path = Bundle,main,path(forResource; birdsound",oflype: "m4a")
let url = URL(fileURLWithPath: path!)
soundPlayer = try? AVAudioPlayer(
contentsOf; url)
soundplayer.play0
tipsLabel.text="不同找到:(A(row),\(col)),还剩(errorCords.count)A"
erro count <= 0(
GameOver = true
Label.text="任务完成 共花费时间(self.0 秒
sender, KO
let path = Bunc Resource:
error", ofType: "m4a")
let url = URL(fileURLWithPath: path!)
soundPlayer = try? AVAudioPlayer(contentsOf: url)
soundPlayer.play()
tipsLabel.text = "找错啦:(\(row),\(col))"
}
}
func displayArrayGraphButtonTips()(
let myview1 = self.view.viewWithTag(2001) as! UllmageView
let myview2 = self.view.viewWithTag(2002) as! UllmageView
myView1.backgroundColor=.darkGray
myView2.backgroundColor= .darkGray
myView1.isUserInteractionEnabled = true
myView2.isUserInteractionEnabled = true
let h = myView1.frame.size.height
let w= myView1.frame.size.width
let padding: CGFloat = 5
let margin: CGFloat = 10
/计算每个格子的高度和宽度
let grid w= (w - margin *2 - padding * CGFloat(cols - 1))/ CGFloat (cols) let grid_h = (h - margin *2 - padding CGFloat(rows - 1)) / CGFloat (rows)
for i in O..<rows {
for j in 0..<cols (
let x = margin + CGFloat(j) * (grid w + padding)
let y = margin + CGFloat(i) * (grid h + padding)
let rect = CGRect(x: x, y:y , width: grid w, height: grid h)
let tag1 = i* cols +j+ 5000
addButton(view: myView1, rect: rect, fileName: fileNamel, tag: tagl)
let fileName2 = iv2[i * cols + j]
let tag2 =i* cols + i + 4000
addButton(view: myView2, rect: rect,fileName: fileName2, tag:tag2)
let btn = UlButton(frame: rect)
btn.setlmage(img, for:.normal)
var mytag =tag
if mytag >= 5000t
mytag -= 5000
else if mytag >=4000 (
mytag -= 4000
let row = Int (mytag / cols)
let col = mytag - cols * row
$0 == (row,col)
]
if result.count >= 1 && TipsFlag
btn.backgroundColor =.blue
1)
else(
btn.backgroundColor = yellow
btn.tag = tag
btn.addTaiget(self, action: #selector(buttonCheckMusicTimer (_:)), for: .touchUpInside) view.addSubview(btn)
]
@IBAction func onTips( 【 sender : UIButton) (
TipsFlag =! TipsFlag
displayArrayGraphButtonTips0
1
@IBAction func onBegin(、 sender : UIButton) (
GameOver = false
beginTimestamp = getCurrentTimeStamp0
timeElapse(0
initGame0 Windows (CRLF)
differenceCreate(mount: 3)
displayArrayGraphButtonTips(0
let btn = UIButton(frame: rect)
btn.setImage(img, for: .normal)
var mytag = tag
if mytag >= 5000(
mytag -= 5000
else if mytag > = 4000 (
mytag -= 4000
let row = Int (mytag / cols)
let col = mytag - cols * row
let result = errorCords.filter (
$O = = (row,col)
if result.count >=1 && TipsFlag (
btn.backgroundColor =.blue
btn taa = taa Windows (CRLF)
btn.addTarget(self,action: #selector(buttonCheckMusicTimer C_:)), for:touchUpInside) view.addSubview(btn)
let result1 = cords.filter (
$O == (row,col)
if result1.count >= 1 (
btn.tag =tag
btn.addTarget(self, action: #selector (buttonCheckMusieTimer(_:)), for.touchuplnside) view.addSubview(btn)
func removeAllSubViews(view:UIView) (
if view.subviews.count> 0 (
view.subviews.forEach(($0.removeFromSuperview0))
@IBAction func onTips(_ sender :UIButton)(
TipsFlag =! TipsFlag
displayArrayGraphButtonTips0
@IBAction func onBegin(_ sender : UIButton)f
GameOver = false
beginTimestamp = getCurrentTimeStamp0
timeElapse()
initGame)
distractorCreate(mount: 10)
differenceCreate(mount: 8)
displayArrayGraphButtonTips0)
@IBAction func onNext(_ sender : UlButton)(
GameOver = true
TipsFlag = false
let myView1= self.view.viewWithTag(2001) as! UllmageView let myView2 = self.view.viewWithTag(2002) as! UIlmageView CurrentBackground += 1
if CurrentBackground > 4(
CurrentBackground = 1
14
let imaae = Ullmaae'named: "back0\(CurrentBackaround)")!
myView1.image = image
myView2.image = image
removeAllSubViews(view: myView1)
removeAllSubViews(view: myView2)
}
func differerceCreate(mount:Int){
for_in 0..<mount{
let col = Int(arc4random()) % cols
let row = Int(arc4randowm()) % rows
errorCords.append((row,col))
let ibdex = Int(arc4random()) % imag.count
let which = Int(arc4random()) % 2
if which == 0 {
iv1[cols*row + cols] = images[index]
}
else
iv2[cols*row + col] = image[index]
}
}
}
@objc func buttinCheckMusic(_sender :UIButton){
let tipsLabel = self.view.viewWith Tag(1001) as! UILabel
var tag = sender.tag
if tag >= 5000{
tag -= 5000
}
else if tag >= 4000{
tag -= 4000
}
let roow =Int(tag/cols)
let col = tag-cols*row
let result = errorCords.filter{
$0 == (row,col)
}
if result.count >= 1 {
let path =Bundle.main.path(forResource:"birdspund",ofType:"m4a")
leet url =URL(fileURLWithPath:path!)
soundplayer=try? AVAidioplyer(conentsof:url)
soundplayer.play()
tipsLayre.text = "不同找到: (\(row),\(col))"
}
else{
let path = Bundle.main.path(forResource:"error",ofType:"m4a")
let url =URL(fileURLWithpath:path!)
soundplayer=TRY? AVAidioplyer(conentsof:url)
soundplayer.play()
tipsLayre.text = "找错:(\(row),\(col))"
}
}
btn1.addTarget(self,action:#selector(buttinCheckMusic(_:)),for:.touchUplnside)
btn1.addTarget(self,action:#selector(buttinCheckMusic(_:)),for:.touchUplnside)
}
let expert = Expert()
let character = Character()
func move(sprite: Character, distance: Int)
{
for i in 1..distance {
sprite.moveForward()
}
}
func moveTurnMove(distance1: Int, isTurnLeft: Bool, distance2: Int)
{
move(sprite: expert, distance: distance1)
if isTurnLeft {
expert.turnLeft()
} else {
expert.turnRight()
}
move(sprite: expert, distance: distance2)
}
expert.turnLeft()
moveTurnMove(distance1: 3, isTurnLeft: false, distance2: 2)
expert.turnLeft()
expert.turnLockDown()
expert.turnLockDown()
expert.turnRight()
moveTurnMove(distance1: 2, isTurnLeft: false, distance2: 3)
moveTurnMove(distance1: 3, isTurnLeft: false, distance2: 2)
expert.turnLeft()
expert.turnLockUp()
move(sprite: character, distance: 2)
character.collectGem()
move(sprite: character, distance: 2)
character.toggleSwitch()
var filteredProspects: [Prospect] {
switch filter {
case .none:
return prospects.people
case .contacted:
return prospects.people.filter { $0.isContacted }
case .uncontacted:
return prospects.people.filter { !$0.isContacted }
}
}
List {
ForEach(filteredProspects) { prospect in
VStack(alignment: .leading) {
Text(prospect.name)
.font(.headline)
Text(prospect.emailAddress)
.foregroundColor(.secondary)
}
}
}
struct ExampleView: View {
var body: some View {
TimelineView(.periodic(from: .now, by: 3.0)) { timeline in
QuipView(date: timeline.date)
}
}
struct QuipView: View {
@StateObject var quips = QuipDatabase()
let date: Date
var body: some View {
Text("_\(quips.sentence)_")
.onChange(of: date) { _ in
quips.advance()
}
}
}
}
class QuipDatabase: ObservableObject {
static var sentences = [
"There are two types of people, those who can extrapolate from incomplete data",
"After all is said and done, more is said than done.",
"Haikus are easy. But sometimes they don't make sense. Refrigerator.",
"Confidence is the feeling you have before you really understand the problem."
]
@Published var sentence: String = QuipDatabase.sentences[0]
var idx = 0
func advance() {
idx = (idx + 1) % QuipDatabase.sentences.count
sentence = QuipDatabase.sentences[idx]
}
}
Text("www.baidu.com")
.background(Color.red)
.foregroundColor(.white)
.padding()
Text("www.baidu.com")
.padding(20)
.background(Color.black)
.foregroundColor(.white)
Text("www.baidu.com")
.padding()
.background(Color.black)
.foregroundColor(.white)
Text("www.baidu.com")
.padding(4)
.background(Color.black)
.foregroundColor(.white)
Text("Swift UI Doing")
.font(.largeTitle)
.foregroundColor(.black)
.padding(15)
.background(Color.yellow)
.padding(15)
.background(Color.orange)
.padding(20)
.background(Color.red)
Text("橙色大背景")
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity,alignment: .leading)
.background(Color.orange)
.font(.largeTitle)
.edgesIgnoringSafeArea(.all)
Text("现在时间是: \(xianzai, formatter: Self.dataFormatter)")
.font(.title)
.padding()
.background(Color.green)
var xianzai = Date()
static let dataFormatter :DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .long
return formatter
}()
Text("文本一 ")
.foregroundColor(.yellow)
.fontWeight(.heavy)
+ Text("文本二 ")
.foregroundColor(.blue)
.strikethrough()
+ Text("文本三 ")
.foregroundColor(.red)
.italic()
+ Text("文本四")
.foregroundColor(.green)
.underline()