LOGG INN
... eller du kan registrere deg nå
68
6290
|
import bpy class KeysAndMouseButtonsPanel(bpy.types.Panel): """Creates a Panel in the Object properties window""" bl_label = "Keys and Mouse Buttons" bl_idname = "OBJECT_PT_keys_and_mouse_buttons" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = "Tools" def draw(self, context): layout = self.layout obj = context.object row = layout.row() row.label(text="Keys and Mouse Buttons:") # Display a list of the current keys and mouse buttons used in Blender keys_and_mouse_buttons = ['A', 'S', 'D', 'Q', 'W', 'E', 'R', 'Left Mouse Button', 'Right Mouse Button'] for key_or_mouse_button in keys_and_mouse_buttons: row = layout.row() row.label(text=key_or_mouse_button) # Add a slider to allow the user to customize the size of the keys and mouse buttons displayed in the plugin layout.separator() layout.label(text="Size:") layout.prop(obj, "size", slider=True) # Add a color picker to allow the user to customize the color of the keys and mouse buttons displayed in the plugin layout.separator() layout.label(text="Color:") layout.prop(obj, "color", text="") def register(): bpy.utils.register_class(KeysAndMouseButtonsPanel) def unregister(): bpy.utils.unregister_class(KeysAndMouseButtonsPanel) if __name__ == "__main__": register()
import bpy class KeysAndMouseButtonsPanel(bpy.types.Panel): """Creates a Panel in the Object properties window""" bl_label = "Keys and Mouse Buttons" bl_idname = "OBJECT_PT_keys_and_mouse_buttons" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = "Tools" def draw(self, context): layout = self.layout obj = context.object row = layout.row() row.label(text="Keys and Mouse Buttons:") # Display a list of the current keys and mouse buttons used in Blender keys_and_mouse_buttons = ['A', 'S', 'D', 'Q', 'W', 'E', 'R', 'Left Mouse Button', 'Right Mouse Button'] for key_or_mouse_button in keys_and_mouse_buttons: row = layout.row() row.label(text=key_or_mouse_button) # Add a slider to allow the user to customize the size of the keys and mouse buttons displayed in the plugin layout.separator() layout.label(text="Size:") layout.prop(obj, "size", slider=True) # Add a color picker to allow the user to customize the color of the keys and mouse buttons displayed in the plugin layout.separator() layout.label(text="Color:") layout.prop(obj, "color", text="") def register(): bpy.utils.register_class(KeysAndMouseButtonsPanel) def unregister(): bpy.utils.unregister_class(KeysAndMouseButtonsPanel) if __name__ == "__main__": register()
<!DOCTYPE html> <html> <head> <style> canvas { border: 1px solid #000; background-color: #111; } </style> </head> <body> <canvas id="gameCanvas" width="500" height="500"></canvas> <script> const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); const gridSize = 25; const gridCount = 20; let snake = [{ x: 7, y: 7 }]; let direction = 'right'; let food = { x: 10, y: 10 }; function draw() { ctx.clearRect(0, 0, canvas.width, canvas.height); // draw snake ctx.fillStyle = '#0f0'; for (let i = 0; i < snake.length; i++) { ctx.fillRect( snake[i].x * gridSize, snake[i].y * gridSize, gridSize, gridSize ); } // draw food ctx.fillStyle = '#f00'; ctx.fillRect(food.x * gridSize, food.y * gridSize, gridSize, gridSize); } function update() { const head = { ...snake[0] }; if (direction === 'up') head.y--; if (direction === 'down') head.y++; if (direction === 'left') head.x--; if (direction === 'right') head.x++; snake.unshift(head); if (head.x === food.x && head.y === food.y) { // if snake eats food, generate new food food = { x: Math.floor(Math.random() * gridCount), y: Math.floor(Math.random() * gridCount) }; } else { // if snake doesn't eat food, remove last segment snake.pop(); } } function main() { update(); draw(); setTimeout(main, 100); } main(); // handle keyboard input document.addEventListener('keydown', event => { if (event.keyCode === 87 && direction !== 'down') direction = 'up'; // W key if (event.keyCode === 83 && direction !== 'up') direction = 'down'; // S key if (event.keyCode === 65 && direction !== 'right') direction = 'left'; // A key if (event.keyCode === 68 && direction !== 'left') direction = 'right'; // D key }); </script> </body> </html>
using System; using System.Linq; namespace DiceGame { class Program { static void Main(string[] args) { // Roll the dice int[] diceValues = RollDice(); // Calculate the points int points = CalculatePoints(diceValues); // Print the points Console.WriteLine("Points: " + points); } // Rolls 6 6-faced dice and returns the values in an array static int[] RollDice() { Random random = new Random(); return Enumerable.Range(1, 6).Select(i => random.Next(1, 7)).ToArray(); } // Calculates the points based on the dice values static int CalculatePoints(int[] diceValues) { // Check if all dice have the same value if (diceValues.All(x => x == diceValues[0])) { return 4000; } // Check if all dice are different if (diceValues.Distinct().Count() == 6) { return 2000; } // Check if three or more dice share one value int value = diceValues.GroupBy(x => x).Where(g => g.Count() >= 3).Select(g => g.Key).FirstOrDefault(); if (value > 0) { return value == 1 ? 1000 : 100 * value; } // Otherwise, calculate points for individual dice return diceValues.Sum(x => x == 1 ? 100 : x == 5 ? 50 : 0); } } }
<!DOCTYPE html> <html> <head> <style> canvas { border: 1px solid #000; background-color: #111; } </style> </head> <body> <canvas id="gameCanvas" width="500" height="500"></canvas> <script> const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); const gridSize = 25; const gridCount = 20; let snake = [{ x: 7, y: 7 }]; let direction = 'right'; let food = { x: 10, y: 10 }; function draw() { ctx.clearRect(0, 0, canvas.width, canvas.height); // draw snake ctx.fillStyle = '#0f0'; for (let i = 0; i < snake.length; i++) { ctx.fillRect( snake[i].x * gridSize, snake[i].y * gridSize, gridSize, gridSize ); } // draw food ctx.fillStyle = '#f00'; ctx.fillRect(food.x * gridSize, food.y * gridSize, gridSize, gridSize); } function update() { const head = { ...snake[0] }; if (direction === 'up') head.y--; if (direction === 'down') head.y++; if (direction === 'left') head.x--; if (direction === 'right') head.x++; snake.unshift(head); if (head.x === food.x && head.y === food.y) { // if snake eats food, generate new food food = { x: Math.floor(Math.random() * gridCount), y: Math.floor(Math.random() * gridCount) }; } else { // if snake doesn't eat food, remove last segment snake.pop(); } } function main() { update(); draw(); setTimeout(main, 100); } main(); // handle keyboard input document.addEventListener('keydown', event => { if (event.keyCode === 87 && direction !== 'down') direction = 'up'; // W key if (event.keyCode === 83 && direction !== 'up') direction = 'down'; // S key if (event.keyCode === 65 && direction !== 'right') direction = 'left'; // A key if (event.keyCode === 68 && direction !== 'left') direction = 'right'; // D key }); </script> </body> </html>
|