mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
784 B
53 lines
784 B
5 years ago
|
package main
|
||
|
|
||
|
import "github.com/01-edu/z01"
|
||
|
|
||
|
const CLOSE = 0
|
||
|
const OPEN = 1
|
||
|
|
||
|
type Door struct {
|
||
|
State int
|
||
|
}
|
||
|
|
||
5 years ago
|
func PrintStr(s string) {
|
||
|
for _, r := range s {
|
||
|
z01.PrintRune(r)
|
||
5 years ago
|
}
|
||
|
z01.PrintRune('\n')
|
||
|
}
|
||
|
|
||
|
func CloseDoor(ptrDoor *Door) {
|
||
|
PrintStr("Door Closing...")
|
||
|
ptrDoor.State = CLOSE
|
||
|
}
|
||
|
|
||
|
func OpenDoor(ptrdoor *Door) {
|
||
|
PrintStr("Door Opening...")
|
||
|
ptrdoor.State = OPEN
|
||
|
}
|
||
|
|
||
|
func IsDoorOpened(ptrDoor *Door) bool {
|
||
|
PrintStr("is the Door opened ?")
|
||
5 years ago
|
return ptrDoor.State == OPEN
|
||
5 years ago
|
}
|
||
|
|
||
|
func IsDoorClosed(ptrDoor *Door) bool {
|
||
|
PrintStr("is the Door closed ?")
|
||
5 years ago
|
return ptrDoor.State == CLOSE
|
||
5 years ago
|
}
|
||
|
|
||
|
func main() {
|
||
|
var door Door
|
||
|
|
||
|
OpenDoor(&door)
|
||
|
if IsDoorClosed(&door) {
|
||
|
OpenDoor(&door)
|
||
|
}
|
||
|
if IsDoorOpened(&door) {
|
||
|
CloseDoor(&door)
|
||
|
}
|
||
|
if door.State == OPEN {
|
||
|
CloseDoor(&door)
|
||
|
}
|
||
|
}
|