// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 < 0.9.0;
contract lec38{
enum CarStatus{
TurnOff,
TurnOn,
Driving,
Stop
}
CarStatus public carStatus;
constructor(){
carStatus = CarStatus.TurnOff;
}
event carCurrentStatus(CarStatus _carStatus, uint256 _carStatusInInt);
function turnOnCar() public {
require(carStatus == CarStatus(0), "To turn on, your car must be turned off");
carStatus = CarStatus(1);
emit carCurrentStatus(carStatus,uint256(carStatus));
}
function DrivingCar() public {
require(carStatus == CarStatus.TurnOn, "To drive a car, your car must be turned on");
carStatus = CarStatus.Driving;
emit carCurrentStatus(carStatus,uint256(carStatus));
}
function StopCar() public {
require(carStatus == CarStatus.Driving, "To drive a car, your car must be turned on");
carStatus = CarStatus.Stop;
emit carCurrentStatus(carStatus,uint256(carStatus));
}
function turnOffCar() public {
require(carStatus == CarStatus.TurnOn
|| carStatus == CarStatus.Stop , "To turn off, your car must be turned on or driving");
carStatus = CarStatus.TurnOff;
emit carCurrentStatus(carStatus,uint256(carStatus));
}
function CheckStatus() public view returns(CarStatus) {
return carStatus;
}
}
솔리디티 강좌 41강 -import 임폴트 (0) | 2021.10.12 |
---|---|
솔리디티 강좌 40강 - library 라이브러리 (0) | 2021.10.10 |
솔리디티 강좌 37강 - call Vs delegate call (0) | 2021.10.06 |
솔리디티 강좌 36강 - call (0) | 2021.10.05 |
솔리디티 강좌 35강 - fallback / receive 함수 (0) | 2021.10.04 |