-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Module #2 (Nowshin Owishi) #29
base: module-2
Are you sure you want to change the base?
Changes from 1 commit
bee70f2
cf27ed2
ec21c5a
9721681
66aec44
5c03c11
2b4d230
8e93356
48ca4d2
4ba03c3
b5a4648
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,15 +178,16 @@ const UseSnake = () => { | |
|
||
//remove food | ||
const removeFood = useCallback(() => { | ||
console.log("delete"); | ||
// console.log("delete food auto"); | ||
setFoods((currentFoods) => | ||
currentFoods.filter((food) => Date.now() - food.start < 10000) | ||
currentFoods.filter((food) => (Date.now() - food.start) < 10000) | ||
); | ||
}, []); | ||
//remove poison | ||
const removePoison = useCallback(() => { | ||
// console.log("delete poison auto"); | ||
setPoison((currentPoison) => | ||
currentPoison.filter((poison) => Date.now() - poison.start < 10000) | ||
currentPoison.filter((poison) => (Date.now() - poison.start) < 10000) | ||
); | ||
}, []); | ||
|
||
|
@@ -200,6 +201,7 @@ const UseSnake = () => { | |
); | ||
} | ||
if (isPoison(head)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Corei13 |
||
console.log("ate poison"); | ||
setPoison((currentPoison) => | ||
currentPoison.filter( | ||
(poison) => poison.x !== head.x && poison.y !== head.y | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @owishiboo See the issue? It will remove a poison even when it matches either x or y. |
||
|
@@ -208,7 +210,7 @@ const UseSnake = () => { | |
} | ||
}, [isFood, isPoison, snake]); | ||
|
||
UseInterval(addFood, 2000); | ||
UseInterval(addFood, 3000); | ||
UseInterval(runSingleStep, 300); | ||
UseInterval(removeFood, 50); | ||
UseInterval(addPoison, 4000); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addFoods
andaddPoison
,removeFood
andremovePoison
works the same, you can merge them to have one addObject function, and one removeObject function.