Advertisement
Guest User

Mock Windows Interface Version 4

a guest
Jul 8th, 2024
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.02 KB | None | 0 0
  1. import React, { useState, useEffect } from 'react';
  2. import { X, Minus, Square, Settings, Power, FileText, Grid, Disc } from 'lucide-react';
  3.  
  4. const Notepad = () => {
  5. const [text, setText] = useState('');
  6. return (
  7. <textarea
  8. className="w-full h-full p-2 resize-none"
  9. value={text}
  10. onChange={(e) => setText(e.target.value)}
  11. />
  12. );
  13. };
  14.  
  15. const Minesweeper = () => {
  16. const [grid, setGrid] = useState([]);
  17. const [gameOver, setGameOver] = useState(false);
  18.  
  19. useEffect(() => {
  20. initializeGrid();
  21. }, []);
  22.  
  23. const initializeGrid = () => {
  24. const newGrid = Array(8).fill().map(() => Array(8).fill({ isMine: false, isRevealed: false, neighborMines: 0 }));
  25. // Place mines and calculate neighbor mines (implementation omitted for brevity)
  26. setGrid(newGrid);
  27. };
  28.  
  29. const revealCell = (row, col) => {
  30. if (gameOver || grid[row][col].isRevealed) return;
  31. const newGrid = [...grid];
  32. newGrid[row][col].isRevealed = true;
  33. if (newGrid[row][col].isMine) {
  34. setGameOver(true);
  35. }
  36. setGrid(newGrid);
  37. };
  38.  
  39. return (
  40. <div className="h-full flex flex-col items-center justify-center">
  41. {grid.map((row, rowIndex) => (
  42. <div key={rowIndex} className="flex">
  43. {row.map((cell, colIndex) => (
  44. <button
  45. key={colIndex}
  46. className={`w-6 h-6 border border-gray-400 ${cell.isRevealed ? 'bg-gray-200' : 'bg-gray-300'}`}
  47. onClick={() => revealCell(rowIndex, colIndex)}
  48. >
  49. {cell.isRevealed && (cell.isMine ? '💣' : cell.neighborMines > 0 ? cell.neighborMines : '')}
  50. </button>
  51. ))}
  52. </div>
  53. ))}
  54. {gameOver && <div className="mt-4">Game Over!</div>}
  55. </div>
  56. );
  57. };
  58.  
  59. const Reversi = () => {
  60. const [board, setBoard] = useState(Array(8).fill().map(() => Array(8).fill(null)));
  61. const [currentPlayer, setCurrentPlayer] = useState('black');
  62.  
  63. useEffect(() => {
  64. const newBoard = [...board];
  65. newBoard[3][3] = newBoard[4][4] = 'white';
  66. newBoard[3][4] = newBoard[4][3] = 'black';
  67. setBoard(newBoard);
  68. }, []);
  69.  
  70. const makeMove = (row, col) => {
  71. // Implementation of move logic omitted for brevity
  72. const newBoard = [...board];
  73. newBoard[row][col] = currentPlayer;
  74. setBoard(newBoard);
  75. setCurrentPlayer(currentPlayer === 'black' ? 'white' : 'black');
  76. };
  77.  
  78. return (
  79. <div className="h-full flex flex-col items-center justify-center">
  80. {board.map((row, rowIndex) => (
  81. <div key={rowIndex} className="flex">
  82. {row.map((cell, colIndex) => (
  83. <button
  84. key={colIndex}
  85. className="w-8 h-8 border border-gray-400 bg-green-600 flex items-center justify-center"
  86. onClick={() => makeMove(rowIndex, colIndex)}
  87. >
  88. {cell && (
  89. <div className={`w-6 h-6 rounded-full ${cell === 'black' ? 'bg-black' : 'bg-white'}`} />
  90. )}
  91. </button>
  92. ))}
  93. </div>
  94. ))}
  95. <div className="mt-4">Current Player: {currentPlayer}</div>
  96. </div>
  97. );
  98. };
  99.  
  100. const Windows95Interface = () => {
  101. const [windows, setWindows] = useState([]);
  102. const [activeWindow, setActiveWindow] = useState(null);
  103. const [startMenuOpen, setStartMenuOpen] = useState(false);
  104. const [backgroundColor, setBackgroundColor] = useState('#008080');
  105.  
  106. const openWindow = (title, content) => {
  107. const newWindow = {
  108. id: Date.now(),
  109. title,
  110. content,
  111. x: 50 + Math.random() * 100,
  112. y: 50 + Math.random() * 100,
  113. width: 400,
  114. height: 300,
  115. minimized: false
  116. };
  117. setWindows([...windows, newWindow]);
  118. setStartMenuOpen(false);
  119. };
  120.  
  121. const closeWindow = (id) => {
  122. setWindows(windows.filter(w => w.id !== id));
  123. };
  124.  
  125. return (
  126. <div
  127. className="w-full h-screen relative overflow-hidden"
  128. style={{ backgroundColor }}
  129. >
  130. {windows.map(window => (
  131. <div
  132. key={window.id}
  133. className="absolute bg-gray-200 border-2 border-gray-400 shadow-lg"
  134. style={{
  135. left: `${window.x}px`,
  136. top: `${window.y}px`,
  137. width: `${window.width}px`,
  138. height: `${window.height}px`,
  139. zIndex: activeWindow === window.id ? 10 : 1
  140. }}
  141. >
  142. <div className="bg-blue-900 text-white px-2 py-1 flex justify-between items-center">
  143. <span>{window.title}</span>
  144. <button onClick={() => closeWindow(window.id)} className="focus:outline-none">
  145. <X size={16} />
  146. </button>
  147. </div>
  148. <div className="p-2 h-[calc(100%-2rem)] overflow-auto">
  149. {window.content}
  150. </div>
  151. </div>
  152. ))}
  153.  
  154. <div className="absolute bottom-0 left-0 right-0 bg-gray-300 h-10 flex items-center px-2">
  155. <button onClick={() => setStartMenuOpen(!startMenuOpen)} className="bg-green-600 text-white px-4 py-1 rounded">Start</button>
  156. {startMenuOpen && (
  157. <div className="absolute bottom-10 left-0 w-56 bg-gray-200 border-2 border-gray-400 shadow-lg">
  158. <button onClick={() => openWindow('Notepad', <Notepad />)} className="w-full text-left px-4 py-2 hover:bg-blue-600 hover:text-white flex items-center">
  159. <FileText size={16} className="mr-2" />
  160. Notepad
  161. </button>
  162. <button onClick={() => openWindow('Minesweeper', <Minesweeper />)} className="w-full text-left px-4 py-2 hover:bg-blue-600 hover:text-white flex items-center">
  163. <Grid size={16} className="mr-2" />
  164. Minesweeper
  165. </button>
  166. <button onClick={() => openWindow('Reversi', <Reversi />)} className="w-full text-left px-4 py-2 hover:bg-blue-600 hover:text-white flex items-center">
  167. <Disc size={16} className="mr-2" />
  168. Reversi
  169. </button>
  170. </div>
  171. )}
  172. </div>
  173. </div>
  174. );
  175. };
  176.  
  177. export default Windows95Interface;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement