-
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
Open
owishiboo
wants to merge
11
commits into
recruit-org:module-2
Choose a base branch
from
owishiboo:module-2
base: module-2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bee70f2
half
owishiboo cf27ed2
half complete
owishiboo ec21c5a
removing bug
owishiboo 9721681
bugs in removing
owishiboo 66aec44
bug while eating
owishiboo 5c03c11
added removeObject and addObject
owishiboo 2b4d230
cannot set remaining
owishiboo 8e93356
complete
owishiboo 48ca4d2
complete 01
owishiboo 4ba03c3
complete 02
owishiboo b5a4648
fixed redundancy
owishiboo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ const Direction = { | |
Bottom: { x: 0, y: 1 }, | ||
}; | ||
|
||
const Cell = ({ x, y, type }) => { | ||
const Cell = ({ x, y, type, remaining }) => { | ||
const getStyles = () => { | ||
switch (type) { | ||
case CellType.Snake: | ||
|
@@ -33,10 +33,11 @@ const Cell = ({ x, y, type }) => { | |
|
||
case CellType.Food: | ||
return { | ||
backgroundColor: "darkorange", | ||
backgroundColor: "tomato", | ||
borderRadius: 20, | ||
width: 32, | ||
height: 32, | ||
transform: `scale(${0.5 + remaining / 20})`, | ||
}; | ||
|
||
case CellType.Poison: | ||
|
@@ -45,6 +46,7 @@ const Cell = ({ x, y, type }) => { | |
borderRadius: 20, | ||
width: 32, | ||
height: 32, | ||
transform: `scale(${0.5 + remaining / 20})`, | ||
}; | ||
|
||
default: | ||
|
@@ -61,7 +63,9 @@ const Cell = ({ x, y, type }) => { | |
height: Config.cellSize, | ||
}} | ||
> | ||
<div className={styles.cell} style={getStyles()}></div> | ||
<div className={styles.cell} style={getStyles()}> | ||
{remaining} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
@@ -207,8 +211,8 @@ const UseSnake = () => { | |
UseInterval(() => addObject("food"), 3000); | ||
UseInterval(() => addObject("poison"), 1000); | ||
UseInterval(runSingleStep, 300); | ||
UseInterval(() => removeObject("food"),50); | ||
UseInterval(()=> removeObject("poison"), 100); | ||
UseInterval(() => removeObject("food"), 50); | ||
UseInterval(() => removeObject("poison"), 100); | ||
|
||
const changeDir = (checkDir, newDir) => { | ||
setDirection((direction) => { | ||
|
@@ -241,28 +245,36 @@ const UseSnake = () => { | |
|
||
return () => window.removeEventListener("keydown", handleNavigation); | ||
}, []); | ||
|
||
return { score, isFood, isSnake, isPoison }; | ||
}; | ||
|
||
//view | ||
const Snake = () => { | ||
const { score, isFood, isSnake, isPoison } = UseSnake(); | ||
const cells = []; | ||
for (let x = 0; x < Config.width; x++) { | ||
for (let y = 0; y < Config.height; y++) { | ||
let type = CellType.Empty; | ||
let type = CellType.Empty, | ||
remaining = undefined; | ||
if (isFood({ x, y })) { | ||
type = CellType.Food; | ||
remaining = | ||
10 - | ||
Math.round( | ||
(Date.now() - | ||
foods.find((food) => food.x === x && food.y === y).createdAt) / | ||
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. as your cell looks like {
x: Math.floor(Math.random() * Config.width),
y: Math.floor(Math.random() * Config.width),
start: Date.now()
} .createdAt should be poisons.find((poison) => poison.x === x && poison.y === y)
.start) /
1000 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. thanks, bro @MahdiMurshed |
||
1000 | ||
); | ||
} else if (isSnake({ x, y })) { | ||
type = CellType.Snake; | ||
} else if (isPoison({ x, y })) { | ||
type = CellType.Poison; | ||
} | ||
cells.push(<Cell key={`${x}-${y}`} x={x} y={y} type={type} />); | ||
cells.push( | ||
<Cell key={`${x}-${y}`} x={x} y={y} type={type} remaining={remaining} /> | ||
); | ||
} | ||
} | ||
return { score, isFood, isSnake, isPoison, cells }; | ||
}; | ||
|
||
//view | ||
const Snake = () => { | ||
const { score, cells } = UseSnake(); | ||
return ( | ||
<div className={styles.container}> | ||
<div | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@royantar0311 I forgot to add the remaining time to the food, so I tried it out today. But the time shows undefined. I can't figure out the problem :")