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.
48 lines
682 B
48 lines
682 B
5 years ago
|
package main
|
||
|
|
||
5 years ago
|
import "fmt"
|
||
5 years ago
|
|
||
5 years ago
|
const (
|
||
|
CLOSE = iota
|
||
|
OPEN
|
||
|
)
|
||
5 years ago
|
|
||
|
type Door struct {
|
||
|
State int
|
||
|
}
|
||
|
|
||
|
func CloseDoor(ptrDoor *Door) {
|
||
5 years ago
|
fmt.Println("Door Closing...")
|
||
5 years ago
|
ptrDoor.State = CLOSE
|
||
|
}
|
||
|
|
||
|
func OpenDoor(ptrdoor *Door) {
|
||
5 years ago
|
fmt.Println("Door Opening...")
|
||
5 years ago
|
ptrdoor.State = OPEN
|
||
|
}
|
||
|
|
||
|
func IsDoorOpened(ptrDoor *Door) bool {
|
||
5 years ago
|
fmt.Println("is the Door opened ?")
|
||
5 years ago
|
return ptrDoor.State == OPEN
|
||
5 years ago
|
}
|
||
|
|
||
|
func IsDoorClosed(ptrDoor *Door) bool {
|
||
5 years ago
|
fmt.Println("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)
|
||
|
}
|
||
|
}
|