Please use swift xcode on this assignment. In this assignment make a program tha
ID: 3599779 • Letter: P
Question
Please use swift xcode on this assignment.
In this assignment make a program that constructs a drawing in a very simple manner analogous to a tiled floor. Consider your method of operating is to create a class that is the template for creating different kinds of tiles. Then, you can see how creative you can be in constructing an interesting pattern using the tiles.
Start with this project template.
Following are your instructions, and the assignment requirements.
You must have a class, called Tile, which you will use to make an object that draws one tile. If you need help getting started creating a class, refer to the previous assignment 6.
In the project Scene class, declare an array to store all the tiles that you create to make the drawing.
In the Scene class, in the setup function, create the Tile objects and add them to the array.
In the Scene class, in the update function, use a for loop to render all the Tile objects stored in the array.
The Tile class must have a minimum of 3 drawing "styles". A style draws a unique drawing primitive or size and shape of primitive.
Tile objects must have the possibility of being different colors. Ie. all tiles must not be an identical color. Beyond that restriction, you are free to make use of color to whatever degree you want.
Your program builds and runs without errors.
Write your program using good coding style, readable formatting, and use good names for functions and variables.
Here is partial parts of the code:
//
// AppDelegate.swift
//
//
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
}
//
// ViewController.swift
//
//
import Cocoa
import Tin
class ViewController: TController {
var scene: Scene!
override func viewWillAppear() {
super.viewWillAppear()
view.window?.title = "Tiles"
makeView(width: 800.0, height: 600.0)
scene = Scene()
present(scene: scene)
scene.view?.showStats = false
}
override func mouseUp(with event: NSEvent) {
}
}
class Scene: TScene {
// scene properties here
override func setup() {
// initialization here
}
override func update() {
background(gray: 0.0)
// drawing here
//view?.stopUpdates()
}
}
Explanation / Answer
class Board(object):
def __init__(self, digitstr):
self.tiles= [[0 for x in range(3)] for y in range(3)]
self.blank_r=-1
self.blank_c=-1
for r in range(0,3):
for c in range(0,3):
self.tiles[r][c]=int(digitstr[3*r+c])
if(self.tiles[r][c]==0):
self.blank_r=r
self.blank_c=c
def __repr__(self):
s=""
for r in range(0,3):
for c in range(0,3):
if(self.tiles[r][c] is not 0):
s=s+str(self.tiles[r][c])+" "
else:
s=s+"_ "
s=s+" "
return s
def move_blank(self,direction):
nr=0
nc=0
if(direction=='up'):
nr=self.blank_r-1
nc=self.blank_c
if(nr<0 or nr>2):
return False
elif(direction=='down'):
nr=self.blank_r+1
nc=self.blank_c
if(nr<0 or nr>2):
return False
elif(direction=='left'):
nr=self.blank_r
nc=self.blank_c-1
if(nc<0 or nc>2):
return False
elif(direction=='right'):
nr=self.blank_r
nc=self.blank_c+1
if(nc<0 or nc>2):
return False
else:
print("invalid direction")
return False
self.tiles[self.blank_r][self.blank_c]=self.tiles[nr][nc]
self.tiles[nr][nc]=0
self.blank_c=nc
self.blank_r=nr
b = Board('142358607')
print(b.tiles)
print(b.blank_r)
print(b.blank_c)
print(b)
b.move_blank('up')
print(b)